@@ -1153,7 +1153,7 @@ static Language getLanguageFromOptions(const LangOptions &LangOpts) {
11531153std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl (
11541154 SourceLocation ImportLoc, StringRef ModuleName, FrontendInputFile Input,
11551155 StringRef OriginalModuleMapFile, StringRef ModuleFileName,
1156- IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS ) {
1156+ std::optional<ThreadSafeCloneConfig> ThreadSafeConfig ) {
11571157 // Construct a compiler invocation for creating this module.
11581158 auto Invocation = std::make_shared<CompilerInvocation>(getInvocation ());
11591159
@@ -1213,18 +1213,24 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
12131213 auto &Inv = *Invocation;
12141214 Instance.setInvocation (std::move (Invocation));
12151215
1216- if (VFS ) {
1217- Instance.createFileManager (std::move (VFS ));
1216+ if (ThreadSafeConfig ) {
1217+ Instance.createFileManager (ThreadSafeConfig-> getVFS ( ));
12181218 } else if (FrontendOpts.ModulesShareFileManager ) {
12191219 Instance.setFileManager (&getFileManager ());
12201220 } else {
12211221 Instance.createFileManager (&getVirtualFileSystem ());
12221222 }
12231223
1224- Instance.createDiagnostics (
1225- Instance.getVirtualFileSystem (),
1226- new ForwardingDiagnosticConsumer (getDiagnosticClient ()),
1227- /* ShouldOwnClient=*/ true );
1224+ if (ThreadSafeConfig) {
1225+ Instance.createDiagnostics (Instance.getVirtualFileSystem (),
1226+ &ThreadSafeConfig->getDiagConsumer (),
1227+ /* ShouldOwnClient=*/ false );
1228+ } else {
1229+ Instance.createDiagnostics (
1230+ Instance.getVirtualFileSystem (),
1231+ new ForwardingDiagnosticConsumer (getDiagnosticClient ()),
1232+ /* ShouldOwnClient=*/ true );
1233+ }
12281234 if (llvm::is_contained (DiagOpts.SystemHeaderWarningsModules , ModuleName))
12291235 Instance.getDiagnostics ().setSuppressSystemWarnings (false );
12301236
@@ -1322,7 +1328,7 @@ static OptionalFileEntryRef getPublicModuleMap(FileEntryRef File,
13221328
13231329std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompile (
13241330 SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName,
1325- IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS ) {
1331+ std::optional<ThreadSafeCloneConfig> ThreadSafeConfig ) {
13261332 StringRef ModuleName = Module->getTopLevelModuleName ();
13271333
13281334 InputKind IK (getLanguageFromOptions (getLangOpts ()), InputKind::ModuleMap);
@@ -1368,7 +1374,7 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompile(
13681374 ImportLoc, ModuleName,
13691375 FrontendInputFile (ModuleMapFilePath, IK, IsSystem),
13701376 ModMap.getModuleMapFileForUniquing (Module)->getName (), ModuleFileName,
1371- std::move (VFS ));
1377+ std::move (ThreadSafeConfig ));
13721378 }
13731379
13741380 // FIXME: We only need to fake up an input file here as a way of
@@ -1386,7 +1392,7 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompile(
13861392 ImportLoc, ModuleName,
13871393 FrontendInputFile (FakeModuleMapFile, IK, +Module->IsSystem ),
13881394 ModMap.getModuleMapFileForUniquing (Module)->getName (), ModuleFileName,
1389- std::move (VFS ));
1395+ std::move (ThreadSafeConfig ));
13901396
13911397 std::unique_ptr<llvm::MemoryBuffer> ModuleMapBuffer =
13921398 llvm::MemoryBuffer::getMemBufferCopy (InferredModuleMapContent);
0 commit comments