1; RUN: %llc_dwarf -filetype=obj -O0 < %s | llvm-dwarfdump -v -debug-info - | FileCheck %s
2
3; This isn't a very pretty test case - I imagine there might be other ways to
4; tickle the optimizers into producing the desired code, but I haven't found
5; them.
6
7; The issue is when a function is inlined into itself, the inlined argument
8; accidentally overwrote the concrete argument and was lost.
9
10; IR generated from the following source compiled with clang -g:
11; void fn1(void *);
12; void fn2(int, int, int, int);
13; void fn3();
14; void fn8();
15; struct C {
16;   int b;
17;   void m_fn2() {
18;     fn8();
19;     if (b) fn2(0, 0, 0, 0);
20;     fn3();
21;   }
22; };
23; C *x;
24; inline void fn7() {}
25; void fn6() {
26;   fn8();
27;   x->m_fn2();
28;   fn7();
29; }
30; void fn3() { fn6(); }
31; void fn4() { x->m_fn2(); }
32; void fn5() { x->m_fn2(); }
33
34; The definition of C and declaration of C::m_fn2
35; CHECK: DW_TAG_structure_type
36; CHECK-NOT: {{DW_TAG|NULL}}
37; CHECK: DW_TAG_member
38; CHECK-NOT: {{DW_TAG|NULL}}
39; CHECK: [[M_FN2_DECL:.*]]: DW_TAG_subprogram
40; CHECK-NOT: DW_TAG
41; CHECK:     DW_AT_name {{.*}} "m_fn2"
42; CHECK-NOT: {{DW_TAG|NULL}}
43; CHECK:     DW_TAG_formal_parameter
44
45; The abstract definition of C::m_fn2
46; CHECK: [[M_FN2_ABS_DEF:.*]]: DW_TAG_subprogram
47; CHECK-NOT: DW_TAG
48; CHECK:   DW_AT_specification {{.*}} {[[M_FN2_DECL]]}
49; CHECK-NOT: DW_TAG
50; CHECK:   DW_AT_inline
51; CHECK-NOT: {{DW_TAG|NULL}}
52; CHECK: [[M_FN2_THIS_ABS_DEF:.*]]:   DW_TAG_formal_parameter
53; CHECK-NOT: DW_TAG
54; CHECK:     DW_AT_name {{.*}} "this"
55
56; Skip some other functions
57; CHECK: DW_TAG_subprogram
58; CHECK: DW_TAG_subprogram
59; CHECK: DW_TAG_subprogram
60
61; The concrete definition of C::m_fn2
62; CHECK: DW_TAG_subprogram
63; CHECK-NOT: DW_TAG
64; CHECK:   DW_AT_abstract_origin {{.*}} {[[M_FN2_ABS_DEF]]}
65; CHECK-NOT: {{DW_TAG|NULL}}
66; CHECK:   DW_TAG_formal_parameter
67; CHECK-NOT: DW_TAG
68; CHECK:     DW_AT_abstract_origin {{.*}} {[[M_FN2_THIS_ABS_DEF]]}
69; CHECK-NOT: {{DW_TAG|NULL}}
70; Inlined fn3:
71; CHECK:     DW_TAG_inlined_subroutine
72; CHECK-NOT: {{DW_TAG|NULL}}
73; Inlined fn6:
74; CHECK:       DW_TAG_inlined_subroutine
75; CHECK-NOT: {{DW_TAG|NULL}}
76; Inlined C::m_fn2:
77; CHECK:         DW_TAG_inlined_subroutine
78; CHECK-NOT: DW_TAG
79; CHECK:           DW_AT_abstract_origin {{.*}} {[[M_FN2_ABS_DEF]]}
80; CHECK-NOT: {{DW_TAG|NULL}}
81; CHECK:           DW_TAG_formal_parameter
82; CHECK-NOT: DW_TAG
83; CHECK:              DW_AT_abstract_origin {{.*}} {[[M_FN2_THIS_ABS_DEF]]}
84
85source_filename = "test/DebugInfo/Generic/recursive_inlining.ll"
86
87%struct.C = type { i32 }
88
89@x = global %struct.C* null, align 8, !dbg !0
90
91; Function Attrs: nounwind
92define void @_Z3fn6v() #0 !dbg !20 {
93entry:
94  tail call void @_Z3fn8v() #3, !dbg !23
95  %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !24, !tbaa !25
96  tail call void @llvm.dbg.value(metadata %struct.C* %0, metadata !29, metadata !32) #3, !dbg !33
97  tail call void @_Z3fn8v() #3, !dbg !34
98  %b.i = getelementptr inbounds %struct.C, %struct.C* %0, i64 0, i32 0, !dbg !35
99  %1 = load i32, i32* %b.i, align 4, !dbg !35, !tbaa !37
100  %tobool.i = icmp eq i32 %1, 0, !dbg !35
101  br i1 %tobool.i, label %_ZN1C5m_fn2Ev.exit, label %if.then.i, !dbg !35
102
103if.then.i:                                        ; preds = %entry
104  tail call void @_Z3fn2iiii(i32 0, i32 0, i32 0, i32 0) #3, !dbg !40
105  br label %_ZN1C5m_fn2Ev.exit, !dbg !40
106
107_ZN1C5m_fn2Ev.exit:                               ; preds = %if.then.i, %entry
108  tail call void @_Z3fn3v() #3, !dbg !42
109  ret void, !dbg !43
110}
111
112declare void @_Z3fn8v() #1
113
114; Function Attrs: nounwind
115
116define linkonce_odr void @_ZN1C5m_fn2Ev(%struct.C* nocapture readonly %this) #0 align 2 !dbg !30 {
117entry:
118  tail call void @llvm.dbg.value(metadata %struct.C* %this, metadata !29, metadata !32), !dbg !44
119  tail call void @_Z3fn8v() #3, !dbg !45
120  %b = getelementptr inbounds %struct.C, %struct.C* %this, i64 0, i32 0, !dbg !46
121  %0 = load i32, i32* %b, align 4, !dbg !46, !tbaa !37
122  %tobool = icmp eq i32 %0, 0, !dbg !46
123  br i1 %tobool, label %if.end, label %if.then, !dbg !46
124
125if.then:                                          ; preds = %entry
126  tail call void @_Z3fn2iiii(i32 0, i32 0, i32 0, i32 0) #3, !dbg !47
127  br label %if.end, !dbg !47
128
129if.end:                                           ; preds = %if.then, %entry
130  tail call void @_Z3fn8v() #3, !dbg !48
131  %1 = load %struct.C*, %struct.C** @x, align 8, !dbg !52, !tbaa !25
132  tail call void @llvm.dbg.value(metadata %struct.C* %1, metadata !29, metadata !32) #3, !dbg !53
133  tail call void @_Z3fn8v() #3, !dbg !54
134  %b.i.i = getelementptr inbounds %struct.C, %struct.C* %1, i64 0, i32 0, !dbg !55
135  %2 = load i32, i32* %b.i.i, align 4, !dbg !55, !tbaa !37
136  %tobool.i.i = icmp eq i32 %2, 0, !dbg !55
137  br i1 %tobool.i.i, label %_Z3fn6v.exit, label %if.then.i.i, !dbg !55
138
139if.then.i.i:                                      ; preds = %if.end
140
141  tail call void @_Z3fn2iiii(i32 0, i32 0, i32 0, i32 0) #3, !dbg !56
142  br label %_Z3fn6v.exit, !dbg !56
143
144_Z3fn6v.exit:                                     ; preds = %if.then.i.i, %if.end
145  tail call void @_Z3fn3v() #3, !dbg !57
146  ret void, !dbg !58
147}
148
149; Function Attrs: nounwind
150define void @_Z3fn3v() #0 !dbg !50 {
151entry:
152  br label %tailrecurse
153
154tailrecurse:                                      ; preds = %tailrecurse.backedge, %entry
155  tail call void @_Z3fn8v() #3, !dbg !59
156  %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !61, !tbaa !25
157  tail call void @llvm.dbg.value(metadata %struct.C* %0, metadata !29, metadata !32) #3, !dbg !62
158  tail call void @_Z3fn8v() #3, !dbg !63
159  %b.i.i = getelementptr inbounds %struct.C, %struct.C* %0, i64 0, i32 0, !dbg !64
160  %1 = load i32, i32* %b.i.i, align 4, !dbg !64, !tbaa !37
161  %tobool.i.i = icmp eq i32 %1, 0, !dbg !64
162  br i1 %tobool.i.i, label %tailrecurse.backedge, label %if.then.i.i, !dbg !64
163
164tailrecurse.backedge:                             ; preds = %if.then.i.i, %tailrecurse
165  br label %tailrecurse
166
167if.then.i.i:                                      ; preds = %tailrecurse
168  tail call void @_Z3fn2iiii(i32 0, i32 0, i32 0, i32 0) #3, !dbg !65
169  br label %tailrecurse.backedge, !dbg !65
170}
171
172; Function Attrs: nounwind
173define void @_Z3fn4v() #0 !dbg !66 {
174entry:
175  %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !67, !tbaa !25
176  tail call void @_ZN1C5m_fn2Ev(%struct.C* %0), !dbg !67
177  ret void, !dbg !67
178}
179
180; Function Attrs: nounwind
181define void @_Z3fn5v() #0 !dbg !68 {
182entry:
183  %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !69, !tbaa !25
184  tail call void @_ZN1C5m_fn2Ev(%struct.C* %0), !dbg !69
185  ret void, !dbg !69
186}
187
188declare void @_Z3fn2iiii(i32, i32, i32, i32) #1
189
190; Function Attrs: nounwind readnone
191declare void @llvm.dbg.value(metadata, metadata, metadata) #2
192
193attributes #0 = { nounwind "less-precise-fpmad"="false" "frame-pointer"="none" "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" }
194attributes #1 = { "less-precise-fpmad"="false" "frame-pointer"="none" "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" }
195attributes #2 = { nounwind readnone }
196attributes #3 = { nounwind }
197
198!llvm.dbg.cu = !{!12}
199!llvm.module.flags = !{!17, !18}
200!llvm.ident = !{!19}
201
202!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
203!1 = !DIGlobalVariable(name: "x", scope: null, file: !2, line: 13, type: !3, isLocal: false, isDefinition: true)
204!2 = !DIFile(filename: "recursive_inlining.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch/missing_concrete_variable_on_darwin/reduce")
205!3 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 64, align: 64)
206!4 = !DICompositeType(tag: DW_TAG_structure_type, name: "C", file: !2, line: 5, size: 32, align: 32, elements: !5, identifier: "_ZTS1C")
207!5 = !{!6, !8}
208!6 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !4, file: !2, line: 6, baseType: !7, size: 32, align: 32)
209!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
210!8 = !DISubprogram(name: "m_fn2", linkageName: "_ZN1C5m_fn2Ev", scope: !4, file: !2, line: 7, type: !9, isLocal: false, isDefinition: false, scopeLine: 7, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true)
211!9 = !DISubroutineType(types: !10)
212!10 = !{null, !11}
213!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
214!12 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !13, producer: "clang version 3.6.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !14, retainedTypes: !15, globals: !16, imports: !14)
215!13 = !DIFile(filename: "<stdin>", directory: "/usr/local/google/home/blaikie/dev/scratch/missing_concrete_variable_on_darwin/reduce")
216!14 = !{}
217!15 = !{!4}
218!16 = !{!0}
219!17 = !{i32 2, !"Dwarf Version", i32 4}
220!18 = !{i32 2, !"Debug Info Version", i32 3}
221!19 = !{!"clang version 3.6.0 "}
222!20 = distinct !DISubprogram(name: "fn6", linkageName: "_Z3fn6v", scope: !2, file: !2, line: 15, type: !21, isLocal: false, isDefinition: true, scopeLine: 15, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !12, retainedNodes: !14)
223!21 = !DISubroutineType(types: !22)
224!22 = !{null}
225!23 = !DILocation(line: 16, scope: !20)
226!24 = !DILocation(line: 17, scope: !20)
227!25 = !{!26, !26, i64 0}
228!26 = !{!"any pointer", !27, i64 0}
229!27 = !{!"omnipotent char", !28, i64 0}
230!28 = !{!"Simple C/C++ TBAA"}
231!29 = !DILocalVariable(name: "this", arg: 1, scope: !30, type: !3, flags: DIFlagArtificial | DIFlagObjectPointer)
232!30 = distinct !DISubprogram(name: "m_fn2", linkageName: "_ZN1C5m_fn2Ev", scope: !4, file: !2, line: 7, type: !9, isLocal: false, isDefinition: true, scopeLine: 7, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !12, declaration: !8, retainedNodes: !31)
233!31 = !{!29}
234!32 = !DIExpression()
235!33 = !DILocation(line: 0, scope: !30, inlinedAt: !24)
236!34 = !DILocation(line: 8, scope: !30, inlinedAt: !24)
237!35 = !DILocation(line: 9, scope: !36, inlinedAt: !24)
238!36 = distinct !DILexicalBlock(scope: !30, file: !2, line: 9)
239!37 = !{!38, !39, i64 0}
240!38 = !{!"struct", !39, i64 0}
241!39 = !{!"int", !27, i64 0}
242!40 = !DILocation(line: 9, scope: !41, inlinedAt: !24)
243!41 = distinct !DILexicalBlock(scope: !36, file: !2, line: 9)
244!42 = !DILocation(line: 10, scope: !30, inlinedAt: !24)
245!43 = !DILocation(line: 19, scope: !20)
246!44 = !DILocation(line: 0, scope: !30)
247!45 = !DILocation(line: 8, scope: !30)
248!46 = !DILocation(line: 9, scope: !36)
249!47 = !DILocation(line: 9, scope: !41)
250!48 = !DILocation(line: 16, scope: !20, inlinedAt: !49)
251!49 = !DILocation(line: 20, scope: !50, inlinedAt: !51)
252!50 = distinct !DISubprogram(name: "fn3", linkageName: "_Z3fn3v", scope: !2, file: !2, line: 20, type: !21, isLocal: false, isDefinition: true, scopeLine: 20, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !12, retainedNodes: !14)
253!51 = !DILocation(line: 10, scope: !30)
254!52 = !DILocation(line: 17, scope: !20, inlinedAt: !49)
255!53 = !DILocation(line: 0, scope: !30, inlinedAt: !52)
256!54 = !DILocation(line: 8, scope: !30, inlinedAt: !52)
257!55 = !DILocation(line: 9, scope: !36, inlinedAt: !52)
258!56 = !DILocation(line: 9, scope: !41, inlinedAt: !52)
259!57 = !DILocation(line: 10, scope: !30, inlinedAt: !52)
260!58 = !DILocation(line: 11, scope: !30)
261!59 = !DILocation(line: 16, scope: !20, inlinedAt: !60)
262!60 = !DILocation(line: 20, scope: !50)
263!61 = !DILocation(line: 17, scope: !20, inlinedAt: !60)
264!62 = !DILocation(line: 0, scope: !30, inlinedAt: !61)
265!63 = !DILocation(line: 8, scope: !30, inlinedAt: !61)
266!64 = !DILocation(line: 9, scope: !36, inlinedAt: !61)
267!65 = !DILocation(line: 9, scope: !41, inlinedAt: !61)
268!66 = distinct !DISubprogram(name: "fn4", linkageName: "_Z3fn4v", scope: !2, file: !2, line: 21, type: !21, isLocal: false, isDefinition: true, scopeLine: 21, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !12, retainedNodes: !14)
269!67 = !DILocation(line: 21, scope: !66)
270!68 = distinct !DISubprogram(name: "fn5", linkageName: "_Z3fn5v", scope: !2, file: !2, line: 22, type: !21, isLocal: false, isDefinition: true, scopeLine: 22, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !12, retainedNodes: !14)
271!69 = !DILocation(line: 22, scope: !68)
272
273