@@ -173,17 +173,11 @@ bool CompilerInstance::createTarget() {
173173 return true ;
174174}
175175
176- llvm::vfs::FileSystem &CompilerInstance::getVirtualFileSystem () const {
177- return getFileManager ().getVirtualFileSystem ();
178- }
179-
180- llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
181- CompilerInstance::getVirtualFileSystemPtr () const {
182- return getFileManager ().getVirtualFileSystemPtr ();
183- }
184-
185- void CompilerInstance::setFileManager (
186- 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 ());
187181 FileMgr = std::move (Value);
188182}
189183
@@ -296,6 +290,20 @@ static void collectVFSEntries(CompilerInstance &CI,
296290 MDC->addFile (E.VPath , E.RPath );
297291}
298292
293+ void CompilerInstance::createVirtualFileSystem (
294+ IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS, DiagnosticConsumer *DC) {
295+ DiagnosticOptions DiagOpts;
296+ DiagnosticsEngine Diags (DiagnosticIDs::create (), DiagOpts, DC,
297+ /* ShouldOwnClient=*/ false );
298+
299+ VFS = createVFSFromCompilerInvocation (getInvocation (), Diags,
300+ std::move (BaseFS), CAS);
301+ // FIXME: Should this go into createVFSFromCompilerInvocation?
302+ if (getFrontendOpts ().ShowStats )
303+ VFS =
304+ llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(std::move (VFS));
305+ }
306+
299307// Diagnostics
300308static void SetUpDiagnosticLog (DiagnosticOptions &DiagOpts,
301309 const CodeGenOptions *CodeGenOpts,
@@ -347,11 +355,10 @@ static void SetupSerializedDiagnostics(DiagnosticOptions &DiagOpts,
347355 }
348356}
349357
350- void CompilerInstance::createDiagnostics (llvm::vfs::FileSystem &VFS,
351- DiagnosticConsumer *Client,
358+ void CompilerInstance::createDiagnostics (DiagnosticConsumer *Client,
352359 bool ShouldOwnClient) {
353- Diagnostics = createDiagnostics (VFS , getDiagnosticOpts (), Client ,
354- ShouldOwnClient, &getCodeGenOpts ());
360+ Diagnostics = createDiagnostics (getVirtualFileSystem () , getDiagnosticOpts (),
361+ Client, ShouldOwnClient, &getCodeGenOpts ());
355362}
356363
357364IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics (
@@ -389,18 +396,9 @@ IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(
389396
390397// File Manager
391398
392- FileManager *CompilerInstance::createFileManager (
393- IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
394- if (!VFS)
395- VFS = FileMgr ? FileMgr->getVirtualFileSystemPtr ()
396- : createVFSFromCompilerInvocation (getInvocation (),
397- getDiagnostics (), CAS);
398- assert (VFS && " FileManager has no VFS?" );
399- if (getFrontendOpts ().ShowStats )
400- VFS =
401- llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(std::move (VFS));
402- FileMgr = llvm::makeIntrusiveRefCnt<FileManager>(getFileSystemOpts (),
403- std::move (VFS));
399+ FileManager *CompilerInstance::createFileManager () {
400+ assert (VFS && " CompilerInstance needs a VFS for creating FileManager" );
401+ FileMgr = llvm::makeIntrusiveRefCnt<FileManager>(getFileSystemOpts (), VFS);
404402 return FileMgr.get ();
405403}
406404
@@ -1401,20 +1399,21 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
14011399 auto &Inv = Instance.getInvocation ();
14021400
14031401 if (ThreadSafeConfig) {
1404- Instance.createFileManager (ThreadSafeConfig->getVFS ());
1402+ Instance.setVirtualFileSystem (ThreadSafeConfig->getVFS ());
1403+ Instance.createFileManager ();
14051404 } else if (FrontendOpts.ModulesShareFileManager ) {
1405+ Instance.setVirtualFileSystem (getVirtualFileSystemPtr ());
14061406 Instance.setFileManager (getFileManagerPtr ());
14071407 } else {
1408- Instance.createFileManager (getVirtualFileSystemPtr ());
1408+ Instance.setVirtualFileSystem (getVirtualFileSystemPtr ());
1409+ Instance.createFileManager ();
14091410 }
14101411
14111412 if (ThreadSafeConfig) {
1412- Instance.createDiagnostics (Instance.getVirtualFileSystem (),
1413- &ThreadSafeConfig->getDiagConsumer (),
1413+ Instance.createDiagnostics (&ThreadSafeConfig->getDiagConsumer (),
14141414 /* ShouldOwnClient=*/ false );
14151415 } else {
14161416 Instance.createDiagnostics (
1417- Instance.getVirtualFileSystem (),
14181417 new ForwardingDiagnosticConsumer (getDiagnosticClient ()),
14191418 /* ShouldOwnClient=*/ true );
14201419 }
0 commit comments