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