261 lines · plain
1; Tests whether resume function retains dbg.value information.2; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split,coro-split)' -S | FileCheck %s3;4; This file is based on coro-debug-frame-variable.ll.5; CHECK-LABEL: define void @_Z3foov(6; CHECK: %[[frame:.*]] = call {{.*}} @llvm.coro.begin7; CHECK: #dbg_value(ptr %[[frame]]8; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, [[OffsetX:[0-9]*]]),9; ^ No deref at the end, as this variable ("x") is an array;10; its value is its address. The entire array is in the frame.11; CHECK: #dbg_assign(ptr %[[frame]]12; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, [[OffsetX]])13;; FIXME: Should we be updating the addresses on assigns here as well?14; CHECK-SAME: , ptr %[[frame]], !DIExpression(),15 16; CHECK: #dbg_value(ptr %[[frame]]17; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, [[OffsetSpill:[0-9]*]], DW_OP_deref),18; CHECK: #dbg_value(ptr %[[frame]]19; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, [[OffsetI:[0-9]*]], DW_OP_deref),20; CHECK: #dbg_value(ptr %[[frame]]21; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, [[OffsetJ:[0-9]*]], DW_OP_deref),22 23; CHECK-LABEL: void @_Z3foov.resume(24; CHECK-SAME: ptr {{.*}} %[[frame:.*]])25; CHECK-SAME: !dbg ![[RESUME_FN_DBG_NUM:[0-9]+]]26; CHECK: %[[frame_alloca:.*]] = alloca ptr27; CHECK-NEXT: #dbg_declare(ptr %begin.debug, ![[FRAME_DI_NUM:[0-9]+]],28; CHECK-NEXT: store ptr %[[frame]], ptr %[[frame_alloca]]29; CHECK: init.ready:30; CHECK: #dbg_value(ptr %[[frame_alloca]], ![[XVAR_RESUME:[0-9]+]],31; CHECK-SAME: !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[OffsetX]])32; CHECK: await.ready: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)39;40; CHECK: ![[RESUME_FN_DBG_NUM]] = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov.resume"41; CHECK: ![[FRAME_DI_NUM]] = !DILocalVariable(name: "__coro_frame"42; CHECK: ![[IVAR_RESUME]] = !DILocalVariable(name: "i"43; CHECK: ![[XVAR_RESUME]] = !DILocalVariable(name: "x"44; CHECK: ![[JVAR_RESUME]] = !DILocalVariable(name: "j"45; CHECK: ![[SPILL_RESUME]] = !DILocalVariable(name: "produced"46 47declare void @consume(i32)48 49define void @_Z3foov(i32 %i, i32 %j) presplitcoroutine !dbg !8 {50entry:51 %__promise = alloca i8, align 852 %x = alloca [10 x i32], align 1653 %produced = call i32 @value_producer()54 %id = call token @llvm.coro.id(i32 16, ptr %__promise, ptr null, ptr null)55 %alloc = call i1 @llvm.coro.alloc(token %id)56 br i1 %alloc, label %coro.alloc, label %coro.init57 58coro.alloc: ; preds = %entry59 %size = call i64 @llvm.coro.size.i64()60 %memory = call ptr @new(i64 %size)61 br label %coro.init62 63coro.init: ; preds = %coro.alloc, %entry64 %phi.entry.alloc = phi ptr [ null, %entry ], [ %memory, %coro.alloc ]65 %begin = call ptr @llvm.coro.begin(token %id, ptr %phi.entry.alloc)66 %ready = call i1 @await_ready()67 br i1 %ready, label %init.ready, label %init.suspend68 69init.suspend: ; preds = %coro.init70 %save = call token @llvm.coro.save(ptr null)71 call void @await_suspend()72 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)73 switch i8 %suspend, label %coro.ret [74 i8 0, label %init.ready75 i8 1, label %init.cleanup76 ]77 78init.cleanup: ; preds = %init.suspend79 br label %cleanup80 81init.ready: ; preds = %init.suspend, %coro.init82 call void @await_resume()83 call void @llvm.dbg.value(metadata i32 0, metadata !6, metadata !DIExpression()), !dbg !1184 %i.init.ready.inc = add nsw i32 0, 185 call void @llvm.dbg.value(metadata i32 %i.init.ready.inc, metadata !6, metadata !DIExpression()), !dbg !1186 call void @llvm.dbg.value(metadata ptr %x, metadata !12, metadata !DIExpression()), !dbg !1787 call void @llvm.dbg.assign(metadata ptr %x, metadata !12, metadata !DIExpression(), metadata !30, metadata ptr %x, metadata !DIExpression()), !dbg !1788 call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 40, i1 false), !dbg !1789 call void @print(i32 %i.init.ready.inc)90 %ready.again = call zeroext i1 @await_ready()91 br i1 %ready.again, label %await.ready, label %await.suspend92 93await.suspend: ; preds = %init.ready94 %save.again = call token @llvm.coro.save(ptr null)95 %from.address = call ptr @from_address(ptr %begin)96 call void @await_suspend()97 %suspend.again = call i8 @llvm.coro.suspend(token %save.again, i1 false)98 switch i8 %suspend.again, label %coro.ret [99 i8 0, label %await.ready100 i8 1, label %await.cleanup101 ]102 103await.cleanup: ; preds = %await.suspend104 br label %cleanup105 106await.ready: ; preds = %await.suspend, %init.ready107 call void @await_resume()108 call void @llvm.dbg.value(metadata i32 0, metadata !18, metadata !DIExpression()), !dbg !11109 store i32 1, ptr %x, align 16, !dbg !20110 %arrayidx1 = getelementptr inbounds [10 x i32], ptr %x, i64 0, i64 1, !dbg !21111 store i32 2, ptr %arrayidx1, align 4, !dbg !22112 %i.await.ready.inc = add nsw i32 %i.init.ready.inc, 1113 call void @consume(i32 %produced)114 call void @consume(i32 %i)115 call void @consume(i32 %j)116 call void @llvm.dbg.value(metadata i32 %produced, metadata !23, metadata !DIExpression()), !dbg !11117 call void @llvm.dbg.value(metadata i32 %i, metadata !6, metadata !DIExpression()), !dbg !11118 call void @llvm.dbg.value(metadata i32 %j, metadata !18, metadata !DIExpression()), !dbg !11119 call void @print(i32 %i.await.ready.inc)120 call void @return_void()121 br label %coro.final122 123coro.final: ; preds = %await.ready124 call void @final_suspend()125 %coro.final.await_ready = call i1 @await_ready()126 br i1 %coro.final.await_ready, label %final.ready, label %final.suspend127 128final.suspend: ; preds = %coro.final129 %final.suspend.coro.save = call token @llvm.coro.save(ptr null)130 %final.suspend.from_address = call ptr @from_address(ptr %begin)131 call void @await_suspend()132 %final.suspend.coro.suspend = call i8 @llvm.coro.suspend(token %final.suspend.coro.save, i1 true)133 switch i8 %final.suspend.coro.suspend, label %coro.ret [134 i8 0, label %final.ready135 i8 1, label %final.cleanup136 ]137 138final.cleanup: ; preds = %final.suspend139 br label %cleanup140 141final.ready: ; preds = %final.suspend, %coro.final142 call void @await_resume()143 br label %cleanup144 145cleanup: ; preds = %final.ready, %final.cleanup, %await.cleanup, %init.cleanup146 %cleanup.dest.slot.0 = phi i32 [ 0, %final.ready ], [ 2, %final.cleanup ], [ 2, %await.cleanup ], [ 2, %init.cleanup ]147 %free.memory = call ptr @llvm.coro.free(token %id, ptr %begin)148 %free = icmp ne ptr %free.memory, null149 br i1 %free, label %coro.free, label %after.coro.free150 151coro.free: ; preds = %cleanup152 call void @delete(ptr %free.memory)153 br label %after.coro.free154 155after.coro.free: ; preds = %coro.free, %cleanup156 switch i32 %cleanup.dest.slot.0, label %unreachable [157 i32 0, label %cleanup.cont158 i32 2, label %coro.ret159 ]160 161cleanup.cont: ; preds = %after.coro.free162 br label %coro.ret163 164coro.ret: ; preds = %cleanup.cont, %after.coro.free, %final.suspend, %await.suspend, %init.suspend165 call void @llvm.coro.end(ptr null, i1 false, token none)166 ret void167 168unreachable: ; preds = %after.coro.free169 unreachable170}171 172; Function Attrs: nofree nosync nounwind readnone speculatable willreturn173declare void @llvm.dbg.declare(metadata, metadata, metadata) #0174 175; Function Attrs: argmemonly nounwind readonly176declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1177 178; Function Attrs: nounwind179declare i1 @llvm.coro.alloc(token) #2180 181; Function Attrs: nounwind readnone182declare i64 @llvm.coro.size.i64() #3183 184; Function Attrs: nounwind185declare token @llvm.coro.save(ptr) #2186 187; Function Attrs: nounwind188declare ptr @llvm.coro.begin(token, ptr writeonly) #2189 190; Function Attrs: nounwind191declare i8 @llvm.coro.suspend(token, i1) #2192 193; Function Attrs: argmemonly nounwind readonly194declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1195 196; Function Attrs: nounwind197declare void @llvm.coro.end(ptr, i1, token) #2198 199declare ptr @new(i64)200 201declare void @delete(ptr)202 203declare i1 @await_ready()204 205declare void @await_suspend()206 207declare void @await_resume()208 209declare void @print(i32)210 211declare ptr @from_address(ptr)212 213declare void @return_void()214 215declare void @final_suspend()216 217declare i32 @value_producer()218 219; Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly220declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4221 222; Function Attrs: nofree nosync nounwind readnone speculatable willreturn223declare void @llvm.dbg.value(metadata, metadata, metadata) #0224 225attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }226attributes #1 = { argmemonly nounwind readonly }227attributes #2 = { nounwind }228attributes #3 = { nounwind readnone }229attributes #4 = { argmemonly nofree nosync nounwind willreturn writeonly }230 231!llvm.dbg.cu = !{!0}232!llvm.linker.options = !{}233!llvm.module.flags = !{!3, !4}234!llvm.ident = !{!5}235 236!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)237!1 = !DIFile(filename: "repro.cpp", directory: ".")238!2 = !{}239!3 = !{i32 7, !"Dwarf Version", i32 4}240!4 = !{i32 2, !"Debug Info Version", i32 3}241!5 = !{!"clang version 11.0.0"}242!6 = !DILocalVariable(name: "i", scope: !7, file: !1, line: 24, type: !10)243!7 = distinct !DILexicalBlock(scope: !8, file: !1, line: 23, column: 12)244!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)245!9 = !DISubroutineType(types: !2)246!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)247!11 = !DILocation(line: 0, scope: !7)248!12 = !DILocalVariable(name: "x", scope: !13, file: !1, line: 34, type: !14)249!13 = distinct !DILexicalBlock(scope: !8, file: !1, line: 23, column: 12)250!14 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, size: 320, elements: !15)251!15 = !{!16}252!16 = !DISubrange(count: 10)253!17 = !DILocation(line: 24, column: 7, scope: !7)254!18 = !DILocalVariable(name: "j", scope: !7, file: !1, line: 32, type: !10)255!19 = !DILocation(line: 42, column: 3, scope: !7)256!20 = !DILocation(line: 42, column: 8, scope: !7)257!21 = !DILocation(line: 43, column: 3, scope: !7)258!22 = !DILocation(line: 43, column: 8, scope: !7)259!23 = !DILocalVariable(name: "produced", scope: !7, file: !1, line:24, type: !10)260!30 = distinct !DIAssignID()261