Skip to content

Commit 45af938

Browse files
authored
[Coroutines] Walk inlinedAt recursively to create legal DILabels (#157099)
This commit resolves a defect in the creation of DILabels for suspend points. While a previous change introduced support for inlined locations, it did not consider that a location might originate from multiple inlinings. Therefore, we extend this to walk iteratively through all `inlinedAt` locations to get to the root.
1 parent 4b3ad50 commit 45af938

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,13 +1568,15 @@ struct SwitchCoroutineSplitter {
15681568
if (DebugLoc SuspendLoc = S->getDebugLoc()) {
15691569
std::string LabelName =
15701570
("__coro_resume_" + Twine(SuspendIndex)).str();
1571-
// Take the "inlined at" location, if present. This is mandatory as
1572-
// the DILabel insertion checks that the scopes of label and the
1573-
// attached location match. This is not the case when the suspend
1574-
// location has been inlined due to pointing to the original scope.
1575-
DILocation *DILoc = SuspendLoc->getInlinedAt();
1576-
if (!DILoc)
1577-
DILoc = SuspendLoc;
1571+
// Take the "inlined at" location recursively, if present. This is
1572+
// mandatory as the DILabel insertion checks that the scopes of label
1573+
// and the attached location match. This is not the case when the
1574+
// suspend location has been inlined due to pointing to the original
1575+
// scope.
1576+
DILocation *DILoc = SuspendLoc;
1577+
while (DILocation *InlinedAt = DILoc->getInlinedAt())
1578+
DILoc = InlinedAt;
1579+
15781580
DILabel *ResumeLabel =
15791581
DBuilder.createLabel(DIS, LabelName, DILoc->getFile(),
15801582
SuspendLoc.getLine(), SuspendLoc.getCol(),

llvm/test/Transforms/Coroutines/coro-split-dbg-labels-inlined.ll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
; RUN: opt %s -passes='cgscc(coro-split)' -S | FileCheck %s
22

3+
; Verifies that suspend points with inlined locations are handled properly,
4+
; i.e., that their debug labels point to the correct subprogram.
5+
36
source_filename = "coro.c"
47

58
; Function Attrs: nounwind uwtable
@@ -96,4 +99,7 @@ attributes #4 = { argmemonly nounwind readonly }
9699
!41 = !DILocation(line: 17, column: 1, scope: !16)
97100

98101
!100 = distinct !DISubprogram(name: "callee", scope: !1, file: !1, line: 8, type: !17, scopeLine: 4, isOptimized: true, unit: !0, retainedNodes: !2)
99-
!101 = !DILocation(line: 12, column: 6, scope: !16)
102+
!101 = !DILocation(line: 42, column: 6, scope: !102, inlinedAt: !103)
103+
104+
!102 = distinct !DISubprogram(name: "callee_recursive", scope: !1, file: !1, line: 8, type: !17, scopeLine: 4, isOptimized: true, unit: !0, retainedNodes: !2)
105+
!103 = !DILocation(line: 12, column: 6, scope: !16)

0 commit comments

Comments
 (0)