diff options
author | Sylvestre Ledru <sylvestre@debian.org> | 2024-11-21 13:04:30 +0100 |
---|---|---|
committer | Sylvestre Ledru <sylvestre@debian.org> | 2024-11-21 13:04:30 +0100 |
commit | a1153cd6fedd4c906a9840987934ca4712e34cb2 (patch) | |
tree | 5b267500546cc06032b49c0153f6aa1e92cbb74c /clang/lib | |
parent | 0b06301a1d839eb5f73559f6c3daf9049c34f3af (diff) | |
download | llvm-a1153cd6fedd4c906a9840987934ca4712e34cb2.zip llvm-a1153cd6fedd4c906a9840987934ca4712e34cb2.tar.gz llvm-a1153cd6fedd4c906a9840987934ca4712e34cb2.tar.bz2 |
Revert "[NFC] Explicitly pass a VFS when creating DiagnosticsEngine (#115852)"
Reverted for causing:
https://github.com/llvm/llvm-project/issues/117145
This reverts commit bdd10d9d249bd1c2a45e3de56a5accd97e953458.
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 30 | ||||
-rw-r--r-- | clang/lib/Frontend/CreateInvocationFromCommandLine.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Frontend/Rewrite/FrontendActions.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Interpreter/Interpreter.cpp | 3 | ||||
-rw-r--r-- | clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Testing/TestAST.cpp | 32 | ||||
-rw-r--r-- | clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Tooling/Tooling.cpp | 9 |
8 files changed, 38 insertions, 48 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index fbfc305..ecc6782 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -332,20 +332,23 @@ static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts, } } -void CompilerInstance::createDiagnostics(llvm::vfs::FileSystem &VFS, - DiagnosticConsumer *Client, +void CompilerInstance::createDiagnostics(DiagnosticConsumer *Client, bool ShouldOwnClient) { - Diagnostics = createDiagnostics(VFS, &getDiagnosticOpts(), Client, - ShouldOwnClient, &getCodeGenOpts()); + Diagnostics = createDiagnostics( + &getDiagnosticOpts(), Client, ShouldOwnClient, &getCodeGenOpts(), + FileMgr ? FileMgr->getVirtualFileSystemPtr() : nullptr); } IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics( - llvm::vfs::FileSystem &VFS, DiagnosticOptions *Opts, - DiagnosticConsumer *Client, bool ShouldOwnClient, - const CodeGenOptions *CodeGenOpts) { + DiagnosticOptions *Opts, DiagnosticConsumer *Client, bool ShouldOwnClient, + const CodeGenOptions *CodeGenOpts, + llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) { IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); - IntrusiveRefCntPtr<DiagnosticsEngine> Diags( - new DiagnosticsEngine(DiagID, Opts)); + IntrusiveRefCntPtr<DiagnosticsEngine> + Diags(new DiagnosticsEngine(DiagID, Opts)); + + if (!VFS) + VFS = llvm::vfs::getRealFileSystem(); // Create the diagnostic client for reporting errors or for // implementing -verify. @@ -369,7 +372,7 @@ IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics( Opts->DiagnosticSerializationFile); // Configure our handling of diagnostics. - ProcessWarningOptions(*Diags, *Opts, VFS); + ProcessWarningOptions(*Diags, *Opts, *VFS); return Diags; } @@ -1237,10 +1240,9 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, auto &Inv = *Invocation; Instance.setInvocation(std::move(Invocation)); - Instance.createDiagnostics( - ImportingInstance.getVirtualFileSystem(), - new ForwardingDiagnosticConsumer(ImportingInstance.getDiagnosticClient()), - /*ShouldOwnClient=*/true); + Instance.createDiagnostics(new ForwardingDiagnosticConsumer( + ImportingInstance.getDiagnosticClient()), + /*ShouldOwnClient=*/true); if (llvm::is_contained(DiagOpts.SystemHeaderWarningsModules, ModuleName)) Instance.getDiagnostics().setSuppressSystemWarnings(false); diff --git a/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp b/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp index d0b855f..638757a 100644 --- a/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp +++ b/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp @@ -22,7 +22,6 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Option/ArgList.h" -#include "llvm/Support/VirtualFileSystem.h" #include "llvm/TargetParser/Host.h" using namespace clang; using namespace llvm::opt; @@ -33,9 +32,7 @@ clang::createInvocation(ArrayRef<const char *> ArgList, assert(!ArgList.empty()); auto Diags = Opts.Diags ? std::move(Opts.Diags) - : CompilerInstance::createDiagnostics( - Opts.VFS ? *Opts.VFS : *llvm::vfs::getRealFileSystem(), - new DiagnosticOptions); + : CompilerInstance::createDiagnostics(new DiagnosticOptions); SmallVector<const char *, 16> Args(ArgList); diff --git a/clang/lib/Frontend/Rewrite/FrontendActions.cpp b/clang/lib/Frontend/Rewrite/FrontendActions.cpp index 5d2e1d7..6e1f949 100644 --- a/clang/lib/Frontend/Rewrite/FrontendActions.cpp +++ b/clang/lib/Frontend/Rewrite/FrontendActions.cpp @@ -247,7 +247,6 @@ public: Instance.setInvocation( std::make_shared<CompilerInvocation>(CI.getInvocation())); Instance.createDiagnostics( - CI.getVirtualFileSystem(), new ForwardingDiagnosticConsumer(CI.getDiagnosticClient()), /*ShouldOwnClient=*/true); Instance.getFrontendOpts().DisableFree = false; diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index 5dc67f6..94f0156 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -15,7 +15,6 @@ #include "IncrementalExecutor.h" #include "IncrementalParser.h" #include "InterpreterUtils.h" -#include "llvm/Support/VirtualFileSystem.h" #ifdef __EMSCRIPTEN__ #include "Wasm.h" #endif // __EMSCRIPTEN__ @@ -107,7 +106,7 @@ CreateCI(const llvm::opt::ArgStringList &Argv) { CompilerInvocation::GetResourcesPath(Argv[0], nullptr); // Create the actual diagnostics engine. - Clang->createDiagnostics(*llvm::vfs::getRealFileSystem()); + Clang->createDiagnostics(); if (!Clang->hasDiagnostics()) return llvm::createStringError(llvm::errc::not_supported, "Initialization failed. " diff --git a/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp b/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp index 168c73d..ae11fbb 100644 --- a/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp +++ b/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp @@ -78,7 +78,6 @@ void ModelInjector::onBodySynthesis(const NamedDecl *D) { CompilerInstance Instance(CI.getPCHContainerOperations()); Instance.setInvocation(std::move(Invocation)); Instance.createDiagnostics( - CI.getVirtualFileSystem(), new ForwardingDiagnosticConsumer(CI.getDiagnosticClient()), /*ShouldOwnClient=*/true); diff --git a/clang/lib/Testing/TestAST.cpp b/clang/lib/Testing/TestAST.cpp index f7348aa..fe8b938 100644 --- a/clang/lib/Testing/TestAST.cpp +++ b/clang/lib/Testing/TestAST.cpp @@ -55,7 +55,7 @@ public: // Provides "empty" ASTContext etc if we fail before parsing gets started. void createMissingComponents(CompilerInstance &Clang) { if (!Clang.hasDiagnostics()) - Clang.createDiagnostics(*llvm::vfs::getRealFileSystem()); + Clang.createDiagnostics(); if (!Clang.hasFileManager()) Clang.createFileManager(); if (!Clang.hasSourceManager()) @@ -82,24 +82,9 @@ TestAST::TestAST(const TestInputs &In) { auto RecoverFromEarlyExit = llvm::make_scope_exit([&] { createMissingComponents(*Clang); }); - std::string Filename = In.FileName; - if (Filename.empty()) - Filename = getFilenameForTesting(In.Language).str(); - - // Set up a VFS with only the virtual file visible. - auto VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); - if (auto Err = VFS->setCurrentWorkingDirectory(In.WorkingDir)) - ADD_FAILURE() << "Failed to setWD: " << Err.message(); - VFS->addFile(Filename, /*ModificationTime=*/0, - llvm::MemoryBuffer::getMemBufferCopy(In.Code, Filename)); - for (const auto &Extra : In.ExtraFiles) - VFS->addFile( - Extra.getKey(), /*ModificationTime=*/0, - llvm::MemoryBuffer::getMemBufferCopy(Extra.getValue(), Extra.getKey())); - // Extra error conditions are reported through diagnostics, set that up first. bool ErrorOK = In.ErrorOK || llvm::StringRef(In.Code).contains("error-ok"); - Clang->createDiagnostics(*VFS, new StoreDiagnostics(Diagnostics, !ErrorOK)); + Clang->createDiagnostics(new StoreDiagnostics(Diagnostics, !ErrorOK)); // Parse cc1 argv, (typically [-std=c++20 input.cc]) into CompilerInvocation. std::vector<const char *> Argv; @@ -108,6 +93,9 @@ TestAST::TestAST(const TestInputs &In) { Argv.push_back(S.c_str()); for (const auto &S : In.ExtraArgs) Argv.push_back(S.c_str()); + std::string Filename = In.FileName; + if (Filename.empty()) + Filename = getFilenameForTesting(In.Language).str(); Argv.push_back(Filename.c_str()); Clang->setInvocation(std::make_unique<CompilerInvocation>()); if (!CompilerInvocation::CreateFromArgs(Clang->getInvocation(), Argv, @@ -117,6 +105,16 @@ TestAST::TestAST(const TestInputs &In) { } assert(!Clang->getInvocation().getFrontendOpts().DisableFree); + // Set up a VFS with only the virtual file visible. + auto VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); + if (auto Err = VFS->setCurrentWorkingDirectory(In.WorkingDir)) + ADD_FAILURE() << "Failed to setWD: " << Err.message(); + VFS->addFile(Filename, /*ModificationTime=*/0, + llvm::MemoryBuffer::getMemBufferCopy(In.Code, Filename)); + for (const auto &Extra : In.ExtraFiles) + VFS->addFile( + Extra.getKey(), /*ModificationTime=*/0, + llvm::MemoryBuffer::getMemBufferCopy(Extra.getValue(), Extra.getKey())); Clang->createFileManager(VFS); // Running the FrontendAction creates the other components: SourceManager, diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp index 5a648df..fd1b7af 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -322,8 +322,7 @@ public: // Create the compiler's actual diagnostics engine. sanitizeDiagOpts(ScanInstance.getDiagnosticOpts()); - ScanInstance.createDiagnostics(DriverFileMgr->getVirtualFileSystem(), - DiagConsumer, /*ShouldOwnClient=*/false); + ScanInstance.createDiagnostics(DiagConsumer, /*ShouldOwnClient=*/false); if (!ScanInstance.hasDiagnostics()) return false; @@ -651,7 +650,7 @@ bool DependencyScanningWorker::computeDependencies( auto DiagOpts = CreateAndPopulateDiagOpts(FinalCCommandLine); sanitizeDiagOpts(*DiagOpts); IntrusiveRefCntPtr<DiagnosticsEngine> Diags = - CompilerInstance::createDiagnostics(*FinalFS, DiagOpts.release(), &DC, + CompilerInstance::createDiagnostics(DiagOpts.release(), &DC, /*ShouldOwnClient=*/false); // Although `Diagnostics` are used only for command-line parsing, the diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp index 88b7349..ffacf9c 100644 --- a/clang/lib/Tooling/Tooling.cpp +++ b/clang/lib/Tooling/Tooling.cpp @@ -387,8 +387,7 @@ bool ToolInvocation::run() { TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), DiagOpts); IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics = CompilerInstance::createDiagnostics( - Files->getVirtualFileSystem(), &*DiagOpts, - DiagConsumer ? DiagConsumer : &DiagnosticPrinter, false); + &*DiagOpts, DiagConsumer ? DiagConsumer : &DiagnosticPrinter, false); // Although `Diagnostics` are used only for command-line parsing, the custom // `DiagConsumer` might expect a `SourceManager` to be present. SourceManager SrcMgr(*Diagnostics, *Files); @@ -457,8 +456,7 @@ bool FrontendActionFactory::runInvocation( std::unique_ptr<FrontendAction> ScopedToolAction(create()); // Create the compiler's actual diagnostics engine. - Compiler.createDiagnostics(Files->getVirtualFileSystem(), DiagConsumer, - /*ShouldOwnClient=*/false); + Compiler.createDiagnostics(DiagConsumer, /*ShouldOwnClient=*/false); if (!Compiler.hasDiagnostics()) return false; @@ -654,8 +652,7 @@ public: DiagnosticConsumer *DiagConsumer) override { std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromCompilerInvocation( Invocation, std::move(PCHContainerOps), - CompilerInstance::createDiagnostics(Files->getVirtualFileSystem(), - &Invocation->getDiagnosticOpts(), + CompilerInstance::createDiagnostics(&Invocation->getDiagnosticOpts(), DiagConsumer, /*ShouldOwnClient=*/false), Files); |