@@ -159,17 +159,11 @@ bool CompilerInstance::createTarget() {
159159  return  true ;
160160}
161161
162- llvm::vfs::FileSystem &CompilerInstance::getVirtualFileSystem () const  {
163-   return  getFileManager ().getVirtualFileSystem ();
164- }
165- 
166- llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
167- CompilerInstance::getVirtualFileSystemPtr () const  {
168-   return  getFileManager ().getVirtualFileSystemPtr ();
169- }
170- 
171- void  CompilerInstance::setFileManager (
172-     llvm::IntrusiveRefCntPtr<FileManager> Value) {
162+ void  CompilerInstance::setFileManager (IntrusiveRefCntPtr<FileManager> Value) {
163+   if  (!hasVirtualFileSystem ())
164+     setVirtualFileSystem (Value->getVirtualFileSystemPtr ());
165+   assert (Value == nullptr  ||
166+          getVirtualFileSystemPtr () == Value->getVirtualFileSystemPtr ());
173167  FileMgr = std::move (Value);
174168}
175169
@@ -282,6 +276,20 @@ static void collectVFSEntries(CompilerInstance &CI,
282276    MDC->addFile (E.VPath , E.RPath );
283277}
284278
279+ void  CompilerInstance::createVirtualFileSystem (
280+     IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS, DiagnosticConsumer *DC) {
281+   DiagnosticOptions DiagOpts;
282+   DiagnosticsEngine Diags (DiagnosticIDs::create (), DiagOpts, DC,
283+                           /* ShouldOwnClient=*/ false );
284+ 
285+   VFS = createVFSFromCompilerInvocation (getInvocation (), Diags,
286+                                         std::move (BaseFS));
287+   //  FIXME: Should this go into createVFSFromCompilerInvocation?
288+   if  (getFrontendOpts ().ShowStats )
289+     VFS =
290+         llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(std::move (VFS));
291+ }
292+ 
285293//  Diagnostics
286294static  void  SetUpDiagnosticLog (DiagnosticOptions &DiagOpts,
287295                               const  CodeGenOptions *CodeGenOpts,
@@ -333,11 +341,10 @@ static void SetupSerializedDiagnostics(DiagnosticOptions &DiagOpts,
333341  }
334342}
335343
336- void  CompilerInstance::createDiagnostics (llvm::vfs::FileSystem &VFS,
337-                                          DiagnosticConsumer *Client,
344+ void  CompilerInstance::createDiagnostics (DiagnosticConsumer *Client,
338345                                         bool  ShouldOwnClient) {
339-   Diagnostics = createDiagnostics (VFS , getDiagnosticOpts (), Client ,
340-                                   ShouldOwnClient, &getCodeGenOpts ());
346+   Diagnostics = createDiagnostics (getVirtualFileSystem () , getDiagnosticOpts (),
347+                                   Client,  ShouldOwnClient, &getCodeGenOpts ());
341348}
342349
343350IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics (
@@ -375,18 +382,9 @@ IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(
375382
376383//  File Manager
377384
378- FileManager *CompilerInstance::createFileManager (
379-     IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
380-   if  (!VFS)
381-     VFS = FileMgr ? FileMgr->getVirtualFileSystemPtr ()
382-                   : createVFSFromCompilerInvocation (getInvocation (),
383-                                                     getDiagnostics ());
384-   assert (VFS && " FileManager has no VFS?" 
385-   if  (getFrontendOpts ().ShowStats )
386-     VFS =
387-         llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(std::move (VFS));
388-   FileMgr = llvm::makeIntrusiveRefCnt<FileManager>(getFileSystemOpts (),
389-                                                    std::move (VFS));
385+ FileManager *CompilerInstance::createFileManager () {
386+   assert (VFS && " CompilerInstance needs a VFS for creating FileManager" 
387+   FileMgr = llvm::makeIntrusiveRefCnt<FileManager>(getFileSystemOpts (), VFS);
390388  return  FileMgr.get ();
391389}
392390
@@ -1167,20 +1165,21 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
11671165  auto  &Inv = Instance.getInvocation ();
11681166
11691167  if  (ThreadSafeConfig) {
1170-     Instance.createFileManager (ThreadSafeConfig->getVFS ());
1168+     Instance.setVirtualFileSystem (ThreadSafeConfig->getVFS ());
1169+     Instance.createFileManager ();
11711170  } else  if  (FrontendOpts.ModulesShareFileManager ) {
1171+     Instance.setVirtualFileSystem (getVirtualFileSystemPtr ());
11721172    Instance.setFileManager (getFileManagerPtr ());
11731173  } else  {
1174-     Instance.createFileManager (getVirtualFileSystemPtr ());
1174+     Instance.setVirtualFileSystem (getVirtualFileSystemPtr ());
1175+     Instance.createFileManager ();
11751176  }
11761177
11771178  if  (ThreadSafeConfig) {
1178-     Instance.createDiagnostics (Instance.getVirtualFileSystem (),
1179-                                &ThreadSafeConfig->getDiagConsumer (),
1179+     Instance.createDiagnostics (&ThreadSafeConfig->getDiagConsumer (),
11801180                               /* ShouldOwnClient=*/ false );
11811181  } else  {
11821182    Instance.createDiagnostics (
1183-         Instance.getVirtualFileSystem (),
11841183        new  ForwardingDiagnosticConsumer (getDiagnosticClient ()),
11851184        /* ShouldOwnClient=*/ true );
11861185  }
0 commit comments