blob: 03ccfed01b635a2c8fba68afabe62e52462fe0ad [file] [log] [blame]
David Blaikie09fdfab2014-08-07 22:22:49 +00001; REQUIRES: object-emission
2
NAKAMURA Takumi15ac9af2014-08-08 02:24:05 +00003; RUN: %llc_dwarf -filetype=obj -O0 < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
David Blaikie09fdfab2014-08-07 22:22:49 +00004
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}}
Paul Robinson78046b42015-08-11 21:36:45 +000041; CHECK: [[M_FN2_DECL:.*]]: DW_TAG_subprogram
David Blaikie09fdfab2014-08-07 22:22:49 +000042; CHECK-NOT: DW_TAG
43; CHECK: DW_AT_name {{.*}} "m_fn2"
44; CHECK-NOT: {{DW_TAG|NULL}}
Paul Robinson78046b42015-08-11 21:36:45 +000045; CHECK: DW_TAG_formal_parameter
David Blaikie09fdfab2014-08-07 22:22:49 +000046
47; The abstract definition of C::m_fn2
48; CHECK: [[M_FN2_ABS_DEF:.*]]: DW_TAG_subprogram
49; CHECK-NOT: DW_TAG
Paul Robinson78046b42015-08-11 21:36:45 +000050; CHECK: DW_AT_specification {{.*}} {[[M_FN2_DECL]]}
David Blaikie09fdfab2014-08-07 22:22:49 +000051; 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
Paul Robinson78046b42015-08-11 21:36:45 +000066; CHECK: DW_AT_abstract_origin {{.*}} {[[M_FN2_ABS_DEF]]}
David Blaikie09fdfab2014-08-07 22:22:49 +000067; 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
Paul Robinson78046b42015-08-11 21:36:45 +000081; CHECK: DW_AT_abstract_origin {{.*}} {[[M_FN2_ABS_DEF]]}
David Blaikie09fdfab2014-08-07 22:22:49 +000082; 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
Adrian Prantl1eadba12016-12-22 00:45:21 +000087source_filename = "test/DebugInfo/Generic/recursive_inlining.ll"
David Blaikie09fdfab2014-08-07 22:22:49 +000088
89%struct.C = type { i32 }
90
Adrian Prantl1eadba12016-12-22 00:45:21 +000091@x = global %struct.C* null, align 8, !dbg !0
David Blaikie09fdfab2014-08-07 22:22:49 +000092
93; Function Attrs: nounwind
Adrian Prantl1eadba12016-12-22 00:45:21 +000094define void @_Z3fn6v() #0 !dbg !20 {
David Blaikie09fdfab2014-08-07 22:22:49 +000095entry:
Adrian Prantl1eadba12016-12-22 00:45:21 +000096 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, i64 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
David Blaikie09fdfab2014-08-07 22:22:49 +0000104
105if.then.i: ; preds = %entry
Adrian Prantl1eadba12016-12-22 00:45:21 +0000106 tail call void @_Z3fn2iiii(i32 0, i32 0, i32 0, i32 0) #3, !dbg !40
107 br label %_ZN1C5m_fn2Ev.exit, !dbg !40
David Blaikie09fdfab2014-08-07 22:22:49 +0000108
Adrian Prantl1eadba12016-12-22 00:45:21 +0000109_ZN1C5m_fn2Ev.exit: ; preds = %if.then.i, %entry
110 tail call void @_Z3fn3v() #3, !dbg !42
111 ret void, !dbg !43
David Blaikie09fdfab2014-08-07 22:22:49 +0000112}
113
114declare void @_Z3fn8v() #1
115
116; Function Attrs: nounwind
Adrian Prantl1eadba12016-12-22 00:45:21 +0000117
118define linkonce_odr void @_ZN1C5m_fn2Ev(%struct.C* nocapture readonly %this) #0 align 2 !dbg !30 {
David Blaikie09fdfab2014-08-07 22:22:49 +0000119entry:
Adrian Prantl1eadba12016-12-22 00:45:21 +0000120 tail call void @llvm.dbg.value(metadata %struct.C* %this, i64 0, 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
David Blaikie09fdfab2014-08-07 22:22:49 +0000126
127if.then: ; preds = %entry
Adrian Prantl1eadba12016-12-22 00:45:21 +0000128 tail call void @_Z3fn2iiii(i32 0, i32 0, i32 0, i32 0) #3, !dbg !47
129 br label %if.end, !dbg !47
David Blaikie09fdfab2014-08-07 22:22:49 +0000130
Adrian Prantl1eadba12016-12-22 00:45:21 +0000131if.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, i64 0, 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
David Blaikie09fdfab2014-08-07 22:22:49 +0000140
141if.then.i.i: ; preds = %if.end
David Blaikie09fdfab2014-08-07 22:22:49 +0000142
Adrian Prantl1eadba12016-12-22 00:45:21 +0000143 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
David Blaikie09fdfab2014-08-07 22:22:49 +0000149}
150
151; Function Attrs: nounwind
Adrian Prantl1eadba12016-12-22 00:45:21 +0000152define void @_Z3fn3v() #0 !dbg !50 {
David Blaikie09fdfab2014-08-07 22:22:49 +0000153entry:
154 br label %tailrecurse
155
156tailrecurse: ; preds = %tailrecurse.backedge, %entry
Adrian Prantl1eadba12016-12-22 00:45:21 +0000157 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, i64 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
David Blaikie09fdfab2014-08-07 22:22:49 +0000165
Adrian Prantl1eadba12016-12-22 00:45:21 +0000166tailrecurse.backedge: ; preds = %if.then.i.i, %tailrecurse
David Blaikie09fdfab2014-08-07 22:22:49 +0000167 br label %tailrecurse
168
169if.then.i.i: ; preds = %tailrecurse
Adrian Prantl1eadba12016-12-22 00:45:21 +0000170 tail call void @_Z3fn2iiii(i32 0, i32 0, i32 0, i32 0) #3, !dbg !65
171 br label %tailrecurse.backedge, !dbg !65
David Blaikie09fdfab2014-08-07 22:22:49 +0000172}
173
174; Function Attrs: nounwind
Adrian Prantl1eadba12016-12-22 00:45:21 +0000175define void @_Z3fn4v() #0 !dbg !66 {
David Blaikie09fdfab2014-08-07 22:22:49 +0000176entry:
Adrian Prantl1eadba12016-12-22 00:45:21 +0000177 %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
David Blaikie09fdfab2014-08-07 22:22:49 +0000180}
181
182; Function Attrs: nounwind
Adrian Prantl1eadba12016-12-22 00:45:21 +0000183define void @_Z3fn5v() #0 !dbg !68 {
David Blaikie09fdfab2014-08-07 22:22:49 +0000184entry:
Adrian Prantl1eadba12016-12-22 00:45:21 +0000185 %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
David Blaikie09fdfab2014-08-07 22:22:49 +0000188}
189
190declare void @_Z3fn2iiii(i32, i32, i32, i32) #1
191
192; Function Attrs: nounwind readnone
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000193declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2
David Blaikie09fdfab2014-08-07 22:22:49 +0000194
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
Adrian Prantl1eadba12016-12-22 00:45:21 +0000200!llvm.dbg.cu = !{!12}
201!llvm.module.flags = !{!17, !18}
202!llvm.ident = !{!19}
David Blaikie09fdfab2014-08-07 22:22:49 +0000203
Adrian Prantl1eadba12016-12-22 00:45:21 +0000204!0 = !DIGlobalVariableExpression(var: !1)
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, variables: !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, variables: !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}
Sanjoy Das00d76a52016-12-29 15:47:05 +0000242!38 = !{!"struct", !39, i64 0}
Adrian Prantl1eadba12016-12-22 00:45:21 +0000243!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, variables: !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, variables: !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, variables: !14)
273!69 = !DILocation(line: 22, scope: !68)
274