Skip to content

Commit 64f6f90

Browse files
authored
[MLIR][LLVM] CallSiteLoc without caller scope not translatable (#90759)
If a CallSiteLoc's caller cannot be translated (returns null), we cannot simply return the translation of the callee location. This is because the resulting DILocation will not have any InlinedAt field for the function it is in, and will fail the LLVM IR verifier.
1 parent ee63f28 commit 64f6f90

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

mlir/lib/Target/LLVMIR/DebugTranslation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ llvm::DILocation *DebugTranslation::translateLoc(Location loc,
406406
if (auto callLoc = dyn_cast<CallSiteLoc>(loc)) {
407407
// For callsites, the caller is fed as the inlinedAt for the callee.
408408
auto *callerLoc = translateLoc(callLoc.getCaller(), scope, inlinedAt);
409+
// If the caller scope does not exist, the callsite cannot be represented
410+
// in LLVM (the callee scope may not match the function it is in).
411+
if (!callerLoc)
412+
return nullptr;
409413
llvmLoc = translateLoc(callLoc.getCallee(), nullptr, callerLoc);
410414
// Fallback: Ignore callee if it has no debug scope.
411415
if (!llvmLoc)

mlir/test/Target/LLVMIR/llvmir-debug.mlir

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,15 @@ llvm.func @func_with_debug(%arg: i64) {
108108
// CHECK: call void @func_no_debug(), !dbg ![[NAMED_LOC:[0-9]+]]
109109
llvm.call @func_no_debug() : () -> () loc("named"("foo.mlir":10:10))
110110

111-
// CHECK: call void @func_no_debug(), !dbg ![[CALLSITE_LOC:[0-9]+]]
111+
// CHECK: call void @func_no_debug(), !dbg ![[MY_SOURCE_LOC:[0-9]+]]
112112
llvm.call @func_no_debug() : () -> () loc(callsite("nodebug.cc":3:4 at "mysource.cc":5:6))
113113

114-
// CHECK: call void @func_no_debug(), !dbg ![[CALLSITE_LOC:[0-9]+]]
114+
// CHECK: call void @func_no_debug(), !dbg ![[MY_SOURCE_LOC]]
115115
llvm.call @func_no_debug() : () -> () loc(callsite("nodebug.cc":3:4 at fused<#sp0>["mysource.cc":5:6]))
116116

117+
// CHECK: call void @func_no_debug(), !dbg ![[MY_SOURCE_LOC]]
118+
llvm.call @func_no_debug() : () -> () loc(callsite(callsite(fused<#callee>["nodebug.cc":3:4] at "foo.mlir":2:4) at fused<#sp0>["mysource.cc":5:6]))
119+
117120
// CHECK: call void @func_no_debug(), !dbg ![[FUSED_LOC:[0-9]+]]
118121
llvm.call @func_no_debug() : () -> () loc(fused[callsite(fused<#callee>["mysource.cc":5:6] at "mysource.cc":1:1), "mysource.cc":1:1])
119122

@@ -153,7 +156,7 @@ llvm.func @empty_types() {
153156
// CHECK: ![[BLOCK_LOC]] = distinct !DILexicalBlock(scope: ![[FUNC_LOC]])
154157
// CHECK: ![[NO_NAME_VAR]] = !DILocalVariable(scope: ![[BLOCK_LOC]])
155158

156-
// CHECK-DAG: ![[CALLSITE_LOC]] = !DILocation(line: 5, column: 6,
159+
// CHECK-DAG: ![[MY_SOURCE_LOC]] = !DILocation(line: 5, column: 6
157160
// CHECK-DAG: ![[FILE_LOC]] = !DILocation(line: 1, column: 2,
158161
// CHECK-DAG: ![[NAMED_LOC]] = !DILocation(line: 10, column: 10
159162
// CHECK-DAG: ![[FUSED_LOC]] = !DILocation(line: 1, column: 1

0 commit comments

Comments
 (0)