Skip to content

Commit 1ba32b2

Browse files
authored
Merge pull request #85051 from swiftlang/revert-84995-jan_svoboda/sandboxing-cherry-pick-fixes
Revert "[ClangImporter] Adjust for LLVM changes (IO sandboxing)"
2 parents c621295 + be3b16b commit 1ba32b2

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,10 +1021,7 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
10211021

10221022
// Note: Reusing the file manager is safe; this is a component that's already
10231023
// reused when building PCM files for the module cache.
1024-
CI.setVirtualFileSystem(
1025-
Impl.Instance->getFileManager().getVirtualFileSystemPtr());
1026-
CI.setFileManager(&Impl.Instance->getFileManager());
1027-
CI.createSourceManager();
1024+
CI.createSourceManager(Impl.Instance->getFileManager());
10281025
auto &clangSrcMgr = CI.getSourceManager();
10291026
auto FID = clangSrcMgr.createFileID(
10301027
std::make_unique<ZeroFilledMemoryBuffer>(1, "<main>"));
@@ -1405,15 +1402,21 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
14051402
if (tracker)
14061403
instance.addDependencyCollector(tracker->getClangCollector());
14071404

1408-
// Now set up the real client for Clang diagnostics---configured with proper
1409-
// options---as opposed to the temporary one we made above.
1410-
auto actualDiagClient = std::make_unique<ClangDiagnosticConsumer>(
1411-
importer->Impl, instance.getDiagnosticOpts(),
1412-
importerOpts.DumpClangDiagnostics);
1405+
{
1406+
// Now set up the real client for Clang diagnostics---configured with proper
1407+
// options---as opposed to the temporary one we made above.
1408+
auto actualDiagClient = std::make_unique<ClangDiagnosticConsumer>(
1409+
importer->Impl, instance.getDiagnosticOpts(),
1410+
importerOpts.DumpClangDiagnostics);
1411+
instance.createDiagnostics(*VFS, actualDiagClient.release());
1412+
}
14131413

1414-
instance.createVirtualFileSystem(std::move(VFS), actualDiagClient.get());
1415-
instance.createFileManager();
1416-
instance.createDiagnostics(actualDiagClient.release());
1414+
// Set up the file manager.
1415+
{
1416+
VFS = clang::createVFSFromCompilerInvocation(
1417+
instance.getInvocation(), instance.getDiagnostics(), std::move(VFS));
1418+
instance.createFileManager(VFS);
1419+
}
14171420

14181421
// Don't stop emitting messages if we ever can't load a module.
14191422
// FIXME: This is actually a general problem: any "fatal" error could mess up
@@ -1432,13 +1435,11 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
14321435
if (ctx.LangOpts.ClangTarget.has_value()) {
14331436
// If '-clang-target' is set, create a mock invocation with the Swift triple
14341437
// to configure CodeGen and Target options for Swift compilation.
1435-
auto swiftTargetClangArgs = importer->getClangCC1Arguments(
1436-
ctx, instance.getVirtualFileSystemPtr(), true);
1438+
auto swiftTargetClangArgs = importer->getClangCC1Arguments(ctx, VFS, true);
14371439
if (!swiftTargetClangArgs)
14381440
return nullptr;
14391441
auto swiftTargetClangInvocation = createClangInvocation(
1440-
importer.get(), importerOpts, instance.getVirtualFileSystemPtr(),
1441-
*swiftTargetClangArgs);
1442+
importer.get(), importerOpts, VFS, *swiftTargetClangArgs);
14421443
if (!swiftTargetClangInvocation)
14431444
return nullptr;
14441445

@@ -1923,14 +1924,15 @@ std::string ClangImporter::getBridgingHeaderContents(
19231924

19241925
invocation->getPreprocessorOpts().resetNonModularOptions();
19251926

1927+
clang::FileManager &fileManager = Impl.Instance->getFileManager();
1928+
19261929
clang::CompilerInstance rewriteInstance(
19271930
std::move(invocation), Impl.Instance->getPCHContainerOperations(),
19281931
&Impl.Instance->getModuleCache());
1929-
rewriteInstance.setVirtualFileSystem(
1930-
Impl.Instance->getFileManager().getVirtualFileSystemPtr());
1931-
rewriteInstance.setFileManager(&Impl.Instance->getFileManager());
1932-
rewriteInstance.createDiagnostics(new clang::IgnoringDiagConsumer);
1933-
rewriteInstance.createSourceManager();
1932+
rewriteInstance.createDiagnostics(fileManager.getVirtualFileSystem(),
1933+
new clang::IgnoringDiagConsumer);
1934+
rewriteInstance.setFileManager(&fileManager);
1935+
rewriteInstance.createSourceManager(fileManager);
19341936
rewriteInstance.setTarget(&Impl.Instance->getTarget());
19351937

19361938
std::string result;
@@ -1978,8 +1980,7 @@ std::string ClangImporter::getBridgingHeaderContents(
19781980
return "";
19791981
}
19801982

1981-
if (auto fileInfo =
1982-
rewriteInstance.getFileManager().getOptionalFileRef(headerPath)) {
1983+
if (auto fileInfo = fileManager.getOptionalFileRef(headerPath)) {
19831984
fileSize = fileInfo->getSize();
19841985
fileModTime = fileInfo->getModificationTime();
19851986
}
@@ -2028,15 +2029,16 @@ ClangImporter::cloneCompilerInstanceForPrecompiling() {
20282029
// Share the CASOption and the underlying CAS.
20292030
invocation->setCASOption(Impl.Invocation->getCASOptsPtr());
20302031

2032+
clang::FileManager &fileManager = Impl.Instance->getFileManager();
2033+
20312034
auto clonedInstance = std::make_unique<clang::CompilerInstance>(
20322035
std::move(invocation), Impl.Instance->getPCHContainerOperations(),
20332036
&Impl.Instance->getModuleCache());
2034-
clonedInstance->setVirtualFileSystem(
2035-
Impl.Instance->getFileManager().getVirtualFileSystemPtr());
2036-
clonedInstance->setFileManager(&Impl.Instance->getFileManager());
2037-
clonedInstance->createDiagnostics(&Impl.Instance->getDiagnosticClient(),
2037+
clonedInstance->createDiagnostics(fileManager.getVirtualFileSystem(),
2038+
&Impl.Instance->getDiagnosticClient(),
20382039
/*ShouldOwnClient=*/false);
2039-
clonedInstance->createSourceManager();
2040+
clonedInstance->setFileManager(&fileManager);
2041+
clonedInstance->createSourceManager(fileManager);
20402042
clonedInstance->setTarget(&Impl.Instance->getTarget());
20412043
clonedInstance->setOutputBackend(Impl.SwiftContext.OutputBackend);
20422044

lib/IRGen/IRGen.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ static std::optional<PGOOptions> buildIRUseOptions(const IRGenOptions &Opts,
261261
/*CSProfileGenFile=*/"",
262262
/*ProfileRemappingFile=*/"",
263263
/*MemoryProfile=*/"",
264+
/*FS=*/FS,
264265
/*Action=*/PGOOptions::IRUse,
265266
/*CSPGOAction=*/IsCS ? PGOOptions::CSIRUse : PGOOptions::NoCSAction,
266267
/*ColdType=*/PGOOptions::ColdFuncOpt::Default,
@@ -276,6 +277,7 @@ static void populatePGOOptions(std::optional<PGOOptions> &Out,
276277
/*CSProfileGenFile=*/ "",
277278
/*ProfileRemappingFile=*/ "",
278279
/*MemoryProfile=*/ "",
280+
/*FS=*/ llvm::vfs::getRealFileSystem(), // TODO: is this fine?
279281
/*Action=*/ PGOOptions::SampleUse,
280282
/*CSPGOAction=*/ PGOOptions::NoCSAction,
281283
/*ColdType=*/ PGOOptions::ColdFuncOpt::Default,
@@ -291,6 +293,7 @@ static void populatePGOOptions(std::optional<PGOOptions> &Out,
291293
/*CSProfileGenFile=*/Opts.InstrProfileOutput,
292294
/*ProfileRemappingFile=*/"",
293295
/*MemoryProfile=*/"",
296+
/*FS=*/llvm::vfs::getRealFileSystem(),
294297
/*Action=*/hasUse ? PGOOptions::IRUse : PGOOptions::NoAction,
295298
/*CSPGOAction=*/PGOOptions::CSIRInstr,
296299
/*ColdType=*/PGOOptions::ColdFuncOpt::Default,
@@ -304,6 +307,7 @@ static void populatePGOOptions(std::optional<PGOOptions> &Out,
304307
/*CSProfileGenFile=*/"",
305308
/*ProfileRemappingFile=*/"",
306309
/*MemoryProfile=*/"",
310+
/*FS=*/llvm::vfs::getRealFileSystem(),
307311
/*Action=*/PGOOptions::IRInstr,
308312
/*CSPGOAction=*/PGOOptions::NoCSAction,
309313
/*ColdType=*/PGOOptions::ColdFuncOpt::Default,
@@ -322,6 +326,7 @@ static void populatePGOOptions(std::optional<PGOOptions> &Out,
322326
/*CSProfileGenFile=*/ "",
323327
/*ProfileRemappingFile=*/ "",
324328
/*MemoryProfile=*/ "",
329+
/*FS=*/ nullptr,
325330
/*Action=*/ PGOOptions::NoAction,
326331
/*CSPGOAction=*/ PGOOptions::NoCSAction,
327332
/*ColdType=*/ PGOOptions::ColdFuncOpt::Default,

0 commit comments

Comments
 (0)