@@ -2163,7 +2163,8 @@ ModuleDecl *ClangImporter::Implementation::loadModule(
21632163 ASTContext &ctx = getNameImporter ().getContext ();
21642164
21652165 // `CxxStdlib` is the only accepted spelling of the C++ stdlib module name.
2166- if (path.front ().Item .is (" std" ))
2166+ if (path.front ().Item .is (" std" ) ||
2167+ path.front ().Item .str ().starts_with (" std_" ))
21672168 return nullptr ;
21682169 if (path.front ().Item == ctx.Id_CxxStdlib ) {
21692170 ImportPath::Builder adjustedPath (ctx.getIdentifier (" std" ), importLoc);
@@ -3985,6 +3986,13 @@ ModuleDecl *ClangModuleUnit::getOverlayModule() const {
39853986 ImportPath::Module::Builder builder (M->getName ());
39863987 (void ) owner.loadModule (SourceLoc (), std::move (builder).get ());
39873988 }
3989+ // If this Clang module is a part of the C++ stdlib, and we haven't loaded
3990+ // the overlay for it so far, it is a split libc++ module (e.g. std_vector).
3991+ // Load the CxxStdlib overlay explicitly.
3992+ if (!overlay && importer::isCxxStdModule (clangModule)) {
3993+ ImportPath::Module::Builder builder (Ctx.Id_CxxStdlib );
3994+ overlay = owner.loadModule (SourceLoc (), std::move (builder).get ());
3995+ }
39883996 auto mutableThis = const_cast <ClangModuleUnit *>(this );
39893997 mutableThis->overlayModule .setPointerAndInt (overlay, true );
39903998 }
@@ -7697,12 +7705,7 @@ const clang::TypedefType *ClangImporter::getTypeDefForCXXCFOptionsDefinition(
76977705
76987706bool importer::requiresCPlusPlus (const clang::Module *module ) {
76997707 // The libc++ modulemap doesn't currently declare the requirement.
7700- if (module ->getTopLevelModuleName () == " std" )
7701- return true ;
7702- // In recent libc++ versions the module is split into multiple top-level
7703- // modules (std_vector, std_utility, etc).
7704- if (module ->getTopLevelModule ()->IsSystem &&
7705- module ->getTopLevelModuleName ().starts_with (" std_" ))
7708+ if (isCxxStdModule (module ))
77067709 return true ;
77077710
77087711 // Modulemaps often declare the requirement for the top-level module only.
@@ -7716,6 +7719,18 @@ bool importer::requiresCPlusPlus(const clang::Module *module) {
77167719 });
77177720}
77187721
7722+ bool importer::isCxxStdModule (const clang::Module *module ) {
7723+ if (module ->getTopLevelModuleName () == " std" )
7724+ return true ;
7725+ // In recent libc++ versions the module is split into multiple top-level
7726+ // modules (std_vector, std_utility, etc).
7727+ if (module ->getTopLevelModule ()->IsSystem &&
7728+ module ->getTopLevelModuleName ().starts_with (" std_" ))
7729+ return true ;
7730+
7731+ return false ;
7732+ }
7733+
77197734llvm::Optional<clang::QualType>
77207735importer::getCxxReferencePointeeTypeOrNone (const clang::Type *type) {
77217736 if (type->isReferenceType ())
0 commit comments