Skip to content
Open
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
1 change: 1 addition & 0 deletions clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ bool IncludeFixerActionFactory::runInvocation(

// Set up Clang.
CompilerInstance Compiler(std::move(Invocation), std::move(PCHContainerOps));
Compiler.setVirtualFileSystem(Files->getVirtualFileSystemPtr());
Compiler.setFileManager(Files);

// Create the compiler's actual diagnostics engine. We want to drop all
Expand Down
5 changes: 5 additions & 0 deletions clang/include/clang/Frontend/ASTUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ class ASTUnit {
return *PPOpts;
}

IntrusiveRefCntPtr<llvm::vfs::FileSystem> getVirtualFileSystemPtr() {
// FIXME: Don't defer VFS ownership to the FileManager.
return FileMgr->getVirtualFileSystemPtr();
}

const FileManager &getFileManager() const { return *FileMgr; }
FileManager &getFileManager() { return *FileMgr; }
IntrusiveRefCntPtr<FileManager> getFileManagerPtr() { return FileMgr; }
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Frontend/CompilerInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ class CompilerInstance : public ModuleLoader {
FileMgr.resetWithoutRelease();
}

/// Replace the current file manager and virtual file system.
/// Replace the current file manager.
void setFileManager(IntrusiveRefCntPtr<FileManager> Value);

/// @}
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Frontend/ASTUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
AST->Reader = nullptr;

// Create a file manager object to provide access to and cache the filesystem.
Clang->setVirtualFileSystem(AST->getVirtualFileSystemPtr());
Clang->setFileManager(AST->getFileManagerPtr());

// Create the source manager.
Expand Down Expand Up @@ -2290,6 +2291,7 @@ void ASTUnit::CodeComplete(
"IR inputs not support here!");

// Use the source and file managers that we were given.
Clang->setVirtualFileSystem(FileMgr->getVirtualFileSystemPtr());
Clang->setFileManager(FileMgr);
Clang->setSourceManager(SourceMgr);

Expand Down
2 changes: 0 additions & 2 deletions clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ bool CompilerInstance::createTarget() {
}

void CompilerInstance::setFileManager(IntrusiveRefCntPtr<FileManager> Value) {
if (!hasVirtualFileSystem())
setVirtualFileSystem(Value->getVirtualFileSystemPtr());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a possible null dereference.

assert(Value == nullptr ||
getVirtualFileSystemPtr() == Value->getVirtualFileSystemPtr());
FileMgr = std::move(Value);
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Frontend/FrontendAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,

// Set the shared objects, these are reset when we finish processing the
// file, otherwise the CompilerInstance will happily destroy them.
CI.setVirtualFileSystem(AST->getVirtualFileSystemPtr());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although CI.getVirtualFileSystemPtr() is being passed into ASTUnit::LoadFromASTFile(), the AST may end up being configured with a different VFS compared to CI which trips the assertion in CompilerInstance::setFileManager(). This is a good opportunity to fix that.

CI.setFileManager(AST->getFileManagerPtr());
CI.setSourceManager(AST->getSourceManagerPtr());
CI.setPreprocessor(AST->getPreprocessorPtr());
Expand Down
10 changes: 3 additions & 7 deletions clang/lib/Frontend/PrecompiledPreamble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,16 +479,12 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
Diagnostics->Reset();
ProcessWarningOptions(*Diagnostics, Clang->getDiagnosticOpts(), *VFS);

VFS = createVFSFromCompilerInvocation(Clang->getInvocation(), *Diagnostics,
VFS);

// Create a file manager object to provide access to and cache the filesystem.
Clang->setFileManager(
llvm::makeIntrusiveRefCnt<FileManager>(Clang->getFileSystemOpts(), VFS));
Clang->createVirtualFileSystem(VFS);
Clang->createFileManager();

// Create the source manager.
Clang->setSourceManager(llvm::makeIntrusiveRefCnt<SourceManager>(
*Diagnostics, Clang->getFileManager()));
Clang->createSourceManager();

auto PreambleDepCollector = std::make_shared<PreambleDependencyCollector>();
Clang->addDependencyCollector(PreambleDepCollector);
Expand Down
1 change: 1 addition & 0 deletions clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ void ModelInjector::onBodySynthesis(const NamedDecl *D) {

// The instance wants to take ownership, however DisableFree frontend option
// is set to true to avoid double free issues
Instance.setVirtualFileSystem(CI.getVirtualFileSystemPtr());
Instance.setFileManager(CI.getFileManagerPtr());
Instance.setSourceManager(SM);
Instance.setPreprocessor(CI.getPreprocessorPtr());
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Tooling/Tooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ bool FrontendActionFactory::runInvocation(
DiagnosticConsumer *DiagConsumer) {
// Create a compiler instance to handle the actual work.
CompilerInstance Compiler(std::move(Invocation), std::move(PCHContainerOps));
Compiler.setVirtualFileSystem(Files->getVirtualFileSystemPtr());
Compiler.setFileManager(Files);

// The FrontendAction can have lifetime requirements for Compiler or its
Expand Down
1 change: 1 addition & 0 deletions clang/tools/clang-installapi/ClangInstallAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ static bool run(ArrayRef<const char *> Args, const char *ProgName) {

// Set up compilation.
std::unique_ptr<CompilerInstance> CI(new CompilerInstance());
CI->setVirtualFileSystem(FM->getVirtualFileSystemPtr());
CI->setFileManager(FM);
CI->createDiagnostics();
if (!CI->hasDiagnostics())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class TestFileCollector : public DependencyFileGenerator {
std::vector<std::string> &Deps;
};

// FIXME: Use the regular Service/Worker/Collector APIs instead of
// reimplementing the action.
class TestDependencyScanningAction : public tooling::ToolAction {
public:
TestDependencyScanningAction(std::vector<std::string> &Deps) : Deps(Deps) {}
Expand All @@ -59,6 +61,7 @@ class TestDependencyScanningAction : public tooling::ToolAction {
DiagnosticConsumer *DiagConsumer) override {
CompilerInstance Compiler(std::move(Invocation),
std::move(PCHContainerOps));
Compiler.setVirtualFileSystem(FileMgr->getVirtualFileSystemPtr());
Compiler.setFileManager(FileMgr);

Compiler.createDiagnostics(DiagConsumer, /*ShouldOwnClient=*/false);
Expand Down
1 change: 1 addition & 0 deletions clang/unittests/Tooling/Syntax/TokensTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class TokenCollectorTest : public ::testing::Test {
FileName, llvm::MemoryBuffer::getMemBufferCopy(Code).release());
CompilerInstance Compiler(std::move(CI));
Compiler.setDiagnostics(Diags);
Compiler.setVirtualFileSystem(FS);
Compiler.setFileManager(FileMgr);
Compiler.setSourceManager(SourceMgr);

Expand Down
1 change: 1 addition & 0 deletions clang/unittests/Tooling/Syntax/TreeTestBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ SyntaxTreeTest::buildTree(StringRef Code, const TestClangConfig &ClangConfig) {
FileName, llvm::MemoryBuffer::getMemBufferCopy(Code).release());
CompilerInstance Compiler(Invocation);
Compiler.setDiagnostics(Diags);
Compiler.setVirtualFileSystem(FS);
Compiler.setFileManager(FileMgr);
Compiler.setSourceManager(SourceMgr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,6 @@ ClangExpressionParser::ClangExpressionParser(
// Make sure clang uses the same VFS as LLDB.
m_compiler->setVirtualFileSystem(
FileSystem::Instance().GetVirtualFileSystem());
m_compiler->createFileManager();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is redundant with line 825.


// 2. Configure the compiler with a set of default options that are
// appropriate for most situations.
Expand Down