@@ -621,6 +621,7 @@ void DwarfCompileUnit::constructAbstractSubprogramScopeDIE(
621621 auto *SP = cast<DISubprogram>(Scope->getScopeNode ());
622622
623623 DIE *ContextDIE;
624+ DwarfCompileUnit *ContextCU = this ;
624625
625626 if (includeMinimalInlineScopes ())
626627 ContextDIE = &getUnitDie ();
@@ -631,18 +632,23 @@ void DwarfCompileUnit::constructAbstractSubprogramScopeDIE(
631632 else if (auto *SPDecl = SP->getDeclaration ()) {
632633 ContextDIE = &getUnitDie ();
633634 getOrCreateSubprogramDIE (SPDecl);
634- } else
635+ } else {
635636 ContextDIE = getOrCreateContextDIE (resolve (SP->getScope ()));
637+ // The scope may be shared with a subprogram that has already been
638+ // constructed in another CU, in which case we need to construct this
639+ // subprogram in the same CU.
640+ ContextCU = DD->lookupCU (ContextDIE->getUnitDie ());
641+ }
636642
637643 // Passing null as the associated node because the abstract definition
638644 // shouldn't be found by lookup.
639- AbsDef = &createAndAddDIE (dwarf::DW_TAG_subprogram, *ContextDIE, nullptr );
640- applySubprogramAttributesToDefinition (SP, *AbsDef);
645+ AbsDef = &ContextCU-> createAndAddDIE (dwarf::DW_TAG_subprogram, *ContextDIE, nullptr );
646+ ContextCU-> applySubprogramAttributesToDefinition (SP, *AbsDef);
641647
642- if (!includeMinimalInlineScopes ())
643- addUInt (*AbsDef, dwarf::DW_AT_inline, None, dwarf::DW_INL_inlined);
644- if (DIE *ObjectPointer = createAndAddScopeChildren (Scope, *AbsDef))
645- addDIEEntry (*AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer);
648+ if (!ContextCU-> includeMinimalInlineScopes ())
649+ ContextCU-> addUInt (*AbsDef, dwarf::DW_AT_inline, None, dwarf::DW_INL_inlined);
650+ if (DIE *ObjectPointer = ContextCU-> createAndAddScopeChildren (Scope, *AbsDef))
651+ ContextCU-> addDIEEntry (*AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer);
646652}
647653
648654DIE *DwarfCompileUnit::constructImportedEntityDIE (
0 commit comments