blob: c1fc70b689b009279b797a068f52c22bb4345f2e [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
87
88
89%struct.C = type { i32 }
90
91@x = global %struct.C* null, align 8
92
93; Function Attrs: nounwind
94define void @_Z3fn6v() #0 {
95entry:
96 tail call void @_Z3fn8v() #3, !dbg !31
David Blaikiea79ac142015-02-27 21:17:42 +000097 %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !32, !tbaa !33
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000098 tail call void @llvm.dbg.value(metadata %struct.C* %0, i64 0, metadata !37, metadata !DIExpression()) #3, !dbg !38
David Blaikie09fdfab2014-08-07 22:22:49 +000099 tail call void @_Z3fn8v() #3, !dbg !39
David Blaikie79e6c742015-02-27 19:29:02 +0000100 %b.i = getelementptr inbounds %struct.C, %struct.C* %0, i64 0, i32 0, !dbg !40
David Blaikiea79ac142015-02-27 21:17:42 +0000101 %1 = load i32, i32* %b.i, align 4, !dbg !40, !tbaa !42
David Blaikie09fdfab2014-08-07 22:22:49 +0000102 %tobool.i = icmp eq i32 %1, 0, !dbg !40
103 br i1 %tobool.i, label %_ZN1C5m_fn2Ev.exit, label %if.then.i, !dbg !40
104
105if.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
108
109_ZN1C5m_fn2Ev.exit: ; preds = %entry, %if.then.i
110 tail call void @_Z3fn3v() #3, !dbg !47
111 ret void, !dbg !48
112}
113
114declare void @_Z3fn8v() #1
115
116; Function Attrs: nounwind
117define linkonce_odr void @_ZN1C5m_fn2Ev(%struct.C* nocapture readonly %this) #0 align 2 {
118entry:
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000119 tail call void @llvm.dbg.value(metadata %struct.C* %this, i64 0, metadata !24, metadata !DIExpression()), !dbg !49
David Blaikie09fdfab2014-08-07 22:22:49 +0000120 tail call void @_Z3fn8v() #3, !dbg !50
David Blaikie79e6c742015-02-27 19:29:02 +0000121 %b = getelementptr inbounds %struct.C, %struct.C* %this, i64 0, i32 0, !dbg !51
David Blaikiea79ac142015-02-27 21:17:42 +0000122 %0 = load i32, i32* %b, align 4, !dbg !51, !tbaa !42
David Blaikie09fdfab2014-08-07 22:22:49 +0000123 %tobool = icmp eq i32 %0, 0, !dbg !51
124 br i1 %tobool, label %if.end, label %if.then, !dbg !51
125
126if.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
129
130if.end: ; preds = %entry, %if.then
131 tail call void @_Z3fn8v() #3, !dbg !53
David Blaikiea79ac142015-02-27 21:17:42 +0000132 %1 = load %struct.C*, %struct.C** @x, align 8, !dbg !56, !tbaa !33
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000133 tail call void @llvm.dbg.value(metadata %struct.C* %1, i64 0, metadata !57, metadata !DIExpression()) #3, !dbg !58
David Blaikie09fdfab2014-08-07 22:22:49 +0000134 tail call void @_Z3fn8v() #3, !dbg !59
David Blaikie79e6c742015-02-27 19:29:02 +0000135 %b.i.i = getelementptr inbounds %struct.C, %struct.C* %1, i64 0, i32 0, !dbg !60
David Blaikiea79ac142015-02-27 21:17:42 +0000136 %2 = load i32, i32* %b.i.i, align 4, !dbg !60, !tbaa !42
David Blaikie09fdfab2014-08-07 22:22:49 +0000137 %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
139
140if.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
143
144_Z3fn6v.exit: ; preds = %if.end, %if.then.i.i
145 tail call void @_Z3fn3v() #3, !dbg !62
146 ret void, !dbg !63
147}
148
149; Function Attrs: nounwind
150define void @_Z3fn3v() #0 {
151entry:
152 br label %tailrecurse
153
154tailrecurse: ; preds = %tailrecurse.backedge, %entry
155 tail call void @_Z3fn8v() #3, !dbg !64
David Blaikiea79ac142015-02-27 21:17:42 +0000156 %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !66, !tbaa !33
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000157 tail call void @llvm.dbg.value(metadata %struct.C* %0, i64 0, metadata !67, metadata !DIExpression()) #3, !dbg !68
David Blaikie09fdfab2014-08-07 22:22:49 +0000158 tail call void @_Z3fn8v() #3, !dbg !69
David Blaikie79e6c742015-02-27 19:29:02 +0000159 %b.i.i = getelementptr inbounds %struct.C, %struct.C* %0, i64 0, i32 0, !dbg !70
David Blaikiea79ac142015-02-27 21:17:42 +0000160 %1 = load i32, i32* %b.i.i, align 4, !dbg !70, !tbaa !42
David Blaikie09fdfab2014-08-07 22:22:49 +0000161 %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
163
164tailrecurse.backedge: ; preds = %tailrecurse, %if.then.i.i
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 !71
169 br label %tailrecurse.backedge, !dbg !71
170}
171
172; Function Attrs: nounwind
173define void @_Z3fn4v() #0 {
174entry:
David Blaikiea79ac142015-02-27 21:17:42 +0000175 %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !72, !tbaa !33
David Blaikie09fdfab2014-08-07 22:22:49 +0000176 tail call void @_ZN1C5m_fn2Ev(%struct.C* %0), !dbg !72
177 ret void, !dbg !72
178}
179
180; Function Attrs: nounwind
181define void @_Z3fn5v() #0 {
182entry:
David Blaikiea79ac142015-02-27 21:17:42 +0000183 %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !73, !tbaa !33
David Blaikie09fdfab2014-08-07 22:22:49 +0000184 tail call void @_ZN1C5m_fn2Ev(%struct.C* %0), !dbg !73
185 ret void, !dbg !73
186}
187
188declare void @_Z3fn2iiii(i32, i32, i32, i32) #1
189
190; Function Attrs: nounwind readnone
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000191declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2
David Blaikie09fdfab2014-08-07 22:22:49 +0000192
193attributes #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" }
194attributes #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" }
195attributes #2 = { nounwind readnone }
196attributes #3 = { nounwind }
197
198!llvm.dbg.cu = !{!0}
199!llvm.module.flags = !{!28, !29}
200!llvm.ident = !{!30}
201
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +0000202!0 = distinct !DICompileUnit(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)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000203!1 = !DIFile(filename: "<stdin>", directory: "/usr/local/google/home/blaikie/dev/scratch/missing_concrete_variable_on_darwin/reduce")
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000204!2 = !{}
205!3 = !{!4}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000206!4 = !DICompositeType(tag: DW_TAG_structure_type, name: "C", line: 5, size: 32, align: 32, file: !5, elements: !6, identifier: "_ZTS1C")
207!5 = !DIFile(filename: "recursive_inlining.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch/missing_concrete_variable_on_darwin/reduce")
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000208!6 = !{!7, !9}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000209!7 = !DIDerivedType(tag: DW_TAG_member, name: "b", line: 6, size: 32, align: 32, file: !5, scope: !"_ZTS1C", baseType: !8)
210!8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
211!9 = !DISubprogram(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 = !DISubroutineType(types: !11)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000213!11 = !{null, !12}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000214!12 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer, baseType: !"_ZTS1C")
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000215!13 = !{!14, !18, !19, !20, !21, !22}
Duncan P. N. Exon Smith814b8e92015-08-28 20:26:49 +0000216!14 = distinct !DISubprogram(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)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000217!15 = !DIFile(filename: "recursive_inlining.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch/missing_concrete_variable_on_darwin/reduce")
218!16 = !DISubroutineType(types: !17)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000219!17 = !{null}
Duncan P. N. Exon Smith814b8e92015-08-28 20:26:49 +0000220!18 = distinct !DISubprogram(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 = distinct !DISubprogram(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 = distinct !DISubprogram(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 = distinct !DISubprogram(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 = distinct !DISubprogram(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)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000225!23 = !{!24}
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000226!24 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !22, type: !25)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000227!25 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !"_ZTS1C")
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000228!26 = !{!27}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000229!27 = !DIGlobalVariable(name: "x", line: 13, isLocal: false, isDefinition: true, scope: null, file: !15, type: !25, variable: %struct.C** @x)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000230!28 = !{i32 2, !"Dwarf Version", i32 4}
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000231!29 = !{i32 2, !"Debug Info Version", i32 3}
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000232!30 = !{!"clang version 3.6.0 "}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000233!31 = !DILocation(line: 16, scope: !14)
234!32 = !DILocation(line: 17, scope: !14)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000235!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"}
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000239!37 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !22, type: !25)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000240!38 = !DILocation(line: 0, scope: !22, inlinedAt: !32)
241!39 = !DILocation(line: 8, scope: !22, inlinedAt: !32)
242!40 = !DILocation(line: 9, scope: !41, inlinedAt: !32)
243!41 = distinct !DILexicalBlock(line: 9, column: 0, file: !5, scope: !22)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000244!42 = !{!43, !44, i64 0}
245!43 = !{!"_ZTS1C", !44, i64 0}
246!44 = !{!"int", !35, i64 0}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000247!45 = !DILocation(line: 9, scope: !46, inlinedAt: !32)
248!46 = distinct !DILexicalBlock(line: 9, column: 0, file: !5, scope: !41)
249!47 = !DILocation(line: 10, scope: !22, inlinedAt: !32)
250!48 = !DILocation(line: 19, scope: !14)
251!49 = !DILocation(line: 0, scope: !22)
252!50 = !DILocation(line: 8, scope: !22)
253!51 = !DILocation(line: 9, scope: !41)
254!52 = !DILocation(line: 9, scope: !46)
255!53 = !DILocation(line: 16, scope: !14, inlinedAt: !54)
256!54 = !DILocation(line: 20, scope: !18, inlinedAt: !55)
257!55 = !DILocation(line: 10, scope: !22)
258!56 = !DILocation(line: 17, scope: !14, inlinedAt: !54)
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000259!57 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !22, type: !25)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000260!58 = !DILocation(line: 0, scope: !22, inlinedAt: !56)
261!59 = !DILocation(line: 8, scope: !22, inlinedAt: !56)
262!60 = !DILocation(line: 9, scope: !41, inlinedAt: !56)
263!61 = !DILocation(line: 9, scope: !46, inlinedAt: !56)
264!62 = !DILocation(line: 10, scope: !22, inlinedAt: !56)
265!63 = !DILocation(line: 11, scope: !22)
266!64 = !DILocation(line: 16, scope: !14, inlinedAt: !65)
267!65 = !DILocation(line: 20, scope: !18)
268!66 = !DILocation(line: 17, scope: !14, inlinedAt: !65)
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000269!67 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !22, type: !25)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000270!68 = !DILocation(line: 0, scope: !22, inlinedAt: !66)
271!69 = !DILocation(line: 8, scope: !22, inlinedAt: !66)
272!70 = !DILocation(line: 9, scope: !41, inlinedAt: !66)
273!71 = !DILocation(line: 9, scope: !46, inlinedAt: !66)
274!72 = !DILocation(line: 21, scope: !19)
275!73 = !DILocation(line: 22, scope: !20)