[clang] [llvm] [mlir] [debuginfo][coro] Emit debug info labels for coroutine resume points (PR #141937)
Paul T Robinson via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 1 10:43:32 PDT 2025
================
@@ -0,0 +1,148 @@
+; Tests that we add DILabels for the suspend points.
+;
+; We check both the generated LLVM:
+; RUN: opt < %s -passes='cgscc(coro-split)' -S | FileCheck %s
+;
+; And the debug info:
+; RUN: opt < %s -passes='cgscc(coro-split),coro-cleanup' \
+; RUN: | llc -O0 -filetype=obj -o - \
+; RUN: | llvm-dwarfdump - \
+; RUN: | FileCheck %s -check-prefix=DWARF
+
+source_filename = "coro.c"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare void @bar(...) local_unnamed_addr #2
+declare void @baz(...) local_unnamed_addr #2
+
+; Roughly equivalent to:
+;
+; task f() {
+; while (true) {
+; bar();
+; co_await std::suspend_always{};
+; baz();
+; co_await std::suspend_always{};
+; }
+; }
+
+; Function Attrs: nounwind uwtable
+define ptr @f() #3 !dbg !16 {
+entry:
+ %0 = tail call token @llvm.coro.id(i32 0, ptr null, ptr @f, ptr null), !dbg !26
+ %1 = tail call i64 @llvm.coro.size.i64(), !dbg !26
+ %frame = tail call ptr @malloc(i64 %1), !dbg !26
+ %2 = tail call ptr @llvm.coro.begin(token %0, ptr %frame) #4, !dbg !26
+ br label %loop1, !dbg !27
+
+loop1: ; preds = %for.cond, %entry
+ tail call void (...) @bar() #7, !dbg !33
+ %3 = tail call token @llvm.coro.save(ptr null), !dbg !34
+ %4 = tail call i8 @llvm.coro.suspend(token %3, i1 false), !dbg !34
+ switch i8 %4, label %coro_Suspend [
+ i8 0, label %loop2
+ i8 1, label %coro_Cleanup
+ ], !dbg !34
+
+loop2: ; preds = %for.cond, %entry
+ tail call void (...) @baz() #7, !dbg !35
+ %5 = tail call token @llvm.coro.save(ptr null), !dbg !36
+ %6 = tail call i8 @llvm.coro.suspend(token %5, i1 false), !dbg !36
+ switch i8 %6, label %coro_Suspend [
+ i8 0, label %loop1
+ i8 1, label %coro_Cleanup
+ ], !dbg !36
+
+coro_Cleanup: ; preds = %for.cond
+ %7 = tail call ptr @llvm.coro.free(token %0, ptr %2), !dbg !37
+ tail call void @free(ptr nonnull %7), !dbg !37
+ br label %coro_Suspend, !dbg !37
+
+coro_Suspend: ; preds = %for.cond, %if.then, %coro_Cleanup
+ tail call i1 @llvm.coro.end(ptr null, i1 false, token none) #4, !dbg !40
+ ret ptr %2, !dbg !41
+}
+
+; Check that the resume function contains the `#dbg_label` instructions.
+; CHECK-LABEL: define ptr @f() #1 !dbg !6 {
+; CHECK: resume.0: ; preds = %resume.entry
+; CHECK-NEXT: #dbg_label(![[RESUME_0:[0-9]+]], !{{[0-9]+}})
+; CHECK: resume.1: ; preds = %resume.entry
+; CHECK-NEXT: #dbg_label(![[RESUME_1:[0-9]+]], !{{[0-9]+}})
+
+; Check that the destroy function contains the `#dbg_label` instructions.
+; CHECK-LABEL: define internal fastcc void @f.destroy({{.*}}) #1 !dbg !38 {
+; CHECK: resume.0: ; preds = %resume.entry
+; CHECK-NEXT: #dbg_label(![[DESTROY_0:[0-9]+]], !{{[0-9]+}})
+; CHECK: resume.1: ; preds = %resume.entry
+; CHECK-NEXT: #dbg_label(![[DESTROY_1:[0-9]+]], !{{[0-9]+}})
+
+; Check that the DILabels are correct.
+; CHECK: ![[RESUME_0]] = !DILabel(scope: !{{[0-9]+}}, name: "__coro_resume_0", file: !{{[0-9]*}}, line: 12, column: 6, isArtificial: true, coroSuspendIdx: 0)
+; CHECK: ![[RESUME_1]] = !DILabel(scope: !{{[0-9]+}}, name: "__coro_resume_1", file: !{{[0-9]*}}, line: 14, column: 6, isArtificial: true, coroSuspendIdx: 1)
+; CHECK: ![[DESTROY_0]] = !DILabel(scope: !{{[0-9]+}}, name: "__coro_resume_0", file: !{{[0-9]*}}, line: 12, column: 6, isArtificial: true, coroSuspendIdx: 0)
+; CHECK: ![[DESTROY_1]] = !DILabel(scope: !{{[0-9]+}}, name: "__coro_resume_1", file: !{{[0-9]*}}, line: 14, column: 6, isArtificial: true, coroSuspendIdx: 1)
+
+; DWARF: {{.*}}DW_TAG_label
+; DWARF-LABEL: DW_AT_name ("__coro_resume_0")
----------------
pogo59 wrote:
```suggestion
; DWARF-NEXT: DW_AT_name ("__coro_resume_0")
```
The `-LABEL` suffix is unfortunately confusing, but it's too widespread to be worth changing.
https://github.com/llvm/llvm-project/pull/141937
More information about the llvm-commits
mailing list