1; RUN: opt -passes='cgscc(inline)' -S %s -o - -S | FileCheck %s --implicit-check-not=dbg.value 2; RUN: opt -passes='cgscc(inline)' -S %s -o - -S --try-experimental-debuginfo-iterators | FileCheck %s --implicit-check-not=dbg.value 3 4;; Test that dbg.value intrinsics are inlined, remapped, and have their 5;; dilocation updated just like normal instructions. This becomes 6;; important when debug-info records case to be instructions. 7;; 8;; test should be inlined into test2 9 10; CHECK: define i32 @test2 11; CHECK-NEXT: entry: 12; CHECK: %k.addr.i = alloca i32, align 4 13; CHECK: %k2.i = alloca i32, align 4 14; CHECK: %0 = load i32, ptr @global_var, align 4, !dbg !9 15; CHECK: store i32 %0, ptr %k.addr.i, align 4 16; CHECK-NEXT: #dbg_value(ptr %k.addr.i, ![[KVAR:[0-9]+]], !DIExpression(), ![[KLINE:[0-9]+]] 17; CHECK-NEXT: #dbg_value(ptr %k2.i, ![[K2VAR:[0-9]+]], !DIExpression(), ![[GLINE:[0-9]+]] 18; CHECK-NEXT: %1 = load i32, ptr %k.addr.i, align 4, 19;; 20;; dbg.values in this block should be remapped to the local load, but also 21;; the Argument to the calling test2 function. 22;; 23; CHECK: if.then.i: 24; CHECK-NEXT: %3 = load i32, ptr %k2.i, 25; CHECK-NEXT: #dbg_value(i32 %3, ![[KVAR]], !DIExpression(), ![[KLINE]] 26; CHECK-NEXT: #dbg_value(i32 %foo, ![[K2VAR]], !DIExpression(), ![[GLINE]] 27; 28;; Similarly, the end block should retain remapped dbg.values, with the second 29;; referring to the @global_var load in the entry block. Check that we clone 30;; from the terminator correctly. 31; 32; CHECK: if.end.i: 33; CHECK-NEXT: store i32 0, ptr %retval.i, align 4, 34; CHECK-NEXT: #dbg_value(i32 0, ![[KVAR]], !DIExpression(), ![[KLINE]] 35; CHECK-NEXT: #dbg_value(i32 %0, ![[K2VAR]], !DIExpression(), ![[GLINE]] 36; CHECK-NEXT: br label %test.exit, 37; 38;; More or less the same checks again in the exit block, this time at the head 39;; of the block, and on a terminator that gets elided. 40; 41; CHECK: test.exit: 42; CHECK-NEXT: #dbg_value(i32 %0, ![[KVAR]], !DIExpression(), ![[KLINE]] 43; CHECK-NEXT: #dbg_value(i32 %bar, ![[K2VAR]], !DIExpression(), ![[GLINE]] 44; CHECK-NEXT: %4 = load i32, ptr %retval.i, align 4, 45; CHECK-NEXT: #dbg_value(i32 1, ![[KVAR]], !DIExpression(), ![[KLINE]] 46; CHECK-NEXT: #dbg_value(i32 1, ![[K2VAR]], !DIExpression(), ![[GLINE]] 47; 48; 49;; Test that the metadata maps onto the correct things, and that the DILocations 50;; attached to the intrinsics have been inlined. 51; 52; CHECK-DAG: ![[TEST2SP:[0-9]+]] = distinct !DISubprogram(name: "test2", 53; CHECK-DAG: ![[INLINESITEBLOCK:[0-9]+]] = distinct !DILexicalBlock(scope: ![[TEST2SP]], 54; CHECK-DAG: ![[TESTSP:[0-9]+]] = distinct !DISubprogram(name: "test", 55; CHECK-DAG: ![[KVAR]] = !DILocalVariable(name: "k", 56; CHECK-DAG: ![[K2VAR]] = !DILocalVariable(name: "k2", 57; CHECK-DAG: ![[KLINE]] = !DILocation(line: 4, scope: ![[TESTSP]], inlinedAt: ![[INLINESITE:[0-9]+]]) 58; CHECK-DAG: ![[INLINESITE]] = distinct !DILocation(line: 14, scope: ![[INLINESITEBLOCK]]) 59; CHECK-DAG: ![[GLINE]] = !DILocation(line: 5, scope: ![[TESTSP]], inlinedAt: ![[INLINESITE:[0-9]+]]) 60 61target triple = "x86_64--" 62 63@global_var = external global i32 64 65define internal i32 @test(i32 %k, i32 %foo, i32 %bar) !dbg !4 { 66entry: 67 %retval = alloca i32, align 4 68 %k.addr = alloca i32, align 4 69 %k2 = alloca i32, align 4 70 store i32 %k, ptr %k.addr, align 4 71 call void @llvm.dbg.value(metadata ptr %k.addr, metadata !13, metadata !DIExpression()), !dbg !14 72 call void @llvm.dbg.value(metadata ptr %k2, metadata !15, metadata !DIExpression()), !dbg !16 73 %0 = load i32, ptr %k.addr, align 4, !dbg !16 74 %call = call i32 @_Z8test_exti(i32 %0), !dbg !16 75 store i32 %call, ptr %k2, align 4, !dbg !16 76 %1 = load i32, ptr %k2, align 4, !dbg !17 77 %cmp = icmp sgt i32 %1, 100, !dbg !17 78 br i1 %cmp, label %if.then, label %if.end, !dbg !17 79 80if.then: ; preds = %entry 81 %2 = load i32, ptr %k2, align 4, !dbg !18 82 call void @llvm.dbg.value(metadata i32 %2, metadata !13, metadata !DIExpression()), !dbg !14 83 call void @llvm.dbg.value(metadata i32 %foo, metadata !15, metadata !DIExpression()), !dbg !16 84 store i32 %2, ptr %retval, !dbg !18 85 br label %return, !dbg !18 86 87if.end: ; preds = %entry 88 store i32 0, ptr %retval, !dbg !19 89 call void @llvm.dbg.value(metadata i32 0, metadata !13, metadata !DIExpression()), !dbg !14 90 call void @llvm.dbg.value(metadata i32 %k, metadata !15, metadata !DIExpression()), !dbg !16 91 br label %return, !dbg !19 92 93return: ; preds = %if.end, %if.then 94 call void @llvm.dbg.value(metadata i32 %k, metadata !13, metadata !DIExpression()), !dbg !14 95 call void @llvm.dbg.value(metadata i32 %bar, metadata !15, metadata !DIExpression()), !dbg !16 96 %3 = load i32, ptr %retval, !dbg !20 97 call void @llvm.dbg.value(metadata i32 1, metadata !13, metadata !DIExpression()), !dbg !14 98 call void @llvm.dbg.value(metadata i32 1, metadata !15, metadata !DIExpression()), !dbg !16 99 ret i32 %3, !dbg !20 100} 101 102declare i32 @_Z8test_exti(i32) 103 104define i32 @test2(i32 %foo, i32 %bar) !dbg !10 { 105entry: 106 %exn.slot = alloca ptr 107 %ehselector.slot = alloca i32 108 %e = alloca i32, align 4 109 %0 = load i32, ptr @global_var, align 4, !dbg !21 110 %call = call i32 @test(i32 %0, i32 %foo, i32 %bar), !dbg !21 111 br label %try.cont, !dbg !23 112 113try.cont: ; preds = %catch, %invoke.cont 114 store i32 1, ptr @global_var, align 4, !dbg !29 115 ret i32 0, !dbg !30 116} 117 118declare void @llvm.dbg.value(metadata, metadata, metadata) #1 119 120!llvm.dbg.cu = !{!0} 121!llvm.module.flags = !{!31} 122 123!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.3 ", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2) 124!1 = !DIFile(filename: "<unknown>", directory: "") 125!2 = !{} 126!4 = distinct !DISubprogram(name: "test", linkageName: "_Z4testi", line: 4, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 4, file: !5, scope: !6, type: !7, retainedNodes: !2) 127!5 = !DIFile(filename: "test.cpp", directory: "") 128!6 = !DIFile(filename: "test.cpp", directory: "") 129!7 = !DISubroutineType(types: !8) 130!8 = !{!9, !9} 131!9 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 132!10 = distinct !DISubprogram(name: "test2", linkageName: "_Z5test2v", line: 11, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 11, file: !5, scope: !6, type: !11, retainedNodes: !2) 133!11 = !DISubroutineType(types: !12) 134!12 = !{!9} 135!13 = !DILocalVariable(name: "k", line: 4, arg: 1, scope: !4, file: !6, type: !9) 136!14 = !DILocation(line: 4, scope: !4) 137!15 = !DILocalVariable(name: "k2", line: 5, scope: !4, file: !6, type: !9) 138!16 = !DILocation(line: 5, scope: !4) 139!17 = !DILocation(line: 6, scope: !4) 140!18 = !DILocation(line: 7, scope: !4) 141!19 = !DILocation(line: 8, scope: !4) 142!20 = !DILocation(line: 9, scope: !4) 143!21 = !DILocation(line: 14, scope: !22) 144!22 = distinct !DILexicalBlock(line: 13, column: 0, file: !5, scope: !10) 145!23 = !DILocation(line: 15, scope: !22) 146!24 = !DILocalVariable(name: "e", line: 16, scope: !10, file: !6, type: !9) 147!25 = !DILocation(line: 16, scope: !10) 148!26 = !DILocation(line: 17, scope: !27) 149!27 = distinct !DILexicalBlock(line: 16, column: 0, file: !5, scope: !10) 150!28 = !DILocation(line: 18, scope: !27) 151!29 = !DILocation(line: 19, scope: !10) 152!30 = !DILocation(line: 20, scope: !10) 153!31 = !{i32 1, !"Debug Info Version", i32 3} 154