@@ -159,17 +159,11 @@ bool CompilerInstance::createTarget() {
159
159
return true ;
160
160
}
161
161
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 ());
173
167
FileMgr = std::move (Value);
174
168
}
175
169
@@ -282,6 +276,20 @@ static void collectVFSEntries(CompilerInstance &CI,
282
276
MDC->addFile (E.VPath , E.RPath );
283
277
}
284
278
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
+
285
293
// Diagnostics
286
294
static void SetUpDiagnosticLog (DiagnosticOptions &DiagOpts,
287
295
const CodeGenOptions *CodeGenOpts,
@@ -333,11 +341,10 @@ static void SetupSerializedDiagnostics(DiagnosticOptions &DiagOpts,
333
341
}
334
342
}
335
343
336
- void CompilerInstance::createDiagnostics (llvm::vfs::FileSystem &VFS,
337
- DiagnosticConsumer *Client,
344
+ void CompilerInstance::createDiagnostics (DiagnosticConsumer *Client,
338
345
bool ShouldOwnClient) {
339
- Diagnostics = createDiagnostics (VFS , getDiagnosticOpts (), Client ,
340
- ShouldOwnClient, &getCodeGenOpts ());
346
+ Diagnostics = createDiagnostics (getVirtualFileSystem () , getDiagnosticOpts (),
347
+ Client, ShouldOwnClient, &getCodeGenOpts ());
341
348
}
342
349
343
350
IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics (
@@ -375,18 +382,9 @@ IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(
375
382
376
383
// File Manager
377
384
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);
390
388
return FileMgr.get ();
391
389
}
392
390
@@ -1167,20 +1165,21 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
1167
1165
auto &Inv = Instance.getInvocation ();
1168
1166
1169
1167
if (ThreadSafeConfig) {
1170
- Instance.createFileManager (ThreadSafeConfig->getVFS ());
1168
+ Instance.setVirtualFileSystem (ThreadSafeConfig->getVFS ());
1169
+ Instance.createFileManager ();
1171
1170
} else if (FrontendOpts.ModulesShareFileManager ) {
1171
+ Instance.setVirtualFileSystem (getVirtualFileSystemPtr ());
1172
1172
Instance.setFileManager (getFileManagerPtr ());
1173
1173
} else {
1174
- Instance.createFileManager (getVirtualFileSystemPtr ());
1174
+ Instance.setVirtualFileSystem (getVirtualFileSystemPtr ());
1175
+ Instance.createFileManager ();
1175
1176
}
1176
1177
1177
1178
if (ThreadSafeConfig) {
1178
- Instance.createDiagnostics (Instance.getVirtualFileSystem (),
1179
- &ThreadSafeConfig->getDiagConsumer (),
1179
+ Instance.createDiagnostics (&ThreadSafeConfig->getDiagConsumer (),
1180
1180
/* ShouldOwnClient=*/ false );
1181
1181
} else {
1182
1182
Instance.createDiagnostics (
1183
- Instance.getVirtualFileSystem (),
1184
1183
new ForwardingDiagnosticConsumer (getDiagnosticClient ()),
1185
1184
/* ShouldOwnClient=*/ true );
1186
1185
}
0 commit comments