blob: 598cea7afeb058b1196732bc45398f0469f29ff4 [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:
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000036 %sum = add i32 %a, %b, !dbg !DILocation(line: 2, scope: !4,
37 inlinedAt: !DILocation(line: 12, scope: !3))
38 ret i32 %sum, !dbg !DILocation(line: 13, scope: !3)
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000039}
40
41define linkonce i32 @foo(i32 %a, i32 %b) {
42entry:
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000043 %sum = add i32 %a, %b, !dbg !DILocation(line: 2, scope: !4)
44 ret i32 %sum, !dbg !DILocation(line: 3, scope: !4)
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000045}
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
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000055; LW: ![[LCU]] = !DICompileUnit({{.*}} subprograms: ![[LSPs:[0-9]+]]
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000056; LW: ![[LSPs]] = !{![[BARSP:[0-9]+]], ![[FOOSP:[0-9]+]]}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000057; LW: ![[BARSP]] = !DISubprogram(name: "bar",
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000058; LW-SAME: function: i32 (i32, i32)* @bar
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000059; LW: ![[FOOSP]] = {{.*}}!DISubprogram(name: "foo",
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000060; LW-NOT: function:
61; LW-SAME: ){{$}}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000062; LW: ![[WCU]] = !DICompileUnit({{.*}} subprograms: ![[WSPs:[0-9]+]]
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000063; LW: ![[WSPs]] = !{![[WEAKFOOSP:[0-9]+]]}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000064; LW: ![[WEAKFOOSP]] = !DISubprogram(name: "foo",
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000065; LW-SAME: function: i32 (i32, i32)* @foo
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000066; LW: ![[FOOINBAR]] = !DILocation(line: 2, scope: ![[FOOSP]], inlinedAt: ![[BARIA:[0-9]+]])
67; LW: ![[BARIA]] = !DILocation(line: 12, scope: ![[BARSP]])
68; LW: ![[BARRET]] = !DILocation(line: 13, scope: ![[BARSP]])
69; LW: ![[FOOCALL]] = !DILocation(line: 52, scope: ![[WEAKFOOSP]])
70; LW: ![[FOORET]] = !DILocation(line: 53, scope: ![[WEAKFOOSP]])
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000071
72; Same as above, but reordered.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000073; WL: ![[WCU]] = !DICompileUnit({{.*}} subprograms: ![[WSPs:[0-9]+]]
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000074; WL: ![[WSPs]] = !{![[WEAKFOOSP:[0-9]+]]}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000075; WL: ![[WEAKFOOSP]] = !DISubprogram(name: "foo",
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000076; WL-SAME: function: i32 (i32, i32)* @foo
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000077; WL: ![[LCU]] = !DICompileUnit({{.*}} subprograms: ![[LSPs:[0-9]+]]
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000078; WL: ![[LSPs]] = !{![[BARSP:[0-9]+]], ![[FOOSP:[0-9]+]]}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000079; WL: ![[BARSP]] = !DISubprogram(name: "bar",
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000080; WL-SAME: function: i32 (i32, i32)* @bar
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000081; WL: ![[FOOSP]] = {{.*}}!DISubprogram(name: "foo",
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000082; Note, for symmetry, this should be "NOT: function:" and "SAME: ){{$}}".
83; WL-SAME: function: i32 (i32, i32)* @foo
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000084; WL: ![[FOOCALL]] = !DILocation(line: 52, scope: ![[WEAKFOOSP]])
85; WL: ![[FOORET]] = !DILocation(line: 53, scope: ![[WEAKFOOSP]])
86; WL: ![[FOOINBAR]] = !DILocation(line: 2, scope: ![[FOOSP]], inlinedAt: ![[BARIA:[0-9]+]])
87; WL: ![[BARIA]] = !DILocation(line: 12, scope: ![[BARSP]])
88; WL: ![[BARRET]] = !DILocation(line: 13, scope: ![[BARSP]])
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000089
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000090!1 = !DICompileUnit(language: DW_LANG_C99, file: !2, subprograms: !{!3, !4}, emissionKind: 1)
91!2 = !DIFile(filename: "bar.c", directory: "/path/to/dir")
92!3 = !DISubprogram(file: !2, scope: !2, line: 11, name: "bar", function: i32 (i32, i32)* @bar, type: !5)
93!4 = !DISubprogram(file: !2, scope: !2, line: 1, name: "foo", function: i32 (i32, i32)* @foo, type: !5)
94!5 = !DISubroutineType(types: !{})
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000095
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
Yaron Keren39972f72015-03-27 13:52:12 +0000112; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000113; 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
Yaron Keren39972f72015-03-27 13:52:12 +0000118; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000119; 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
Yaron Keren39972f72015-03-27 13:52:12 +0000129; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}foo.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000130; 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
Yaron Keren39972f72015-03-27 13:52:12 +0000139; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}foo.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000140; 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
Yaron Keren39972f72015-03-27 13:52:12 +0000147; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000148; 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
Yaron Keren39972f72015-03-27 13:52:12 +0000153; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000154; 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