1; RUN: %llc_dwarf -O0 -filetype=obj < %s | llvm-dwarfdump -debug-info - | FileCheck %s
2
3; The formal parameter 'b' for Function 'x' when inlined within 'a' is lost on
4; powerpc64 (and on x86_64 at at least -O2). Presumably this is a SelectionDAG
5; issue.
6; FIXME: arm64 is an alias for aarch64 on macs, apparently?
7; XFAIL: powerpc64, aarch64, arm64, hexagon, riscv, sparc
8
9; Build from the following source with clang -O2.
10
11; The important details are that 'x's abstract definition is first built during
12; the definition of 'b', where the parameter to 'x' is constant and so 'x's 's'
13; variable is optimized away. No abstract definition DIE for 's' is constructed.
14; Then, during 'a' emission, the abstract DbgVariable for 's' is created, but
15; the abstract DIE isn't (since the abstract definition for 'b' is already
16; built). This results in 's' inlined in 'a' being emitted with its name, line,
17; file there, rather than referencing an abstract definition.
18
19; extern int t;
20;
21; void f(int);
22;
23; inline void x(bool b) {
24;   if (b) {
25;     int s = t;
26;     f(s);
27;   }
28;   f(0);
29; }
30;
31; void b() {
32;   x(false);
33; }
34;
35; void a(bool u) {
36;   x(u);
37; }
38
39; CHECK: [[X_DECL:.*]]: DW_TAG_subprogram
40; CHECK-NOT: DW_TAG
41; CHECK:   DW_AT_name ("x")
42; CHECK-NOT: {{DW_TAG|NULL}}
43; CHECK:   DW_TAG_formal_parameter
44; CHECK-NOT: DW_TAG
45; CHECK:     DW_AT_name ("b")
46; CHECK-NOT: {{DW_TAG|NULL}}
47; CHECK:       DW_TAG_lexical_block
48; CHECK-NOT: {{DW_TAG|NULL}}
49; CHECK:   DW_TAG_variable
50; CHECK-NOT: DW_TAG
51; CHECK:         DW_AT_name ("s")
52
53; CHECK: DW_TAG_subprogram
54; CHECK-NOT: DW_TAG
55; CHECK:   DW_AT_name ("b")
56; CHECK-NOT: {{DW_TAG|NULL}}
57; CHECK:   DW_TAG_inlined_subroutine
58; CHECK-NOT: DW_TAG
59; CHECK:     DW_AT_abstract_origin {{.*}}[[X_DECL]]
60; CHECK-NOT: {{DW_TAG|NULL}}
61; CHECK:     DW_TAG_formal_parameter
62; CHECK-NOT: DW_TAG
63; CHECK:       DW_AT_abstract_origin {{.*}} "b"
64; Notice 'x's local variable 's' is missing. Not necessarily a bug here,
65; since it's been optimized entirely away and it should be described in
66; abstract subprogram.
67; CHECK-NOT: DW_TAG
68; CHECK: NULL
69; CHECK-NOT: DW_TAG
70; CHECK: NULL
71
72; CHECK: DW_TAG_subprogram
73; CHECK-NOT: DW_TAG
74; CHECK:   DW_AT_name ("a")
75; CHECK-NOT: {{DW_TAG|NULL}}
76; CHECK:   DW_TAG_formal_parameter
77; CHECK-NOT: {{DW_TAG|NULL}}
78; CHECK:   DW_TAG_inlined_subroutine
79; CHECK-NOT: DW_TAG
80; CHECK:     DW_AT_abstract_origin {{.*}}[[X_DECL]]
81; CHECK-NOT: {{DW_TAG|NULL}}
82; FIXME: This formal parameter goes missing at least at -O2 (& on
83; mips/powerpc), maybe before that. Perhaps SelectionDAG is to blame (and
84; fastisel succeeds).
85; CHECK:     DW_TAG_formal_parameter
86; CHECK-NOT: DW_TAG
87; CHECK:       DW_AT_location
88; CHECK:       DW_AT_abstract_origin {{.*}} "b"
89
90; CHECK-NOT: {{DW_TAG|NULL}}
91; CHECK:     DW_TAG_lexical_block
92; CHECK-NOT: {{DW_TAG|NULL}}
93; CHECK:       DW_TAG_variable
94; CHECK-NOT: DW_TAG
95; CHECK:         DW_AT_abstract_origin {{.*}} "s"
96
97@t = external global i32
98
99; Function Attrs: uwtable
100define void @_Z1bv() #0 !dbg !4 {
101entry:
102  tail call void @llvm.dbg.value(metadata i1 false, metadata !25, metadata !DIExpression()), !dbg !27
103  tail call void @_Z1fi(i32 0), !dbg !28
104  ret void, !dbg !29
105}
106
107; Function Attrs: uwtable
108define void @_Z1ab(i1 zeroext %u) #0 !dbg !8 {
109entry:
110  tail call void @llvm.dbg.value(metadata i1 %u, metadata !13, metadata !DIExpression()), !dbg !30
111  tail call void @llvm.dbg.value(metadata i1 %u, metadata !31, metadata !DIExpression()), !dbg !33
112  br i1 %u, label %if.then.i, label %_Z1xb.exit, !dbg !34
113
114if.then.i:                                        ; preds = %entry
115  %0 = load i32, i32* @t, align 4, !dbg !35, !tbaa !36
116  tail call void @llvm.dbg.value(metadata i32 %0, metadata !40, metadata !DIExpression()), !dbg !35
117  tail call void @_Z1fi(i32 %0), !dbg !41
118  br label %_Z1xb.exit, !dbg !42
119
120_Z1xb.exit:                                       ; preds = %entry, %if.then.i
121  tail call void @_Z1fi(i32 0), !dbg !43
122  ret void, !dbg !44
123}
124
125declare void @_Z1fi(i32) #1
126
127; Function Attrs: nounwind readnone
128declare void @llvm.dbg.value(metadata, metadata, metadata) #2
129
130attributes #0 = { uwtable "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
131attributes #1 = { "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
132attributes #2 = { nounwind readnone }
133
134!llvm.dbg.cu = !{!0}
135!llvm.module.flags = !{!21, !22}
136!llvm.ident = !{!23}
137
138!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 ", isOptimized: true, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
139!1 = !DIFile(filename: "missing-abstract-variables.cc", directory: "/tmp/dbginfo")
140!2 = !{}
141!4 = distinct !DISubprogram(name: "b", linkageName: "_Z1bv", line: 13, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, scopeLine: 13, file: !1, scope: !5, type: !6, retainedNodes: !2)
142!5 = !DIFile(filename: "missing-abstract-variables.cc", directory: "/tmp/dbginfo")
143!6 = !DISubroutineType(types: !7)
144!7 = !{null}
145!8 = distinct !DISubprogram(name: "a", linkageName: "_Z1ab", line: 17, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, scopeLine: 17, file: !1, scope: !5, type: !9, retainedNodes: !12)
146!9 = !DISubroutineType(types: !10)
147!10 = !{null, !11}
148!11 = !DIBasicType(tag: DW_TAG_base_type, name: "bool", size: 8, align: 8, encoding: DW_ATE_boolean)
149!12 = !{!13}
150!13 = !DILocalVariable(name: "u", line: 17, arg: 1, scope: !8, file: !5, type: !11)
151!14 = distinct !DISubprogram(name: "x", linkageName: "_Z1xb", line: 5, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, scopeLine: 5, file: !1, scope: !5, type: !9, retainedNodes: !15)
152!15 = !{!16, !17}
153!16 = !DILocalVariable(name: "b", line: 5, arg: 1, scope: !14, file: !5, type: !11)
154!17 = !DILocalVariable(name: "s", line: 7, scope: !18, file: !5, type: !20)
155!18 = distinct !DILexicalBlock(line: 6, column: 0, file: !1, scope: !19)
156!19 = distinct !DILexicalBlock(line: 6, column: 0, file: !1, scope: !14)
157!20 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
158!21 = !{i32 2, !"Dwarf Version", i32 4}
159!22 = !{i32 2, !"Debug Info Version", i32 3}
160!23 = !{!"clang version 3.5.0 "}
161!24 = !{i1 false}
162!25 = !DILocalVariable(name: "b", line: 5, arg: 1, scope: !14, file: !5, type: !11)
163!26 = !DILocation(line: 14, scope: !4)
164!27 = !DILocation(line: 5, scope: !14, inlinedAt: !26)
165!28 = !DILocation(line: 10, scope: !14, inlinedAt: !26)
166!29 = !DILocation(line: 15, scope: !4)
167!30 = !DILocation(line: 17, scope: !8)
168!31 = !DILocalVariable(name: "b", line: 5, arg: 1, scope: !14, file: !5, type: !11)
169!32 = !DILocation(line: 18, scope: !8)
170!33 = !DILocation(line: 5, scope: !14, inlinedAt: !32)
171!34 = !DILocation(line: 6, scope: !19, inlinedAt: !32)
172!35 = !DILocation(line: 7, scope: !18, inlinedAt: !32)
173!36 = !{!37, !37, i64 0}
174!37 = !{!"int", !38, i64 0}
175!38 = !{!"omnipotent char", !39, i64 0}
176!39 = !{!"Simple C/C++ TBAA"}
177!40 = !DILocalVariable(name: "s", line: 7, scope: !18, file: !5, type: !20)
178!41 = !DILocation(line: 8, scope: !18, inlinedAt: !32)
179!42 = !DILocation(line: 9, scope: !18, inlinedAt: !32)
180!43 = !DILocation(line: 10, scope: !14, inlinedAt: !32)
181!44 = !DILocation(line: 19, scope: !8)
182