@@ -162,17 +162,11 @@ bool CompilerInstance::createTarget() {
162
162
return true ;
163
163
}
164
164
165
- llvm::vfs::FileSystem &CompilerInstance::getVirtualFileSystem () const {
166
- return getFileManager ().getVirtualFileSystem ();
167
- }
168
-
169
- llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
170
- CompilerInstance::getVirtualFileSystemPtr () const {
171
- return getFileManager ().getVirtualFileSystemPtr ();
172
- }
173
-
174
- void CompilerInstance::setFileManager (
175
- llvm::IntrusiveRefCntPtr<FileManager> Value) {
165
+ void CompilerInstance::setFileManager (IntrusiveRefCntPtr<FileManager> Value) {
166
+ if (!hasVirtualFileSystem ())
167
+ setVirtualFileSystem (Value->getVirtualFileSystemPtr ());
168
+ assert (Value == nullptr ||
169
+ getVirtualFileSystemPtr () == Value->getVirtualFileSystemPtr ());
176
170
FileMgr = std::move (Value);
177
171
}
178
172
@@ -285,6 +279,20 @@ static void collectVFSEntries(CompilerInstance &CI,
285
279
MDC->addFile (E.VPath , E.RPath );
286
280
}
287
281
282
+ void CompilerInstance::createVirtualFileSystem (
283
+ IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS, DiagnosticConsumer *DC) {
284
+ DiagnosticOptions DiagOpts;
285
+ DiagnosticsEngine Diags (DiagnosticIDs::create (), DiagOpts, DC,
286
+ /* ShouldOwnClient=*/ false );
287
+
288
+ VFS = createVFSFromCompilerInvocation (getInvocation (), Diags,
289
+ std::move (BaseFS));
290
+ // FIXME: Should this go into createVFSFromCompilerInvocation?
291
+ if (getFrontendOpts ().ShowStats )
292
+ VFS =
293
+ llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(std::move (VFS));
294
+ }
295
+
288
296
// Diagnostics
289
297
static void SetUpDiagnosticLog (DiagnosticOptions &DiagOpts,
290
298
const CodeGenOptions *CodeGenOpts,
@@ -336,11 +344,10 @@ static void SetupSerializedDiagnostics(DiagnosticOptions &DiagOpts,
336
344
}
337
345
}
338
346
339
- void CompilerInstance::createDiagnostics (llvm::vfs::FileSystem &VFS,
340
- DiagnosticConsumer *Client,
347
+ void CompilerInstance::createDiagnostics (DiagnosticConsumer *Client,
341
348
bool ShouldOwnClient) {
342
- Diagnostics = createDiagnostics (VFS , getDiagnosticOpts (), Client ,
343
- ShouldOwnClient, &getCodeGenOpts ());
349
+ Diagnostics = createDiagnostics (getVirtualFileSystem () , getDiagnosticOpts (),
350
+ Client, ShouldOwnClient, &getCodeGenOpts ());
344
351
}
345
352
346
353
IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics (
@@ -378,18 +385,9 @@ IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(
378
385
379
386
// File Manager
380
387
381
- FileManager *CompilerInstance::createFileManager (
382
- IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
383
- if (!VFS)
384
- VFS = FileMgr ? FileMgr->getVirtualFileSystemPtr ()
385
- : createVFSFromCompilerInvocation (getInvocation (),
386
- getDiagnostics ());
387
- assert (VFS && " FileManager has no VFS?" );
388
- if (getFrontendOpts ().ShowStats )
389
- VFS =
390
- llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(std::move (VFS));
391
- FileMgr = llvm::makeIntrusiveRefCnt<FileManager>(getFileSystemOpts (),
392
- std::move (VFS));
388
+ FileManager *CompilerInstance::createFileManager () {
389
+ assert (VFS && " CompilerInstance needs a VFS for creating FileManager" );
390
+ FileMgr = llvm::makeIntrusiveRefCnt<FileManager>(getFileSystemOpts (), VFS);
393
391
return FileMgr.get ();
394
392
}
395
393
@@ -1170,20 +1168,21 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
1170
1168
auto &Inv = Instance.getInvocation ();
1171
1169
1172
1170
if (ThreadSafeConfig) {
1173
- Instance.createFileManager (ThreadSafeConfig->getVFS ());
1171
+ Instance.setVirtualFileSystem (ThreadSafeConfig->getVFS ());
1172
+ Instance.createFileManager ();
1174
1173
} else if (FrontendOpts.ModulesShareFileManager ) {
1174
+ Instance.setVirtualFileSystem (getVirtualFileSystemPtr ());
1175
1175
Instance.setFileManager (getFileManagerPtr ());
1176
1176
} else {
1177
- Instance.createFileManager (getVirtualFileSystemPtr ());
1177
+ Instance.setVirtualFileSystem (getVirtualFileSystemPtr ());
1178
+ Instance.createFileManager ();
1178
1179
}
1179
1180
1180
1181
if (ThreadSafeConfig) {
1181
- Instance.createDiagnostics (Instance.getVirtualFileSystem (),
1182
- &ThreadSafeConfig->getDiagConsumer (),
1182
+ Instance.createDiagnostics (&ThreadSafeConfig->getDiagConsumer (),
1183
1183
/* ShouldOwnClient=*/ false );
1184
1184
} else {
1185
1185
Instance.createDiagnostics (
1186
- Instance.getVirtualFileSystem (),
1187
1186
new ForwardingDiagnosticConsumer (getDiagnosticClient ()),
1188
1187
/* ShouldOwnClient=*/ true );
1189
1188
}
0 commit comments