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