From 36408e75696d97ccf0e054335c5beb29843183fe Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Wed, 4 Jun 2014 23:50:52 +0000 Subject: DebugInfo: Reapply r209984 (reverted in r210143), asserting that abstract DbgVariables have DIEs. Abstract variables within abstract scopes that are entirely optimized away in their first inlining are omitted because their scope is not present so the variable is never created. Instead, we should ensure the scope is created so the variable can be added, even if it's been optimized away in its first inlining. This fixes the incorrect debug info in missing-abstract-variable.ll (added in r210143) and passes an asserts self-hosting build, so hopefully there's not more of these issues left behind... *fingers crossed*. llvm-svn: 210221 --- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 43 +++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp') diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 73496b0c382..4dd36830a44 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1052,24 +1052,49 @@ DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &DV, return findAbstractVariable(DV, ScopeLoc.getScope(DV->getContext())); } -DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &DV, - const MDNode *ScopeNode) { +DbgVariable *DwarfDebug::getExistingAbstractVariable(DIVariable &DV, + DIVariable &Cleansed) { LLVMContext &Ctx = DV->getContext(); // More then one inlined variable corresponds to one abstract variable. - DIVariable Var = cleanseInlinedVariable(DV, Ctx); - auto I = AbstractVariables.find(Var); + // FIXME: This duplication of variables when inlining should probably be + // removed. It's done to allow each DIVariable to describe its location + // because the DebugLoc on the dbg.value/declare isn't accurate. We should + // make it accurate then remove this duplication/cleansing stuff. + Cleansed = cleanseInlinedVariable(DV, Ctx); + auto I = AbstractVariables.find(Cleansed); if (I != AbstractVariables.end()) return I->second.get(); + return nullptr; +} - LexicalScope *Scope = LScopes.findAbstractScope(ScopeNode); - if (!Scope) - return nullptr; - +DbgVariable *DwarfDebug::createAbstractVariable(DIVariable &Var, + LexicalScope *Scope) { auto AbsDbgVariable = make_unique(Var, nullptr, this); addScopeVariable(Scope, AbsDbgVariable.get()); return (AbstractVariables[Var] = std::move(AbsDbgVariable)).get(); } +DbgVariable *DwarfDebug::getOrCreateAbstractVariable(DIVariable &DV, + const MDNode *ScopeNode) { + DIVariable Cleansed = DV; + if (DbgVariable *Var = getExistingAbstractVariable(DV, Cleansed)) + return Var; + + return createAbstractVariable(Cleansed, + LScopes.getOrCreateAbstractScope(ScopeNode)); +} + +DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &DV, + const MDNode *ScopeNode) { + DIVariable Cleansed = DV; + if (DbgVariable *Var = getExistingAbstractVariable(DV, Cleansed)) + return Var; + + if (LexicalScope *Scope = LScopes.findAbstractScope(ScopeNode)) + return createAbstractVariable(Cleansed, Scope); + return nullptr; +} + // If Var is a current function argument then add it to CurrentFnArguments list. bool DwarfDebug::addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope) { if (!LScopes.isCurrentFunctionScope(Scope)) @@ -1513,7 +1538,7 @@ void DwarfDebug::endFunction(const MachineFunction *MF) { assert(DV && DV.isVariable()); if (!ProcessedVars.insert(DV)) continue; - findAbstractVariable(DV, DV.getContext()); + getOrCreateAbstractVariable(DV, DV.getContext()); } constructAbstractSubprogramScopeDIE(TheCU, AScope); } -- cgit v1.2.3