summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
diff options
context:
space:
mode:
authorHans Wennborg <hans@chromium.org>2023-09-29 14:09:04 +0200
committerHans Wennborg <hans@chromium.org>2023-09-29 14:23:31 +0200
commiteee1f7cef856241ad7d66b715c584d29b1c89ca9 (patch)
tree8201bea81903f1dc28b2921b79611efc1f5e39b0 /llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
parent00f2d9b0ebcd3a4d56945c5260b8e891087a7861 (diff)
Revert "[DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)"
This caused asserts: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:2331: virtual void llvm::DwarfDebug::endFunctionImpl(const llvm::MachineFunction *): Assertion `LScopes.getAbstractScopesList().size() == NumAbstractSubprograms && "getOrCreateAbstractScope() inserted an abstract subprogram scope"' failed. See comment on the code review for reproducer. > RFC https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544 > > Similar to imported declarations, the patch tracks function-local types in > DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with > the aforementioned metadata change and provided a support of function-local > types scoped within a lexical block. > > The patch assumes that DICompileUnit's 'enums field' no longer tracks local > types and DwarfDebug would assert if any locally-scoped types get placed there. > > Reviewed By: jmmartinez > > Differential Revision: https://reviews.llvm.org/D144006 This reverts commit f8aab289b5549086062588fba627b0e4d3a5ab15.
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp60
1 files changed, 20 insertions, 40 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index b14d1dd58367..42bf75573750 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -592,9 +592,10 @@ void DwarfCompileUnit::constructScopeDIE(LexicalScope *Scope,
return;
// Emit lexical blocks.
- DIE *ScopeDIE = getOrCreateLexicalBlockDIE(Scope, ParentScopeDIE);
+ DIE *ScopeDIE = constructLexicalScopeDIE(Scope);
assert(ScopeDIE && "Scope DIE should not be null.");
+ ParentScopeDIE.addChild(ScopeDIE);
createAndAddScopeChildren(Scope, *ScopeDIE);
}
@@ -714,39 +715,24 @@ DIE *DwarfCompileUnit::constructInlinedScopeDIE(LexicalScope *Scope,
return ScopeDIE;
}
-DIE *DwarfCompileUnit::getOrCreateLexicalBlockDIE(LexicalScope *Scope,
- DIE &ParentScopeDIE) {
+// Construct new DW_TAG_lexical_block for this scope and attach
+// DW_AT_low_pc/DW_AT_high_pc labels.
+DIE *DwarfCompileUnit::constructLexicalScopeDIE(LexicalScope *Scope) {
if (DD->isLexicalScopeDIENull(Scope))
return nullptr;
const auto *DS = Scope->getScopeNode();
- DIE *ScopeDIE = nullptr;
-
- // FIXME: We may have a concrete DIE for this scope already created.
- // This may happen when we emit local variables for an abstract tree of
- // an inlined function: if a local variable has a templated type with
- // a function-local type as a template parameter. See PR55680 for details
- // (see also llvm/test/DebugInfo/Generic/local-type-as-template-parameter.ll).
- if (!Scope->isAbstractScope() && !Scope->getInlinedAt()) {
- if (auto It = LexicalBlockDIEs.find(DS); It != LexicalBlockDIEs.end()) {
- ScopeDIE = It->second;
- assert(!ScopeDIE->findAttribute(dwarf::DW_AT_low_pc) &&
- !ScopeDIE->findAttribute(dwarf::DW_AT_ranges));
- assert(ScopeDIE->getParent() == &ParentScopeDIE);
- }
- }
- if (!ScopeDIE) {
- ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_lexical_block);
- ParentScopeDIE.addChild(ScopeDIE);
-
- if (Scope->isAbstractScope()) {
- assert(!getAbstractScopeDIEs().count(DS) &&
- "Abstract DIE for this scope exists!");
- getAbstractScopeDIEs()[DS] = ScopeDIE;
- return ScopeDIE;
- }
- if (!Scope->getInlinedAt())
- LexicalBlockDIEs[DS] = ScopeDIE;
+ auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_lexical_block);
+ if (Scope->isAbstractScope()) {
+ assert(!getAbstractScopeDIEs().count(DS) &&
+ "Abstract DIE for this scope exists!");
+ getAbstractScopeDIEs()[DS] = ScopeDIE;
+ return ScopeDIE;
+ }
+ if (!Scope->getInlinedAt()) {
+ assert(!LexicalBlockDIEs.count(DS) &&
+ "Concrete out-of-line DIE for this scope exists!");
+ LexicalBlockDIEs[DS] = ScopeDIE;
}
attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges());
@@ -1700,21 +1686,15 @@ void DwarfCompileUnit::createBaseTypeDIEs() {
}
}
-DIE *DwarfCompileUnit::getLocalContextDIE(const DILexicalBlock *LB) {
+DIE *DwarfCompileUnit::getLexicalBlockDIE(const DILexicalBlock *LB) {
// Assume if there is an abstract tree all the DIEs are already emitted.
bool isAbstract = getAbstractScopeDIEs().count(LB->getSubprogram());
if (isAbstract && getAbstractScopeDIEs().count(LB))
return getAbstractScopeDIEs()[LB];
assert(!isAbstract && "Missed lexical block DIE in abstract tree!");
- // Check if we have a concrete DIE.
- if (auto It = LexicalBlockDIEs.find(LB); It != LexicalBlockDIEs.end())
- return It->second;
-
- // If nothing available found, we cannot just create a new lexical block,
- // because it isn't known where to put it into the DIE tree.
- // So, we may only try to find the most close avaiable parent DIE.
- return getOrCreateContextDIE(LB->getScope()->getNonLexicalBlockFileScope());
+ // Return a concrete DIE if it exists or nullptr otherwise.
+ return LexicalBlockDIEs.lookup(LB);
}
DIE *DwarfCompileUnit::getOrCreateContextDIE(const DIScope *Context) {
@@ -1722,7 +1702,7 @@ DIE *DwarfCompileUnit::getOrCreateContextDIE(const DIScope *Context) {
if (auto *LFScope = dyn_cast<DILexicalBlockFile>(Context))
Context = LFScope->getNonLexicalBlockFileScope();
if (auto *LScope = dyn_cast<DILexicalBlock>(Context))
- return getLocalContextDIE(LScope);
+ return getLexicalBlockDIE(LScope);
// Otherwise the context must be a DISubprogram.
auto *SPScope = cast<DISubprogram>(Context);