1 ; RUN: llvm-link %s %S/Inputs/subprogram-linkonce-weak.ll -S -o %t1 2 ; RUN: FileCheck %s -check-prefix=LW -check-prefix=CHECK <%t1 3 ; RUN: llvm-link %S/Inputs/subprogram-linkonce-weak.ll %s -S -o %t2 4 ; RUN: FileCheck %s -check-prefix=WL -check-prefix=CHECK <%t2 5 ; REQUIRES: default_triple 6 7 ; This testcase tests the following flow: 8 ; - File A defines a linkonce version of @foo which has inlined into @bar. 9 ; - File B defines a weak version of @foo (different definition). 10 ; - Linkage rules state File B version of @foo wins. 11 ; - @bar still has inlined debug info related to the linkonce @foo. 12 ; 13 ; This should fix PR22792, although the testcase was hand-written. There's a 14 ; RUN line with a crasher for llc at the end with checks for the DWARF output. 15 16 ; The LW prefix means linkonce (this file) first, then weak (the other file). 17 ; The WL prefix means weak (the other file) first, then linkonce (this file). 18 19 ; We'll see @bar before @foo if this file is first. 20 ; LW: define i32 @bar({{.*}} !dbg ![[BARSP:[0-9]+]] 21 ; LW: %sum = add i32 %a, %b, !dbg ![[FOOINBAR:[0-9]+]] 22 ; LW: ret i32 %sum, !dbg ![[BARRET:[0-9]+]] 23 ; LW: define weak i32 @foo({{.*}} !dbg ![[WEAKFOOSP:[0-9]+]] 24 ; LW: %sum = call i32 @fastadd(i32 %a, i32 %b), !dbg ![[FOOCALL:[0-9]+]] 25 ; LW: ret i32 %sum, !dbg ![[FOORET:[0-9]+]] 26 27 ; We'll see @foo before @bar if this file is second. 28 ; WL: define weak i32 @foo({{.*}} !dbg ![[WEAKFOOSP:[0-9]+]] 29 ; WL: %sum = call i32 @fastadd(i32 %a, i32 %b), !dbg ![[FOOCALL:[0-9]+]] 30 ; WL: ret i32 %sum, !dbg ![[FOORET:[0-9]+]] 31 ; WL: define i32 @bar({{.*}} !dbg ![[BARSP:[0-9]+]] 32 ; WL: %sum = add i32 %a, %b, !dbg ![[FOOINBAR:[0-9]+]] 33 ; WL: ret i32 %sum, !dbg ![[BARRET:[0-9]+]] 34 35 define i32 @bar(i32 %a, i32 %b) !dbg !3 { 36 entry: 37 %sum = add i32 %a, %b, !dbg !DILocation(line: 2, scope: !4, 38 inlinedAt: !DILocation(line: 12, scope: !3)) 39 ret i32 %sum, !dbg !DILocation(line: 13, scope: !3) 40 } 41 42 define linkonce i32 @foo(i32 %a, i32 %b) !dbg !4 { 43 entry: 44 %sum = add i32 %a, %b, !dbg !DILocation(line: 2, scope: !4) 45 ret i32 %sum, !dbg !DILocation(line: 3, scope: !4) 46 } 47 48 !llvm.module.flags = !{!0} 49 !0 = !{i32 2, !"Debug Info Version", i32 3} 50 51 ; CHECK-LABEL: !llvm.dbg.cu = 52 ; LW-SAME: !{![[LCU:[0-9]+]], ![[WCU:[0-9]+]]} 53 ; WL-SAME: !{![[WCU:[0-9]+]], ![[LCU:[0-9]+]]} 54 !llvm.dbg.cu = !{!1} 55 56 ; LW: ![[LCU]] = distinct !DICompileUnit( 57 ; LW: ![[WCU]] = distinct !DICompileUnit( 58 ; LW: ![[BARSP]] = distinct !DISubprogram(name: "bar",{{.*}} unit: ![[LCU]] 59 ; LW: ![[FOOINBAR]] = !DILocation(line: 2, scope: ![[FOOSP:.*]], inlinedAt: ![[BARIA:[0-9]+]]) 60 ; LW: ![[FOOSP]] = distinct !DISubprogram(name: "foo",{{.*}} unit: ![[LCU]] 61 ; LW: ![[BARIA]] = !DILocation(line: 12, scope: ![[BARSP]]) 62 ; LW: ![[BARRET]] = !DILocation(line: 13, scope: ![[BARSP]]) 63 ; LW: ![[WEAKFOOSP]] = distinct !DISubprogram(name: "foo",{{.*}} unit: ![[WCU]] 64 ; LW: ![[FOOCALL]] = !DILocation(line: 52, scope: ![[WEAKFOOSP]]) 65 ; LW: ![[FOORET]] = !DILocation(line: 53, scope: ![[WEAKFOOSP]]) 66 67 ; Same as above, but reordered. 68 ; WL: ![[WCU]] = distinct !DICompileUnit( 69 ; WL: ![[LCU]] = distinct !DICompileUnit( 70 ; WL: ![[WEAKFOOSP]] = distinct !DISubprogram(name: "foo",{{.*}} unit: ![[WCU]] 71 ; WL: ![[FOOCALL]] = !DILocation(line: 52, scope: ![[WEAKFOOSP]]) 72 ; WL: ![[FOORET]] = !DILocation(line: 53, scope: ![[WEAKFOOSP]]) 73 ; WL: ![[BARSP]] = distinct !DISubprogram(name: "bar",{{.*}} unit: ![[LCU]] 74 ; WL: ![[FOOINBAR]] = !DILocation(line: 2, scope: ![[FOOSP:.*]], inlinedAt: ![[BARIA:[0-9]+]]) 75 ; WL: ![[FOOSP]] = distinct !DISubprogram(name: "foo",{{.*}} unit: ![[LCU]] 76 ; WL: ![[BARIA]] = !DILocation(line: 12, scope: ![[BARSP]]) 77 ; WL: ![[BARRET]] = !DILocation(line: 13, scope: ![[BARSP]]) 78 79 !1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, emissionKind: FullDebug) 80 !2 = !DIFile(filename: "bar.c", directory: "/path/to/dir") 81 !3 = distinct !DISubprogram(file: !2, scope: !2, line: 11, name: "bar", type: !5, unit: !1) 82 !4 = distinct !DISubprogram(file: !2, scope: !2, line: 1, name: "foo", type: !5, unit: !1) 83 !5 = !DISubroutineType(types: !{}) 84 85 ; Crasher for llc. 86 ; REQUIRES: object-emission 87 ; RUN: %llc_dwarf -filetype=obj -O0 %t1 -o %t1.o 88 ; RUN: llvm-dwarfdump %t1.o --all | FileCheck %s -check-prefix=DWLW -check-prefix=DW 89 ; RUN: %llc_dwarf -filetype=obj -O0 %t2 -o %t2.o 90 ; RUN: llvm-dwarfdump %t2.o --all | FileCheck %s -check-prefix=DWWL -check-prefix=DW 91 ; Check that the debug info for the discarded linkonce version of @foo doesn't 92 ; reference any code, and that the other subprograms look correct. 93 94 ; DW-LABEL: .debug_info contents: 95 ; DWLW: DW_TAG_compile_unit 96 ; DWLW: DW_AT_name {{.*}}"bar.c" 97 ; DWLW: DW_TAG_subprogram 98 ; DWLW-NOT: DW_AT_low_pc 99 ; DWLW-NOT: DW_AT_high_pc 100 ; DWLW: DW_AT_name {{.*}}foo 101 ; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c" 102 ; DWLW: DW_AT_decl_line {{.*}}(1) 103 ; DWLW: DW_TAG_subprogram 104 ; DWLW: DW_AT_low_pc 105 ; DWLW: DW_AT_high_pc 106 ; DWLW: DW_AT_name {{.*}}bar 107 ; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c" 108 ; DWLW: DW_AT_decl_line {{.*}}(11) 109 110 ; DWLW: DW_TAG_inlined_subroutine 111 ; DWLW: DW_AT_abstract_origin 112 ; DWLW: DW_TAG_compile_unit 113 ; DWLW: DW_AT_name {{.*}}"foo.c" 114 ; DWLW: DW_TAG_subprogram 115 ; DWLW: DW_AT_low_pc 116 ; DWLW: DW_AT_high_pc 117 ; DWLW: DW_AT_name {{.*}}foo 118 ; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}foo.c" 119 ; DWLW: DW_AT_decl_line {{.*}}(51) 120 121 ; The DWARF output is already symmetric (just reordered). 122 ; DWWL: DW_TAG_compile_unit 123 ; DWWL: DW_AT_name {{.*}}"foo.c" 124 ; DWWL: DW_TAG_subprogram 125 ; DWWL: DW_AT_low_pc 126 ; DWWL: DW_AT_high_pc 127 ; DWWL: DW_AT_name {{.*}}foo 128 ; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}foo.c" 129 ; DWWL: DW_AT_decl_line {{.*}}(51) 130 ; DWWL: DW_TAG_compile_unit 131 ; DWWL: DW_AT_name {{.*}}"bar.c" 132 ; DWWL: DW_TAG_subprogram 133 ; DWWL-NOT: DW_AT_low_pc 134 ; DWWL-NOT: DW_AT_high_pc 135 ; DWWL: DW_AT_name {{.*}}foo 136 ; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c" 137 ; DWWL: DW_AT_decl_line {{.*}}(1) 138 ; DWWL: DW_TAG_subprogram 139 ; DWWL: DW_AT_low_pc 140 ; DWWL: DW_AT_high_pc 141 ; DWWL: DW_AT_name {{.*}}bar 142 ; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c" 143 ; DWWL: DW_AT_decl_line {{.*}}(11) 144 ; DWWL: DW_TAG_inlined_subroutine 145 ; DWWL: DW_AT_abstract_origin 146 147 ; DW-LABEL: .debug_line contents: 148 ; Check that we have the right things in the line table as well. 149 150 ; DWLW-LABEL: file_names[ 1]: 151 ; DWLW-NEXT: name: "bar.c" 152 ; DWLW: 2 0 1 0 0 is_stmt prologue_end 153 ; DWLW-LABEL: file_names[ 1]: 154 ; DWLW-NEXT: name: "foo.c" 155 ; DWLW: 52 0 1 0 0 is_stmt prologue_end 156 ; DWLW-NOT: prologue_end 157 158 ; DWWL-LABEL: file_names[ 1]: 159 ; DWWL-NEXT: name: "foo.c" 160 ; DWWL: 52 0 1 0 0 is_stmt prologue_end 161 ; DWWL-LABEL: file_names[ 1]: 162 ; DWWL-NEXT: name: "bar.c" 163 ; DWWL: 2 0 1 0 0 is_stmt prologue_end 164 ; DWWL-NOT: prologue_end 165