@@ -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,18 @@ 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
+ ClangInvocationFileMapping fileMapping =
968
+ getClangInvocationFileMapping (ctx, nullptr , /* supressDiagnostic*/ true );
969
+ if (fileMapping.requiresBuiltinHeadersInSystemModules ) {
970
+ invocationArgStrs.push_back (" -Xclang" );
971
+ invocationArgStrs.push_back (" -fbuiltin-headers-in-system-modules" );
972
+ }
960
973
}
961
974
962
975
bool ClangImporter::canReadPCH (StringRef PCHFilename) {
@@ -1124,7 +1137,8 @@ ClangImporter::getOrCreatePCH(const ClangImporterOptions &ImporterOptions,
1124
1137
}
1125
1138
1126
1139
std::vector<std::string>
1127
- ClangImporter::getClangDriverArguments (ASTContext &ctx, bool ignoreClangTarget) {
1140
+ ClangImporter::getClangDriverArguments (ASTContext &ctx,
1141
+ bool requiresBuiltinHeadersInSystemModules, bool ignoreClangTarget) {
1128
1142
assert (!ctx.ClangImporterOpts .DirectClangCC1ModuleBuild &&
1129
1143
" direct-clang-cc1-module-build should not call this function" );
1130
1144
std::vector<std::string> invocationArgStrs;
@@ -1140,14 +1154,15 @@ ClangImporter::getClangDriverArguments(ASTContext &ctx, bool ignoreClangTarget)
1140
1154
getEmbedBitcodeInvocationArguments (invocationArgStrs, ctx);
1141
1155
break ;
1142
1156
}
1143
- addCommonInvocationArguments (invocationArgStrs, ctx, ignoreClangTarget);
1157
+ addCommonInvocationArguments (invocationArgStrs, ctx,
1158
+ requiresBuiltinHeadersInSystemModules, ignoreClangTarget);
1144
1159
return invocationArgStrs;
1145
1160
}
1146
1161
1147
1162
std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments (
1148
1163
ClangImporter *importer, ASTContext &ctx,
1149
1164
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
1150
- bool ignoreClangTarget) {
1165
+ bool requiresBuiltinHeadersInSystemModules, bool ignoreClangTarget) {
1151
1166
std::unique_ptr<clang::CompilerInvocation> CI;
1152
1167
1153
1168
// Set up a temporary diagnostic client to report errors from parsing the
@@ -1210,7 +1225,8 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
1210
1225
CI->getFrontendOpts ().IndexStorePath = ctx.ClangImporterOpts .IndexStorePath ;
1211
1226
} else {
1212
1227
// Otherwise, create cc1 arguments from driver args.
1213
- auto driverArgs = getClangDriverArguments (ctx, ignoreClangTarget);
1228
+ auto driverArgs = getClangDriverArguments (ctx,
1229
+ requiresBuiltinHeadersInSystemModules, ignoreClangTarget);
1214
1230
1215
1231
llvm::SmallVector<const char *> invocationArgs;
1216
1232
invocationArgs.reserve (driverArgs.size ());
@@ -1370,14 +1386,12 @@ ClangImporter::create(ASTContext &ctx,
1370
1386
1371
1387
// Create a new Clang compiler invocation.
1372
1388
{
1373
- if (auto ClangArgs = getClangCC1Arguments (importer.get (), ctx, VFS))
1389
+ if (auto ClangArgs = getClangCC1Arguments (importer.get (), ctx, VFS,
1390
+ fileMapping.requiresBuiltinHeadersInSystemModules ))
1374
1391
importer->Impl .ClangArgs = *ClangArgs;
1375
1392
else
1376
1393
return nullptr ;
1377
1394
1378
- if (fileMapping.requiresBuiltinHeadersInSystemModules )
1379
- importer->Impl .ClangArgs .push_back (" -fbuiltin-headers-in-system-modules" );
1380
-
1381
1395
ArrayRef<std::string> invocationArgStrs = importer->Impl .ClangArgs ;
1382
1396
if (importerOpts.DumpClangDiagnostics ) {
1383
1397
llvm::errs () << " clang importer cc1 args: '" ;
@@ -1465,8 +1479,9 @@ ClangImporter::create(ASTContext &ctx,
1465
1479
if (ctx.LangOpts .ClangTarget .has_value ()) {
1466
1480
// If '-clang-target' is set, create a mock invocation with the Swift triple
1467
1481
// to configure CodeGen and Target options for Swift compilation.
1468
- auto swiftTargetClangArgs =
1469
- getClangCC1Arguments (importer.get (), ctx, VFS, true );
1482
+ auto swiftTargetClangArgs = getClangCC1Arguments (importer.get (), ctx, VFS,
1483
+ /* requiresBuiltinHeadersInSystemModulestrue*/ false ,
1484
+ /* ignoreClangTarget*/ true );
1470
1485
if (!swiftTargetClangArgs)
1471
1486
return nullptr ;
1472
1487
auto swiftTargetClangInvocation = createClangInvocation (
0 commit comments