blob: 78a576d763580989ba1fb3e81d9577a52124e8ad [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
Mehdi Aminid178f4f2015-09-16 05:34:32 +00005; REQUIRES: default_triple
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +00006
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
35define i32 @bar(i32 %a, i32 %b) {
36entry:
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000037 %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)
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000040}
41
42define linkonce i32 @foo(i32 %a, i32 %b) {
43entry:
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000044 %sum = add i32 %a, %b, !dbg !DILocation(line: 2, scope: !4)
45 ret i32 %sum, !dbg !DILocation(line: 3, scope: !4)
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000046}
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
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +000056; LW: ![[LCU]] = distinct !DICompileUnit({{.*}} subprograms: ![[LSPs:[0-9]+]]
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000057; LW: ![[LSPs]] = !{![[BARSP:[0-9]+]], ![[FOOSP:[0-9]+]]}
Duncan P. N. Exon Smith814b8e92015-08-28 20:26:49 +000058; LW: ![[BARSP]] = distinct !DISubprogram(name: "bar",
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000059; LW-SAME: function: i32 (i32, i32)* @bar
Duncan P. N. Exon Smith814b8e92015-08-28 20:26:49 +000060; LW: ![[FOOSP]] = distinct !DISubprogram(name: "foo",
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000061; LW-NOT: function:
62; LW-SAME: ){{$}}
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +000063; LW: ![[WCU]] = distinct !DICompileUnit({{.*}} subprograms: ![[WSPs:[0-9]+]]
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000064; LW: ![[WSPs]] = !{![[WEAKFOOSP:[0-9]+]]}
Duncan P. N. Exon Smith814b8e92015-08-28 20:26:49 +000065; LW: ![[WEAKFOOSP]] = distinct !DISubprogram(name: "foo",
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000066; LW-SAME: function: i32 (i32, i32)* @foo
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000067; 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]])
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000072
73; Same as above, but reordered.
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +000074; WL: ![[WCU]] = distinct !DICompileUnit({{.*}} subprograms: ![[WSPs:[0-9]+]]
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000075; WL: ![[WSPs]] = !{![[WEAKFOOSP:[0-9]+]]}
Duncan P. N. Exon Smith814b8e92015-08-28 20:26:49 +000076; WL: ![[WEAKFOOSP]] = distinct !DISubprogram(name: "foo",
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000077; WL-SAME: function: i32 (i32, i32)* @foo
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +000078; WL: ![[LCU]] = distinct !DICompileUnit({{.*}} subprograms: ![[LSPs:[0-9]+]]
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000079; WL: ![[LSPs]] = !{![[BARSP:[0-9]+]], ![[FOOSP:[0-9]+]]}
Duncan P. N. Exon Smith814b8e92015-08-28 20:26:49 +000080; WL: ![[BARSP]] = distinct !DISubprogram(name: "bar",
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000081; WL-SAME: function: i32 (i32, i32)* @bar
Duncan P. N. Exon Smith814b8e92015-08-28 20:26:49 +000082; WL: ![[FOOSP]] = distinct !DISubprogram(name: "foo",
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000083; Note, for symmetry, this should be "NOT: function:" and "SAME: ){{$}}".
84; WL-SAME: function: i32 (i32, i32)* @foo
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000085; 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]])
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000090
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +000091!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, subprograms: !{!3, !4}, emissionKind: 1)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000092!2 = !DIFile(filename: "bar.c", directory: "/path/to/dir")
Duncan P. N. Exon Smith814b8e92015-08-28 20:26:49 +000093!3 = distinct !DISubprogram(file: !2, scope: !2, line: 11, name: "bar", function: i32 (i32, i32)* @bar, type: !5)
94!4 = distinct !DISubprogram(file: !2, scope: !2, line: 1, name: "foo", function: i32 (i32, i32)* @foo, type: !5)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000095!5 = !DISubroutineType(types: !{})
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000096
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
Yaron Keren39972f72015-03-27 13:52:12 +0000113; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000114; 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
Yaron Keren39972f72015-03-27 13:52:12 +0000119; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000120; 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
Yaron Keren39972f72015-03-27 13:52:12 +0000130; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}foo.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000131; 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
Yaron Keren39972f72015-03-27 13:52:12 +0000140; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}foo.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000141; 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
Yaron Keren39972f72015-03-27 13:52:12 +0000148; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000149; 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
Yaron Keren39972f72015-03-27 13:52:12 +0000154; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000155; 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