Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 28 additions & 30 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,10 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {

// Note: Reusing the file manager is safe; this is a component that's already
// reused when building PCM files for the module cache.
CI.createSourceManager(Impl.Instance->getFileManager());
CI.setVirtualFileSystem(
Impl.Instance->getFileManager().getVirtualFileSystemPtr());
CI.setFileManager(&Impl.Instance->getFileManager());
CI.createSourceManager();
auto &clangSrcMgr = CI.getSourceManager();
auto FID = clangSrcMgr.createFileID(
std::make_unique<ZeroFilledMemoryBuffer>(1, "<main>"));
Expand Down Expand Up @@ -1394,21 +1397,15 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
if (tracker)
instance.addDependencyCollector(tracker->getClangCollector());

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

// Set up the file manager.
{
VFS = clang::createVFSFromCompilerInvocation(
instance.getInvocation(), instance.getDiagnostics(), std::move(VFS));
instance.createFileManager(VFS);
}
instance.createVirtualFileSystem(std::move(VFS), actualDiagClient.get());
instance.createFileManager();
instance.createDiagnostics(actualDiagClient.release());

// Don't stop emitting messages if we ever can't load a module.
// FIXME: This is actually a general problem: any "fatal" error could mess up
Expand All @@ -1427,11 +1424,13 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
if (ctx.LangOpts.ClangTarget.has_value()) {
// If '-clang-target' is set, create a mock invocation with the Swift triple
// to configure CodeGen and Target options for Swift compilation.
auto swiftTargetClangArgs = importer->getClangCC1Arguments(ctx, VFS, true);
auto swiftTargetClangArgs = importer->getClangCC1Arguments(
ctx, instance.getVirtualFileSystemPtr(), true);
if (!swiftTargetClangArgs)
return nullptr;
auto swiftTargetClangInvocation = createClangInvocation(
importer.get(), importerOpts, VFS, *swiftTargetClangArgs);
importer.get(), importerOpts, instance.getVirtualFileSystemPtr(),
*swiftTargetClangArgs);
if (!swiftTargetClangInvocation)
return nullptr;

Expand Down Expand Up @@ -1916,15 +1915,14 @@ std::string ClangImporter::getBridgingHeaderContents(

invocation->getPreprocessorOpts().resetNonModularOptions();

clang::FileManager &fileManager = Impl.Instance->getFileManager();

clang::CompilerInstance rewriteInstance(
std::move(invocation), Impl.Instance->getPCHContainerOperations(),
&Impl.Instance->getModuleCache());
rewriteInstance.createDiagnostics(fileManager.getVirtualFileSystem(),
new clang::IgnoringDiagConsumer);
rewriteInstance.setFileManager(&fileManager);
rewriteInstance.createSourceManager(fileManager);
rewriteInstance.setVirtualFileSystem(
Impl.Instance->getFileManager().getVirtualFileSystemPtr());
rewriteInstance.setFileManager(&Impl.Instance->getFileManager());
rewriteInstance.createDiagnostics(new clang::IgnoringDiagConsumer);
rewriteInstance.createSourceManager();
rewriteInstance.setTarget(&Impl.Instance->getTarget());

std::string result;
Expand Down Expand Up @@ -1972,7 +1970,8 @@ std::string ClangImporter::getBridgingHeaderContents(
return "";
}

if (auto fileInfo = fileManager.getOptionalFileRef(headerPath)) {
if (auto fileInfo =
rewriteInstance.getFileManager().getOptionalFileRef(headerPath)) {
fileSize = fileInfo->getSize();
fileModTime = fileInfo->getModificationTime();
}
Expand Down Expand Up @@ -2021,16 +2020,15 @@ ClangImporter::cloneCompilerInstanceForPrecompiling() {
// Share the CASOption and the underlying CAS.
invocation->setCASOption(Impl.Invocation->getCASOptsPtr());

clang::FileManager &fileManager = Impl.Instance->getFileManager();

auto clonedInstance = std::make_unique<clang::CompilerInstance>(
std::move(invocation), Impl.Instance->getPCHContainerOperations(),
&Impl.Instance->getModuleCache());
clonedInstance->createDiagnostics(fileManager.getVirtualFileSystem(),
&Impl.Instance->getDiagnosticClient(),
clonedInstance->setVirtualFileSystem(
Impl.Instance->getFileManager().getVirtualFileSystemPtr());
clonedInstance->setFileManager(&Impl.Instance->getFileManager());
clonedInstance->createDiagnostics(&Impl.Instance->getDiagnosticClient(),
/*ShouldOwnClient=*/false);
clonedInstance->setFileManager(&fileManager);
clonedInstance->createSourceManager(fileManager);
clonedInstance->createSourceManager();
clonedInstance->setTarget(&Impl.Instance->getTarget());
clonedInstance->setOutputBackend(Impl.SwiftContext.OutputBackend);

Expand Down
5 changes: 0 additions & 5 deletions lib/IRGen/IRGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ static std::optional<PGOOptions> buildIRUseOptions(const IRGenOptions &Opts,
/*CSProfileGenFile=*/"",
/*ProfileRemappingFile=*/"",
/*MemoryProfile=*/"",
/*FS=*/FS,
/*Action=*/PGOOptions::IRUse,
/*CSPGOAction=*/IsCS ? PGOOptions::CSIRUse : PGOOptions::NoCSAction,
/*ColdType=*/PGOOptions::ColdFuncOpt::Default,
Expand All @@ -277,7 +276,6 @@ static void populatePGOOptions(std::optional<PGOOptions> &Out,
/*CSProfileGenFile=*/ "",
/*ProfileRemappingFile=*/ "",
/*MemoryProfile=*/ "",
/*FS=*/ llvm::vfs::getRealFileSystem(), // TODO: is this fine?
/*Action=*/ PGOOptions::SampleUse,
/*CSPGOAction=*/ PGOOptions::NoCSAction,
/*ColdType=*/ PGOOptions::ColdFuncOpt::Default,
Expand All @@ -293,7 +291,6 @@ static void populatePGOOptions(std::optional<PGOOptions> &Out,
/*CSProfileGenFile=*/Opts.InstrProfileOutput,
/*ProfileRemappingFile=*/"",
/*MemoryProfile=*/"",
/*FS=*/llvm::vfs::getRealFileSystem(),
/*Action=*/hasUse ? PGOOptions::IRUse : PGOOptions::NoAction,
/*CSPGOAction=*/PGOOptions::CSIRInstr,
/*ColdType=*/PGOOptions::ColdFuncOpt::Default,
Expand All @@ -307,7 +304,6 @@ static void populatePGOOptions(std::optional<PGOOptions> &Out,
/*CSProfileGenFile=*/"",
/*ProfileRemappingFile=*/"",
/*MemoryProfile=*/"",
/*FS=*/llvm::vfs::getRealFileSystem(),
/*Action=*/PGOOptions::IRInstr,
/*CSPGOAction=*/PGOOptions::NoCSAction,
/*ColdType=*/PGOOptions::ColdFuncOpt::Default,
Expand All @@ -326,7 +322,6 @@ static void populatePGOOptions(std::optional<PGOOptions> &Out,
/*CSProfileGenFile=*/ "",
/*ProfileRemappingFile=*/ "",
/*MemoryProfile=*/ "",
/*FS=*/ nullptr,
/*Action=*/ PGOOptions::NoAction,
/*CSPGOAction=*/ PGOOptions::NoCSAction,
/*ColdType=*/ PGOOptions::ColdFuncOpt::Default,
Expand Down