[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 03:58:50 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:

If a function was inlined into multiple other functions and optimized out, constructAbstractSubprogramScopeDIE will be called twice for the function's DISubprogram. This may cause a subprogram abstract DIE to have duplicate children. We want to avoid that.

> like what bad thing happens if the insertion happened here at/next to the contains?

I'm not aware of any issues with merging lookup and insertion here, so I proceeded with it. 

https://github.com/llvm/llvm-project/pull/159104


More information about the llvm-commits mailing list