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