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