[llvm] [DebugInfo][DwarfDebug] Separate creation and population of abstract subprogram DIEs (PR #159104)
Vladislav Dzhidzhoev via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 17 04:19:09 PDT 2025
================
@@ -1237,8 +1224,47 @@ void DwarfCompileUnit::constructAbstractSubprogramScopeDIE(
DD->getDwarfVersion() <= 4 ? std::optional<dwarf::Form>()
: dwarf::DW_FORM_implicit_const,
dwarf::DW_INL_inlined);
- if (DIE *ObjectPointer = ContextCU->createAndAddScopeChildren(Scope, AbsDef))
- ContextCU->addDIEEntry(AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer);
+
+ return AbsDef;
+}
+
+std::pair<DIE *, DwarfCompileUnit *>
+DwarfCompileUnit::getOrCreateAbstractSubprogramContextDIE(
+ const DISubprogram *SP) {
+ bool Minimal = includeMinimalInlineScopes();
+ bool IgnoreScope = shouldPlaceInUnitDIE(SP, Minimal);
+ DIE *ContextDIE = getOrCreateSubprogramContextDIE(SP, IgnoreScope);
+
+ if (auto *SPDecl = SP->getDeclaration())
+ if (!Minimal)
+ getOrCreateSubprogramDIE(SPDecl, nullptr);
+
+ // The scope may be shared with a subprogram that has already been
+ // constructed in another CU, in which case we need to construct this
+ // subprogram in the same CU.
+ auto *ContextCU = IgnoreScope ? this : DD->lookupCU(ContextDIE->getUnitDie());
+
+ return std::make_pair(ContextDIE, ContextCU);
+}
+
+void DwarfCompileUnit::constructAbstractSubprogramScopeDIE(
+ LexicalScope *Scope) {
+ auto *SP = cast<DISubprogram>(Scope->getScopeNode());
+
+ if (getFinalizedAbstractSubprograms().contains(SP)) {
----------------
dzhidzhoev wrote:
> This may cause a subprogram abstract DIE to have duplicate children.
This is covered by the test `llvm/test/DebugInfo/AArch64/populate-abstract-sp-once.ll`. I've added a comment to `DwarfFile::FinalizedAbstractSubprograms` definition, and to DwarfCompileUnit.cpp as well.
https://github.com/llvm/llvm-project/pull/159104
More information about the llvm-commits
mailing list