@@ -791,7 +791,8 @@ getEmbedBitcodeInvocationArguments(std::vector<std::string> &invocationArgStrs,
791791void
792792importer::addCommonInvocationArguments (
793793 std::vector<std::string> &invocationArgStrs,
794- ASTContext &ctx, bool ignoreClangTarget) {
794+ ASTContext &ctx, bool requiresBuiltinHeadersInSystemModules,
795+ bool ignoreClangTarget) {
795796 using ImporterImpl = ClangImporter::Implementation;
796797 llvm::Triple triple = ctx.LangOpts .Target ;
797798 // Use clang specific target triple if given.
@@ -961,6 +962,16 @@ importer::addCommonInvocationArguments(
961962 }
962963 }
963964 }
965+
966+ for (auto &overlay : searchPathOpts.VFSOverlayFiles ) {
967+ invocationArgStrs.push_back (" -ivfsoverlay" );
968+ invocationArgStrs.push_back (overlay);
969+ }
970+
971+ if (requiresBuiltinHeadersInSystemModules) {
972+ invocationArgStrs.push_back (" -Xclang" );
973+ invocationArgStrs.push_back (" -fbuiltin-headers-in-system-modules" );
974+ }
964975}
965976
966977bool ClangImporter::canReadPCH (StringRef PCHFilename) {
@@ -1144,13 +1155,13 @@ ClangImporter::getClangDriverArguments(ASTContext &ctx, bool ignoreClangTarget)
11441155 getEmbedBitcodeInvocationArguments (invocationArgStrs, ctx);
11451156 break ;
11461157 }
1147- addCommonInvocationArguments (invocationArgStrs, ctx, ignoreClangTarget);
1158+ addCommonInvocationArguments (invocationArgStrs, ctx,
1159+ requiresBuiltinHeadersInSystemModules, ignoreClangTarget);
11481160 return invocationArgStrs;
11491161}
11501162
11511163std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments (
1152- ClangImporter *importer, ASTContext &ctx,
1153- llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
1164+ ASTContext &ctx, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
11541165 bool ignoreClangTarget) {
11551166 std::unique_ptr<clang::CompilerInvocation> CI;
11561167
@@ -1165,7 +1176,7 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
11651176 llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> tempDiagOpts{
11661177 new clang::DiagnosticOptions};
11671178 auto *tempDiagClient =
1168- new ClangDiagnosticConsumer (importer-> Impl , *tempDiagOpts,
1179+ new ClangDiagnosticConsumer (Impl, *tempDiagOpts,
11691180 ctx.ClangImporterOpts .DumpClangDiagnostics );
11701181 auto clangDiags = clang::CompilerInstance::createDiagnostics (
11711182 tempDiagOpts.get (), tempDiagClient,
@@ -1255,20 +1266,18 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
12551266 // resilient and provide a module even if there were building it.
12561267 auto TempVFS = clang::createVFSFromCompilerInvocation (
12571268 *CI, *clangDiags,
1258- VFS ? VFS : importer-> Impl .SwiftContext .SourceMgr .getFileSystem ());
1269+ VFS ? VFS : Impl.SwiftContext .SourceMgr .getFileSystem ());
12591270
12601271 std::vector<std::string> FilteredModuleMapFiles;
12611272 for (auto ModuleMapFile : CI->getFrontendOpts ().ModuleMapFiles ) {
12621273 if (ctx.ClangImporterOpts .HasClangIncludeTreeRoot ) {
12631274 // There is no need to add any module map file here. Issue a warning and
12641275 // drop the option.
1265- importer->Impl .diagnose (SourceLoc (), diag::module_map_ignored,
1266- ModuleMapFile);
1276+ Impl.diagnose (SourceLoc (), diag::module_map_ignored, ModuleMapFile);
12671277 } else if (TempVFS->exists (ModuleMapFile)) {
12681278 FilteredModuleMapFiles.push_back (ModuleMapFile);
12691279 } else {
1270- importer->Impl .diagnose (SourceLoc (), diag::module_map_not_found,
1271- ModuleMapFile);
1280+ Impl.diagnose (SourceLoc (), diag::module_map_not_found, ModuleMapFile);
12721281 }
12731282 }
12741283 CI->getFrontendOpts ().ModuleMapFiles = FilteredModuleMapFiles;
@@ -1337,6 +1346,9 @@ ClangImporter::create(ASTContext &ctx,
13371346 ClangInvocationFileMapping fileMapping =
13381347 getClangInvocationFileMapping (ctx, nullptr , ignoreFileMapping);
13391348
1349+ importer->requiresBuiltinHeadersInSystemModules =
1350+ fileMapping.requiresBuiltinHeadersInSystemModules ;
1351+
13401352 // Avoid creating indirect file system when using include tree.
13411353 if (!ctx.ClangImporterOpts .HasClangIncludeTreeRoot ) {
13421354 // Wrap Swift's FS to allow Clang to override the working directory
@@ -1377,14 +1389,11 @@ ClangImporter::create(ASTContext &ctx,
13771389
13781390 // Create a new Clang compiler invocation.
13791391 {
1380- if (auto ClangArgs = getClangCC1Arguments (importer. get (), ctx, VFS))
1392+ if (auto ClangArgs = importer-> getClangCC1Arguments (ctx, VFS))
13811393 importer->Impl .ClangArgs = *ClangArgs;
13821394 else
13831395 return nullptr ;
13841396
1385- if (fileMapping.requiresBuiltinHeadersInSystemModules )
1386- importer->Impl .ClangArgs .push_back (" -fbuiltin-headers-in-system-modules" );
1387-
13881397 ArrayRef<std::string> invocationArgStrs = importer->Impl .ClangArgs ;
13891398 if (importerOpts.DumpClangDiagnostics ) {
13901399 llvm::errs () << " clang importer cc1 args: '" ;
@@ -1472,8 +1481,7 @@ ClangImporter::create(ASTContext &ctx,
14721481 if (ctx.LangOpts .ClangTarget .has_value ()) {
14731482 // If '-clang-target' is set, create a mock invocation with the Swift triple
14741483 // to configure CodeGen and Target options for Swift compilation.
1475- auto swiftTargetClangArgs =
1476- getClangCC1Arguments (importer.get (), ctx, VFS, true );
1484+ auto swiftTargetClangArgs = importer->getClangCC1Arguments (ctx, VFS, true );
14771485 if (!swiftTargetClangArgs)
14781486 return nullptr ;
14791487 auto swiftTargetClangInvocation = createClangInvocation (
0 commit comments