diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h index 27bba8e64859d..f66df89aad904 100644 --- a/clang/include/clang/Frontend/ASTUnit.h +++ b/clang/include/clang/Frontend/ASTUnit.h @@ -729,16 +729,15 @@ class ASTUnit { /// \returns - The initialized ASTUnit or null if the AST failed to load. static std::unique_ptr LoadFromASTFile( StringRef Filename, const PCHContainerReader &PCHContainerRdr, - WhatToLoad ToLoad, std::shared_ptr DiagOpts, + WhatToLoad ToLoad, IntrusiveRefCntPtr VFS, + std::shared_ptr DiagOpts, IntrusiveRefCntPtr Diags, const FileSystemOptions &FileSystemOpts, const HeaderSearchOptions &HSOpts, const LangOptions *LangOpts = nullptr, bool OnlyLocalDecls = false, CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None, bool AllowASTWithCompilerErrors = false, - bool UserFilesAreVolatile = false, - IntrusiveRefCntPtr VFS = - llvm::vfs::getRealFileSystem()); + bool UserFilesAreVolatile = false); private: /// Helper function for \c LoadFromCompilerInvocation() and diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp index 96e28fb10284f..847913d4b03fd 100644 --- a/clang/lib/CrossTU/CrossTranslationUnit.cpp +++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp @@ -577,8 +577,8 @@ CrossTranslationUnitContext::ASTLoader::loadFromDump(StringRef ASTDumpPath) { DiagnosticIDs::create(), *DiagOpts, DiagClient); return ASTUnit::LoadFromASTFile( ASTDumpPath, CI.getPCHContainerOperations()->getRawReader(), - ASTUnit::LoadEverything, DiagOpts, Diags, CI.getFileSystemOpts(), - CI.getHeaderSearchOpts()); + ASTUnit::LoadEverything, CI.getVirtualFileSystemPtr(), DiagOpts, Diags, + CI.getFileSystemOpts(), CI.getHeaderSearchOpts()); } /// Load the AST from a source-file, which is supposed to be located inside the diff --git a/clang/lib/Frontend/ASTMerge.cpp b/clang/lib/Frontend/ASTMerge.cpp index 10c10458466bc..0dff69d613bcf 100644 --- a/clang/lib/Frontend/ASTMerge.cpp +++ b/clang/lib/Frontend/ASTMerge.cpp @@ -47,7 +47,8 @@ void ASTMergeAction::ExecuteAction() { /*ShouldOwnClient=*/true); std::unique_ptr Unit = ASTUnit::LoadFromASTFile( ASTFiles[I], CI.getPCHContainerReader(), ASTUnit::LoadEverything, - nullptr, Diags, CI.getFileSystemOpts(), CI.getHeaderSearchOpts()); + CI.getVirtualFileSystemPtr(), nullptr, Diags, CI.getFileSystemOpts(), + CI.getHeaderSearchOpts()); if (!Unit) continue; diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 8b35af152cbc8..cb445682ac48b 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -808,12 +808,13 @@ void ASTUnit::ConfigureDiags(IntrusiveRefCntPtr Diags, std::unique_ptr ASTUnit::LoadFromASTFile( StringRef Filename, const PCHContainerReader &PCHContainerRdr, - WhatToLoad ToLoad, std::shared_ptr DiagOpts, + WhatToLoad ToLoad, IntrusiveRefCntPtr VFS, + std::shared_ptr DiagOpts, IntrusiveRefCntPtr Diags, const FileSystemOptions &FileSystemOpts, const HeaderSearchOptions &HSOpts, const LangOptions *LangOpts, bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics, bool AllowASTWithCompilerErrors, - bool UserFilesAreVolatile, IntrusiveRefCntPtr VFS) { + bool UserFilesAreVolatile) { std::unique_ptr AST(new ASTUnit(true)); // Recover resources if we crash before exiting this method. diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index ca37e0661476d..6cc3b65a16cb2 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -864,7 +864,8 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, std::unique_ptr AST = ASTUnit::LoadFromASTFile( InputFile, CI.getPCHContainerReader(), ASTUnit::LoadPreprocessorOnly, - nullptr, ASTDiags, CI.getFileSystemOpts(), CI.getHeaderSearchOpts()); + CI.getVirtualFileSystemPtr(), nullptr, ASTDiags, CI.getFileSystemOpts(), + CI.getHeaderSearchOpts()); if (!AST) return false; @@ -931,9 +932,9 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, StringRef InputFile = Input.getFile(); std::unique_ptr AST = ASTUnit::LoadFromASTFile( - InputFile, CI.getPCHContainerReader(), ASTUnit::LoadEverything, nullptr, - Diags, CI.getFileSystemOpts(), CI.getHeaderSearchOpts(), - &CI.getLangOpts()); + InputFile, CI.getPCHContainerReader(), ASTUnit::LoadEverything, + CI.getVirtualFileSystemPtr(), nullptr, Diags, CI.getFileSystemOpts(), + CI.getHeaderSearchOpts(), &CI.getLangOpts()); if (!AST) return false; diff --git a/clang/tools/c-index-test/core_main.cpp b/clang/tools/c-index-test/core_main.cpp index 25104304322d4..5a3086a7fc08f 100644 --- a/clang/tools/c-index-test/core_main.cpp +++ b/clang/tools/c-index-test/core_main.cpp @@ -275,12 +275,13 @@ static bool printSourceSymbolsFromModule(StringRef modulePath, HeaderSearchOptions HSOpts; + auto VFS = llvm::vfs::getRealFileSystem(); + auto DiagOpts = std::make_shared(); IntrusiveRefCntPtr Diags = - CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(), - *DiagOpts); + CompilerInstance::createDiagnostics(*VFS, *DiagOpts); std::unique_ptr AU = ASTUnit::LoadFromASTFile( - modulePath, *pchRdr, ASTUnit::LoadASTOnly, DiagOpts, Diags, + modulePath, *pchRdr, ASTUnit::LoadASTOnly, VFS, DiagOpts, Diags, FileSystemOpts, HSOpts, /*LangOpts=*/nullptr, /*OnlyLocalDecls=*/true, CaptureDiagsKind::None, /*AllowASTWithCompilerErrors=*/true, diff --git a/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp b/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp index ddb2944e3820b..6d8f86b13fa36 100644 --- a/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp +++ b/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp @@ -157,8 +157,8 @@ static bool HandleAST(StringRef AstPath) { std::unique_ptr Unit = ASTUnit::LoadFromASTFile( AstPath, CI->getPCHContainerOperations()->getRawReader(), - ASTUnit::LoadASTOnly, DiagOpts, DiagEngine, CI->getFileSystemOpts(), - CI->getHeaderSearchOpts()); + ASTUnit::LoadASTOnly, CI->getVirtualFileSystemPtr(), DiagOpts, DiagEngine, + CI->getFileSystemOpts(), CI->getHeaderSearchOpts()); if (!Unit) return false; diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 9526f629bda42..6518e7d4d530f 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -4180,13 +4180,14 @@ enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx, FileSystemOptions FileSystemOpts; HeaderSearchOptions HSOpts; + auto VFS = llvm::vfs::getRealFileSystem(); + auto DiagOpts = std::make_shared(); IntrusiveRefCntPtr Diags = - CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(), - *DiagOpts); + CompilerInstance::createDiagnostics(*VFS, *DiagOpts); std::unique_ptr AU = ASTUnit::LoadFromASTFile( ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(), - ASTUnit::LoadEverything, DiagOpts, Diags, FileSystemOpts, HSOpts, + ASTUnit::LoadEverything, VFS, DiagOpts, Diags, FileSystemOpts, HSOpts, /*LangOpts=*/nullptr, CXXIdx->getOnlyLocalDecls(), CaptureDiagsKind::All, /*AllowASTWithCompilerErrors=*/true, /*UserFilesAreVolatile=*/true); diff --git a/clang/unittests/Frontend/ASTUnitTest.cpp b/clang/unittests/Frontend/ASTUnitTest.cpp index 7160453b17daa..dfdbe90e72f1f 100644 --- a/clang/unittests/Frontend/ASTUnitTest.cpp +++ b/clang/unittests/Frontend/ASTUnitTest.cpp @@ -98,7 +98,8 @@ TEST_F(ASTUnitTest, SaveLoadPreservesLangOptionsInPrintingPolicy) { std::unique_ptr AU = ASTUnit::LoadFromASTFile( ASTFileName, PCHContainerOps->getRawReader(), ASTUnit::LoadEverything, - DiagOpts, Diags, FileSystemOptions(), HSOpts); + llvm::vfs::getRealFileSystem(), DiagOpts, Diags, FileSystemOptions(), + HSOpts); if (!AU) FAIL() << "failed to load ASTUnit";