1 ; REQUIRES: object-emission
3 ; RUN: %llc_dwarf -filetype=obj -O0 < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
5 ; This isn't a very pretty test case - I imagine there might be other ways to
6 ; tickle the optimizers into producing the desired code, but I haven't found
9 ; The issue is when a function is inlined into itself, the inlined argument
10 ; accidentally overwrote the concrete argument and was lost.
12 ; IR generated from the following source compiled with clang -g:
14 ; void fn2(int, int, int, int);
21 ; if (b) fn2(0, 0, 0, 0);
26 ; inline void fn7() {}
32 ; void fn3() { fn6(); }
33 ; void fn4() { x->m_fn2(); }
34 ; void fn5() { x->m_fn2(); }
36 ; The definition of C and declaration of C::m_fn2
37 ; CHECK: DW_TAG_structure_type
38 ; CHECK-NOT: {{DW_TAG|NULL}}
39 ; CHECK: DW_TAG_member
40 ; CHECK-NOT: {{DW_TAG|NULL}}
41 ; CHECK: DW_TAG_subprogram
43 ; CHECK: DW_AT_name {{.*}} "m_fn2"
44 ; CHECK-NOT: {{DW_TAG|NULL}}
45 ; CHECK: [[M_FN2_THIS_DECL:.*]]: DW_TAG_formal_parameter
47 ; The abstract definition of C::m_fn2
48 ; CHECK: [[M_FN2_ABS_DEF:.*]]: DW_TAG_subprogram
50 ; CHECK: DW_AT_specification {{.*}} "_ZN1C5m_fn2Ev"
53 ; CHECK-NOT: {{DW_TAG|NULL}}
54 ; CHECK: [[M_FN2_THIS_ABS_DEF:.*]]: DW_TAG_formal_parameter
56 ; CHECK: DW_AT_name {{.*}} "this"
58 ; Skip some other functions
59 ; CHECK: DW_TAG_subprogram
60 ; CHECK: DW_TAG_subprogram
61 ; CHECK: DW_TAG_subprogram
63 ; The concrete definition of C::m_fn2
64 ; CHECK: DW_TAG_subprogram
66 ; CHECK: DW_AT_abstract_origin {{.*}} {[[M_FN2_ABS_DEF]]} "_ZN1C5m_fn2Ev"
67 ; CHECK-NOT: {{DW_TAG|NULL}}
68 ; CHECK: DW_TAG_formal_parameter
70 ; CHECK: DW_AT_abstract_origin {{.*}} {[[M_FN2_THIS_ABS_DEF]]}
71 ; CHECK-NOT: {{DW_TAG|NULL}}
73 ; CHECK: DW_TAG_inlined_subroutine
74 ; CHECK-NOT: {{DW_TAG|NULL}}
76 ; CHECK: DW_TAG_inlined_subroutine
77 ; CHECK-NOT: {{DW_TAG|NULL}}
79 ; CHECK: DW_TAG_inlined_subroutine
81 ; CHECK: DW_AT_abstract_origin {{.*}} {[[M_FN2_ABS_DEF]]} "_ZN1C5m_fn2Ev"
82 ; CHECK-NOT: {{DW_TAG|NULL}}
83 ; CHECK: DW_TAG_formal_parameter
85 ; CHECK: DW_AT_abstract_origin {{.*}} {[[M_FN2_THIS_ABS_DEF]]}
89 %struct.C = type { i32 }
91 @x = global %struct.C* null, align 8
93 ; Function Attrs: nounwind
94 define void @_Z3fn6v() #0 {
96 tail call void @_Z3fn8v() #3, !dbg !31
97 %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !32, !tbaa !33
98 tail call void @llvm.dbg.value(metadata %struct.C* %0, i64 0, metadata !37, metadata !MDExpression()) #3, !dbg !38
99 tail call void @_Z3fn8v() #3, !dbg !39
100 %b.i = getelementptr inbounds %struct.C, %struct.C* %0, i64 0, i32 0, !dbg !40
101 %1 = load i32, i32* %b.i, align 4, !dbg !40, !tbaa !42
102 %tobool.i = icmp eq i32 %1, 0, !dbg !40
103 br i1 %tobool.i, label %_ZN1C5m_fn2Ev.exit, label %if.then.i, !dbg !40
105 if.then.i: ; preds = %entry
106 tail call void @_Z3fn2iiii(i32 0, i32 0, i32 0, i32 0) #3, !dbg !45
107 br label %_ZN1C5m_fn2Ev.exit, !dbg !45
109 _ZN1C5m_fn2Ev.exit: ; preds = %entry, %if.then.i
110 tail call void @_Z3fn3v() #3, !dbg !47
114 declare void @_Z3fn8v() #1
116 ; Function Attrs: nounwind
117 define linkonce_odr void @_ZN1C5m_fn2Ev(%struct.C* nocapture readonly %this) #0 align 2 {
119 tail call void @llvm.dbg.value(metadata %struct.C* %this, i64 0, metadata !24, metadata !MDExpression()), !dbg !49
120 tail call void @_Z3fn8v() #3, !dbg !50
121 %b = getelementptr inbounds %struct.C, %struct.C* %this, i64 0, i32 0, !dbg !51
122 %0 = load i32, i32* %b, align 4, !dbg !51, !tbaa !42
123 %tobool = icmp eq i32 %0, 0, !dbg !51
124 br i1 %tobool, label %if.end, label %if.then, !dbg !51
126 if.then: ; preds = %entry
127 tail call void @_Z3fn2iiii(i32 0, i32 0, i32 0, i32 0) #3, !dbg !52
128 br label %if.end, !dbg !52
130 if.end: ; preds = %entry, %if.then
131 tail call void @_Z3fn8v() #3, !dbg !53
132 %1 = load %struct.C*, %struct.C** @x, align 8, !dbg !56, !tbaa !33
133 tail call void @llvm.dbg.value(metadata %struct.C* %1, i64 0, metadata !57, metadata !MDExpression()) #3, !dbg !58
134 tail call void @_Z3fn8v() #3, !dbg !59
135 %b.i.i = getelementptr inbounds %struct.C, %struct.C* %1, i64 0, i32 0, !dbg !60
136 %2 = load i32, i32* %b.i.i, align 4, !dbg !60, !tbaa !42
137 %tobool.i.i = icmp eq i32 %2, 0, !dbg !60
138 br i1 %tobool.i.i, label %_Z3fn6v.exit, label %if.then.i.i, !dbg !60
140 if.then.i.i: ; preds = %if.end
141 tail call void @_Z3fn2iiii(i32 0, i32 0, i32 0, i32 0) #3, !dbg !61
142 br label %_Z3fn6v.exit, !dbg !61
144 _Z3fn6v.exit: ; preds = %if.end, %if.then.i.i
145 tail call void @_Z3fn3v() #3, !dbg !62
149 ; Function Attrs: nounwind
150 define void @_Z3fn3v() #0 {
152 br label %tailrecurse
154 tailrecurse: ; preds = %tailrecurse.backedge, %entry
155 tail call void @_Z3fn8v() #3, !dbg !64
156 %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !66, !tbaa !33
157 tail call void @llvm.dbg.value(metadata %struct.C* %0, i64 0, metadata !67, metadata !MDExpression()) #3, !dbg !68
158 tail call void @_Z3fn8v() #3, !dbg !69
159 %b.i.i = getelementptr inbounds %struct.C, %struct.C* %0, i64 0, i32 0, !dbg !70
160 %1 = load i32, i32* %b.i.i, align 4, !dbg !70, !tbaa !42
161 %tobool.i.i = icmp eq i32 %1, 0, !dbg !70
162 br i1 %tobool.i.i, label %tailrecurse.backedge, label %if.then.i.i, !dbg !70
164 tailrecurse.backedge: ; preds = %tailrecurse, %if.then.i.i
165 br label %tailrecurse
167 if.then.i.i: ; preds = %tailrecurse
168 tail call void @_Z3fn2iiii(i32 0, i32 0, i32 0, i32 0) #3, !dbg !71
169 br label %tailrecurse.backedge, !dbg !71
172 ; Function Attrs: nounwind
173 define void @_Z3fn4v() #0 {
175 %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !72, !tbaa !33
176 tail call void @_ZN1C5m_fn2Ev(%struct.C* %0), !dbg !72
180 ; Function Attrs: nounwind
181 define void @_Z3fn5v() #0 {
183 %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !73, !tbaa !33
184 tail call void @_ZN1C5m_fn2Ev(%struct.C* %0), !dbg !73
188 declare void @_Z3fn2iiii(i32, i32, i32, i32) #1
190 ; Function Attrs: nounwind readnone
191 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2
193 attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
194 attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
195 attributes #2 = { nounwind readnone }
196 attributes #3 = { nounwind }
199 !llvm.module.flags = !{!28, !29}
202 !0 = !MDCompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.6.0 ", isOptimized: true, emissionKind: 1, file: !1, enums: !2, retainedTypes: !3, subprograms: !13, globals: !26, imports: !2)
203 !1 = !MDFile(filename: "<stdin>", directory: "/usr/local/google/home/blaikie/dev/scratch/missing_concrete_variable_on_darwin/reduce")
206 !4 = !MDCompositeType(tag: DW_TAG_structure_type, name: "C", line: 5, size: 32, align: 32, file: !5, elements: !6, identifier: "_ZTS1C")
207 !5 = !MDFile(filename: "recursive_inlining.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch/missing_concrete_variable_on_darwin/reduce")
209 !7 = !MDDerivedType(tag: DW_TAG_member, name: "b", line: 6, size: 32, align: 32, file: !5, scope: !"_ZTS1C", baseType: !8)
210 !8 = !MDBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
211 !9 = !MDSubprogram(name: "m_fn2", linkageName: "_ZN1C5m_fn2Ev", line: 7, isLocal: false, isDefinition: false, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 7, file: !5, scope: !"_ZTS1C", type: !10)
212 !10 = !MDSubroutineType(types: !11)
214 !12 = !MDDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer, baseType: !"_ZTS1C")
215 !13 = !{!14, !18, !19, !20, !21, !22}
216 !14 = !MDSubprogram(name: "fn6", linkageName: "_Z3fn6v", line: 15, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 15, file: !5, scope: !15, type: !16, function: void ()* @_Z3fn6v, variables: !2)
217 !15 = !MDFile(filename: "recursive_inlining.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch/missing_concrete_variable_on_darwin/reduce")
218 !16 = !MDSubroutineType(types: !17)
220 !18 = !MDSubprogram(name: "fn3", linkageName: "_Z3fn3v", line: 20, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 20, file: !5, scope: !15, type: !16, function: void ()* @_Z3fn3v, variables: !2)
221 !19 = !MDSubprogram(name: "fn4", linkageName: "_Z3fn4v", line: 21, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 21, file: !5, scope: !15, type: !16, function: void ()* @_Z3fn4v, variables: !2)
222 !20 = !MDSubprogram(name: "fn5", linkageName: "_Z3fn5v", line: 22, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 22, file: !5, scope: !15, type: !16, function: void ()* @_Z3fn5v, variables: !2)
223 !21 = !MDSubprogram(name: "fn7", linkageName: "_Z3fn7v", line: 14, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 14, file: !5, scope: !15, type: !16, variables: !2)
224 !22 = !MDSubprogram(name: "m_fn2", linkageName: "_ZN1C5m_fn2Ev", line: 7, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 7, file: !5, scope: !"_ZTS1C", type: !10, function: void (%struct.C*)* @_ZN1C5m_fn2Ev, declaration: !9, variables: !23)
226 !24 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !22, type: !25)
227 !25 = !MDDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !"_ZTS1C")
229 !27 = !MDGlobalVariable(name: "x", line: 13, isLocal: false, isDefinition: true, scope: null, file: !15, type: !25, variable: %struct.C** @x)
230 !28 = !{i32 2, !"Dwarf Version", i32 4}
231 !29 = !{i32 2, !"Debug Info Version", i32 3}
232 !30 = !{!"clang version 3.6.0 "}
233 !31 = !MDLocation(line: 16, scope: !14)
234 !32 = !MDLocation(line: 17, scope: !14)
235 !33 = !{!34, !34, i64 0}
236 !34 = !{!"any pointer", !35, i64 0}
237 !35 = !{!"omnipotent char", !36, i64 0}
238 !36 = !{!"Simple C/C++ TBAA"}
239 !37 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !22, type: !25, inlinedAt: !32)
240 !38 = !MDLocation(line: 0, scope: !22, inlinedAt: !32)
241 !39 = !MDLocation(line: 8, scope: !22, inlinedAt: !32)
242 !40 = !MDLocation(line: 9, scope: !41, inlinedAt: !32)
243 !41 = distinct !MDLexicalBlock(line: 9, column: 0, file: !5, scope: !22)
244 !42 = !{!43, !44, i64 0}
245 !43 = !{!"_ZTS1C", !44, i64 0}
246 !44 = !{!"int", !35, i64 0}
247 !45 = !MDLocation(line: 9, scope: !46, inlinedAt: !32)
248 !46 = distinct !MDLexicalBlock(line: 9, column: 0, file: !5, scope: !41)
249 !47 = !MDLocation(line: 10, scope: !22, inlinedAt: !32)
250 !48 = !MDLocation(line: 19, scope: !14)
251 !49 = !MDLocation(line: 0, scope: !22)
252 !50 = !MDLocation(line: 8, scope: !22)
253 !51 = !MDLocation(line: 9, scope: !41)
254 !52 = !MDLocation(line: 9, scope: !46)
255 !53 = !MDLocation(line: 16, scope: !14, inlinedAt: !54)
256 !54 = !MDLocation(line: 20, scope: !18, inlinedAt: !55)
257 !55 = !MDLocation(line: 10, scope: !22)
258 !56 = !MDLocation(line: 17, scope: !14, inlinedAt: !54)
259 !57 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !22, type: !25, inlinedAt: !56)
260 !58 = !MDLocation(line: 0, scope: !22, inlinedAt: !56)
261 !59 = !MDLocation(line: 8, scope: !22, inlinedAt: !56)
262 !60 = !MDLocation(line: 9, scope: !41, inlinedAt: !56)
263 !61 = !MDLocation(line: 9, scope: !46, inlinedAt: !56)
264 !62 = !MDLocation(line: 10, scope: !22, inlinedAt: !56)
265 !63 = !MDLocation(line: 11, scope: !22)
266 !64 = !MDLocation(line: 16, scope: !14, inlinedAt: !65)
267 !65 = !MDLocation(line: 20, scope: !18)
268 !66 = !MDLocation(line: 17, scope: !14, inlinedAt: !65)
269 !67 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !22, type: !25, inlinedAt: !66)
270 !68 = !MDLocation(line: 0, scope: !22, inlinedAt: !66)
271 !69 = !MDLocation(line: 8, scope: !22, inlinedAt: !66)
272 !70 = !MDLocation(line: 9, scope: !41, inlinedAt: !66)
273 !71 = !MDLocation(line: 9, scope: !46, inlinedAt: !66)
274 !72 = !MDLocation(line: 21, scope: !19)
275 !73 = !MDLocation(line: 22, scope: !20)