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
3 changes: 2 additions & 1 deletion amd/comgr/src/comgr-clang-command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ SmallVector<StringRef, 1> getInputFiles(driver::Command &Command) {

} // namespace
ClangCommand::ClangCommand(driver::Command &Command,
DiagnosticOptions &DiagOpts, vfs::FileSystem &VFS,
DiagnosticOptions &DiagOpts,
IntrusiveRefCntPtr<vfs::FileSystem> VFS,
ExecuteFnTy &&ExecuteImpl)
: Command(Command), DiagOpts(DiagOpts), VFS(VFS),
ExecuteImpl(std::move(ExecuteImpl)) {}
Expand Down
7 changes: 4 additions & 3 deletions amd/comgr/src/comgr-clang-command.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class ClangCommand final : public CachedCommandAdaptor {
public:
using ExecuteFnTy = std::function<amd_comgr_status_t(
clang::driver::Command &, llvm::raw_ostream &, clang::DiagnosticOptions &,
llvm::vfs::FileSystem &)>;
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>)>;

private:
clang::driver::Command &Command;
clang::DiagnosticOptions &DiagOpts;
llvm::vfs::FileSystem &VFS;
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS;
ExecuteFnTy ExecuteImpl;

// To avoid copies, store the output of execute, such that readExecuteOutput
Expand All @@ -39,7 +39,8 @@ class ClangCommand final : public CachedCommandAdaptor {

public:
ClangCommand(clang::driver::Command &Command,
clang::DiagnosticOptions &DiagOpts, llvm::vfs::FileSystem &VFS,
clang::DiagnosticOptions &DiagOpts,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
ExecuteFnTy &&ExecuteImpl);

bool canCache() const override;
Expand Down
11 changes: 6 additions & 5 deletions amd/comgr/src/comgr-compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,10 @@ void logArgv(raw_ostream &OS, StringRef ProgramName,
OS.flush();
}

amd_comgr_status_t executeCommand(const Command &Job, raw_ostream &LogS,
DiagnosticOptions &DiagOpts,
llvm::vfs::FileSystem &FS) {
amd_comgr_status_t
executeCommand(const Command &Job, raw_ostream &LogS,
DiagnosticOptions &DiagOpts,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) {
TextDiagnosticPrinter DiagClient(LogS, DiagOpts);
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs);
DiagnosticsEngine Diags(DiagID, DiagOpts, &DiagClient, false);
Expand All @@ -661,7 +662,7 @@ amd_comgr_status_t executeCommand(const Command &Job, raw_ostream &LogS,

std::unique_ptr<CompilerInstance> Clang(new CompilerInstance());
Clang->setVerboseOutputStream(LogS);
Clang->setFileManager(new FileManager(Clang->getFileSystemOpts(), &FS));
Clang->setVirtualFileSystem(FS);
if (!Argv.back()) {
Argv.pop_back();
}
Expand Down Expand Up @@ -777,7 +778,7 @@ AMDGPUCompiler::executeInProcessDriver(ArrayRef<const char *> Args) {

auto Cache = CommandCache::get(LogS);
for (auto &Job : C->getJobs()) {
ClangCommand C(Job, *DiagOpts, *OverlayFS, executeCommand);
ClangCommand C(Job, *DiagOpts, OverlayFS, executeCommand);
if (Cache) {
if (auto Status = Cache->execute(C, LogS)) {
return Status;
Expand Down
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());
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());
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();

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