diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index b9919073e8267..e1a230f7588c6 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -11927,7 +11927,9 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) { return false; // Variables in other module units shouldn't be forced to be emitted. - if (VD->isInAnotherModuleUnit()) + auto *VM = VD->getOwningModule(); + if (VM && VM->getTopLevelModule()->isModulePurview() && + VM->getTopLevelModule() != getCurrentNamedModule()) return false; // Variables that can be needed in other TUs are required.