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