[Linker] Also treat a DIImportedEntity scope DISubprogram as needed.
[oota-llvm.git] / lib / Linker / IRMover.cpp
index aadaa73ae3d00ba3e28077072dd278547c33df18..16de0ec88f42af184316883b8d11daf889fcfa74 100644 (file)
@@ -1212,7 +1212,7 @@ void IRLinker::findNeededSubprograms(ValueToValueMapTy &ValueMap) {
     auto *CU = cast<DICompileUnit>(CompileUnits->getOperand(I));
     assert(CU && "Expected valid compile unit");
     // Ensure that we don't remove subprograms referenced by DIImportedEntity.
-    // It is not legal to have a DIImportedEntity with a null entity.
+    // It is not legal to have a DIImportedEntity with a null entity or scope.
     // FIXME: The DISubprogram for functions not linked in but kept due to
     // being referenced by a DIImportedEntity should also get their
     // IsDefinition flag is unset.
@@ -1220,6 +1220,8 @@ void IRLinker::findNeededSubprograms(ValueToValueMapTy &ValueMap) {
     for (auto *IE : CU->getImportedEntities()) {
       if (auto *SP = dyn_cast<DISubprogram>(IE->getEntity()))
         ImportedEntitySPs.insert(SP);
+      if (auto *SP = dyn_cast<DISubprogram>(IE->getScope()))
+        ImportedEntitySPs.insert(SP);
     }
     for (auto *Op : CU->getSubprograms()) {
       // Unless we were doing function importing and deferred metadata linking,