mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Don't CHECK-fail when emitting IR with cross-file locations. (#5447)
If a function contains instructions whose locations are in another file, skip providing debug locations for those instructions rather than CHECK-failing. This happens when emitting a thunk where the signature is declared in one file and the call target is in another file: some parts of the thunk use the original signature as their locations, whereas other parts of it use the location of the call target.
This commit is contained in:
@@ -153,9 +153,16 @@ auto FunctionContext::GetDebugLoc(SemIR::InstId inst_id) -> llvm::DebugLoc {
|
||||
return llvm::DebugLoc();
|
||||
}
|
||||
auto loc = file_context_->GetLocForDI(inst_id);
|
||||
CARBON_CHECK(loc.filename == di_subprogram_->getFile()->getFilename(),
|
||||
"Instructions located in a different file from their "
|
||||
"enclosing function aren't handled yet");
|
||||
if (loc.filename != di_subprogram_->getFile()->getFilename()) {
|
||||
// Location is from a different file. We can't represent that directly
|
||||
// within the scope of this function's subprogram, and we don't want to
|
||||
// generate a new subprogram, so just discard the location information. This
|
||||
// happens for thunks when emitting the portion of the thunk that is
|
||||
// duplicated from the original signature.
|
||||
//
|
||||
// TODO: Handle this case better.
|
||||
return llvm::DebugLoc();
|
||||
}
|
||||
return llvm::DILocation::get(builder_.getContext(), loc.line_number,
|
||||
loc.column_number, di_subprogram_);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user