@@ -172,11 +172,11 @@ bool CompilerInstance::createTarget() {
172172  return  true ;
173173}
174174
175- llvm::vfs::FileSystem &CompilerInstance::getVirtualFileSystem () const  {
176-   return  getFileManager ().getVirtualFileSystem ();
177- }
178- 
179175void  CompilerInstance::setFileManager (FileManager *Value) {
176+   if  (!hasVirtualFileSystem ())
177+     setVirtualFileSystem (Value->getVirtualFileSystemPtr ());
178+   assert (Value == nullptr  ||
179+          getVirtualFileSystemPtr () == Value->getVirtualFileSystemPtr ());
180180  FileMgr = Value;
181181}
182182
@@ -287,6 +287,20 @@ static void collectVFSEntries(CompilerInstance &CI,
287287    MDC->addFile (E.VPath , E.RPath );
288288}
289289
290+ void  CompilerInstance::createVirtualFileSystem (
291+     IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS, DiagnosticConsumer *DC) {
292+   DiagnosticOptions DiagOpts;
293+   DiagnosticsEngine Diags (new  DiagnosticIDs, DiagOpts, DC,
294+                           /* ShouldOwnClient=*/ false );
295+ 
296+   VFS = createVFSFromCompilerInvocation (getInvocation (), Diags,
297+                                         std::move (BaseFS), CAS);
298+   //  FIXME: Should this go into createVFSFromCompilerInvocation?
299+   if  (getFrontendOpts ().ShowStats )
300+     VFS =
301+         llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(std::move (VFS));
302+ }
303+ 
290304//  Diagnostics
291305static  void  SetUpDiagnosticLog (DiagnosticOptions &DiagOpts,
292306                               const  CodeGenOptions *CodeGenOpts,
@@ -338,11 +352,10 @@ static void SetupSerializedDiagnostics(DiagnosticOptions &DiagOpts,
338352  }
339353}
340354
341- void  CompilerInstance::createDiagnostics (llvm::vfs::FileSystem &VFS,
342-                                          DiagnosticConsumer *Client,
355+ void  CompilerInstance::createDiagnostics (DiagnosticConsumer *Client,
343356                                         bool  ShouldOwnClient) {
344-   Diagnostics = createDiagnostics (VFS , getDiagnosticOpts (), Client ,
345-                                   ShouldOwnClient, &getCodeGenOpts ());
357+   Diagnostics = createDiagnostics (getVirtualFileSystem () , getDiagnosticOpts (),
358+                                   Client,  ShouldOwnClient, &getCodeGenOpts ());
346359}
347360
348361IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics (
@@ -381,17 +394,9 @@ IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(
381394
382395//  File Manager
383396
384- FileManager *CompilerInstance::createFileManager (
385-     IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
386-   if  (!VFS)
387-     VFS = FileMgr ? &FileMgr->getVirtualFileSystem ()
388-                   : createVFSFromCompilerInvocation (getInvocation (),
389-                                                     getDiagnostics (), CAS);
390-   assert (VFS && " FileManager has no VFS?" 
391-   if  (getFrontendOpts ().ShowStats )
392-     VFS =
393-         llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(std::move (VFS));
394-   FileMgr = new  FileManager (getFileSystemOpts (), std::move (VFS));
397+ FileManager *CompilerInstance::createFileManager () {
398+   assert (VFS && " CompilerInstance needs a VFS for creating FileManager" 
399+   FileMgr = llvm::makeIntrusiveRefCnt<FileManager>(getFileSystemOpts (), VFS);
395400  return  FileMgr.get ();
396401}
397402
@@ -1388,20 +1393,21 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
13881393  auto  &Inv = Instance.getInvocation ();
13891394
13901395  if  (ThreadSafeConfig) {
1391-     Instance.createFileManager (ThreadSafeConfig->getVFS ());
1396+     Instance.setVirtualFileSystem (ThreadSafeConfig->getVFS ());
1397+     Instance.createFileManager ();
13921398  } else  if  (FrontendOpts.ModulesShareFileManager ) {
1399+     Instance.setVirtualFileSystem (getVirtualFileSystemPtr ());
13931400    Instance.setFileManager (&getFileManager ());
13941401  } else  {
1395-     Instance.createFileManager (&getVirtualFileSystem ());
1402+     Instance.setVirtualFileSystem (&getVirtualFileSystem ());
1403+     Instance.createFileManager ();
13961404  }
13971405
13981406  if  (ThreadSafeConfig) {
1399-     Instance.createDiagnostics (Instance.getVirtualFileSystem (),
1400-                                &ThreadSafeConfig->getDiagConsumer (),
1407+     Instance.createDiagnostics (&ThreadSafeConfig->getDiagConsumer (),
14011408                               /* ShouldOwnClient=*/ false );
14021409  } else  {
14031410    Instance.createDiagnostics (
1404-         Instance.getVirtualFileSystem (),
14051411        new  ForwardingDiagnosticConsumer (getDiagnosticClient ()),
14061412        /* ShouldOwnClient=*/ true );
14071413  }
0 commit comments