blob: e8bc67765bb80cc54b0251b8e78e0431ae94700f [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.
Peter Collingbourned4bff302015-11-05 22:03:56 +000020; LW: define i32 @bar({{.*}} !dbg ![[BARSP:[0-9]+]]
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000021; LW: %sum = add i32 %a, %b, !dbg ![[FOOINBAR:[0-9]+]]
22; LW: ret i32 %sum, !dbg ![[BARRET:[0-9]+]]
Peter Collingbourned4bff302015-11-05 22:03:56 +000023; LW: define weak i32 @foo({{.*}} !dbg ![[WEAKFOOSP:[0-9]+]]
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000024; 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.
Peter Collingbourned4bff302015-11-05 22:03:56 +000028; WL: define weak i32 @foo({{.*}} !dbg ![[WEAKFOOSP:[0-9]+]]
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000029; WL: %sum = call i32 @fastadd(i32 %a, i32 %b), !dbg ![[FOOCALL:[0-9]+]]
30; WL: ret i32 %sum, !dbg ![[FOORET:[0-9]+]]
Peter Collingbourned4bff302015-11-05 22:03:56 +000031; WL: define i32 @bar({{.*}} !dbg ![[BARSP:[0-9]+]]
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000032; WL: %sum = add i32 %a, %b, !dbg ![[FOOINBAR:[0-9]+]]
33; WL: ret i32 %sum, !dbg ![[BARRET:[0-9]+]]
34
Peter Collingbourned4bff302015-11-05 22:03:56 +000035define i32 @bar(i32 %a, i32 %b) !dbg !3 {
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000036entry:
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
Peter Collingbourned4bff302015-11-05 22:03:56 +000042define linkonce i32 @foo(i32 %a, i32 %b) !dbg !4 {
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000043entry:
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]+]]
Peter Collingbourned4bff302015-11-05 22:03:56 +000057; LW: ![[LSPs]] = !{![[BARSP]], ![[FOOSP:[0-9]+]]}
Duncan P. N. Exon Smith814b8e92015-08-28 20:26:49 +000058; LW: ![[BARSP]] = distinct !DISubprogram(name: "bar",
Duncan P. N. Exon Smith814b8e92015-08-28 20:26:49 +000059; LW: ![[FOOSP]] = distinct !DISubprogram(name: "foo",
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +000060; LW: ![[WCU]] = distinct !DICompileUnit({{.*}} subprograms: ![[WSPs:[0-9]+]]
Peter Collingbourned4bff302015-11-05 22:03:56 +000061; LW: ![[WSPs]] = !{![[WEAKFOOSP]]}
Duncan P. N. Exon Smith814b8e92015-08-28 20:26:49 +000062; LW: ![[WEAKFOOSP]] = distinct !DISubprogram(name: "foo",
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000063; LW: ![[FOOINBAR]] = !DILocation(line: 2, scope: ![[FOOSP]], inlinedAt: ![[BARIA:[0-9]+]])
64; LW: ![[BARIA]] = !DILocation(line: 12, scope: ![[BARSP]])
65; LW: ![[BARRET]] = !DILocation(line: 13, scope: ![[BARSP]])
66; LW: ![[FOOCALL]] = !DILocation(line: 52, scope: ![[WEAKFOOSP]])
67; LW: ![[FOORET]] = !DILocation(line: 53, scope: ![[WEAKFOOSP]])
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000068
69; Same as above, but reordered.
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +000070; WL: ![[WCU]] = distinct !DICompileUnit({{.*}} subprograms: ![[WSPs:[0-9]+]]
Peter Collingbourned4bff302015-11-05 22:03:56 +000071; WL: ![[WSPs]] = !{![[WEAKFOOSP]]}
Duncan P. N. Exon Smith814b8e92015-08-28 20:26:49 +000072; WL: ![[WEAKFOOSP]] = distinct !DISubprogram(name: "foo",
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +000073; WL: ![[LCU]] = distinct !DICompileUnit({{.*}} subprograms: ![[LSPs:[0-9]+]]
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000074; WL: ![[LSPs]] = !{![[BARSP:[0-9]+]], ![[FOOSP:[0-9]+]]}
Duncan P. N. Exon Smith814b8e92015-08-28 20:26:49 +000075; WL: ![[BARSP]] = distinct !DISubprogram(name: "bar",
Duncan P. N. Exon Smith814b8e92015-08-28 20:26:49 +000076; WL: ![[FOOSP]] = distinct !DISubprogram(name: "foo",
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000077; WL: ![[FOOCALL]] = !DILocation(line: 52, scope: ![[WEAKFOOSP]])
78; WL: ![[FOORET]] = !DILocation(line: 53, scope: ![[WEAKFOOSP]])
79; WL: ![[FOOINBAR]] = !DILocation(line: 2, scope: ![[FOOSP]], inlinedAt: ![[BARIA:[0-9]+]])
80; WL: ![[BARIA]] = !DILocation(line: 12, scope: ![[BARSP]])
81; WL: ![[BARRET]] = !DILocation(line: 13, scope: ![[BARSP]])
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000082
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +000083!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, subprograms: !{!3, !4}, emissionKind: 1)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000084!2 = !DIFile(filename: "bar.c", directory: "/path/to/dir")
Peter Collingbourned4bff302015-11-05 22:03:56 +000085!3 = distinct !DISubprogram(file: !2, scope: !2, line: 11, name: "bar", type: !5)
86!4 = distinct !DISubprogram(file: !2, scope: !2, line: 1, name: "foo", type: !5)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000087!5 = !DISubroutineType(types: !{})
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +000088
89; Crasher for llc.
90; REQUIRES: object-emission
91; RUN: %llc_dwarf -filetype=obj -O0 %t1 -o %t1.o
92; RUN: llvm-dwarfdump %t1.o -debug-dump=all | FileCheck %s -check-prefix=DWLW -check-prefix=DW
93; RUN: %llc_dwarf -filetype=obj -O0 %t2 -o %t2.o
94; RUN: llvm-dwarfdump %t2.o -debug-dump=all | FileCheck %s -check-prefix=DWWL -check-prefix=DW
95; Check that the debug info for the discarded linkonce version of @foo doesn't
96; reference any code, and that the other subprograms look correct.
97
98; DW-LABEL: .debug_info contents:
99; DWLW: DW_TAG_compile_unit
100; DWLW: DW_AT_name {{.*}}"bar.c"
101; DWLW: DW_TAG_subprogram
102; DWLW-NOT: DW_AT_low_pc
103; DWLW-NOT: DW_AT_high_pc
104; DWLW: DW_AT_name {{.*}}foo
Yaron Keren39972f72015-03-27 13:52:12 +0000105; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000106; DWLW: DW_AT_decl_line {{.*}}(1)
107; DWLW: DW_TAG_subprogram
108; DWLW: DW_AT_low_pc
109; DWLW: DW_AT_high_pc
110; DWLW: DW_AT_name {{.*}}bar
Yaron Keren39972f72015-03-27 13:52:12 +0000111; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000112; DWLW: DW_AT_decl_line {{.*}}(11)
113
114; DWLW: DW_TAG_inlined_subroutine
115; DWLW: DW_AT_abstract_origin
116; DWLW: DW_TAG_compile_unit
117; DWLW: DW_AT_name {{.*}}"foo.c"
118; DWLW: DW_TAG_subprogram
119; DWLW: DW_AT_low_pc
120; DWLW: DW_AT_high_pc
121; DWLW: DW_AT_name {{.*}}foo
Yaron Keren39972f72015-03-27 13:52:12 +0000122; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}foo.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000123; DWLW: DW_AT_decl_line {{.*}}(51)
124
125; The DWARF output is already symmetric (just reordered).
126; DWWL: DW_TAG_compile_unit
127; DWWL: DW_AT_name {{.*}}"foo.c"
128; DWWL: DW_TAG_subprogram
129; DWWL: DW_AT_low_pc
130; DWWL: DW_AT_high_pc
131; DWWL: DW_AT_name {{.*}}foo
Yaron Keren39972f72015-03-27 13:52:12 +0000132; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}foo.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000133; DWWL: DW_AT_decl_line {{.*}}(51)
134; DWWL: DW_TAG_compile_unit
135; DWWL: DW_AT_name {{.*}}"bar.c"
136; DWWL: DW_TAG_subprogram
137; DWWL-NOT: DW_AT_low_pc
138; DWWL-NOT: 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{{/|\\}}bar.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000141; DWWL: DW_AT_decl_line {{.*}}(1)
142; DWWL: DW_TAG_subprogram
143; DWWL: DW_AT_low_pc
144; DWWL: DW_AT_high_pc
145; DWWL: DW_AT_name {{.*}}bar
Yaron Keren39972f72015-03-27 13:52:12 +0000146; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
Duncan P. N. Exon Smithc947892d2015-03-26 18:35:30 +0000147; DWWL: DW_AT_decl_line {{.*}}(11)
148; DWWL: DW_TAG_inlined_subroutine
149; DWWL: DW_AT_abstract_origin
150
151; DW-LABEL: .debug_line contents:
152; Check that we have the right things in the line table as well.
153
154; DWLW-LABEL: file_names[{{ *}}1]{{.*}} bar.c
155; DWLW: 2 0 1 0 0 is_stmt prologue_end
156; DWLW-LABEL: file_names[{{ *}}1]{{.*}} foo.c
157; DWLW: 52 0 1 0 0 is_stmt prologue_end
158; DWLW-NOT: prologue_end
159
160; DWWL-LABEL: file_names[{{ *}}1]{{.*}} foo.c
161; DWWL: 52 0 1 0 0 is_stmt prologue_end
162; DWWL-LABEL: file_names[{{ *}}1]{{.*}} bar.c
163; DWWL: 2 0 1 0 0 is_stmt prologue_end
164; DWWL-NOT: prologue_end