@@ -405,49 +405,28 @@ bool CompilerInstance::setup(const CompilerInvocation &Invok,
405405 return false ;
406406}
407407
408- static bool loadAndValidateVFSOverlay (
409- const std::string &File,
410- const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &BaseFS,
411- const llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> &OverlayFS,
412- DiagnosticEngine &Diag) {
413- auto Buffer = BaseFS->getBufferForFile (File);
414- if (!Buffer) {
415- Diag.diagnose (SourceLoc (), diag::cannot_open_file, File,
416- Buffer.getError ().message ());
408+ bool CompilerInstance::setUpVirtualFileSystemOverlays () {
409+ auto ExpectedOverlay =
410+ Invocation.getSearchPathOptions ().makeOverlayFileSystem (
411+ SourceMgr.getFileSystem ());
412+ if (!ExpectedOverlay) {
413+ llvm::handleAllErrors (
414+ ExpectedOverlay.takeError (), [&](const llvm::FileError &FE) {
415+ if (FE.convertToErrorCode () == std::errc::no_such_file_or_directory) {
416+ Diagnostics.diagnose (SourceLoc (), diag::cannot_open_file,
417+ FE.getFileName (), FE.messageWithoutFileInfo ());
418+ } else {
419+ Diagnostics.diagnose (SourceLoc (), diag::invalid_vfs_overlay_file,
420+ FE.getFileName ());
421+ }
422+ });
417423 return true ;
418424 }
419425
420- auto VFS = llvm::vfs::getVFSFromYAML (std::move (Buffer.get ()),
421- nullptr , File);
422- if (!VFS) {
423- Diag.diagnose (SourceLoc (), diag::invalid_vfs_overlay_file, File);
424- return true ;
425- }
426- OverlayFS->pushOverlay (std::move (VFS));
426+ SourceMgr.setFileSystem (*ExpectedOverlay);
427427 return false ;
428428}
429429
430- bool CompilerInstance::setUpVirtualFileSystemOverlays () {
431- auto BaseFS = SourceMgr.getFileSystem ();
432- auto OverlayFS = llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>(
433- new llvm::vfs::OverlayFileSystem (BaseFS));
434- bool hadAnyFailure = false ;
435- bool hasOverlays = false ;
436- for (const auto &File : Invocation.getSearchPathOptions ().VFSOverlayFiles ) {
437- hasOverlays = true ;
438- hadAnyFailure |=
439- loadAndValidateVFSOverlay (File, BaseFS, OverlayFS, Diagnostics);
440- }
441-
442- // If we successfully loaded all the overlays, let the source manager and
443- // diagnostic engine take advantage of the overlay file system.
444- if (!hadAnyFailure && hasOverlays) {
445- SourceMgr.setFileSystem (OverlayFS);
446- }
447-
448- return hadAnyFailure;
449- }
450-
451430void CompilerInstance::setUpLLVMArguments () {
452431 // Honor -Xllvm.
453432 if (!Invocation.getFrontendOptions ().LLVMArgs .empty ()) {
0 commit comments