Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when disabling debug info #4249

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions toolchain/lower/function_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ auto FunctionContext::LowerInst(SemIR::InstId inst_id) -> void {
auto inst = sem_ir().insts().Get(inst_id);
CARBON_VLOG() << "Lowering " << inst_id << ": " << inst << "\n";
builder_.getInserter().SetCurrentInstId(inst_id);
auto loc = file_context_->GetDiagnosticLoc(inst_id);
builder_.SetCurrentDebugLocation(
llvm::DILocation::get(builder_.getContext(), loc.line_number,
loc.column_number, di_subprogram_));
if (di_subprogram_) {
auto loc = file_context_->GetDiagnosticLoc(inst_id);
builder_.SetCurrentDebugLocation(
llvm::DILocation::get(builder_.getContext(), loc.line_number,
loc.column_number, di_subprogram_));
}

CARBON_KIND_SWITCH(inst) {
#define CARBON_SEM_IR_INST_KIND(Name) \
Expand All @@ -112,7 +114,9 @@ auto FunctionContext::LowerInst(SemIR::InstId inst_id) -> void {
}

builder_.getInserter().SetCurrentInstId(SemIR::InstId::Invalid);
builder_.SetCurrentDebugLocation(llvm::DebugLoc());
if (di_subprogram_) {
builder_.SetCurrentDebugLocation(llvm::DebugLoc());
}
}

auto FunctionContext::GetBlockArg(SemIR::InstBlockId block_id,
Expand Down
8 changes: 8 additions & 0 deletions toolchain/lower/testdata/debug/nodebug.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/debug/nodebug.carbon

fn F() {
}

// CHECK:STDOUT: ; ModuleID = 'nodebug.carbon'
// CHECK:STDOUT: source_filename = "nodebug.carbon"
// CHECK:STDOUT:
// CHECK:STDOUT: define void @F() {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void
// CHECK:STDOUT: }
Loading