Skip to content

Commit b2475e2

Browse files
committed
Test cases
1 parent d4633fb commit b2475e2

File tree

5 files changed

+171
-15
lines changed

5 files changed

+171
-15
lines changed

llvm/test/DebugInfo/Generic/debug-label.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
; CHECK-NEXT: DW_AT_name {{.*}}"top"
66
; CHECK-NEXT: DW_AT_decl_file [DW_FORM_data1] {{.*}}debug-label.c
77
; CHECK-NEXT: DW_AT_decl_line [DW_FORM_data1] {{.*}}4
8+
; CHECK-NEXT: DW_AT_decl_column [DW_FORM_data1] {{.*}}9
89
; CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] {{.*}}{{0x[0-9a-f]+}}
910
; CHECK: DW_TAG_label
1011
; CHECK-NEXT: DW_AT_name {{.*}}"done"
@@ -22,6 +23,7 @@
2223
; ASM-NEXT: DW_AT_name
2324
; ASM: 1 {{.*}} DW_AT_decl_file
2425
; ASM-NEXT: 4 {{.*}} DW_AT_decl_line
26+
; ASM-NEXT: 9 {{.*}} DW_AT_decl_column
2527
; ASM-NEXT: [[TOP_LOW_PC]]{{.*}} DW_AT_low_pc
2628
; ASM: DW_TAG_label
2729
; ASM-NEXT: DW_AT_name
@@ -68,7 +70,7 @@ declare void @llvm.dbg.label(metadata)
6870
!7 = !DISubroutineType(types: !8)
6971
!8 = !{!9, !9, !9}
7072
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
71-
!10 = !DILabel(scope: !6, name: "top", file: !1, line: 4)
73+
!10 = !DILabel(scope: !6, name: "top", file: !1, line: 4, column: 9)
7274
!11 = !DILocation(line: 4, column: 1, scope: !6)
7375
!12 = !DILabel(scope: !15, name: "done", file: !1, line: 7)
7476
!13 = !DILocation(line: 7, column: 1, scope: !6)

llvm/test/Transforms/Coroutines/coro-debug-dbg.values.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; Tests whether resume function would remain dbg.value infomation.
1+
; Tests whether resume function retains dbg.value information.
22
; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split,coro-split)' -S | FileCheck %s
33
;
44
; This file is based on coro-debug-frame-variable.ll.

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ entry:
1919
%3 = call i8 @llvm.coro.suspend(token none, i1 false), !dbg !17
2020
%conv = sext i8 %3 to i32, !dbg !17
2121
%late_local = alloca i32, align 4
22-
call void @coro.devirt.trigger(ptr null)
2322
switch i32 %conv, label %sw.default [
2423
i32 0, label %sw.bb
2524
i32 1, label %sw.bb1
@@ -113,12 +112,6 @@ declare ptr @llvm.coro.free(token, ptr nocapture readonly) #2
113112
; Function Attrs: nounwind
114113
declare i1 @llvm.coro.end(ptr, i1, token) #5
115114

116-
; Function Attrs: alwaysinline
117-
define private void @coro.devirt.trigger(ptr) #6 {
118-
entry:
119-
ret void
120-
}
121-
122115
; Function Attrs: argmemonly nounwind readonly
123116
declare ptr @llvm.coro.subfn.addr(ptr nocapture readonly, i8) #2
124117

@@ -170,15 +163,20 @@ attributes #7 = { noduplicate }
170163
!31 = !DILocalVariable(name: "allocated", scope: !6, file: !7, line: 55, type: !11)
171164
!32 = !DILocalVariable(name: "inline_asm", scope: !6, file: !7, line: 55, type: !11)
172165

166+
; Check that the original function is visible and capture its debug info id.
173167
; CHECK: define ptr @flink(i32 %x) #0 personality i32 0 !dbg ![[ORIG:[0-9]+]]
168+
169+
; Check that the resume function is present and capture its debug info id.
170+
; Also check that it contains `#dbg_declare` and `#dbg_value` debug instructions
171+
; making the debug variables available to the debugger.
172+
;
174173
; CHECK: define internal fastcc void @flink.resume(ptr noundef nonnull align 8 dereferenceable(40) %0) #0 personality i32 0 !dbg ![[RESUME:[0-9]+]]
175174
; CHECK: entry.resume:
176175
; CHECK: %[[DBG_PTR:.*]] = alloca ptr
177-
; CHECK: #dbg_declare(ptr %[[DBG_PTR]], ![[RESUME_COROHDL:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst,
178-
; CHECK: #dbg_declare(ptr %[[DBG_PTR]], ![[RESUME_X:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[EXPR_TAIL:.*]])
179-
; CHECK: store ptr {{.*}}, ptr %[[DBG_PTR]]
176+
; CHECK-NEXT: #dbg_declare(ptr %[[DBG_PTR]], ![[RESUME_COROHDL:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst,
177+
; CHECK-NEXT: #dbg_declare(ptr %[[DBG_PTR]], ![[RESUME_X:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[EXPR_TAIL:.*]])
178+
; CHECK-NEXT: store ptr {{.*}}, ptr %[[DBG_PTR]]
180179
; CHECK-NOT: alloca ptr
181-
; CHECK: call void @coro.devirt.trigger(ptr null)
182180
; CHECK: #dbg_value(i8 0, ![[RESUME_CONST:[0-9]+]], !DIExpression(DW_OP_LLVM_convert, 8, DW_ATE_signed, DW_OP_LLVM_convert, 32, DW_ATE_signed),
183181
; CHECK: #dbg_value(ptr %[[DBG_PTR]], ![[RESUME_DIRECT:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref),
184182
; Note that keeping the undef value here could be acceptable, too.
@@ -194,18 +192,26 @@ attributes #7 = { noduplicate }
194192
; CHECK: [[DEFAULT_DEST]]:
195193
; CHECK-NOT: {{.*}}:
196194
; CHECK: #dbg_value(i32 %[[CALLBR_RES]]
195+
196+
; Check that the destroy and cleanup functions are present and capture their debug info id.
197+
;
197198
; CHECK: define internal fastcc void @flink.destroy(ptr noundef nonnull align 8 dereferenceable(40) %0) #0 personality i32 0 !dbg ![[DESTROY:[0-9]+]]
198199
; CHECK: define internal fastcc void @flink.cleanup(ptr noundef nonnull align 8 dereferenceable(40) %0) #0 personality i32 0 !dbg ![[CLEANUP:[0-9]+]]
199200

201+
; Check that the linkage name of the original function is set correctly.
202+
;
200203
; CHECK: ![[ORIG]] = distinct !DISubprogram(name: "f", linkageName: "flink"
201-
202204
; CHECK: ![[RESUME]] = distinct !DISubprogram(name: "f", linkageName: "flink.resume"
205+
206+
; Check that metadata for local variables in the resume function is set correctly.
207+
;
203208
; CHECK: ![[RESUME_COROHDL]] = !DILocalVariable(name: "coro_hdl", scope: ![[RESUME]]
204209
; CHECK: ![[RESUME_X]] = !DILocalVariable(name: "x", arg: 1, scope: ![[RESUME]]
205210
; CHECK: ![[RESUME_CONST]] = !DILocalVariable(name: "direct_const", scope: ![[RESUME]]
206211
; CHECK: ![[RESUME_DIRECT]] = !DILocalVariable(name: "direct_mem", scope: ![[RESUME]]
207212
; CHECK: ![[RESUME_DIRECT_VALUE]] = !DILocalVariable(name: "direct_value", scope: ![[RESUME]]
208213

214+
; Check that the linkage names are set correctly for the destroy and cleanup functions.
215+
;
209216
; CHECK: ![[DESTROY]] = distinct !DISubprogram(name: "f", linkageName: "flink.destroy"
210-
211217
; CHECK: ![[CLEANUP]] = distinct !DISubprogram(name: "f", linkageName: "flink.cleanup"
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
; Tests that we add DILabels for the suspend points.
2+
;
3+
; We check both the generated LLVM:
4+
; RUN: opt < %s -passes='cgscc(coro-split)' -S | FileCheck %s
5+
;
6+
; And the debug info:
7+
; RUN: opt < %s -passes='cgscc(coro-split),coro-cleanup' \
8+
; RUN: | llc -O0 -filetype=obj -o - \
9+
; RUN: | llvm-dwarfdump - \
10+
; RUN: | FileCheck %s -check-prefix=DWARF
11+
12+
source_filename = "coro.c"
13+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
14+
target triple = "x86_64-unknown-linux-gnu"
15+
16+
declare void @bar(...) local_unnamed_addr #2
17+
declare void @baz(...) local_unnamed_addr #2
18+
19+
; Roughly equivalent to:
20+
;
21+
; task f() {
22+
; while (true) {
23+
; bar();
24+
; co_await std::suspend_always{};
25+
; baz();
26+
; co_await std::suspend_always{};
27+
; }
28+
; }
29+
30+
; Function Attrs: nounwind uwtable
31+
define ptr @f() #3 !dbg !16 {
32+
entry:
33+
%0 = tail call token @llvm.coro.id(i32 0, ptr null, ptr @f, ptr null), !dbg !26
34+
%1 = tail call i64 @llvm.coro.size.i64(), !dbg !26
35+
%frame = tail call ptr @malloc(i64 %1), !dbg !26
36+
%2 = tail call ptr @llvm.coro.begin(token %0, ptr %frame) #4, !dbg !26
37+
br label %loop1, !dbg !27
38+
39+
loop1: ; preds = %for.cond, %entry
40+
tail call void (...) @bar() #7, !dbg !33
41+
%3 = tail call token @llvm.coro.save(ptr null), !dbg !34
42+
%4 = tail call i8 @llvm.coro.suspend(token %3, i1 false), !dbg !34
43+
switch i8 %4, label %coro_Suspend [
44+
i8 0, label %loop2
45+
i8 1, label %coro_Cleanup
46+
], !dbg !34
47+
48+
loop2: ; preds = %for.cond, %entry
49+
tail call void (...) @baz() #7, !dbg !35
50+
%5 = tail call token @llvm.coro.save(ptr null), !dbg !36
51+
%6 = tail call i8 @llvm.coro.suspend(token %5, i1 false), !dbg !36
52+
switch i8 %6, label %coro_Suspend [
53+
i8 0, label %loop1
54+
i8 1, label %coro_Cleanup
55+
], !dbg !36
56+
57+
coro_Cleanup: ; preds = %for.cond
58+
%7 = tail call ptr @llvm.coro.free(token %0, ptr %2), !dbg !37
59+
tail call void @free(ptr nonnull %7), !dbg !37
60+
br label %coro_Suspend, !dbg !37
61+
62+
coro_Suspend: ; preds = %for.cond, %if.then, %coro_Cleanup
63+
tail call i1 @llvm.coro.end(ptr null, i1 false, token none) #4, !dbg !40
64+
ret ptr %2, !dbg !41
65+
}
66+
67+
; Check that the resume function contains the `#dbg_label` instructions.
68+
; CHECK-LABEL: define ptr @f() #1 !dbg !6 {
69+
; CHECK: resume.0: ; preds = %resume.entry
70+
; CHECK-NEXT: #dbg_label(![[RESUME_0:[0-9]+]], !{{[0-9]+}})
71+
; CHECK: resume.1: ; preds = %resume.entry
72+
; CHECK-NEXT: #dbg_label(![[RESUME_1:[0-9]+]], !{{[0-9]+}})
73+
74+
; Check that the destroy function contains the `#dbg_label` instructions.
75+
; CHECK-LABEL: define internal fastcc void @f.destroy({{.*}}) #1 !dbg !38 {
76+
; CHECK: resume.0: ; preds = %resume.entry
77+
; CHECK-NEXT: #dbg_label(![[DESTROY_0:[0-9]+]], !{{[0-9]+}})
78+
; CHECK: resume.1: ; preds = %resume.entry
79+
; CHECK-NEXT: #dbg_label(![[DESTROY_1:[0-9]+]], !{{[0-9]+}})
80+
81+
; Check that the DILabels are correct.
82+
; CHECK: ![[RESUME_0]] = !DILabel(scope: !{{[0-9]+}}, name: "__coro_resume_0", file: !{{[0-9]*}}, line: 12, column: 6, isArtificial: true, coroSuspendIdx: 0)
83+
; CHECK: ![[RESUME_1]] = !DILabel(scope: !{{[0-9]+}}, name: "__coro_resume_1", file: !{{[0-9]*}}, line: 14, column: 6, isArtificial: true, coroSuspendIdx: 1)
84+
; CHECK: ![[DESTROY_0]] = !DILabel(scope: !{{[0-9]+}}, name: "__coro_resume_0", file: !{{[0-9]*}}, line: 12, column: 6, isArtificial: true, coroSuspendIdx: 0)
85+
; CHECK: ![[DESTROY_1]] = !DILabel(scope: !{{[0-9]+}}, name: "__coro_resume_1", file: !{{[0-9]*}}, line: 14, column: 6, isArtificial: true, coroSuspendIdx: 1)
86+
87+
; DWARF: {{.*}}DW_TAG_label
88+
; DWARF-LABEL: DW_AT_name ("__coro_resume_0")
89+
; DWARF-NEXT: DW_AT_decl_file
90+
; DWARF-NEXT: DW_AT_decl_line (12)
91+
; DWARF-NEXT: DW_AT_decl_column (6)
92+
; DWARF-NEXT: DW_AT_artificial (true)
93+
; DWARF-NEXT: DW_AT_LLVM_coro_suspend_idx (0x00)
94+
; DWARF-NEXT: DW_AT_low_pc
95+
96+
97+
; Function Attrs: argmemonly nounwind readonly
98+
declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #5
99+
100+
; Function Attrs: nounwind
101+
declare noalias ptr @malloc(i64) local_unnamed_addr #6
102+
declare i64 @llvm.coro.size.i64() #1
103+
declare ptr @llvm.coro.begin(token, ptr writeonly) #7
104+
declare token @llvm.coro.save(ptr) #7
105+
declare i8 @llvm.coro.suspend(token, i1) #7
106+
declare ptr @llvm.coro.free(token, ptr nocapture readonly) #5
107+
declare void @free(ptr nocapture) local_unnamed_addr #6
108+
declare i1 @llvm.coro.end(ptr, i1, token) #7
109+
110+
attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
111+
attributes #1 = { nounwind readnone }
112+
attributes #2 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
113+
attributes #3 = { nounwind uwtable presplitcoroutine "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
114+
attributes #4 = { noduplicate }
115+
attributes #5 = { argmemonly nounwind readonly }
116+
attributes #6 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
117+
attributes #7 = { nounwind }
118+
attributes #8 = { alwaysinline nounwind }
119+
120+
!llvm.dbg.cu = !{!0}
121+
!llvm.module.flags = !{!3, !4}
122+
!llvm.ident = !{!5}
123+
124+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 4.0.0 - manually edited", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
125+
!1 = !DIFile(filename: "coro.c", directory: "/home/gor/build/bin")
126+
!2 = !{}
127+
!3 = !{i32 2, !"Dwarf Version", i32 4}
128+
!4 = !{i32 2, !"Debug Info Version", i32 3}
129+
!5 = !{!"clang version 4.0.0 - manually edited"}
130+
!9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
131+
!16 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 8, type: !17, isLocal: false, isDefinition: true, scopeLine: 8, isOptimized: true, unit: !0, retainedNodes: !20)
132+
!17 = !DISubroutineType(types: !18)
133+
!18 = !{!19}
134+
!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64, align: 64)
135+
!20 = !{!21, !22, !24}
136+
!21 = !DILocalVariable(name: "coro_hdl", scope: !16, file: !1, line: 9, type: !19)
137+
!22 = !DILocalVariable(name: "i", scope: !23, file: !1, line: 11, type: !9)
138+
!23 = distinct !DILexicalBlock(scope: !16, file: !1, line: 11, column: 3)
139+
!24 = !DILocalVariable(name: "coro_mem", scope: !16, file: !1, line: 16, type: !19)
140+
!26 = !DILocation(line: 9, column: 3, scope: !16)
141+
!27 = !DILocation(line: 10, column: 8, scope: !23)
142+
!33 = !DILocation(line: 11, column: 6, scope: !23)
143+
!34 = !DILocation(line: 12, column: 6, scope: !23)
144+
!35 = !DILocation(line: 13, column: 6, scope: !23)
145+
!36 = !DILocation(line: 14, column: 6, scope: !23)
146+
!37 = !DILocation(line: 16, column: 3, scope: !16)
147+
!40 = !DILocation(line: 16, column: 3, scope: !16)
148+
!41 = !DILocation(line: 17, column: 1, scope: !16)

0 commit comments

Comments
 (0)