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