Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions clang/include/clang/Frontend/ASTUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,16 +729,15 @@ class ASTUnit {
/// \returns - The initialized ASTUnit or null if the AST failed to load.
static std::unique_ptr<ASTUnit> LoadFromASTFile(
StringRef Filename, const PCHContainerReader &PCHContainerRdr,
WhatToLoad ToLoad, std::shared_ptr<DiagnosticOptions> DiagOpts,
WhatToLoad ToLoad, IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it is better to pass vfs::FileSystem& to avoid ref counting? The caller should hold onto VFS during the function call and no ownership is transferred here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree in principle, but ASTUnit is special when it comes to lifetimes and actually typically does outlive the caller. Moreover, the VFS is used to create a FileManager that currently does take the ownership.

std::shared_ptr<DiagnosticOptions> DiagOpts,
IntrusiveRefCntPtr<DiagnosticsEngine> 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<llvm::vfs::FileSystem> VFS =
llvm::vfs::getRealFileSystem());
bool UserFilesAreVolatile = false);

private:
/// Helper function for \c LoadFromCompilerInvocation() and
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CrossTU/CrossTranslationUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Frontend/ASTMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ void ASTMergeAction::ExecuteAction() {
/*ShouldOwnClient=*/true);
std::unique_ptr<ASTUnit> 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;
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Frontend/ASTUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,12 +808,13 @@ void ASTUnit::ConfigureDiags(IntrusiveRefCntPtr<DiagnosticsEngine> Diags,

std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
StringRef Filename, const PCHContainerReader &PCHContainerRdr,
WhatToLoad ToLoad, std::shared_ptr<DiagnosticOptions> DiagOpts,
WhatToLoad ToLoad, IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
std::shared_ptr<DiagnosticOptions> DiagOpts,
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
const FileSystemOptions &FileSystemOpts, const HeaderSearchOptions &HSOpts,
const LangOptions *LangOpts, bool OnlyLocalDecls,
CaptureDiagsKind CaptureDiagnostics, bool AllowASTWithCompilerErrors,
bool UserFilesAreVolatile, IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
bool UserFilesAreVolatile) {
std::unique_ptr<ASTUnit> AST(new ASTUnit(true));

// Recover resources if we crash before exiting this method.
Expand Down
9 changes: 5 additions & 4 deletions clang/lib/Frontend/FrontendAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,8 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,

std::unique_ptr<ASTUnit> 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;

Expand Down Expand Up @@ -931,9 +932,9 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
StringRef InputFile = Input.getFile();

std::unique_ptr<ASTUnit> 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;
Expand Down
7 changes: 4 additions & 3 deletions clang/tools/c-index-test/core_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,13 @@ static bool printSourceSymbolsFromModule(StringRef modulePath,

HeaderSearchOptions HSOpts;

auto VFS = llvm::vfs::getRealFileSystem();

auto DiagOpts = std::make_shared<DiagnosticOptions>();
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(),
*DiagOpts);
CompilerInstance::createDiagnostics(*VFS, *DiagOpts);
std::unique_ptr<ASTUnit> 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,
Expand Down
4 changes: 2 additions & 2 deletions clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ static bool HandleAST(StringRef AstPath) {

std::unique_ptr<ASTUnit> 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;
Expand Down
7 changes: 4 additions & 3 deletions clang/tools/libclang/CIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4180,13 +4180,14 @@ enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx,
FileSystemOptions FileSystemOpts;
HeaderSearchOptions HSOpts;

auto VFS = llvm::vfs::getRealFileSystem();

auto DiagOpts = std::make_shared<DiagnosticOptions>();
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(),
*DiagOpts);
CompilerInstance::createDiagnostics(*VFS, *DiagOpts);
std::unique_ptr<ASTUnit> 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);
Expand Down
3 changes: 2 additions & 1 deletion clang/unittests/Frontend/ASTUnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ TEST_F(ASTUnitTest, SaveLoadPreservesLangOptionsInPrintingPolicy) {

std::unique_ptr<ASTUnit> 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";
Expand Down