@@ -173,12 +173,11 @@ bool CompilerInstance::createTarget() {
173173 return true ;
174174}
175175
176- llvm::vfs::FileSystem &CompilerInstance::getVirtualFileSystem () const {
177- return getFileManager ().getVirtualFileSystem ();
178- }
179-
180- void CompilerInstance::setFileManager (
181- llvm::IntrusiveRefCntPtr<FileManager> Value) {
176+ void CompilerInstance::setFileManager (IntrusiveRefCntPtr<FileManager> Value) {
177+ if (!hasVirtualFileSystem ())
178+ setVirtualFileSystem (Value->getVirtualFileSystemPtr ());
179+ assert (Value == nullptr ||
180+ getVirtualFileSystemPtr () == Value->getVirtualFileSystemPtr ());
182181 FileMgr = std::move (Value);
183182}
184183
@@ -298,6 +297,20 @@ static void collectVFSEntries(CompilerInstance &CI,
298297 MDC->addFile (E.VPath , E.RPath );
299298}
300299
300+ void CompilerInstance::createVirtualFileSystem (
301+ IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS, DiagnosticConsumer *DC) {
302+ DiagnosticOptions DiagOpts;
303+ DiagnosticsEngine Diags (DiagnosticIDs::create (), DiagOpts, DC,
304+ /* ShouldOwnClient=*/ false );
305+
306+ VFS = createVFSFromCompilerInvocation (getInvocation (), Diags,
307+ std::move (BaseFS), CAS);
308+ // FIXME: Should this go into createVFSFromCompilerInvocation?
309+ if (getFrontendOpts ().ShowStats )
310+ VFS =
311+ llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(std::move (VFS));
312+ }
313+
301314// Diagnostics
302315static void SetUpDiagnosticLog (DiagnosticOptions &DiagOpts,
303316 const CodeGenOptions *CodeGenOpts,
@@ -349,11 +362,10 @@ static void SetupSerializedDiagnostics(DiagnosticOptions &DiagOpts,
349362 }
350363}
351364
352- void CompilerInstance::createDiagnostics (llvm::vfs::FileSystem &VFS,
353- DiagnosticConsumer *Client,
365+ void CompilerInstance::createDiagnostics (DiagnosticConsumer *Client,
354366 bool ShouldOwnClient) {
355- Diagnostics = createDiagnostics (VFS , getDiagnosticOpts (), Client ,
356- ShouldOwnClient, &getCodeGenOpts ());
367+ Diagnostics = createDiagnostics (getVirtualFileSystem () , getDiagnosticOpts (),
368+ Client, ShouldOwnClient, &getCodeGenOpts ());
357369}
358370
359371IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics (
@@ -391,18 +403,9 @@ IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(
391403
392404// File Manager
393405
394- FileManager *CompilerInstance::createFileManager (
395- IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
396- if (!VFS)
397- VFS = FileMgr ? &FileMgr->getVirtualFileSystem ()
398- : createVFSFromCompilerInvocation (getInvocation (),
399- getDiagnostics (), CAS);
400- assert (VFS && " FileManager has no VFS?" );
401- if (getFrontendOpts ().ShowStats )
402- VFS =
403- llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(std::move (VFS));
404- FileMgr = llvm::makeIntrusiveRefCnt<FileManager>(getFileSystemOpts (),
405- std::move (VFS));
406+ FileManager *CompilerInstance::createFileManager () {
407+ assert (VFS && " CompilerInstance needs a VFS for creating FileManager" );
408+ FileMgr = llvm::makeIntrusiveRefCnt<FileManager>(getFileSystemOpts (), VFS);
406409 return FileMgr.get ();
407410}
408411
@@ -1400,20 +1403,21 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
14001403 auto &Inv = Instance.getInvocation ();
14011404
14021405 if (ThreadSafeConfig) {
1403- Instance.createFileManager (ThreadSafeConfig->getVFS ());
1406+ Instance.setVirtualFileSystem (ThreadSafeConfig->getVFS ());
1407+ Instance.createFileManager ();
14041408 } else if (FrontendOpts.ModulesShareFileManager ) {
1409+ Instance.setVirtualFileSystem (getVirtualFileSystemPtr ());
14051410 Instance.setFileManager (getFileManagerPtr ());
14061411 } else {
1407- Instance.createFileManager (&getVirtualFileSystem ());
1412+ Instance.setVirtualFileSystem (getVirtualFileSystemPtr ());
1413+ Instance.createFileManager ();
14081414 }
14091415
14101416 if (ThreadSafeConfig) {
1411- Instance.createDiagnostics (Instance.getVirtualFileSystem (),
1412- &ThreadSafeConfig->getDiagConsumer (),
1417+ Instance.createDiagnostics (&ThreadSafeConfig->getDiagConsumer (),
14131418 /* ShouldOwnClient=*/ false );
14141419 } else {
14151420 Instance.createDiagnostics (
1416- Instance.getVirtualFileSystem (),
14171421 new ForwardingDiagnosticConsumer (getDiagnosticClient ()),
14181422 /* ShouldOwnClient=*/ true );
14191423 }
0 commit comments