Skip to content

Commit 2fb060e

Browse files
authored
Revert "[coroutines] Use DILocation from new storage for hoisted dbg.declare" (#75282)
Reverts #75104 Original commit causes clang to generate invalid IR: ``` mismatched subprogram between llvm.dbg.declare variable and !dbg attachment call void @llvm.dbg.declare(metadata ptr %4, metadata !34468, metadata !DIExpression(DW_OP_plus_uconst, 176)), !dbg !34467 ```
1 parent 9ed2056 commit 2fb060e

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,11 +2891,9 @@ 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-
if (I->getDebugLoc())
2897-
DVI->setDebugLoc(I->getDebugLoc());
2898-
} else if (isa<Argument>(Storage))
2896+
else if (isa<Argument>(Storage))
28992897
InsertPt = F->getEntryBlock().begin();
29002898
if (InsertPt)
29012899
DVI->moveBefore(*(*InsertPt)->getParent(), *InsertPt);

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

Lines changed: 13 additions & 16 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({{.+}}), !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]]
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]+]]
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,20 +48,18 @@
4848
; CHECK: await.ready:
4949
;
5050
; CHECK-DAG: ![[IVAR]] = !DILocalVariable(name: "i"
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]])
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]])
5453
; CHECK-DAG: ![[XVAR]] = !DILocalVariable(name: "x"
5554
; CHECK-DAG: ![[JVAR]] = !DILocalVariable(name: "j"
56-
; CHECK-DAG: ![[JDBGLOC]] = !DILocation(line: 32, column: 7, scope: ![[BLK_SCOPE]])
55+
; CHECK-DAG: ![[JDBGLOC]] = !DILocation(line: 32, column: 7, scope: ![[SCOPE]])
5756

5857
; CHECK-DAG: ![[XVAR_RESUME]] = !DILocalVariable(name: "x"
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)
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)
6260
; CHECK-DAG: ![[IVAR_RESUME]] = !DILocalVariable(name: "i"
6361
; CHECK-DAG: ![[JVAR_RESUME]] = !DILocalVariable(name: "j"
64-
; CHECK-DAG: ![[JDBGLOC_RESUME]] = !DILocation(line: 32, column: 7, scope: ![[RESUME_BLK_SCOPE]])
62+
; CHECK-DAG: ![[JDBGLOC_RESUME]] = !DILocation(line: 32, column: 7, scope: ![[RESUME_SCOPE]])
6563
define void @f() presplitcoroutine !dbg !8 {
6664
entry:
6765
%__promise = alloca i8, align 8
@@ -73,13 +71,13 @@ entry:
7371
br i1 %alloc, label %coro.alloc, label %coro.init
7472

7573
coro.alloc: ; preds = %entry
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
74+
%size = call i64 @llvm.coro.size.i64()
75+
%memory = call ptr @new(i64 %size)
76+
br label %coro.init
7977

8078
coro.init: ; preds = %coro.alloc, %entry
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
79+
%phi.entry.alloc = phi ptr [ null, %entry ], [ %memory, %coro.alloc ]
80+
%begin = call ptr @llvm.coro.begin(token %id, ptr %phi.entry.alloc)
8381
%ready = call i1 @await_ready()
8482
br i1 %ready, label %init.ready, label %init.suspend
8583

@@ -241,4 +239,3 @@ declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)
241239
!20 = !DILocation(line: 43, column: 3, scope: !7)
242240
!21 = !DILocation(line: 43, column: 8, scope: !7)
243241
!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)