211 lines · plain
1; Tests that debug information is sane after coro-split2; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s3 4source_filename = "simple-repro.c"5target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"6target triple = "x86_64-unknown-linux-gnu"7 8; Function Attrs: noinline nounwind9define ptr @flink(i32 %x) #0 personality i32 0 !dbg !6 {10entry:11 %x.addr = alloca i32, align 412 %coro_hdl = alloca ptr, align 813 store i32 %x, ptr %x.addr, align 414 %0 = call token @llvm.coro.id(i32 0, ptr null, ptr @flink, ptr null), !dbg !1615 %1 = call i64 @llvm.coro.size.i64(), !dbg !1616 %call = call ptr @malloc(i64 %1), !dbg !1617 %2 = call ptr @llvm.coro.begin(token %0, ptr %call), !dbg !1618 store ptr %2, ptr %coro_hdl, align 8, !dbg !1619 %3 = call i8 @llvm.coro.suspend(token none, i1 false), !dbg !1720 %conv = sext i8 %3 to i32, !dbg !1721 %late_local = alloca i32, align 422 switch i32 %conv, label %sw.default [23 i32 0, label %sw.bb24 i32 1, label %sw.bb125 ], !dbg !1726 27sw.bb: ; preds = %entry28 %direct = load i32, ptr %x.addr, align 4, !dbg !1429 %gep = getelementptr inbounds [16 x i8], ptr undef, i32 %direct, !dbg !1430 call void @llvm.dbg.declare(metadata ptr %gep, metadata !27, metadata !13), !dbg !1431 call void @llvm.dbg.value(metadata i32 %conv, metadata !26, metadata !13), !dbg !1432 call void @llvm.dbg.value(metadata i32 %direct, metadata !25, metadata !13), !dbg !1433 call void @llvm.dbg.declare(metadata ptr %x.addr, metadata !12, metadata !13), !dbg !1434 call void @llvm.dbg.declare(metadata ptr %coro_hdl, metadata !15, metadata !13), !dbg !1635 call void @llvm.dbg.declare(metadata ptr %late_local, metadata !29, metadata !13), !dbg !1636 call void @llvm.dbg.value(metadata i32 %direct, metadata !30, metadata !13), !dbg !1437 ; don't crash when encountering nonsensical debug info, verfifier doesn't yet reject these38 call void @llvm.dbg.declare(metadata ptr null, metadata !28, metadata !13), !dbg !1639 call void @llvm.dbg.declare(metadata !{}, metadata !28, metadata !13), !dbg !1640 %new_storgae = invoke ptr @allocate()41 to label %next unwind label %ehcleanup, !dbg !1842 43next:44 br label %sw.epilog, !dbg !1845 46sw.bb1: ; preds = %entry47 br label %coro_Cleanup, !dbg !1848 49sw.default: ; preds = %entry50 br label %coro_Suspend, !dbg !1851 52sw.epilog: ; preds = %sw.bb53 call void @llvm.dbg.declare(metadata ptr %new_storgae, metadata !31, metadata !13), !dbg !1654 %4 = load i32, ptr %x.addr, align 4, !dbg !2055 %add = add nsw i32 %4, 1, !dbg !2156 store i32 %add, ptr %x.addr, align 4, !dbg !2257 %asm_res = callbr i32 asm "", "=r,r,!i"(i32 %x)58 to label %coro_Cleanup [label %indirect.dest]59 60indirect.dest:61 call void @log(), !dbg !1862 br label %coro_Cleanup63 64coro_Cleanup: ; preds = %sw.epilog, %sw.bb165 %5 = load ptr, ptr %coro_hdl, align 8, !dbg !2466 %6 = call ptr @llvm.coro.free(token %0, ptr %5), !dbg !2467 call void @free(ptr %6), !dbg !2468 call void @llvm.dbg.value(metadata i32 %asm_res, metadata !32, metadata !13), !dbg !1669 br label %coro_Suspend, !dbg !2470 71coro_Suspend: ; preds = %coro_Cleanup, %sw.default72 call void @llvm.coro.end(ptr null, i1 false, token none), !dbg !2473 %7 = load ptr, ptr %coro_hdl, align 8, !dbg !2474 store i32 0, ptr %late_local, !dbg !2475 ret ptr %7, !dbg !2476 77ehcleanup:78 %ex = landingpad { ptr, i32 }79 catch ptr null80 call void @print({ ptr, i32 } %ex)81 unreachable82}83 84; Function Attrs: nounwind readnone speculatable85declare void @llvm.dbg.value(metadata, metadata, metadata)86 87; Function Attrs: nounwind readnone speculatable88declare void @llvm.dbg.declare(metadata, metadata, metadata)89 90; Function Attrs: argmemonly nounwind readonly91declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)92 93declare ptr @malloc(i64)94declare ptr @allocate() 95declare void @print({ ptr, i32 })96declare void @log()97 98; Function Attrs: nounwind readnone99declare i64 @llvm.coro.size.i64()100 101; Function Attrs: nounwind102declare ptr @llvm.coro.begin(token, ptr writeonly)103 104; Function Attrs: nounwind105declare i8 @llvm.coro.suspend(token, i1)106 107declare void @free(ptr)108 109; Function Attrs: argmemonly nounwind readonly110declare ptr @llvm.coro.free(token, ptr nocapture readonly)111 112; Function Attrs: nounwind113declare void @llvm.coro.end(ptr, i1, token)114 115; Function Attrs: argmemonly nounwind readonly116declare ptr @llvm.coro.subfn.addr(ptr nocapture readonly, i8)117 118attributes #0 = { noinline nounwind presplitcoroutine }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 5.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)125!1 = !DIFile(filename: "<stdin>", directory: "C:\5CGitHub\5Cllvm\5Cbuild\5CDebug\5Cbin")126!2 = !{}127!3 = !{i32 2, !"Dwarf Version", i32 4}128!4 = !{i32 2, !"Debug Info Version", i32 3}129!5 = !{!"clang version 5.0.0"}130!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))131!7 = !DIFile(filename: "simple-repro.c", directory: "C:\5CGitHub\5Cllvm\5Cbuild\5CDebug\5Cbin")132!8 = !DISubroutineType(types: !9)133!9 = !{!10, !11}134!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)135!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)136!12 = !DILocalVariable(name: "x", arg: 1, scope: !6, file: !7, line: 55, type: !11)137!13 = !DIExpression()138!14 = !DILocation(line: 55, column: 13, scope: !6)139!15 = !DILocalVariable(name: "coro_hdl", scope: !6, file: !7, line: 56, type: !10)140!16 = !DILocation(line: 56, column: 3, scope: !6)141!17 = !DILocation(line: 58, column: 5, scope: !6)142!18 = !DILocation(line: 58, column: 5, scope: !19)143!19 = distinct !DILexicalBlock(scope: !6, file: !7, line: 58, column: 5)144!20 = !DILocation(line: 59, column: 9, scope: !6)145!21 = !DILocation(line: 59, column: 10, scope: !6)146!22 = !DILocation(line: 59, column: 7, scope: !6)147!23 = !DILocation(line: 59, column: 5, scope: !6)148!24 = !DILocation(line: 62, column: 3, scope: !6)149; These variables were added manually.150!25 = !DILocalVariable(name: "direct_mem", scope: !6, file: !7, line: 55, type: !11)151!26 = !DILocalVariable(name: "direct_const", scope: !6, file: !7, line: 55, type: !11)152!27 = !DILocalVariable(name: "undefined", scope: !6, file: !7, line: 55, type: !11)153!28 = !DILocalVariable(name: "null", scope: !6, file: !7, line: 55, type: !11)154!29 = !DILocalVariable(name: "partial_dead", scope: !6, file: !7, line: 55, type: !11)155!30 = !DILocalVariable(name: "direct_value", scope: !6, file: !7, line: 55, type: !11)156!31 = !DILocalVariable(name: "allocated", scope: !6, file: !7, line: 55, type: !11)157!32 = !DILocalVariable(name: "inline_asm", scope: !6, file: !7, line: 55, type: !11)158 159; Check that the original function is visible and capture its debug info id.160; CHECK: define ptr @flink(i32 %x) #0 personality i32 0 !dbg ![[ORIG:[0-9]+]]161 162; Check that the resume function is present and capture its debug info id.163; Also check that it contains `#dbg_declare` and `#dbg_value` debug instructions164; making the debug variables available to the debugger.165;166; CHECK: define internal fastcc void @flink.resume(ptr noundef nonnull align 8 dereferenceable(40) %0) #0 personality i32 0 !dbg ![[RESUME:[0-9]+]]167; CHECK: entry.resume:168; CHECK: %[[DBG_PTR:.*]] = alloca ptr169; CHECK-NEXT: #dbg_declare(ptr %[[DBG_PTR]], ![[RESUME_COROHDL:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst,170; CHECK-NEXT: #dbg_declare(ptr %[[DBG_PTR]], ![[RESUME_X:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[EXPR_TAIL:.*]])171; CHECK-NEXT: store ptr {{.*}}, ptr %[[DBG_PTR]]172; CHECK-NOT: alloca ptr173; 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),174; CHECK: #dbg_value(ptr %[[DBG_PTR]], ![[RESUME_DIRECT:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref),175; Note that keeping the undef value here could be acceptable, too.176; CHECK-NOT: #dbg_declare(ptr undef, !{{[0-9]+}}, !DIExpression(),177; CHECK: #dbg_value(ptr %[[DBG_PTR]], ![[RESUME_DIRECT_VALUE:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref),178; Check that the dbg.declare intrinsic of invoke instruction is hanled correctly.179; CHECK: %[[ALLOCATED_STORAGE:.+]] = invoke ptr @allocate()180; CHECK-NEXT: to label %[[NORMAL_DEST:.+]] unwind181; CHECK: [[NORMAL_DEST]]182; CHECK-NEXT: #dbg_declare(ptr %[[ALLOCATED_STORAGE]]183; CHECK: %[[CALLBR_RES:.+]] = callbr i32 asm184; CHECK-NEXT: to label %[[DEFAULT_DEST:.+]] [label185; CHECK: [[DEFAULT_DEST]]:186; CHECK-NOT: {{.*}}:187; CHECK: #dbg_value(i32 %[[CALLBR_RES]]188 189; Check that the destroy and cleanup functions are present and capture their debug info id.190;191; CHECK: define internal fastcc void @flink.destroy(ptr noundef nonnull align 8 dereferenceable(40) %0) #0 personality i32 0 !dbg ![[DESTROY:[0-9]+]]192; CHECK: define internal fastcc void @flink.cleanup(ptr noundef nonnull align 8 dereferenceable(40) %0) #0 personality i32 0 !dbg ![[CLEANUP:[0-9]+]]193 194; Check that the linkage name of the original function is set correctly.195;196; CHECK: ![[ORIG]] = distinct !DISubprogram(name: "f", linkageName: "flink"197; CHECK: ![[RESUME]] = distinct !DISubprogram(name: "f", linkageName: "flink.resume"198 199; Check that metadata for local variables in the resume function is set correctly.200;201; CHECK: ![[RESUME_COROHDL]] = !DILocalVariable(name: "coro_hdl", scope: ![[RESUME]]202; CHECK: ![[RESUME_X]] = !DILocalVariable(name: "x", arg: 1, scope: ![[RESUME]]203; CHECK: ![[RESUME_CONST]] = !DILocalVariable(name: "direct_const", scope: ![[RESUME]]204; CHECK: ![[RESUME_DIRECT]] = !DILocalVariable(name: "direct_mem", scope: ![[RESUME]]205; CHECK: ![[RESUME_DIRECT_VALUE]] = !DILocalVariable(name: "direct_value", scope: ![[RESUME]]206 207; Check that the linkage names are set correctly for the destroy and cleanup functions.208;209; CHECK: ![[DESTROY]] = distinct !DISubprogram(name: "f", linkageName: "flink.destroy"210; CHECK: ![[CLEANUP]] = distinct !DISubprogram(name: "f", linkageName: "flink.cleanup"211