Skip to content

Commit 4374d66

Browse files
jansvoboda11Deniz Dizman
authored andcommitted
[ClangImporter] Adjust for LLVM changes (IO sandboxing) (swiftlang#84995)
1 parent 77b1de0 commit 4374d66

File tree

2 files changed

+28
-35
lines changed

2 files changed

+28
-35
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,10 @@ 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.createSourceManager(Impl.Instance->getFileManager());
1024+
CI.setVirtualFileSystem(
1025+
Impl.Instance->getFileManager().getVirtualFileSystemPtr());
1026+
CI.setFileManager(&Impl.Instance->getFileManager());
1027+
CI.createSourceManager();
10251028
auto &clangSrcMgr = CI.getSourceManager();
10261029
auto FID = clangSrcMgr.createFileID(
10271030
std::make_unique<ZeroFilledMemoryBuffer>(1, "<main>"));
@@ -1402,21 +1405,15 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
14021405
if (tracker)
14031406
instance.addDependencyCollector(tracker->getClangCollector());
14041407

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-
}
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);
14131413

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

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

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

19251924
invocation->getPreprocessorOpts().resetNonModularOptions();
19261925

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

19381936
std::string result;
@@ -1980,7 +1978,8 @@ std::string ClangImporter::getBridgingHeaderContents(
19801978
return "";
19811979
}
19821980

1983-
if (auto fileInfo = fileManager.getOptionalFileRef(headerPath)) {
1981+
if (auto fileInfo =
1982+
rewriteInstance.getFileManager().getOptionalFileRef(headerPath)) {
19841983
fileSize = fileInfo->getSize();
19851984
fileModTime = fileInfo->getModificationTime();
19861985
}
@@ -2029,16 +2028,15 @@ ClangImporter::cloneCompilerInstanceForPrecompiling() {
20292028
// Share the CASOption and the underlying CAS.
20302029
invocation->setCASOption(Impl.Invocation->getCASOptsPtr());
20312030

2032-
clang::FileManager &fileManager = Impl.Instance->getFileManager();
2033-
20342031
auto clonedInstance = std::make_unique<clang::CompilerInstance>(
20352032
std::move(invocation), Impl.Instance->getPCHContainerOperations(),
20362033
&Impl.Instance->getModuleCache());
2037-
clonedInstance->createDiagnostics(fileManager.getVirtualFileSystem(),
2038-
&Impl.Instance->getDiagnosticClient(),
2034+
clonedInstance->setVirtualFileSystem(
2035+
Impl.Instance->getFileManager().getVirtualFileSystemPtr());
2036+
clonedInstance->setFileManager(&Impl.Instance->getFileManager());
2037+
clonedInstance->createDiagnostics(&Impl.Instance->getDiagnosticClient(),
20392038
/*ShouldOwnClient=*/false);
2040-
clonedInstance->setFileManager(&fileManager);
2041-
clonedInstance->createSourceManager(fileManager);
2039+
clonedInstance->createSourceManager();
20422040
clonedInstance->setTarget(&Impl.Instance->getTarget());
20432041
clonedInstance->setOutputBackend(Impl.SwiftContext.OutputBackend);
20442042

lib/IRGen/IRGen.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ static std::optional<PGOOptions> buildIRUseOptions(const IRGenOptions &Opts,
261261
/*CSProfileGenFile=*/"",
262262
/*ProfileRemappingFile=*/"",
263263
/*MemoryProfile=*/"",
264-
/*FS=*/FS,
265264
/*Action=*/PGOOptions::IRUse,
266265
/*CSPGOAction=*/IsCS ? PGOOptions::CSIRUse : PGOOptions::NoCSAction,
267266
/*ColdType=*/PGOOptions::ColdFuncOpt::Default,
@@ -277,7 +276,6 @@ static void populatePGOOptions(std::optional<PGOOptions> &Out,
277276
/*CSProfileGenFile=*/ "",
278277
/*ProfileRemappingFile=*/ "",
279278
/*MemoryProfile=*/ "",
280-
/*FS=*/ llvm::vfs::getRealFileSystem(), // TODO: is this fine?
281279
/*Action=*/ PGOOptions::SampleUse,
282280
/*CSPGOAction=*/ PGOOptions::NoCSAction,
283281
/*ColdType=*/ PGOOptions::ColdFuncOpt::Default,
@@ -293,7 +291,6 @@ static void populatePGOOptions(std::optional<PGOOptions> &Out,
293291
/*CSProfileGenFile=*/Opts.InstrProfileOutput,
294292
/*ProfileRemappingFile=*/"",
295293
/*MemoryProfile=*/"",
296-
/*FS=*/llvm::vfs::getRealFileSystem(),
297294
/*Action=*/hasUse ? PGOOptions::IRUse : PGOOptions::NoAction,
298295
/*CSPGOAction=*/PGOOptions::CSIRInstr,
299296
/*ColdType=*/PGOOptions::ColdFuncOpt::Default,
@@ -307,7 +304,6 @@ static void populatePGOOptions(std::optional<PGOOptions> &Out,
307304
/*CSProfileGenFile=*/"",
308305
/*ProfileRemappingFile=*/"",
309306
/*MemoryProfile=*/"",
310-
/*FS=*/llvm::vfs::getRealFileSystem(),
311307
/*Action=*/PGOOptions::IRInstr,
312308
/*CSPGOAction=*/PGOOptions::NoCSAction,
313309
/*ColdType=*/PGOOptions::ColdFuncOpt::Default,
@@ -326,7 +322,6 @@ static void populatePGOOptions(std::optional<PGOOptions> &Out,
326322
/*CSProfileGenFile=*/ "",
327323
/*ProfileRemappingFile=*/ "",
328324
/*MemoryProfile=*/ "",
329-
/*FS=*/ nullptr,
330325
/*Action=*/ PGOOptions::NoAction,
331326
/*CSPGOAction=*/ PGOOptions::NoCSAction,
332327
/*ColdType=*/ PGOOptions::ColdFuncOpt::Default,

0 commit comments

Comments
 (0)