Skip to content

Commit 18a182b

Browse files
authored
[coro] Fix crash due to DILabel in LineTableOnly mode (#148095)
Since the recent commit de3c841, the `CoroSplit` pass adds `DILabel`s to help find the location of a suspension point from its suspension point id. Those labels are added in both `DebugEmissionKind::FullDebug` and `DebugEmissionKind::LineTableOnly` mode. The idea was that this information is necessary to reconstruct async stack traces and should hence also be available for LineTableOnly. Unfortunately, it turns out that the DWARF backend does not expect to find any DILabel debug metadata if the emission kind is set to LineTableOnly. The Dwarf backend simply runs into an assertion in that case. This commit fixes the issue by only adding `DILabel` for FullDebug.
1 parent ba0df98 commit 18a182b

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,12 +1484,9 @@ struct SwitchCoroutineSplitter {
14841484
// If there is no DISubprogram for F, it implies the function is compiled
14851485
// without debug info. So we also don't generate debug info for the
14861486
// suspension points.
1487-
bool AddDebugLabels =
1488-
(DIS && DIS->getUnit() &&
1489-
(DIS->getUnit()->getEmissionKind() ==
1490-
DICompileUnit::DebugEmissionKind::FullDebug ||
1491-
DIS->getUnit()->getEmissionKind() ==
1492-
DICompileUnit::DebugEmissionKind::LineTablesOnly));
1487+
bool AddDebugLabels = DIS && DIS->getUnit() &&
1488+
(DIS->getUnit()->getEmissionKind() ==
1489+
DICompileUnit::DebugEmissionKind::FullDebug);
14931490

14941491
// resume.entry:
14951492
// %index.addr = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i32

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
; Tests that we add DILabels for the suspend points.
22
;
3-
; We check both the generated LLVM:
3+
; Check the generated LLVM:
44
; RUN: opt < %s -passes='cgscc(coro-split)' -S | FileCheck %s
55
;
6-
; And the debug info:
6+
; Check the generated DWARF debug info:
77
; REQUIRES: object-emission
88
; RUN: opt < %s -passes='cgscc(coro-split),coro-cleanup' \
99
; RUN: | %llc_dwarf -O0 -filetype=obj -o - \
1010
; RUN: | llvm-dwarfdump - \
1111
; RUN: | FileCheck %s -check-prefix=DWARF
12+
;
13+
; Check that we don't emit any DILabel if in `LineTablesOnly` mode
14+
; RUN: sed -e 's/emissionKind: FullDebug/emissionKind: LineTablesOnly/' %s \
15+
; RUN: | opt -passes='cgscc(coro-split)' -S \
16+
; RUN: | FileCheck %s -check-prefix=LINE-TABLE
1217

1318
source_filename = "coro.c"
1419

@@ -83,6 +88,12 @@ coro_Suspend: ; preds = %for.cond, %if.then,
8388
; CHECK: ![[DESTROY_0]] = !DILabel(scope: !{{[0-9]+}}, name: "__coro_resume_0", file: !{{[0-9]*}}, line: 12, column: 6, isArtificial: true, coroSuspendIdx: 0)
8489
; CHECK: ![[DESTROY_1]] = !DILabel(scope: !{{[0-9]+}}, name: "__coro_resume_1", file: !{{[0-9]*}}, line: 14, column: 6, isArtificial: true, coroSuspendIdx: 1)
8590

91+
; Check the we do not emit any DILabels in LineTablesOnly mode.
92+
; The DWARF emitter cannot handle this and would run into an assertion.
93+
; LINE-TABLE: !DICompileUnit{{.*}}LineTablesOnly
94+
; LINE-TABLE-NOT: DILabel
95+
96+
8697
; DWARF: {{.*}}DW_TAG_label
8798
; DWARF-NEXT: DW_AT_name ("__coro_resume_0")
8899
; DWARF-NEXT: DW_AT_decl_file

0 commit comments

Comments
 (0)