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