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