@@ -789,7 +789,8 @@ getEmbedBitcodeInvocationArguments(std::vector<std::string> &invocationArgStrs,
789789void
790790importer::addCommonInvocationArguments (
791791 std::vector<std::string> &invocationArgStrs,
792- ASTContext &ctx, bool ignoreClangTarget) {
792+ ASTContext &ctx, bool requiresBuiltinHeadersInSystemModules,
793+ bool ignoreClangTarget) {
793794 using ImporterImpl = ClangImporter::Implementation;
794795 llvm::Triple triple = ctx.LangOpts .Target ;
795796 // Use clang specific target triple if given.
@@ -957,6 +958,16 @@ importer::addCommonInvocationArguments(
957958 }
958959 }
959960 }
961+
962+ for (auto &overlay : searchPathOpts.VFSOverlayFiles ) {
963+ invocationArgStrs.push_back (" -ivfsoverlay" );
964+ invocationArgStrs.push_back (overlay);
965+ }
966+
967+ if (requiresBuiltinHeadersInSystemModules) {
968+ invocationArgStrs.push_back (" -Xclang" );
969+ invocationArgStrs.push_back (" -fbuiltin-headers-in-system-modules" );
970+ }
960971}
961972
962973bool ClangImporter::canReadPCH (StringRef PCHFilename) {
@@ -1140,13 +1151,13 @@ ClangImporter::getClangDriverArguments(ASTContext &ctx, bool ignoreClangTarget)
11401151 getEmbedBitcodeInvocationArguments (invocationArgStrs, ctx);
11411152 break ;
11421153 }
1143- addCommonInvocationArguments (invocationArgStrs, ctx, ignoreClangTarget);
1154+ addCommonInvocationArguments (invocationArgStrs, ctx,
1155+ requiresBuiltinHeadersInSystemModules, ignoreClangTarget);
11441156 return invocationArgStrs;
11451157}
11461158
11471159std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments (
1148- ClangImporter *importer, ASTContext &ctx,
1149- llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
1160+ ASTContext &ctx, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
11501161 bool ignoreClangTarget) {
11511162 std::unique_ptr<clang::CompilerInvocation> CI;
11521163
@@ -1161,7 +1172,7 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
11611172 llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> tempDiagOpts{
11621173 new clang::DiagnosticOptions};
11631174 auto *tempDiagClient =
1164- new ClangDiagnosticConsumer (importer-> Impl , *tempDiagOpts,
1175+ new ClangDiagnosticConsumer (Impl, *tempDiagOpts,
11651176 ctx.ClangImporterOpts .DumpClangDiagnostics );
11661177 auto clangDiags = clang::CompilerInstance::createDiagnostics (
11671178 tempDiagOpts.get (), tempDiagClient,
@@ -1248,20 +1259,18 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
12481259 // resilient and provide a module even if there were building it.
12491260 auto TempVFS = clang::createVFSFromCompilerInvocation (
12501261 *CI, *clangDiags,
1251- VFS ? VFS : importer-> Impl .SwiftContext .SourceMgr .getFileSystem ());
1262+ VFS ? VFS : Impl.SwiftContext .SourceMgr .getFileSystem ());
12521263
12531264 std::vector<std::string> FilteredModuleMapFiles;
12541265 for (auto ModuleMapFile : CI->getFrontendOpts ().ModuleMapFiles ) {
12551266 if (ctx.ClangImporterOpts .HasClangIncludeTreeRoot ) {
12561267 // There is no need to add any module map file here. Issue a warning and
12571268 // drop the option.
1258- importer->Impl .diagnose (SourceLoc (), diag::module_map_ignored,
1259- ModuleMapFile);
1269+ Impl.diagnose (SourceLoc (), diag::module_map_ignored, ModuleMapFile);
12601270 } else if (TempVFS->exists (ModuleMapFile)) {
12611271 FilteredModuleMapFiles.push_back (ModuleMapFile);
12621272 } else {
1263- importer->Impl .diagnose (SourceLoc (), diag::module_map_not_found,
1264- ModuleMapFile);
1273+ Impl.diagnose (SourceLoc (), diag::module_map_not_found, ModuleMapFile);
12651274 }
12661275 }
12671276 CI->getFrontendOpts ().ModuleMapFiles = FilteredModuleMapFiles;
@@ -1330,6 +1339,9 @@ ClangImporter::create(ASTContext &ctx,
13301339 ClangInvocationFileMapping fileMapping =
13311340 getClangInvocationFileMapping (ctx, nullptr , ignoreFileMapping);
13321341
1342+ importer->requiresBuiltinHeadersInSystemModules =
1343+ fileMapping.requiresBuiltinHeadersInSystemModules ;
1344+
13331345 // Avoid creating indirect file system when using include tree.
13341346 if (!ctx.ClangImporterOpts .HasClangIncludeTreeRoot ) {
13351347 // Wrap Swift's FS to allow Clang to override the working directory
@@ -1370,14 +1382,11 @@ ClangImporter::create(ASTContext &ctx,
13701382
13711383 // Create a new Clang compiler invocation.
13721384 {
1373- if (auto ClangArgs = getClangCC1Arguments (importer. get (), ctx, VFS))
1385+ if (auto ClangArgs = importer-> getClangCC1Arguments (ctx, VFS))
13741386 importer->Impl .ClangArgs = *ClangArgs;
13751387 else
13761388 return nullptr ;
13771389
1378- if (fileMapping.requiresBuiltinHeadersInSystemModules )
1379- importer->Impl .ClangArgs .push_back (" -fbuiltin-headers-in-system-modules" );
1380-
13811390 ArrayRef<std::string> invocationArgStrs = importer->Impl .ClangArgs ;
13821391 if (importerOpts.DumpClangDiagnostics ) {
13831392 llvm::errs () << " clang importer cc1 args: '" ;
@@ -1465,8 +1474,7 @@ ClangImporter::create(ASTContext &ctx,
14651474 if (ctx.LangOpts .ClangTarget .has_value ()) {
14661475 // If '-clang-target' is set, create a mock invocation with the Swift triple
14671476 // to configure CodeGen and Target options for Swift compilation.
1468- auto swiftTargetClangArgs =
1469- getClangCC1Arguments (importer.get (), ctx, VFS, true );
1477+ auto swiftTargetClangArgs = importer->getClangCC1Arguments (ctx, VFS, true );
14701478 if (!swiftTargetClangArgs)
14711479 return nullptr ;
14721480 auto swiftTargetClangInvocation = createClangInvocation (
0 commit comments