llvm.org GIT mirror llvm / c39f36d
PR20038: DebugInfo: Inlined call sites where the caller has debug info but the call itself has no debug location. This situation does bad things when inlined, so I've fixed Clang not to produce inlinable call sites without locations when the caller has debug info (in the one case where I could find that this occurred). This updates the PR20038 test case to be what clang now produces, and readds the assertion that had to be removed due to this bug. I've also beefed up the debug info verifier to help diagnose these issues in the future, and I hope to add checks to the inliner to just assert-fail if it encounters this situation. If, in the future, we decide we have to cope with this situation, the right thing to do is probably to just remove all the DebugLocs from the inlined instructions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211723 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 6 years ago
4 changed file(s) with 102 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
785785 for (const auto &Var : ConcreteVariables) {
786786 DIE *VariableDie = Var->getDIE();
787787 // FIXME: There shouldn't be any variables without DIEs.
788 if (!VariableDie)
789 continue;
788 assert(VariableDie);
790789 // FIXME: Consider the time-space tradeoff of just storing the unit pointer
791790 // in the ConcreteVariables list, rather than looking it up again here.
792791 // DIE::getUnit isn't simple - it walks parent pointers, etc.
136136 /// getOrCreateLexicalScope - Find lexical scope for the given DebugLoc. If
137137 /// not available then create new lexical scope.
138138 LexicalScope *LexicalScopes::getOrCreateLexicalScope(DebugLoc DL) {
139 if (DL.isUnknown())
140 return nullptr;
139141 MDNode *Scope = nullptr;
140142 MDNode *InlinedAt = nullptr;
141143 DL.getScopeAndInlinedAt(Scope, InlinedAt, MF->getFunction()->getContext());
171173 std::make_tuple(Parent, DIDescriptor(Scope),
172174 nullptr, false)).first;
173175
174 if (!Parent && DIDescriptor(Scope).isSubprogram() &&
175 DISubprogram(Scope).describes(MF->getFunction()))
176 if (!Parent) {
177 assert(DIDescriptor(Scope).isSubprogram());
178 assert(DISubprogram(Scope).describes(MF->getFunction()));
179 assert(!CurrentFnLexicalScope);
176180 CurrentFnLexicalScope = &I->second;
181 }
177182
178183 return &I->second;
179184 }
531531 if (isLValueReference() && isRValueReference())
532532 return false;
533533
534 if (auto *F = getFunction()) {
535 LLVMContext &Ctxt = F->getContext();
536 for (auto &BB : *F) {
537 for (auto &I : BB) {
538 DebugLoc DL = I.getDebugLoc();
539 if (DL.isUnknown())
540 continue;
541
542 MDNode *Scope = nullptr;
543 MDNode *IA = nullptr;
544 // walk the inlined-at scopes
545 while (DL.getScopeAndInlinedAt(Scope, IA, F->getContext()), IA)
546 DL = DebugLoc::getFromDILocation(IA);
547 DL.getScopeAndInlinedAt(Scope, IA, Ctxt);
548 assert(!IA);
549 while (!DIDescriptor(Scope).isSubprogram()) {
550 DILexicalBlockFile D(Scope);
551 Scope = D.isLexicalBlockFile()
552 ? D.getScope()
553 : DebugLoc::getFromDILexicalBlock(Scope).getScope(Ctxt);
554 }
555 if (!DISubprogram(Scope).describes(F))
556 return false;
557 }
558 }
559 }
534560 return DbgNode->getNumOperands() == 20;
535561 }
536562
1717 ; CHECK-NOT: DW_TAG
1818 ; CHECK: DW_AT_name {{.*}} "~C"
1919
20 ; CHECK: [[D1_ABS:.*]]: DW_TAG_subprogram
21 ; CHECK-NOT: DW_TAG
22 ; CHECK: DW_AT_MIPS_linkage_name {{.*}} "_ZN1CD1Ev"
23 ; CHECK-NOT: {{DW_TAG|NULL}}
24 ; CHECK: [[D1_THIS_ABS:.*]]: DW_TAG_formal_parameter
25 ; CHECK-NOT: DW_TAG
26 ; CHECK: DW_AT_name {{.*}} "this"
27
2028 ; CHECK: DW_TAG_subprogram
2129 ; CHECK-NOT: DW_TAG
2230 ; CHECK: DW_AT_name {{.*}} "fun4"
31 ; CHECK-NOT: {{DW_TAG|NULL}}
32 ; CHECK: DW_TAG_lexical_block
33 ; CHECK-NOT: {{DW_TAG|NULL}}
34 ; CHECK: DW_TAG_inlined_subroutine
35 ; CHECK-NOT: DW_TAG
36 ; CHECK: DW_AT_abstract_origin {{.*}} {[[D1_ABS]]}
37 ; CHECK-NOT: {{DW_TAG|NULL}}
38 ; CHECK: DW_TAG_formal_parameter
39 ; CHECK-NOT: DW_TAG
40 ; CHECK: DW_AT_abstract_origin {{.*}} {[[D1_THIS_ABS]]}
2341
24 ; FIXME: The dtor is inlined into fun4 and should have an inlined_subroutine
25 ; entry. (it may be necessary to put some non-trivial instruction, such as an
26 ; assignment to a global, in the dtor just to ensure its emission/inlining)
42 ; FIXME: D2 is actually inlined into D1 but doesn't show up here, possibly due
43 ; to there being no work in D2 (calling another member function from the dtor
44 ; causes D2 to show up, calling a free function doesn't).
2745
28 ; CHECK-NOT: DW_TAG_inlined_subroutine
29
30 ; CHECK: DW_TAG_subprogram
3146 ; CHECK-NOT: DW_TAG
32 ; CHECK: DW_AT_MIPS_linkage_name {{.*}} "_ZN1CD1Ev"
33
34 ; FIXME: But I think where the real issue is for PR20038 is that the D1 ctor, ;
35 ; calling and inlining D2, doesn't end up with an inlined_subroutine. Though this
36 ; might be more the result of a lack of any actual work in D2 (again, could use
37 ; an assignment to global, etc)
38
39 ; CHECK-NOT: DW_TAG_inlined_subroutine
47 ; CHECK: NULL
48 ; CHECK-NOT: DW_TAG
49 ; CHECK: NULL
50 ; CHECK-NOT: DW_TAG
51 ; CHECK: NULL
4052
4153 %struct.C = type { i8 }
4254
4658 define void @_Z4fun4v() #0 {
4759 entry:
4860 %this.addr.i.i = alloca %struct.C*, align 8, !dbg !21
49 %this.addr.i = alloca %struct.C*, align 8
61 %this.addr.i = alloca %struct.C*, align 8, !dbg !22
5062 %agg.tmp.ensured = alloca %struct.C, align 1
5163 %cleanup.cond = alloca i1
52 %0 = load i8* @b, align 1, !dbg !22
53 %tobool = trunc i8 %0 to i1, !dbg !22
64 %0 = load i8* @b, align 1, !dbg !24
65 %tobool = trunc i8 %0 to i1, !dbg !24
5466 store i1 false, i1* %cleanup.cond
55 br i1 %tobool, label %land.rhs, label %land.end, !dbg !22
67 br i1 %tobool, label %land.rhs, label %land.end, !dbg !24
5668
5769 land.rhs: ; preds = %entry
58 store i1 true, i1* %cleanup.cond, !dbg !23
70 store i1 true, i1* %cleanup.cond, !dbg !25
5971 br label %land.end
6072
6173 land.end: ; preds = %land.rhs, %entry
6274 %1 = phi i1 [ false, %entry ], [ true, %land.rhs ]
63 %cleanup.is_active = load i1* %cleanup.cond
64 br i1 %cleanup.is_active, label %cleanup.action, label %cleanup.done
75 %cleanup.is_active = load i1* %cleanup.cond, !dbg !27
76 br i1 %cleanup.is_active, label %cleanup.action, label %cleanup.done, !dbg !27
6577
6678 cleanup.action: ; preds = %land.end
67 store %struct.C* %agg.tmp.ensured, %struct.C** %this.addr.i, align 8
68 call void @llvm.dbg.declare(metadata !{%struct.C** %this.addr.i}, metadata !25), !dbg !27
69 %this1.i = load %struct.C** %this.addr.i
79 store %struct.C* %agg.tmp.ensured, %struct.C** %this.addr.i, align 8, !dbg !22
80 call void @llvm.dbg.declare(metadata !{%struct.C** %this.addr.i}, metadata !29), !dbg !31
81 %this1.i = load %struct.C** %this.addr.i, !dbg !22
7082 store %struct.C* %this1.i, %struct.C** %this.addr.i.i, align 8, !dbg !21
71 call void @llvm.dbg.declare(metadata !{%struct.C** %this.addr.i.i}, metadata !28), !dbg !29
83 call void @llvm.dbg.declare(metadata !{%struct.C** %this.addr.i.i}, metadata !32), !dbg !33
7284 %this1.i.i = load %struct.C** %this.addr.i.i, !dbg !21
73 br label %cleanup.done
85 br label %cleanup.done, !dbg !22
7486
7587 cleanup.done: ; preds = %cleanup.action, %land.end
76 ret void, !dbg !22
88 ret void, !dbg !34
7789 }
7890
7991 ; Function Attrs: alwaysinline nounwind
8092 define void @_ZN1CD1Ev(%struct.C* %this) unnamed_addr #1 align 2 {
8193 entry:
82 %this.addr.i = alloca %struct.C*, align 8, !dbg !21
94 %this.addr.i = alloca %struct.C*, align 8, !dbg !37
8395 %this.addr = alloca %struct.C*, align 8
8496 store %struct.C* %this, %struct.C** %this.addr, align 8
85 call void @llvm.dbg.declare(metadata !{%struct.C** %this.addr}, metadata !25), !dbg !27
97 call void @llvm.dbg.declare(metadata !{%struct.C** %this.addr}, metadata !29), !dbg !38
8698 %this1 = load %struct.C** %this.addr
87 store %struct.C* %this1, %struct.C** %this.addr.i, align 8, !dbg !21
88 call void @llvm.dbg.declare(metadata !{%struct.C** %this.addr.i}, metadata !28), !dbg !29
89 %this1.i = load %struct.C** %this.addr.i, !dbg !21
90 ret void, !dbg !21
99 store %struct.C* %this1, %struct.C** %this.addr.i, align 8, !dbg !37
100 call void @llvm.dbg.declare(metadata !{%struct.C** %this.addr.i}, metadata !32), !dbg !39
101 %this1.i = load %struct.C** %this.addr.i, !dbg !37
102 ret void, !dbg !37
91103 }
92104
93105 ; Function Attrs: alwaysinline nounwind
95107 entry:
96108 %this.addr = alloca %struct.C*, align 8
97109 store %struct.C* %this, %struct.C** %this.addr, align 8
98 call void @llvm.dbg.declare(metadata !{%struct.C** %this.addr}, metadata !28), !dbg !30
110 call void @llvm.dbg.declare(metadata !{%struct.C** %this.addr}, metadata !32), !dbg !40
99111 %this1 = load %struct.C** %this.addr
100 ret void, !dbg !31
112 ret void, !dbg !41
101113 }
102114
103115 ; Function Attrs: nounwind readnone
132144 !18 = metadata !{i32 2, metadata !"Dwarf Version", i32 4}
133145 !19 = metadata !{i32 2, metadata !"Debug Info Version", i32 1}
134146 !20 = metadata !{metadata !"clang version 3.5.0 "}
135 !21 = metadata !{i32 6, i32 0, metadata !17, null}
136 !22 = metadata !{i32 5, i32 0, metadata !12, null}
137 !23 = metadata !{i32 5, i32 0, metadata !24, null}
138 !24 = metadata !{i32 786443, metadata !5, metadata !12, i32 5, i32 0, i32 1, i32 1} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/PR20038.cpp]
139 !25 = metadata !{i32 786689, metadata !17, metadata !"this", null, i32 16777216, metadata !26, i32 1088, i32 0} ; [ DW_TAG_arg_variable ] [this] [line 0]
140 !26 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64, i64 64, i64 0, i32 0, metadata !"_ZTS1C"} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from _ZTS1C]
141 !27 = metadata !{i32 0, i32 0, metadata !17, null}
142 !28 = metadata !{i32 786689, metadata !16, metadata !"this", null, i32 16777216, metadata !26, i32 1088, i32 0} ; [ DW_TAG_arg_variable ] [this] [line 0]
143 !29 = metadata !{i32 0, i32 0, metadata !16, metadata !21}
144 !30 = metadata !{i32 0, i32 0, metadata !16, null}
145 !31 = metadata !{i32 6, i32 0, metadata !16, null}
147 !21 = metadata !{i32 6, i32 0, metadata !17, metadata !22}
148 !22 = metadata !{i32 5, i32 0, metadata !23, null}
149 !23 = metadata !{i32 786443, metadata !5, metadata !12, i32 5, i32 0, i32 3, i32 3} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/PR20038.cpp]
150 !24 = metadata !{i32 5, i32 0, metadata !12, null}
151 !25 = metadata !{i32 5, i32 0, metadata !26, null}
152 !26 = metadata !{i32 786443, metadata !5, metadata !12, i32 5, i32 0, i32 1, i32 1} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/PR20038.cpp]
153 !27 = metadata !{i32 5, i32 0, metadata !28, null}
154 !28 = metadata !{i32 786443, metadata !5, metadata !12, i32 5, i32 0, i32 2, i32 2} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/PR20038.cpp]
155 !29 = metadata !{i32 786689, metadata !17, metadata !"this", null, i32 16777216, metadata !30, i32 1088, i32 0} ; [ DW_TAG_arg_variable ] [this] [line 0]
156 !30 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64, i64 64, i64 0, i32 0, metadata !"_ZTS1C"} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from _ZTS1C]
157 !31 = metadata !{i32 0, i32 0, metadata !17, metadata !22}
158 !32 = metadata !{i32 786689, metadata !16, metadata !"this", null, i32 16777216, metadata !30, i32 1088, i32 0} ; [ DW_TAG_arg_variable ] [this] [line 0]
159 !33 = metadata !{i32 0, i32 0, metadata !16, metadata !21}
160 !34 = metadata !{i32 5, i32 0, metadata !35, null}
161 !35 = metadata !{i32 786443, metadata !5, metadata !36, i32 5, i32 0, i32 5, i32 5} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/PR20038.cpp]
162 !36 = metadata !{i32 786443, metadata !5, metadata !12, i32 5, i32 0, i32 4, i32 4} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/PR20038.cpp]
163 !37 = metadata !{i32 6, i32 0, metadata !17, null}
164 !38 = metadata !{i32 0, i32 0, metadata !17, null}
165 !39 = metadata !{i32 0, i32 0, metadata !16, metadata !37}
166 !40 = metadata !{i32 0, i32 0, metadata !16, null}
167 !41 = metadata !{i32 6, i32 0, metadata !16, null}