1; RUN: llvm-link %s %S/Inputs/subprogram-linkonce-weak-odr.ll -S -o %t1 2; RUN: FileCheck %s -check-prefix=LW -check-prefix=CHECK <%t1 3; RUN: llvm-link %S/Inputs/subprogram-linkonce-weak-odr.ll %s -S -o %t2 4; RUN: FileCheck %s -check-prefix=WL -check-prefix=CHECK <%t2 5 6; This testcase tests the following flow: 7; - File A defines a linkonce_odr version of @foo which has inlined into @bar. 8; - File B defines a weak_odr version of @foo (identical definition). 9; - Linkage rules state File B version of @foo wins. 10; - Debug info for the subprograms of @foo match exactly. Without 11; intervention, the same subprogram would show up in both compile units, and 12; it would get associated with the compile unit where it was linkonce. 13; - @bar has inlined debug info related to the linkonce_odr @foo. 14; 15; This checks a corner case for the fix for PR22792, where subprograms match 16; exactly. It's a companion for subprogram-linkonce-weak.ll. 17 18; The LW prefix means linkonce (this file) first, then weak (the other file). 19; The WL prefix means weak (the other file) first, then linkonce (this file). 20 21; We'll see @bar before @foo if this file is first. 22; LW-LABEL: define i32 @bar( 23; LW: %sum = add i32 %a, %b, !dbg ![[FOOINBAR:[0-9]+]] 24; LW: ret i32 %sum, !dbg ![[BARRET:[0-9]+]] 25; LW-LABEL: define weak_odr i32 @foo( 26; LW: %sum = add i32 %a, %b, !dbg ![[FOOADD:[0-9]+]] 27; LW: ret i32 %sum, !dbg ![[FOORET:[0-9]+]] 28 29; We'll see @foo before @bar if this file is second. 30; WL-LABEL: define weak_odr i32 @foo( 31; WL: %sum = add i32 %a, %b, !dbg ![[FOOADD:[0-9]+]] 32; WL: ret i32 %sum, !dbg ![[FOORET:[0-9]+]] 33; WL-LABEL: define i32 @bar( 34; WL: %sum = add i32 %a, %b, !dbg ![[FOOINBAR:[0-9]+]] 35; WL: ret i32 %sum, !dbg ![[BARRET:[0-9]+]] 36 37define i32 @bar(i32 %a, i32 %b) { 38entry: 39 %sum = add i32 %a, %b, !dbg !MDLocation(line: 2, scope: !4, 40 inlinedAt: !MDLocation(line: 12, scope: !3)) 41 ret i32 %sum, !dbg !MDLocation(line: 13, scope: !3) 42} 43 44define linkonce_odr i32 @foo(i32 %a, i32 %b) { 45entry: 46 %sum = add i32 %a, %b, !dbg !MDLocation(line: 2, scope: !4) 47 ret i32 %sum, !dbg !MDLocation(line: 3, scope: !4) 48} 49 50!llvm.module.flags = !{!0} 51!0 = !{i32 2, !"Debug Info Version", i32 3} 52 53; CHECK-LABEL: !llvm.dbg.cu = 54; LW-SAME: !{![[LCU:[0-9]+]], ![[WCU:[0-9]+]]} 55; WL-SAME: !{![[WCU:[0-9]+]], ![[LCU:[0-9]+]]} 56!llvm.dbg.cu = !{!1} 57 58; LW: ![[LCU]] = !MDCompileUnit({{.*}} subprograms: ![[LSPs:[0-9]+]] 59; LW: ![[LSPs]] = !{![[BARSP:[0-9]+]], ![[FOOSP:[0-9]+]]} 60; LW: ![[BARSP]] = !MDSubprogram(name: "bar", 61; LW-SAME: function: i32 (i32, i32)* @bar 62; LW: ![[FOOSP]] = {{.*}}!MDSubprogram(name: "foo", 63; LW-NOT: function: 64; LW-SAME: ){{$}} 65; LW: ![[WCU]] = !MDCompileUnit({{.*}} subprograms: ![[WSPs:[0-9]+]] 66; LW: ![[WSPs]] = !{![[WEAKFOOSP:[0-9]+]]} 67; LW: ![[WEAKFOOSP]] = !MDSubprogram(name: "foo", 68; LW-SAME: function: i32 (i32, i32)* @foo 69; LW: ![[FOOINBAR]] = !MDLocation(line: 2, scope: ![[FOOSP]], inlinedAt: ![[BARIA:[0-9]+]]) 70; LW: ![[BARIA]] = !MDLocation(line: 12, scope: ![[BARSP]]) 71; LW: ![[BARRET]] = !MDLocation(line: 13, scope: ![[BARSP]]) 72; LW: ![[FOOADD]] = !MDLocation(line: 2, scope: ![[WEAKFOOSP]]) 73; LW: ![[FOORET]] = !MDLocation(line: 3, scope: ![[WEAKFOOSP]]) 74 75; Same as above, but reordered. 76; WL: ![[WCU]] = !MDCompileUnit({{.*}} subprograms: ![[WSPs:[0-9]+]] 77; WL: ![[WSPs]] = !{![[WEAKFOOSP:[0-9]+]]} 78; WL: ![[WEAKFOOSP]] = !MDSubprogram(name: "foo", 79; WL-SAME: function: i32 (i32, i32)* @foo 80; WL: ![[LCU]] = !MDCompileUnit({{.*}} subprograms: ![[LSPs:[0-9]+]] 81; Note: for symmetry, LSPs would have a different copy of the subprogram. 82; WL: ![[LSPs]] = !{![[BARSP:[0-9]+]], ![[WEAKFOOSP:[0-9]+]]} 83; WL: ![[BARSP]] = !MDSubprogram(name: "bar", 84; WL-SAME: function: i32 (i32, i32)* @bar 85; WL: ![[FOOADD]] = !MDLocation(line: 2, scope: ![[WEAKFOOSP]]) 86; WL: ![[FOORET]] = !MDLocation(line: 3, scope: ![[WEAKFOOSP]]) 87; WL: ![[FOOINBAR]] = !MDLocation(line: 2, scope: ![[WEAKFOOSP]], inlinedAt: ![[BARIA:[0-9]+]]) 88; WL: ![[BARIA]] = !MDLocation(line: 12, scope: ![[BARSP]]) 89; WL: ![[BARRET]] = !MDLocation(line: 13, scope: ![[BARSP]]) 90 91!1 = !MDCompileUnit(language: DW_LANG_C99, file: !2, subprograms: !{!3, !4}, emissionKind: 1) 92!2 = !MDFile(filename: "bar.c", directory: "/path/to/dir") 93!3 = !MDSubprogram(file: !2, scope: !2, line: 11, name: "bar", function: i32 (i32, i32)* @bar, type: !6) 94!4 = !MDSubprogram(file: !5, scope: !5, line: 1, name: "foo", function: i32 (i32, i32)* @foo, type: !6) 95!5 = !MDFile(filename: "foo.h", directory: "/path/to/dir") 96!6 = !MDSubroutineType(types: !{}) 97 98; Crasher for llc. 99; REQUIRES: object-emission 100; RUN: %llc_dwarf -filetype=obj -O0 %t1 -o %t1.o 101; RUN: llvm-dwarfdump %t1.o -debug-dump=all | FileCheck %s -check-prefix=DWLW -check-prefix=DW 102; RUN: %llc_dwarf -filetype=obj -O0 %t2 -o %t2.o 103; RUN: llvm-dwarfdump %t2.o -debug-dump=all | FileCheck %s -check-prefix=DWWL -check-prefix=DW 104; Check that the debug info puts the subprogram (with PCs) in the correct 105; compile unit. 106 107; DW-LABEL: .debug_info contents: 108; DWLW: DW_TAG_compile_unit 109; DWLW: DW_AT_name {{.*}}"bar.c" 110; Note: If we stop emitting foo here, the comment below for DWWL (and the 111; check) should be copied up here. 112; DWLW: DW_TAG_subprogram 113; DWLW-NOT: DW_AT_low_pc 114; DWLW-NOT: DW_AT_high_pc 115; DWLW: DW_AT_name {{.*}}foo 116; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}foo.h" 117; DWLW: DW_AT_decl_line {{.*}}(1) 118; DWLW: DW_TAG_subprogram 119; DWLW: DW_AT_low_pc 120; DWLW: DW_AT_high_pc 121; DWLW: DW_AT_name {{.*}}bar 122; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c" 123; DWLW: DW_AT_decl_line {{.*}}(11) 124; DWLW: DW_TAG_inlined_subroutine 125; DWLW: DW_AT_abstract_origin 126; DWLW: DW_TAG_compile_unit 127; DWLW: DW_AT_name {{.*}}"foo.c" 128; DWLW: DW_TAG_subprogram 129; DWLW: DW_AT_low_pc 130; DWLW: DW_AT_high_pc 131; DWLW: DW_AT_name {{.*}}foo 132; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}foo.h" 133; DWLW: DW_AT_decl_line {{.*}}(1) 134 135; The DWARF output is already symmetric (just reordered). 136; DWWL: DW_TAG_compile_unit 137; DWWL: DW_AT_name {{.*}}"foo.c" 138; DWWL: DW_TAG_subprogram 139; DWWL: DW_AT_low_pc 140; DWWL: DW_AT_high_pc 141; DWWL: DW_AT_name {{.*}}foo 142; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}foo.h" 143; DWWL: DW_AT_decl_line {{.*}}(1) 144; DWWL: DW_TAG_compile_unit 145; DWWL: DW_AT_name {{.*}}"bar.c" 146; Note: for symmetry, foo would also show up in this compile unit 147; (alternatively, it wouldn't show up in the DWLW case). If we start emitting 148; foo here, this should be updated by checking that we don't emit low_pc and 149; high_pc for it. 150; DWWL-NOT: DW_AT_name {{.*}}foo 151; DWWL: DW_TAG_subprogram 152; DWWL-NOT: DW_AT_name {{.*}}foo 153; DWWL: DW_AT_low_pc 154; DWWL: DW_AT_high_pc 155; DWWL-NOT: DW_AT_name {{.*}}foo 156; DWWL: DW_AT_name {{.*}}bar 157; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c" 158; DWWL: DW_AT_decl_line {{.*}}(11) 159; DWWL: DW_TAG_inlined_subroutine 160; DWWL: DW_AT_abstract_origin 161 162; DW-LABEL: .debug_line contents: 163; Check that we have the right things in the line table as well. 164 165; DWLW-LABEL: file_names[{{ *}}1]{{.*}} bar.c 166; DWLW-LABEL: file_names[{{ *}}2]{{.*}} foo.h 167; DWLW: 2 0 2 0 0 is_stmt prologue_end 168; DWLW-LABEL: file_names[{{ *}}1]{{.*}} foo.h 169; DWLW: 2 0 1 0 0 is_stmt prologue_end 170; DWLW-NOT: prologue_end 171 172; DWWL-LABEL: file_names[{{ *}}1]{{.*}} foo.h 173; DWWL: 2 0 1 0 0 is_stmt prologue_end 174; DWWL-LABEL: file_names[{{ *}}1]{{.*}} bar.c 175; DWWL-LABEL: file_names[{{ *}}2]{{.*}} foo.h 176; DWWL: 2 0 2 0 0 is_stmt prologue_end 177; DWWL-NOT: prologue_end 178