@@ -789,7 +789,8 @@ getEmbedBitcodeInvocationArguments(std::vector<std::string> &invocationArgStrs,
789
789
void
790
790
importer::addCommonInvocationArguments (
791
791
std::vector<std::string> &invocationArgStrs,
792
- ASTContext &ctx, bool ignoreClangTarget) {
792
+ ASTContext &ctx, bool requiresBuiltinHeadersInSystemModules,
793
+ bool ignoreClangTarget) {
793
794
using ImporterImpl = ClangImporter::Implementation;
794
795
llvm::Triple triple = ctx.LangOpts .Target ;
795
796
// Use clang specific target triple if given.
@@ -957,6 +958,16 @@ importer::addCommonInvocationArguments(
957
958
}
958
959
}
959
960
}
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
+ }
960
971
}
961
972
962
973
bool ClangImporter::canReadPCH (StringRef PCHFilename) {
@@ -1140,13 +1151,13 @@ ClangImporter::getClangDriverArguments(ASTContext &ctx, bool ignoreClangTarget)
1140
1151
getEmbedBitcodeInvocationArguments (invocationArgStrs, ctx);
1141
1152
break ;
1142
1153
}
1143
- addCommonInvocationArguments (invocationArgStrs, ctx, ignoreClangTarget);
1154
+ addCommonInvocationArguments (invocationArgStrs, ctx,
1155
+ requiresBuiltinHeadersInSystemModules, ignoreClangTarget);
1144
1156
return invocationArgStrs;
1145
1157
}
1146
1158
1147
1159
std::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,
1150
1161
bool ignoreClangTarget) {
1151
1162
std::unique_ptr<clang::CompilerInvocation> CI;
1152
1163
@@ -1161,7 +1172,7 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
1161
1172
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> tempDiagOpts{
1162
1173
new clang::DiagnosticOptions};
1163
1174
auto *tempDiagClient =
1164
- new ClangDiagnosticConsumer (importer-> Impl , *tempDiagOpts,
1175
+ new ClangDiagnosticConsumer (Impl, *tempDiagOpts,
1165
1176
ctx.ClangImporterOpts .DumpClangDiagnostics );
1166
1177
auto clangDiags = clang::CompilerInstance::createDiagnostics (
1167
1178
tempDiagOpts.get (), tempDiagClient,
@@ -1248,20 +1259,18 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
1248
1259
// resilient and provide a module even if there were building it.
1249
1260
auto TempVFS = clang::createVFSFromCompilerInvocation (
1250
1261
*CI, *clangDiags,
1251
- VFS ? VFS : importer-> Impl .SwiftContext .SourceMgr .getFileSystem ());
1262
+ VFS ? VFS : Impl.SwiftContext .SourceMgr .getFileSystem ());
1252
1263
1253
1264
std::vector<std::string> FilteredModuleMapFiles;
1254
1265
for (auto ModuleMapFile : CI->getFrontendOpts ().ModuleMapFiles ) {
1255
1266
if (ctx.ClangImporterOpts .HasClangIncludeTreeRoot ) {
1256
1267
// There is no need to add any module map file here. Issue a warning and
1257
1268
// drop the option.
1258
- importer->Impl .diagnose (SourceLoc (), diag::module_map_ignored,
1259
- ModuleMapFile);
1269
+ Impl.diagnose (SourceLoc (), diag::module_map_ignored, ModuleMapFile);
1260
1270
} else if (TempVFS->exists (ModuleMapFile)) {
1261
1271
FilteredModuleMapFiles.push_back (ModuleMapFile);
1262
1272
} else {
1263
- importer->Impl .diagnose (SourceLoc (), diag::module_map_not_found,
1264
- ModuleMapFile);
1273
+ Impl.diagnose (SourceLoc (), diag::module_map_not_found, ModuleMapFile);
1265
1274
}
1266
1275
}
1267
1276
CI->getFrontendOpts ().ModuleMapFiles = FilteredModuleMapFiles;
@@ -1330,6 +1339,9 @@ ClangImporter::create(ASTContext &ctx,
1330
1339
ClangInvocationFileMapping fileMapping =
1331
1340
getClangInvocationFileMapping (ctx, nullptr , ignoreFileMapping);
1332
1341
1342
+ importer->requiresBuiltinHeadersInSystemModules =
1343
+ fileMapping.requiresBuiltinHeadersInSystemModules ;
1344
+
1333
1345
// Avoid creating indirect file system when using include tree.
1334
1346
if (!ctx.ClangImporterOpts .HasClangIncludeTreeRoot ) {
1335
1347
// Wrap Swift's FS to allow Clang to override the working directory
@@ -1370,14 +1382,11 @@ ClangImporter::create(ASTContext &ctx,
1370
1382
1371
1383
// Create a new Clang compiler invocation.
1372
1384
{
1373
- if (auto ClangArgs = getClangCC1Arguments (importer. get (), ctx, VFS))
1385
+ if (auto ClangArgs = importer-> getClangCC1Arguments (ctx, VFS))
1374
1386
importer->Impl .ClangArgs = *ClangArgs;
1375
1387
else
1376
1388
return nullptr ;
1377
1389
1378
- if (fileMapping.requiresBuiltinHeadersInSystemModules )
1379
- importer->Impl .ClangArgs .push_back (" -fbuiltin-headers-in-system-modules" );
1380
-
1381
1390
ArrayRef<std::string> invocationArgStrs = importer->Impl .ClangArgs ;
1382
1391
if (importerOpts.DumpClangDiagnostics ) {
1383
1392
llvm::errs () << " clang importer cc1 args: '" ;
@@ -1465,8 +1474,7 @@ ClangImporter::create(ASTContext &ctx,
1465
1474
if (ctx.LangOpts .ClangTarget .has_value ()) {
1466
1475
// If '-clang-target' is set, create a mock invocation with the Swift triple
1467
1476
// 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 );
1470
1478
if (!swiftTargetClangArgs)
1471
1479
return nullptr ;
1472
1480
auto swiftTargetClangInvocation = createClangInvocation (
0 commit comments