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.
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,