Skip to content

Commit 31cf6df

Browse files
authored
[coroutines] Use DILocation from new storage for hoisted dbg.declare (#75104)
Make the hoisted dbg.declare inherent the DILocation scope from the new storage. After hoisting, the dbg.declare is moved into the block that defines the new storage. This could create an inconsistency in the debug location scope hierarchy where the scope of hoisted dbg.declare (i.e. DILexicalBlock) is enclosed with the scope of the block (i.e. DISubprogram). This confuses LiveDebugValues pass to think that the hoisted dbg.declare is killed in that block and does not generate DBG_VALUE in other blocks. Debugger won't be able to track its value anymore.
1 parent 8005ee6 commit 31cf6df

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,9 +2891,11 @@ void coro::salvageDebugInfo(
28912891
// dbg.declare does.
28922892
if (isa<DbgDeclareInst>(DVI)) {
28932893
std::optional<BasicBlock::iterator> InsertPt;
2894-
if (auto *I = dyn_cast<Instruction>(Storage))
2894+
if (auto *I = dyn_cast<Instruction>(Storage)) {
28952895
InsertPt = I->getInsertionPointAfterDef();
2896-
else if (isa<Argument>(Storage))
2896+
if (I->getDebugLoc())
2897+
DVI->setDebugLoc(I->getDebugLoc());
2898+
} else if (isa<Argument>(Storage))
28972899
InsertPt = F->getEntryBlock().begin();
28982900
if (InsertPt)
28992901
DVI->moveBefore(*(*InsertPt)->getParent(), *InsertPt);

llvm/test/Transforms/Coroutines/coro-debug-frame-variable.ll

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
; CHECK: entry:
3232
; CHECK: %j = alloca i32, align 4
3333
; CHECK: call void @llvm.dbg.declare(metadata ptr %j, metadata ![[JVAR:[0-9]+]], metadata !DIExpression()), !dbg ![[JDBGLOC:[0-9]+]]
34-
; CHECK: %[[MEMORY:.*]] = call ptr @new
35-
; CHECK: call void @llvm.dbg.declare(metadata ptr %[[MEMORY]], metadata ![[XVAR:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 32)), !dbg ![[IDBGLOC:[0-9]+]]
34+
; CHECK: %[[MEMORY:.*]] = call ptr @new({{.+}}), !dbg ![[IDBGLOC:[0-9]+]]
35+
; CHECK: call void @llvm.dbg.declare(metadata ptr %[[MEMORY]], metadata ![[XVAR:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 32)), !dbg ![[IDBGLOC]]
3636
; CHECK: call void @llvm.dbg.declare(metadata ptr %[[MEMORY]], metadata ![[IVAR:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 20)), !dbg ![[IDBGLOC]]
3737
; CHECK: await.ready:
3838
;
@@ -48,18 +48,20 @@
4848
; CHECK: await.ready:
4949
;
5050
; CHECK-DAG: ![[IVAR]] = !DILocalVariable(name: "i"
51-
; CHECK-DAG: ![[SCOPE:[0-9]+]] = distinct !DILexicalBlock(scope: !6, file: !1, line: 23, column: 12)
52-
; CHECK-DAG: ![[IDBGLOC]] = !DILocation(line: 24, column: 7, scope: ![[SCOPE]])
51+
; CHECK-DAG: ![[PROG_SCOPE:[0-9]+]] = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov"
52+
; CHECK-DAG: ![[BLK_SCOPE:[0-9]+]] = distinct !DILexicalBlock(scope: ![[PROG_SCOPE]], file: !1, line: 23, column: 12)
53+
; CHECK-DAG: ![[IDBGLOC]] = !DILocation(line: 23, column: 6, scope: ![[PROG_SCOPE]])
5354
; CHECK-DAG: ![[XVAR]] = !DILocalVariable(name: "x"
5455
; CHECK-DAG: ![[JVAR]] = !DILocalVariable(name: "j"
55-
; CHECK-DAG: ![[JDBGLOC]] = !DILocation(line: 32, column: 7, scope: ![[SCOPE]])
56+
; CHECK-DAG: ![[JDBGLOC]] = !DILocation(line: 32, column: 7, scope: ![[BLK_SCOPE]])
5657

5758
; CHECK-DAG: ![[XVAR_RESUME]] = !DILocalVariable(name: "x"
58-
; CHECK-DAG: ![[IDBGLOC_RESUME]] = !DILocation(line: 24, column: 7, scope: ![[RESUME_SCOPE:[0-9]+]])
59-
; CHECK-DAG: ![[RESUME_SCOPE]] = distinct !DILexicalBlock(scope: !22, file: !1, line: 23, column: 12)
59+
; CHECK-DAG: ![[RESUME_PROG_SCOPE:[0-9]+]] = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov"
60+
; CHECK-DAG: ![[IDBGLOC_RESUME]] = !DILocation(line: 24, column: 7, scope: ![[RESUME_BLK_SCOPE:[0-9]+]])
61+
; CHECK-DAG: ![[RESUME_BLK_SCOPE]] = distinct !DILexicalBlock(scope: ![[RESUME_PROG_SCOPE]], file: !1, line: 23, column: 12)
6062
; CHECK-DAG: ![[IVAR_RESUME]] = !DILocalVariable(name: "i"
6163
; CHECK-DAG: ![[JVAR_RESUME]] = !DILocalVariable(name: "j"
62-
; CHECK-DAG: ![[JDBGLOC_RESUME]] = !DILocation(line: 32, column: 7, scope: ![[RESUME_SCOPE]])
64+
; CHECK-DAG: ![[JDBGLOC_RESUME]] = !DILocation(line: 32, column: 7, scope: ![[RESUME_BLK_SCOPE]])
6365
define void @f() presplitcoroutine !dbg !8 {
6466
entry:
6567
%__promise = alloca i8, align 8
@@ -71,13 +73,13 @@ entry:
7173
br i1 %alloc, label %coro.alloc, label %coro.init
7274

7375
coro.alloc: ; preds = %entry
74-
%size = call i64 @llvm.coro.size.i64()
75-
%memory = call ptr @new(i64 %size)
76-
br label %coro.init
76+
%size = call i64 @llvm.coro.size.i64(), !dbg !23
77+
%memory = call ptr @new(i64 %size), !dbg !23
78+
br label %coro.init, !dbg !23
7779

7880
coro.init: ; preds = %coro.alloc, %entry
79-
%phi.entry.alloc = phi ptr [ null, %entry ], [ %memory, %coro.alloc ]
80-
%begin = call ptr @llvm.coro.begin(token %id, ptr %phi.entry.alloc)
81+
%phi.entry.alloc = phi ptr [ null, %entry ], [ %memory, %coro.alloc ], !dbg !23
82+
%begin = call ptr @llvm.coro.begin(token %id, ptr %phi.entry.alloc), !dbg !23
8183
%ready = call i1 @await_ready()
8284
br i1 %ready, label %init.ready, label %init.suspend
8385

@@ -239,3 +241,4 @@ declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)
239241
!20 = !DILocation(line: 43, column: 3, scope: !7)
240242
!21 = !DILocation(line: 43, column: 8, scope: !7)
241243
!22 = distinct !DILexicalBlock(scope: !8, file: !1, line: 23, column: 12)
244+
!23 = !DILocation(line: 23, column: 6, scope: !8)

0 commit comments

Comments
 (0)