1
; 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
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.
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.
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).
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]+]]
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]+]]
34
define i32 @bar(i32 %a, i32 %b) {
36
%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)
41
define linkonce i32 @foo(i32 %a, i32 %b) {
43
%sum = add i32 %a, %b, !dbg !DILocation(line: 2, scope: !4)
44
ret i32 %sum, !dbg !DILocation(line: 3, scope: !4)
47
!llvm.module.flags = !{!0}
48
!0 = !{i32 2, !"Debug Info Version", i32 3}
50
; CHECK-LABEL: !llvm.dbg.cu =
51
; LW-SAME: !{![[LCU:[0-9]+]], ![[WCU:[0-9]+]]}
52
; WL-SAME: !{![[WCU:[0-9]+]], ![[LCU:[0-9]+]]}
55
; LW: ![[LCU]] = !DICompileUnit({{.*}} subprograms: ![[LSPs:[0-9]+]]
56
; LW: ![[LSPs]] = !{![[BARSP:[0-9]+]], ![[FOOSP:[0-9]+]]}
57
; LW: ![[BARSP]] = !DISubprogram(name: "bar",
58
; LW-SAME: function: i32 (i32, i32)* @bar
59
; LW: ![[FOOSP]] = {{.*}}!DISubprogram(name: "foo",
62
; LW: ![[WCU]] = !DICompileUnit({{.*}} subprograms: ![[WSPs:[0-9]+]]
63
; LW: ![[WSPs]] = !{![[WEAKFOOSP:[0-9]+]]}
64
; LW: ![[WEAKFOOSP]] = !DISubprogram(name: "foo",
65
; LW-SAME: function: i32 (i32, i32)* @foo
66
; 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]])
72
; Same as above, but reordered.
73
; WL: ![[WCU]] = !DICompileUnit({{.*}} subprograms: ![[WSPs:[0-9]+]]
74
; WL: ![[WSPs]] = !{![[WEAKFOOSP:[0-9]+]]}
75
; WL: ![[WEAKFOOSP]] = !DISubprogram(name: "foo",
76
; WL-SAME: function: i32 (i32, i32)* @foo
77
; WL: ![[LCU]] = !DICompileUnit({{.*}} subprograms: ![[LSPs:[0-9]+]]
78
; WL: ![[LSPs]] = !{![[BARSP:[0-9]+]], ![[FOOSP:[0-9]+]]}
79
; WL: ![[BARSP]] = !DISubprogram(name: "bar",
80
; WL-SAME: function: i32 (i32, i32)* @bar
81
; WL: ![[FOOSP]] = {{.*}}!DISubprogram(name: "foo",
82
; Note, for symmetry, this should be "NOT: function:" and "SAME: ){{$}}".
83
; WL-SAME: function: i32 (i32, i32)* @foo
84
; 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]])
90
!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: !{})
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.
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
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)
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
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)
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
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
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
158
; DW-LABEL: .debug_line contents:
159
; Check that we have the right things in the line table as well.
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
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