diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -278,7 +278,7 @@ /// Get the FI entries, sorted by fragment offset. ArrayRef getFrameIndexExprs() const; bool hasFrameIndexExprs() const { return holds(); } - void addMMIEntry(const DbgVariable &V); + void addMMIEntry(const DIExpression *Expr, int FI); // Translate tag to proper Dwarf tag. dwarf::Tag getTag() const { diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -305,12 +305,8 @@ return FrameIndexExprs; } -void DbgVariable::addMMIEntry(const DbgVariable &V) { - assert(V.getVariable() == getVariable() && "conflicting variable"); - assert(V.getInlinedAt() == getInlinedAt() && "conflicting inlined-at location"); - +void DbgVariable::addMMIEntry(const DIExpression *Expr, int FI) { auto &FrameIndexExprs = get().FrameIndexExprs; - auto &VFrameIndexExprs = V.get().FrameIndexExprs; // FIXME: This logic should not be necessary anymore, as we now have proper // deduplication. However, without it, we currently run into the assertion @@ -322,12 +318,10 @@ return; } - for (const auto &FIE : VFrameIndexExprs) - // Ignore duplicate entries. - if (llvm::none_of(FrameIndexExprs, [&](const FrameIndexExpr &Other) { - return FIE.FI == Other.FI && FIE.Expr == Other.Expr; - })) - FrameIndexExprs.push_back(FIE); + if (llvm::none_of(FrameIndexExprs, [&](const FrameIndexExpr &Other) { + return FI == Other.FI && Expr == Other.Expr; + })) + FrameIndexExprs.push_back({FI, Expr}); assert((FrameIndexExprs.size() == 1 || llvm::all_of(FrameIndexExprs, @@ -1574,6 +1568,15 @@ } ensureAbstractEntityIsCreatedIfScoped(TheCU, Var.first, Scope->getScopeNode()); + + if (DbgVariable *DbgVar = MFVars.lookup(Var)) { + if (DbgVar->hasFrameIndexExprs()) + DbgVar->addMMIEntry(VI.Expr, VI.getStackSlot()); + else + DbgVar->addEntryValueExpr(VI.getEntryValueRegister(), *VI.Expr); + continue; + } + auto RegVar = std::make_unique( cast(Var.first), Var.second); if (VI.inStackSlot()) @@ -1582,16 +1585,9 @@ RegVar->initializeEntryValue(VI.getEntryValueRegister(), *VI.Expr); LLVM_DEBUG(dbgs() << "Created DbgVariable for " << VI.Var->getName() << "\n"); - - if (DbgVariable *DbgVar = MFVars.lookup(Var)) { - if (DbgVar->hasFrameIndexExprs()) - DbgVar->addMMIEntry(*RegVar); - else - DbgVar->addEntryValueExpr(VI.getEntryValueRegister(), *VI.Expr); - } else if (InfoHolder.addScopeVariable(Scope, RegVar.get())) { - MFVars.insert({Var, RegVar.get()}); - ConcreteEntities.push_back(std::move(RegVar)); - } + InfoHolder.addScopeVariable(Scope, RegVar.get()); + MFVars.insert({Var, RegVar.get()}); + ConcreteEntities.push_back(std::move(RegVar)); } } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h b/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h --- a/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h @@ -150,8 +150,7 @@ MCSymbol *getRnglistsTableBaseSym() const { return RnglistsTableBaseSym; } void setRnglistsTableBaseSym(MCSymbol *Sym) { RnglistsTableBaseSym = Sym; } - /// \returns false if the variable was merged with a previous one. - bool addScopeVariable(LexicalScope *LS, DbgVariable *Var); + void addScopeVariable(LexicalScope *LS, DbgVariable *Var); void addScopeLabel(LexicalScope *LS, DbgLabel *Label); diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp @@ -102,21 +102,15 @@ StrPool.emit(*Asm, StrSection, OffsetSection, UseRelativeOffsets); } -bool DwarfFile::addScopeVariable(LexicalScope *LS, DbgVariable *Var) { +void DwarfFile::addScopeVariable(LexicalScope *LS, DbgVariable *Var) { auto &ScopeVars = ScopeVariables[LS]; const DILocalVariable *DV = Var->getVariable(); if (unsigned ArgNum = DV->getArg()) { - auto Cached = ScopeVars.Args.find(ArgNum); - if (Cached == ScopeVars.Args.end()) - ScopeVars.Args[ArgNum] = Var; - else { - Cached->second->addMMIEntry(*Var); - return false; - } + auto Ret = ScopeVars.Args.insert({ArgNum, Var}); + assert(Ret.second); } else { ScopeVars.Locals.push_back(Var); } - return true; } void DwarfFile::addScopeLabel(LexicalScope *LS, DbgLabel *Label) {