1 ; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split<reuse-storage>),function(sroa)' -S | FileCheck %s
3 ; Checks whether the dbg.declare for `__promise` remains valid under O2.
5 ; CHECK-LABEL: define internal fastcc void @f.resume({{.*}})
7 ; CHECK: call void @llvm.dbg.declare(metadata ptr %begin, metadata ![[PROMISEVAR_RESUME:[0-9]+]], metadata !DIExpression(
9 ; CHECK: ![[PROMISEVAR_RESUME]] = !DILocalVariable(name: "__promise"
10 %promise_type = type { i32, i32, double }
12 define void @f() presplitcoroutine !dbg !8 {
14 %__promise = alloca %promise_type, align 8
15 %id = call token @llvm.coro.id(i32 16, ptr %__promise, ptr null, ptr null)
16 %alloc = call i1 @llvm.coro.alloc(token %id)
17 br i1 %alloc, label %coro.alloc, label %coro.init
19 coro.alloc: ; preds = %entry
20 %size = call i64 @llvm.coro.size.i64()
21 %memory = call ptr @new(i64 %size)
24 coro.init: ; preds = %coro.alloc, %entry
25 %phi.entry.alloc = phi ptr [ null, %entry ], [ %memory, %coro.alloc ]
26 %begin = call ptr @llvm.coro.begin(token %id, ptr %phi.entry.alloc)
27 call void @llvm.dbg.declare(metadata ptr %__promise, metadata !6, metadata !DIExpression()), !dbg !18
28 store i32 1, ptr %__promise, align 8
29 %j.i = getelementptr inbounds %promise_type, ptr %__promise, i64 0, i32 1
30 store i32 2, ptr %j.i, align 4
31 %k.i = getelementptr inbounds %promise_type, ptr %__promise, i64 0, i32 2
32 store double 3.000000e+00, ptr %k.i, align 8
33 %ready = call i1 @await_ready()
34 br i1 %ready, label %init.ready, label %init.suspend
36 init.suspend: ; preds = %coro.init
37 %save = call token @llvm.coro.save(ptr null)
38 call void @await_suspend()
39 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
40 switch i8 %suspend, label %coro.ret [
41 i8 0, label %init.ready
42 i8 1, label %init.cleanup
45 init.cleanup: ; preds = %init.suspend
48 init.ready: ; preds = %init.suspend, %coro.init
49 call void @await_resume()
50 %ready.again = call zeroext i1 @await_ready()
51 br i1 %ready.again, label %await.ready, label %await.suspend
53 await.suspend: ; preds = %init.ready
54 %save.again = call token @llvm.coro.save(ptr null)
55 %from.address = call ptr @from_address(ptr %begin)
56 call void @await_suspend()
57 %suspend.again = call i8 @llvm.coro.suspend(token %save.again, i1 false)
58 switch i8 %suspend.again, label %coro.ret [
59 i8 0, label %await.ready
60 i8 1, label %await.cleanup
63 await.cleanup: ; preds = %await.suspend
66 await.ready: ; preds = %await.suspend, %init.ready
67 call void @await_resume()
68 call void @return_void()
71 coro.final: ; preds = %await.ready
72 call void @final_suspend()
73 %coro.final.await_ready = call i1 @await_ready()
74 br i1 %coro.final.await_ready, label %final.ready, label %final.suspend
76 final.suspend: ; preds = %coro.final
77 %final.suspend.coro.save = call token @llvm.coro.save(ptr null)
78 %final.suspend.from_address = call ptr @from_address(ptr %begin)
79 call void @await_suspend()
80 %final.suspend.coro.suspend = call i8 @llvm.coro.suspend(token %final.suspend.coro.save, i1 true)
81 switch i8 %final.suspend.coro.suspend, label %coro.ret [
82 i8 0, label %final.ready
83 i8 1, label %final.cleanup
86 final.cleanup: ; preds = %final.suspend
89 final.ready: ; preds = %final.suspend, %coro.final
90 call void @await_resume()
93 cleanup: ; preds = %final.ready, %final.cleanup, %await.cleanup, %init.cleanup
94 %cleanup.dest.slot.0 = phi i32 [ 0, %final.ready ], [ 2, %final.cleanup ], [ 2, %await.cleanup ], [ 2, %init.cleanup ]
95 %free.memory = call ptr @llvm.coro.free(token %id, ptr %begin)
96 %free = icmp ne ptr %free.memory, null
97 br i1 %free, label %coro.free, label %after.coro.free
99 coro.free: ; preds = %cleanup
100 call void @delete(ptr %free.memory)
101 br label %after.coro.free
103 after.coro.free: ; preds = %coro.free, %cleanup
104 switch i32 %cleanup.dest.slot.0, label %unreachable [
105 i32 0, label %cleanup.cont
106 i32 2, label %coro.ret
109 cleanup.cont: ; preds = %after.coro.free
112 coro.ret: ; preds = %cleanup.cont, %after.coro.free, %final.suspend, %await.suspend, %init.suspend
113 %end = call i1 @llvm.coro.end(ptr null, i1 false, token none)
116 unreachable: ; preds = %after.coro.free
121 declare void @llvm.dbg.declare(metadata, metadata, metadata)
122 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
123 declare i1 @llvm.coro.alloc(token)
124 declare i64 @llvm.coro.size.i64()
125 declare token @llvm.coro.save(ptr)
126 declare ptr @llvm.coro.begin(token, ptr writeonly)
127 declare i8 @llvm.coro.suspend(token, i1)
128 declare ptr @llvm.coro.free(token, ptr nocapture readonly)
129 declare i1 @llvm.coro.end(ptr, i1, token)
131 declare ptr @new(i64)
132 declare void @delete(ptr)
133 declare i1 @await_ready()
134 declare void @await_suspend()
135 declare void @await_resume()
136 declare void @print(i32)
137 declare ptr @from_address(ptr)
138 declare void @return_void()
139 declare void @final_suspend()
142 !llvm.linker.options = !{}
143 !llvm.module.flags = !{!3, !4}
146 !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)
147 !1 = !DIFile(filename: "coro-debug.cpp", directory: ".")
149 !3 = !{i32 7, !"Dwarf Version", i32 4}
150 !4 = !{i32 2, !"Debug Info Version", i32 3}
151 !5 = !{!"clang version 11.0.0"}
152 !6 = !DILocalVariable(name: "__promise", scope: !7, file: !1, line: 24, type: !10)
153 !7 = distinct !DILexicalBlock(scope: !8, file: !1, line: 23, column: 12)
154 !8 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !8, file: !1, line: 23, type: !9, scopeLine: 23, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
155 !9 = !DISubroutineType(types: !2)
156 !10 = !DIDerivedType(tag: DW_TAG_typedef, name: "promise_type", scope: !8, file: !1, line: 15, baseType: !11)
157 !11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "promise_type", scope: !8, file: !1, line: 10, size: 128, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !12, identifier: "_ZTSN4coro12promise_typeE")
158 !12 = !{!13, !14, !15}
159 !13 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !8, file: !1, line: 10, baseType: !16, size: 32)
160 !14 = !DIDerivedType(tag: DW_TAG_member, name: "j", scope: !8, file: !1, line: 10, baseType: !16, size: 32, offset: 32)
161 !15 = !DIDerivedType(tag: DW_TAG_member, name: "k", scope: !8, file: !1, line: 10, baseType: !17, size: 64, offset: 64)
162 !16 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
163 !17 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)
164 !18 = !DILocation(line: 0, scope: !7)