xref: /llvm-project/llvm/test/Transforms/Coroutines/coro-debug.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; Tests that debug information is sane after coro-split
2; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
3; RUN: opt --try-experimental-debuginfo-iterators < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
4
5source_filename = "simple-repro.c"
6target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
7target triple = "x86_64-unknown-linux-gnu"
8
9; Function Attrs: noinline nounwind
10define ptr @f(i32 %x) #0 personality i32 0 !dbg !6 {
11entry:
12  %x.addr = alloca i32, align 4
13  %coro_hdl = alloca ptr, align 8
14  store i32 %x, ptr %x.addr, align 4
15  %0 = call token @llvm.coro.id(i32 0, ptr null, ptr @f, ptr null), !dbg !16
16  %1 = call i64 @llvm.coro.size.i64(), !dbg !16
17  %call = call ptr @malloc(i64 %1), !dbg !16
18  %2 = call ptr @llvm.coro.begin(token %0, ptr %call) #7, !dbg !16
19  store ptr %2, ptr %coro_hdl, align 8, !dbg !16
20  %3 = call i8 @llvm.coro.suspend(token none, i1 false), !dbg !17
21  %conv = sext i8 %3 to i32, !dbg !17
22  %late_local = alloca i32, align 4
23  call void @coro.devirt.trigger(ptr null)
24  switch i32 %conv, label %sw.default [
25    i32 0, label %sw.bb
26    i32 1, label %sw.bb1
27  ], !dbg !17
28
29sw.bb:                                            ; preds = %entry
30  %direct = load i32, ptr %x.addr, align 4, !dbg !14
31  %gep = getelementptr inbounds [16 x i8], ptr undef, i32 %direct, !dbg !14
32  call void @llvm.dbg.declare(metadata ptr %gep, metadata !27, metadata !13), !dbg !14
33  call void @llvm.dbg.declare(metadata i32 %conv, metadata !26, metadata !13), !dbg !14
34  call void @llvm.dbg.declare(metadata i32 %direct, metadata !25, metadata !13), !dbg !14
35  call void @llvm.dbg.declare(metadata ptr %x.addr, metadata !12, metadata !13), !dbg !14
36  call void @llvm.dbg.declare(metadata ptr %coro_hdl, metadata !15, metadata !13), !dbg !16
37  call void @llvm.dbg.declare(metadata ptr %late_local, metadata !29, metadata !13), !dbg !16
38  call void @llvm.dbg.value(metadata i32 %direct, metadata !30, metadata !13), !dbg !14
39  ; don't crash when encountering nonsensical debug info, verfifier doesn't yet reject these
40  call void @llvm.dbg.declare(metadata ptr null, metadata !28, metadata !13), !dbg !16
41  call void @llvm.dbg.declare(metadata !{}, metadata !28, metadata !13), !dbg !16
42  %new_storgae = invoke ptr @allocate()
43    to label %next unwind label %ehcleanup, !dbg !18
44
45next:
46  br label %sw.epilog, !dbg !18
47
48sw.bb1:                                           ; preds = %entry
49  br label %coro_Cleanup, !dbg !18
50
51sw.default:                                       ; preds = %entry
52  br label %coro_Suspend, !dbg !18
53
54sw.epilog:                                        ; preds = %sw.bb
55  call void @llvm.dbg.declare(metadata ptr %new_storgae, metadata !31, metadata !13), !dbg !16
56  %4 = load i32, ptr %x.addr, align 4, !dbg !20
57  %add = add nsw i32 %4, 1, !dbg !21
58  store i32 %add, ptr %x.addr, align 4, !dbg !22
59  %asm_res = callbr i32 asm "", "=r,r,!i"(i32 %x)
60          to label %coro_Cleanup [label %indirect.dest]
61
62indirect.dest:
63  call void @log(), !dbg !18
64  br label %coro_Cleanup
65
66coro_Cleanup:                                     ; preds = %sw.epilog, %sw.bb1
67  %5 = load ptr, ptr %coro_hdl, align 8, !dbg !24
68  %6 = call ptr @llvm.coro.free(token %0, ptr %5), !dbg !24
69  call void @free(ptr %6), !dbg !24
70  call void @llvm.dbg.declare(metadata i32 %asm_res, metadata !32, metadata !13), !dbg !16
71  br label %coro_Suspend, !dbg !24
72
73coro_Suspend:                                     ; preds = %coro_Cleanup, %sw.default
74  %7 = call i1 @llvm.coro.end(ptr null, i1 false, token none) #7, !dbg !24
75  %8 = load ptr, ptr %coro_hdl, align 8, !dbg !24
76  store i32 0, ptr %late_local, !dbg !24
77  ret ptr %8, !dbg !24
78
79ehcleanup:
80  %ex = landingpad { ptr, i32 }
81          catch ptr null
82  call void @print({ ptr, i32 } %ex)
83  unreachable
84}
85
86; Function Attrs: nounwind readnone speculatable
87declare void @llvm.dbg.value(metadata, metadata, metadata) #1
88
89; Function Attrs: nounwind readnone speculatable
90declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
91
92; Function Attrs: argmemonly nounwind readonly
93declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #2
94
95declare ptr @malloc(i64) #3
96declare ptr @allocate()
97declare void @print({ ptr, i32 })
98declare void @log()
99
100; Function Attrs: nounwind readnone
101declare i64 @llvm.coro.size.i64() #4
102
103; Function Attrs: nounwind
104declare ptr @llvm.coro.begin(token, ptr writeonly) #5
105
106; Function Attrs: nounwind
107declare i8 @llvm.coro.suspend(token, i1) #5
108
109declare void @free(ptr) #3
110
111; Function Attrs: argmemonly nounwind readonly
112declare ptr @llvm.coro.free(token, ptr nocapture readonly) #2
113
114; Function Attrs: nounwind
115declare i1 @llvm.coro.end(ptr, i1, token) #5
116
117; Function Attrs: alwaysinline
118define private void @coro.devirt.trigger(ptr) #6 {
119entry:
120  ret void
121}
122
123; Function Attrs: argmemonly nounwind readonly
124declare ptr @llvm.coro.subfn.addr(ptr nocapture readonly, i8) #2
125
126attributes #0 = { noinline nounwind 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-features"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
127attributes #1 = { nounwind readnone speculatable }
128attributes #2 = { argmemonly nounwind readonly }
129attributes #3 = { "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-features"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
130attributes #4 = { nounwind readnone }
131attributes #5 = { nounwind }
132attributes #6 = { alwaysinline }
133attributes #7 = { noduplicate }
134
135!llvm.dbg.cu = !{!0}
136!llvm.module.flags = !{!3, !4}
137!llvm.ident = !{!5}
138
139!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 5.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
140!1 = !DIFile(filename: "<stdin>", directory: "C:\5CGitHub\5Cllvm\5Cbuild\5CDebug\5Cbin")
141!2 = !{}
142!3 = !{i32 2, !"Dwarf Version", i32 4}
143!4 = !{i32 2, !"Debug Info Version", i32 3}
144!5 = !{!"clang version 5.0.0"}
145!6 = distinct !DISubprogram(name: "f", linkageName: "flink", scope: !7, file: !7, line: 55, type: !8, isLocal: false, isDefinition: true, scopeLine: 55, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2, declaration: !DISubprogram(name: "f", linkageName: "flink", scope: !7, file: !7, line: 55, type: !8, isLocal: false, isDefinition: false, flags: DIFlagPrototyped))
146!7 = !DIFile(filename: "simple-repro.c", directory: "C:\5CGitHub\5Cllvm\5Cbuild\5CDebug\5Cbin")
147!8 = !DISubroutineType(types: !9)
148!9 = !{!10, !11}
149!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
150!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
151!12 = !DILocalVariable(name: "x", arg: 1, scope: !6, file: !7, line: 55, type: !11)
152!13 = !DIExpression()
153!14 = !DILocation(line: 55, column: 13, scope: !6)
154!15 = !DILocalVariable(name: "coro_hdl", scope: !6, file: !7, line: 56, type: !10)
155!16 = !DILocation(line: 56, column: 3, scope: !6)
156!17 = !DILocation(line: 58, column: 5, scope: !6)
157!18 = !DILocation(line: 58, column: 5, scope: !19)
158!19 = distinct !DILexicalBlock(scope: !6, file: !7, line: 58, column: 5)
159!20 = !DILocation(line: 59, column: 9, scope: !6)
160!21 = !DILocation(line: 59, column: 10, scope: !6)
161!22 = !DILocation(line: 59, column: 7, scope: !6)
162!23 = !DILocation(line: 59, column: 5, scope: !6)
163!24 = !DILocation(line: 62, column: 3, scope: !6)
164; These variables were added manually.
165!25 = !DILocalVariable(name: "direct_mem", scope: !6, file: !7, line: 55, type: !11)
166!26 = !DILocalVariable(name: "direct_const", scope: !6, file: !7, line: 55, type: !11)
167!27 = !DILocalVariable(name: "undefined", scope: !6, file: !7, line: 55, type: !11)
168!28 = !DILocalVariable(name: "null", scope: !6, file: !7, line: 55, type: !11)
169!29 = !DILocalVariable(name: "partial_dead", scope: !6, file: !7, line: 55, type: !11)
170!30 = !DILocalVariable(name: "direct_value", scope: !6, file: !7, line: 55, type: !11)
171!31 = !DILocalVariable(name: "allocated", scope: !6, file: !7, line: 55, type: !11)
172!32 = !DILocalVariable(name: "inline_asm", scope: !6, file: !7, line: 55, type: !11)
173
174; CHECK: define ptr @f(i32 %x) #0 personality i32 0 !dbg ![[ORIG:[0-9]+]]
175; CHECK: define internal fastcc void @f.resume(ptr noundef nonnull align 8 dereferenceable(40) %0) #0 personality i32 0 !dbg ![[RESUME:[0-9]+]]
176; CHECK: entry.resume:
177; CHECK: %[[DBG_PTR:.*]] = alloca ptr
178; CHECK: #dbg_declare(ptr %[[DBG_PTR]], ![[RESUME_COROHDL:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst,
179; CHECK: #dbg_declare(ptr %[[DBG_PTR]], ![[RESUME_X:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[EXPR_TAIL:.*]])
180; CHECK: #dbg_declare(ptr %[[DBG_PTR]], ![[RESUME_DIRECT:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[EXPR_TAIL]])
181; CHECK: store ptr {{.*}}, ptr %[[DBG_PTR]]
182; CHECK-NOT: alloca ptr
183; CHECK: #dbg_declare(i8 0, ![[RESUME_CONST:[0-9]+]], !DIExpression(DW_OP_LLVM_convert, 8, DW_ATE_signed, DW_OP_LLVM_convert, 32, DW_ATE_signed),
184; Note that keeping the undef value here could be acceptable, too.
185; CHECK-NOT: #dbg_declare(ptr undef, !{{[0-9]+}}, !DIExpression(),
186; CHECK: call void @coro.devirt.trigger(ptr null)
187; CHECK: #dbg_value(ptr {{.*}}, ![[RESUME_DIRECT_VALUE:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref),
188; Check that the dbg.declare intrinsic of invoke instruction is hanled correctly.
189; CHECK: %[[ALLOCATED_STORAGE:.+]] = invoke ptr @allocate()
190; CHECK-NEXT: to label %[[NORMAL_DEST:.+]] unwind
191; CHECK: [[NORMAL_DEST]]
192; CHECK-NEXT: #dbg_declare(ptr %[[ALLOCATED_STORAGE]]
193; CHECK: %[[CALLBR_RES:.+]] = callbr i32 asm
194; CHECK-NEXT: to label %[[DEFAULT_DEST:.+]] [label
195; CHECK: [[DEFAULT_DEST]]:
196; CHECK-NOT: {{.*}}:
197; CHECK: #dbg_declare(i32 %[[CALLBR_RES]]
198; CHECK: define internal fastcc void @f.destroy(ptr noundef nonnull align 8 dereferenceable(40) %0) #0 personality i32 0 !dbg ![[DESTROY:[0-9]+]]
199; CHECK: define internal fastcc void @f.cleanup(ptr noundef nonnull align 8 dereferenceable(40) %0) #0 personality i32 0 !dbg ![[CLEANUP:[0-9]+]]
200
201; CHECK: ![[ORIG]] = distinct !DISubprogram(name: "f", linkageName: "flink"
202
203; CHECK: ![[RESUME]] = distinct !DISubprogram(name: "f", linkageName: "flink"
204; CHECK: ![[RESUME_COROHDL]] = !DILocalVariable(name: "coro_hdl", scope: ![[RESUME]]
205; CHECK: ![[RESUME_X]] = !DILocalVariable(name: "x", arg: 1, scope: ![[RESUME]]
206; CHECK: ![[RESUME_DIRECT]] = !DILocalVariable(name: "direct_mem", scope: ![[RESUME]]
207; CHECK: ![[RESUME_CONST]] = !DILocalVariable(name: "direct_const", scope: ![[RESUME]]
208; CHECK: ![[RESUME_DIRECT_VALUE]] = !DILocalVariable(name: "direct_value", scope: ![[RESUME]]
209
210; CHECK: ![[DESTROY]] = distinct !DISubprogram(name: "f", linkageName: "flink"
211
212; CHECK: ![[CLEANUP]] = distinct !DISubprogram(name: "f", linkageName: "flink"
213