1 ; Tests whether resume function would remain dbg.value infomation.
2 ; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split,coro-split)' -S | FileCheck %s
3 ; RUN: opt --try-experimental-debuginfo-iterators < %s -passes='module(coro-early),cgscc(coro-split,coro-split)' -S | FileCheck %s
5 ; This file is based on coro-debug-frame-variable.ll.
6 ; CHECK-LABEL: define void @f(
7 ; CHECK: %[[frame:.*]] = call {{.*}} @llvm.coro.begin
8 ; CHECK: #dbg_value(ptr %[[frame]]
9 ; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, [[OffsetX:[0-9]*]]),
10 ; ^ No deref at the end, as this variable ("x") is an array;
11 ; its value is its address. The entire array is in the frame.
12 ; CHECK: #dbg_assign(ptr %[[frame]]
13 ; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, [[OffsetX]])
14 ;; FIXME: Should we be updating the addresses on assigns here as well?
15 ; CHECK-SAME: , ptr %[[frame]], !DIExpression(),
17 ; CHECK: #dbg_value(ptr %[[frame]]
18 ; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, [[OffsetSpill:[0-9]*]], DW_OP_deref),
19 ; CHECK: #dbg_value(ptr %[[frame]]
20 ; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, [[OffsetI:[0-9]*]], DW_OP_deref),
21 ; CHECK: #dbg_value(ptr %[[frame]]
22 ; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, [[OffsetJ:[0-9]*]], DW_OP_deref),
24 ; CHECK-LABEL: void @f.resume(
25 ; CHECK-SAME: ptr {{.*}} %[[frame:.*]])
26 ; CHECK-SAME: !dbg ![[RESUME_FN_DBG_NUM:[0-9]+]]
27 ; CHECK: %[[frame_alloca:.*]] = alloca ptr
28 ; CHECK-NEXT: store ptr %[[frame]], ptr %[[frame_alloca]]
30 ; CHECK: #dbg_value(ptr %[[frame_alloca]], ![[XVAR_RESUME:[0-9]+]],
31 ; CHECK-SAME: !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[OffsetX]])
33 ; CHECK: #dbg_value(ptr %[[frame_alloca]], ![[SPILL_RESUME:[0-9]+]]
34 ; CHECK-SAME: !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[OffsetSpill]], DW_OP_deref)
35 ; CHECK: #dbg_value(ptr %[[frame_alloca]], ![[IVAR_RESUME:[0-9]+]],
36 ; CHECK-SAME: !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[OffsetI]], DW_OP_deref)
37 ; CHECK: #dbg_value(ptr %[[frame_alloca]], ![[JVAR_RESUME:[0-9]+]],
38 ; CHECK-SAME: !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[OffsetJ]], DW_OP_deref)
40 ; CHECK: ![[RESUME_FN_DBG_NUM]] = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov"
41 ; CHECK: ![[IVAR_RESUME]] = !DILocalVariable(name: "i"
42 ; CHECK: ![[XVAR_RESUME]] = !DILocalVariable(name: "x"
43 ; CHECK: ![[JVAR_RESUME]] = !DILocalVariable(name: "j"
44 ; CHECK: ![[SPILL_RESUME]] = !DILocalVariable(name: "produced"
46 declare void @consume(i32)
48 define void @f(i32 %i, i32 %j) presplitcoroutine !dbg !8 {
50 %__promise = alloca i8, align 8
51 %x = alloca [10 x i32], align 16
52 %produced = call i32 @value_producer()
53 %id = call token @llvm.coro.id(i32 16, ptr %__promise, ptr null, ptr null)
54 %alloc = call i1 @llvm.coro.alloc(token %id)
55 br i1 %alloc, label %coro.alloc, label %coro.init
57 coro.alloc: ; preds = %entry
58 %size = call i64 @llvm.coro.size.i64()
59 %memory = call ptr @new(i64 %size)
62 coro.init: ; preds = %coro.alloc, %entry
63 %phi.entry.alloc = phi ptr [ null, %entry ], [ %memory, %coro.alloc ]
64 %begin = call ptr @llvm.coro.begin(token %id, ptr %phi.entry.alloc)
65 %ready = call i1 @await_ready()
66 br i1 %ready, label %init.ready, label %init.suspend
68 init.suspend: ; preds = %coro.init
69 %save = call token @llvm.coro.save(ptr null)
70 call void @await_suspend()
71 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
72 switch i8 %suspend, label %coro.ret [
73 i8 0, label %init.ready
74 i8 1, label %init.cleanup
77 init.cleanup: ; preds = %init.suspend
80 init.ready: ; preds = %init.suspend, %coro.init
81 call void @await_resume()
82 call void @llvm.dbg.value(metadata i32 0, metadata !6, metadata !DIExpression()), !dbg !11
83 %i.init.ready.inc = add nsw i32 0, 1
84 call void @llvm.dbg.value(metadata i32 %i.init.ready.inc, metadata !6, metadata !DIExpression()), !dbg !11
85 call void @llvm.dbg.value(metadata ptr %x, metadata !12, metadata !DIExpression()), !dbg !17
86 call void @llvm.dbg.assign(metadata ptr %x, metadata !12, metadata !DIExpression(), metadata !30, metadata ptr %x, metadata !DIExpression()), !dbg !17
87 call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 40, i1 false), !dbg !17
88 call void @print(i32 %i.init.ready.inc)
89 %ready.again = call zeroext i1 @await_ready()
90 br i1 %ready.again, label %await.ready, label %await.suspend
92 await.suspend: ; preds = %init.ready
93 %save.again = call token @llvm.coro.save(ptr null)
94 %from.address = call ptr @from_address(ptr %begin)
95 call void @await_suspend()
96 %suspend.again = call i8 @llvm.coro.suspend(token %save.again, i1 false)
97 switch i8 %suspend.again, label %coro.ret [
98 i8 0, label %await.ready
99 i8 1, label %await.cleanup
102 await.cleanup: ; preds = %await.suspend
105 await.ready: ; preds = %await.suspend, %init.ready
106 call void @await_resume()
107 call void @llvm.dbg.value(metadata i32 0, metadata !18, metadata !DIExpression()), !dbg !11
108 store i32 1, ptr %x, align 16, !dbg !20
109 %arrayidx1 = getelementptr inbounds [10 x i32], ptr %x, i64 0, i64 1, !dbg !21
110 store i32 2, ptr %arrayidx1, align 4, !dbg !22
111 %i.await.ready.inc = add nsw i32 %i.init.ready.inc, 1
112 call void @consume(i32 %produced)
113 call void @consume(i32 %i)
114 call void @consume(i32 %j)
115 call void @llvm.dbg.value(metadata i32 %produced, metadata !23, metadata !DIExpression()), !dbg !11
116 call void @llvm.dbg.value(metadata i32 %i, metadata !6, metadata !DIExpression()), !dbg !11
117 call void @llvm.dbg.value(metadata i32 %j, metadata !18, metadata !DIExpression()), !dbg !11
118 call void @print(i32 %i.await.ready.inc)
119 call void @return_void()
122 coro.final: ; preds = %await.ready
123 call void @final_suspend()
124 %coro.final.await_ready = call i1 @await_ready()
125 br i1 %coro.final.await_ready, label %final.ready, label %final.suspend
127 final.suspend: ; preds = %coro.final
128 %final.suspend.coro.save = call token @llvm.coro.save(ptr null)
129 %final.suspend.from_address = call ptr @from_address(ptr %begin)
130 call void @await_suspend()
131 %final.suspend.coro.suspend = call i8 @llvm.coro.suspend(token %final.suspend.coro.save, i1 true)
132 switch i8 %final.suspend.coro.suspend, label %coro.ret [
133 i8 0, label %final.ready
134 i8 1, label %final.cleanup
137 final.cleanup: ; preds = %final.suspend
140 final.ready: ; preds = %final.suspend, %coro.final
141 call void @await_resume()
144 cleanup: ; preds = %final.ready, %final.cleanup, %await.cleanup, %init.cleanup
145 %cleanup.dest.slot.0 = phi i32 [ 0, %final.ready ], [ 2, %final.cleanup ], [ 2, %await.cleanup ], [ 2, %init.cleanup ]
146 %free.memory = call ptr @llvm.coro.free(token %id, ptr %begin)
147 %free = icmp ne ptr %free.memory, null
148 br i1 %free, label %coro.free, label %after.coro.free
150 coro.free: ; preds = %cleanup
151 call void @delete(ptr %free.memory)
152 br label %after.coro.free
154 after.coro.free: ; preds = %coro.free, %cleanup
155 switch i32 %cleanup.dest.slot.0, label %unreachable [
156 i32 0, label %cleanup.cont
157 i32 2, label %coro.ret
160 cleanup.cont: ; preds = %after.coro.free
163 coro.ret: ; preds = %cleanup.cont, %after.coro.free, %final.suspend, %await.suspend, %init.suspend
164 %end = call i1 @llvm.coro.end(ptr null, i1 false, token none)
167 unreachable: ; preds = %after.coro.free
171 ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
172 declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
174 ; Function Attrs: argmemonly nounwind readonly
175 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1
177 ; Function Attrs: nounwind
178 declare i1 @llvm.coro.alloc(token) #2
180 ; Function Attrs: nounwind readnone
181 declare i64 @llvm.coro.size.i64() #3
183 ; Function Attrs: nounwind
184 declare token @llvm.coro.save(ptr) #2
186 ; Function Attrs: nounwind
187 declare ptr @llvm.coro.begin(token, ptr writeonly) #2
189 ; Function Attrs: nounwind
190 declare i8 @llvm.coro.suspend(token, i1) #2
192 ; Function Attrs: argmemonly nounwind readonly
193 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1
195 ; Function Attrs: nounwind
196 declare i1 @llvm.coro.end(ptr, i1, token) #2
198 declare ptr @new(i64)
200 declare void @delete(ptr)
202 declare i1 @await_ready()
204 declare void @await_suspend()
206 declare void @await_resume()
208 declare void @print(i32)
210 declare ptr @from_address(ptr)
212 declare void @return_void()
214 declare void @final_suspend()
216 declare i32 @value_producer()
218 ; Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly
219 declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4
221 ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
222 declare void @llvm.dbg.value(metadata, metadata, metadata) #0
224 attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
225 attributes #1 = { argmemonly nounwind readonly }
226 attributes #2 = { nounwind }
227 attributes #3 = { nounwind readnone }
228 attributes #4 = { argmemonly nofree nosync nounwind willreturn writeonly }
231 !llvm.linker.options = !{}
232 !llvm.module.flags = !{!3, !4}
235 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, splitDebugInlining: false, nameTableKind: None)
236 !1 = !DIFile(filename: "repro.cpp", directory: ".")
238 !3 = !{i32 7, !"Dwarf Version", i32 4}
239 !4 = !{i32 2, !"Debug Info Version", i32 3}
240 !5 = !{!"clang version 11.0.0"}
241 !6 = !DILocalVariable(name: "i", scope: !7, file: !1, line: 24, type: !10)
242 !7 = distinct !DILexicalBlock(scope: !8, file: !1, line: 23, column: 12)
243 !8 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 23, type: !9, scopeLine: 23, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
244 !9 = !DISubroutineType(types: !2)
245 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
246 !11 = !DILocation(line: 0, scope: !7)
247 !12 = !DILocalVariable(name: "x", scope: !13, file: !1, line: 34, type: !14)
248 !13 = distinct !DILexicalBlock(scope: !8, file: !1, line: 23, column: 12)
249 !14 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, size: 320, elements: !15)
251 !16 = !DISubrange(count: 10)
252 !17 = !DILocation(line: 24, column: 7, scope: !7)
253 !18 = !DILocalVariable(name: "j", scope: !7, file: !1, line: 32, type: !10)
254 !19 = !DILocation(line: 42, column: 3, scope: !7)
255 !20 = !DILocation(line: 42, column: 8, scope: !7)
256 !21 = !DILocation(line: 43, column: 3, scope: !7)
257 !22 = !DILocation(line: 43, column: 8, scope: !7)
258 !23 = !DILocalVariable(name: "produced", scope: !7, file: !1, line:24, type: !10)
259 !30 = distinct !DIAssignID()