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