@@ -791,7 +791,8 @@ getEmbedBitcodeInvocationArguments(std::vector<std::string> &invocationArgStrs,
791
791
void
792
792
importer::addCommonInvocationArguments (
793
793
std::vector<std::string> &invocationArgStrs,
794
- ASTContext &ctx, bool ignoreClangTarget) {
794
+ ASTContext &ctx, bool requiresBuiltinHeadersInSystemModules,
795
+ bool ignoreClangTarget) {
795
796
using ImporterImpl = ClangImporter::Implementation;
796
797
llvm::Triple triple = ctx.LangOpts .Target ;
797
798
// Use clang specific target triple if given.
@@ -961,6 +962,16 @@ importer::addCommonInvocationArguments(
961
962
}
962
963
}
963
964
}
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
+ }
964
975
}
965
976
966
977
bool ClangImporter::canReadPCH (StringRef PCHFilename) {
@@ -1144,13 +1155,13 @@ ClangImporter::getClangDriverArguments(ASTContext &ctx, bool ignoreClangTarget)
1144
1155
getEmbedBitcodeInvocationArguments (invocationArgStrs, ctx);
1145
1156
break ;
1146
1157
}
1147
- addCommonInvocationArguments (invocationArgStrs, ctx, ignoreClangTarget);
1158
+ addCommonInvocationArguments (invocationArgStrs, ctx,
1159
+ requiresBuiltinHeadersInSystemModules, ignoreClangTarget);
1148
1160
return invocationArgStrs;
1149
1161
}
1150
1162
1151
1163
std::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,
1154
1165
bool ignoreClangTarget) {
1155
1166
std::unique_ptr<clang::CompilerInvocation> CI;
1156
1167
@@ -1165,7 +1176,7 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
1165
1176
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> tempDiagOpts{
1166
1177
new clang::DiagnosticOptions};
1167
1178
auto *tempDiagClient =
1168
- new ClangDiagnosticConsumer (importer-> Impl , *tempDiagOpts,
1179
+ new ClangDiagnosticConsumer (Impl, *tempDiagOpts,
1169
1180
ctx.ClangImporterOpts .DumpClangDiagnostics );
1170
1181
auto clangDiags = clang::CompilerInstance::createDiagnostics (
1171
1182
tempDiagOpts.get (), tempDiagClient,
@@ -1255,20 +1266,18 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
1255
1266
// resilient and provide a module even if there were building it.
1256
1267
auto TempVFS = clang::createVFSFromCompilerInvocation (
1257
1268
*CI, *clangDiags,
1258
- VFS ? VFS : importer-> Impl .SwiftContext .SourceMgr .getFileSystem ());
1269
+ VFS ? VFS : Impl.SwiftContext .SourceMgr .getFileSystem ());
1259
1270
1260
1271
std::vector<std::string> FilteredModuleMapFiles;
1261
1272
for (auto ModuleMapFile : CI->getFrontendOpts ().ModuleMapFiles ) {
1262
1273
if (ctx.ClangImporterOpts .HasClangIncludeTreeRoot ) {
1263
1274
// There is no need to add any module map file here. Issue a warning and
1264
1275
// drop the option.
1265
- importer->Impl .diagnose (SourceLoc (), diag::module_map_ignored,
1266
- ModuleMapFile);
1276
+ Impl.diagnose (SourceLoc (), diag::module_map_ignored, ModuleMapFile);
1267
1277
} else if (TempVFS->exists (ModuleMapFile)) {
1268
1278
FilteredModuleMapFiles.push_back (ModuleMapFile);
1269
1279
} else {
1270
- importer->Impl .diagnose (SourceLoc (), diag::module_map_not_found,
1271
- ModuleMapFile);
1280
+ Impl.diagnose (SourceLoc (), diag::module_map_not_found, ModuleMapFile);
1272
1281
}
1273
1282
}
1274
1283
CI->getFrontendOpts ().ModuleMapFiles = FilteredModuleMapFiles;
@@ -1337,6 +1346,9 @@ ClangImporter::create(ASTContext &ctx,
1337
1346
ClangInvocationFileMapping fileMapping =
1338
1347
getClangInvocationFileMapping (ctx, nullptr , ignoreFileMapping);
1339
1348
1349
+ importer->requiresBuiltinHeadersInSystemModules =
1350
+ fileMapping.requiresBuiltinHeadersInSystemModules ;
1351
+
1340
1352
// Avoid creating indirect file system when using include tree.
1341
1353
if (!ctx.ClangImporterOpts .HasClangIncludeTreeRoot ) {
1342
1354
// Wrap Swift's FS to allow Clang to override the working directory
@@ -1377,14 +1389,11 @@ ClangImporter::create(ASTContext &ctx,
1377
1389
1378
1390
// Create a new Clang compiler invocation.
1379
1391
{
1380
- if (auto ClangArgs = getClangCC1Arguments (importer. get (), ctx, VFS))
1392
+ if (auto ClangArgs = importer-> getClangCC1Arguments (ctx, VFS))
1381
1393
importer->Impl .ClangArgs = *ClangArgs;
1382
1394
else
1383
1395
return nullptr ;
1384
1396
1385
- if (fileMapping.requiresBuiltinHeadersInSystemModules )
1386
- importer->Impl .ClangArgs .push_back (" -fbuiltin-headers-in-system-modules" );
1387
-
1388
1397
ArrayRef<std::string> invocationArgStrs = importer->Impl .ClangArgs ;
1389
1398
if (importerOpts.DumpClangDiagnostics ) {
1390
1399
llvm::errs () << " clang importer cc1 args: '" ;
@@ -1472,8 +1481,7 @@ ClangImporter::create(ASTContext &ctx,
1472
1481
if (ctx.LangOpts .ClangTarget .has_value ()) {
1473
1482
// If '-clang-target' is set, create a mock invocation with the Swift triple
1474
1483
// 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 );
1477
1485
if (!swiftTargetClangArgs)
1478
1486
return nullptr ;
1479
1487
auto swiftTargetClangInvocation = createClangInvocation (
0 commit comments