Home | History | Annotate | Download | only in Linker
      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({{.*}} subprograms: ![[LSPs:[0-9]+]]
     57 ; LW: ![[LSPs]] = !{![[BARSP]], ![[FOOSP:[0-9]+]]}
     58 ; LW: ![[BARSP]] = distinct !DISubprogram(name: "bar",
     59 ; LW: ![[FOOSP]] = distinct !DISubprogram(name: "foo",
     60 ; LW: ![[WCU]] = distinct !DICompileUnit({{.*}} subprograms: ![[WSPs:[0-9]+]]
     61 ; LW: ![[WSPs]] = !{![[WEAKFOOSP]]}
     62 ; LW: ![[WEAKFOOSP]] = distinct !DISubprogram(name: "foo",
     63 ; LW: ![[FOOINBAR]] = !DILocation(line: 2, scope: ![[FOOSP]], inlinedAt: ![[BARIA:[0-9]+]])
     64 ; LW: ![[BARIA]] = !DILocation(line: 12, scope: ![[BARSP]])
     65 ; LW: ![[BARRET]] = !DILocation(line: 13, scope: ![[BARSP]])
     66 ; LW: ![[FOOCALL]] = !DILocation(line: 52, scope: ![[WEAKFOOSP]])
     67 ; LW: ![[FOORET]] = !DILocation(line: 53, scope: ![[WEAKFOOSP]])
     68 
     69 ; Same as above, but reordered.
     70 ; WL: ![[WCU]] = distinct !DICompileUnit({{.*}} subprograms: ![[WSPs:[0-9]+]]
     71 ; WL: ![[WSPs]] = !{![[WEAKFOOSP]]}
     72 ; WL: ![[WEAKFOOSP]] = distinct !DISubprogram(name: "foo",
     73 ; WL: ![[LCU]] = distinct !DICompileUnit({{.*}} subprograms: ![[LSPs:[0-9]+]]
     74 ; WL: ![[LSPs]] = !{![[BARSP:[0-9]+]], ![[FOOSP:[0-9]+]]}
     75 ; WL: ![[BARSP]] = distinct !DISubprogram(name: "bar",
     76 ; WL: ![[FOOSP]] = distinct !DISubprogram(name: "foo",
     77 ; WL: ![[FOOCALL]] = !DILocation(line: 52, scope: ![[WEAKFOOSP]])
     78 ; WL: ![[FOORET]] = !DILocation(line: 53, scope: ![[WEAKFOOSP]])
     79 ; WL: ![[FOOINBAR]] = !DILocation(line: 2, scope: ![[FOOSP]], inlinedAt: ![[BARIA:[0-9]+]])
     80 ; WL: ![[BARIA]] = !DILocation(line: 12, scope: ![[BARSP]])
     81 ; WL: ![[BARRET]] = !DILocation(line: 13, scope: ![[BARSP]])
     82 
     83 !1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, subprograms: !{!3, !4}, emissionKind: 1)
     84 !2 = !DIFile(filename: "bar.c", directory: "/path/to/dir")
     85 !3 = distinct !DISubprogram(file: !2, scope: !2, line: 11, name: "bar", type: !5)
     86 !4 = distinct !DISubprogram(file: !2, scope: !2, line: 1, name: "foo", type: !5)
     87 !5 = !DISubroutineType(types: !{})
     88 
     89 ; Crasher for llc.
     90 ; REQUIRES: object-emission
     91 ; RUN: %llc_dwarf -filetype=obj -O0 %t1 -o %t1.o
     92 ; RUN: llvm-dwarfdump %t1.o -debug-dump=all | FileCheck %s -check-prefix=DWLW -check-prefix=DW
     93 ; RUN: %llc_dwarf -filetype=obj -O0 %t2 -o %t2.o
     94 ; RUN: llvm-dwarfdump %t2.o -debug-dump=all | FileCheck %s -check-prefix=DWWL -check-prefix=DW
     95 ; Check that the debug info for the discarded linkonce version of @foo doesn't
     96 ; reference any code, and that the other subprograms look correct.
     97 
     98 ; DW-LABEL: .debug_info contents:
     99 ; DWLW:     DW_TAG_compile_unit
    100 ; DWLW:       DW_AT_name {{.*}}"bar.c"
    101 ; DWLW:       DW_TAG_subprogram
    102 ; DWLW-NOT:     DW_AT_low_pc
    103 ; DWLW-NOT:     DW_AT_high_pc
    104 ; DWLW:         DW_AT_name {{.*}}foo
    105 ; DWLW:         DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
    106 ; DWLW:         DW_AT_decl_line {{.*}}(1)
    107 ; DWLW:       DW_TAG_subprogram
    108 ; DWLW:         DW_AT_low_pc
    109 ; DWLW:         DW_AT_high_pc
    110 ; DWLW:         DW_AT_name {{.*}}bar
    111 ; DWLW:         DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
    112 ; DWLW:         DW_AT_decl_line {{.*}}(11)
    113 
    114 ; DWLW:         DW_TAG_inlined_subroutine
    115 ; DWLW:           DW_AT_abstract_origin
    116 ; DWLW:     DW_TAG_compile_unit
    117 ; DWLW:       DW_AT_name {{.*}}"foo.c"
    118 ; DWLW:       DW_TAG_subprogram
    119 ; DWLW:         DW_AT_low_pc
    120 ; DWLW:         DW_AT_high_pc
    121 ; DWLW:         DW_AT_name {{.*}}foo
    122 ; DWLW:         DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}foo.c"
    123 ; DWLW:         DW_AT_decl_line {{.*}}(51)
    124 
    125 ; The DWARF output is already symmetric (just reordered).
    126 ; DWWL:     DW_TAG_compile_unit
    127 ; DWWL:       DW_AT_name {{.*}}"foo.c"
    128 ; DWWL:       DW_TAG_subprogram
    129 ; DWWL:         DW_AT_low_pc
    130 ; DWWL:         DW_AT_high_pc
    131 ; DWWL:         DW_AT_name {{.*}}foo
    132 ; DWWL:         DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}foo.c"
    133 ; DWWL:         DW_AT_decl_line {{.*}}(51)
    134 ; DWWL:     DW_TAG_compile_unit
    135 ; DWWL:       DW_AT_name {{.*}}"bar.c"
    136 ; DWWL:       DW_TAG_subprogram
    137 ; DWWL-NOT:     DW_AT_low_pc
    138 ; DWWL-NOT:     DW_AT_high_pc
    139 ; DWWL:         DW_AT_name {{.*}}foo
    140 ; DWWL:         DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
    141 ; DWWL:         DW_AT_decl_line {{.*}}(1)
    142 ; DWWL:       DW_TAG_subprogram
    143 ; DWWL:         DW_AT_low_pc
    144 ; DWWL:         DW_AT_high_pc
    145 ; DWWL:         DW_AT_name {{.*}}bar
    146 ; DWWL:         DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
    147 ; DWWL:         DW_AT_decl_line {{.*}}(11)
    148 ; DWWL:         DW_TAG_inlined_subroutine
    149 ; DWWL:           DW_AT_abstract_origin
    150 
    151 ; DW-LABEL:   .debug_line contents:
    152 ; Check that we have the right things in the line table as well.
    153 
    154 ; DWLW-LABEL: file_names[{{ *}}1]{{.*}} bar.c
    155 ; DWLW:        2 0 1 0 0 is_stmt prologue_end
    156 ; DWLW-LABEL: file_names[{{ *}}1]{{.*}} foo.c
    157 ; DWLW:       52 0 1 0 0 is_stmt prologue_end
    158 ; DWLW-NOT:                      prologue_end
    159 
    160 ; DWWL-LABEL: file_names[{{ *}}1]{{.*}} foo.c
    161 ; DWWL:       52 0 1 0 0 is_stmt prologue_end
    162 ; DWWL-LABEL: file_names[{{ *}}1]{{.*}} bar.c
    163 ; DWWL:        2 0 1 0 0 is_stmt prologue_end
    164 ; DWWL-NOT:                      prologue_end
    165