Skip to content

Commit a1153cd

Browse files
committed
Revert "[NFC] Explicitly pass a VFS when creating DiagnosticsEngine (#115852)"
Reverted for causing: #117145 This reverts commit bdd10d9.
1 parent 0b06301 commit a1153cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+134
-192
lines changed

clang-tools-extra/clang-include-fixer/IncludeFixer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ bool IncludeFixerActionFactory::runInvocation(
9595

9696
// Create the compiler's actual diagnostics engine. We want to drop all
9797
// diagnostics here.
98-
Compiler.createDiagnostics(Files->getVirtualFileSystem(),
99-
new clang::IgnoringDiagConsumer,
98+
Compiler.createDiagnostics(new clang::IgnoringDiagConsumer,
10099
/*ShouldOwnClient=*/true);
101100
Compiler.createSourceManager(*Files);
102101

clang-tools-extra/clangd/Compiler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
110110
CIOpts.VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory);
111111
CIOpts.CC1Args = CC1Args;
112112
CIOpts.RecoverOnError = true;
113-
CIOpts.Diags = CompilerInstance::createDiagnostics(
114-
*CIOpts.VFS, new DiagnosticOptions, &D, false);
113+
CIOpts.Diags =
114+
CompilerInstance::createDiagnostics(new DiagnosticOptions, &D, false);
115115
CIOpts.ProbePrecompiled = false;
116116
std::unique_ptr<CompilerInvocation> CI = createInvocation(ArgStrs, CIOpts);
117117
if (!CI)
@@ -148,7 +148,7 @@ prepareCompilerInstance(std::unique_ptr<clang::CompilerInvocation> CI,
148148
auto Clang = std::make_unique<CompilerInstance>(
149149
std::make_shared<PCHContainerOperations>());
150150
Clang->setInvocation(std::move(CI));
151-
Clang->createDiagnostics(*VFS, &DiagsClient, false);
151+
Clang->createDiagnostics(&DiagsClient, false);
152152

153153
if (auto VFSWithRemapping = createVFSFromCompilerInvocation(
154154
Clang->getInvocation(), Clang->getDiagnostics(), VFS))

clang-tools-extra/clangd/ModulesBuilder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ bool IsModuleFileUpToDate(PathRef ModuleFilePath,
188188

189189
clang::clangd::IgnoreDiagnostics IgnoreDiags;
190190
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
191-
CompilerInstance::createDiagnostics(*VFS, new DiagnosticOptions,
192-
&IgnoreDiags,
191+
CompilerInstance::createDiagnostics(new DiagnosticOptions, &IgnoreDiags,
193192
/*ShouldOwnClient=*/false);
194193

195194
LangOptions LangOpts;

clang-tools-extra/clangd/Preamble.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,8 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
613613
for (const auto &L : ASTListeners)
614614
L->sawDiagnostic(D, Diag);
615615
});
616-
auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory);
617616
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> PreambleDiagsEngine =
618-
CompilerInstance::createDiagnostics(*VFS, &CI.getDiagnosticOpts(),
617+
CompilerInstance::createDiagnostics(&CI.getDiagnosticOpts(),
619618
&PreambleDiagnostics,
620619
/*ShouldOwnClient=*/false);
621620
const Config &Cfg = Config::current();
@@ -652,6 +651,7 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
652651
for (const auto &L : ASTListeners)
653652
L->beforeExecute(CI);
654653
});
654+
auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory);
655655
llvm::SmallString<32> AbsFileName(FileName);
656656
VFS->makeAbsolute(AbsFileName);
657657
auto StatCache = std::make_shared<PreambleFileStatusCache>(AbsFileName);

clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -609,24 +609,23 @@ TEST_F(PragmaIncludeTest, ExportInUnnamedBuffer) {
609609
)cpp";
610610
Inputs.ExtraFiles["foo.h"] = "";
611611

612-
// Create unnamed memory buffers for all the files.
613-
auto VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
614-
VFS->addFile(Filename, /*ModificationTime=*/0,
615-
llvm::MemoryBuffer::getMemBufferCopy(Code, /*BufferName=*/""));
616-
for (const auto &Extra : Inputs.ExtraFiles)
617-
VFS->addFile(Extra.getKey(), /*ModificationTime=*/0,
618-
llvm::MemoryBuffer::getMemBufferCopy(Extra.getValue(),
619-
/*BufferName=*/""));
620-
621612
auto Clang = std::make_unique<CompilerInstance>(
622613
std::make_shared<PCHContainerOperations>());
623-
Clang->createDiagnostics(*VFS);
614+
Clang->createDiagnostics();
624615

625616
Clang->setInvocation(std::make_unique<CompilerInvocation>());
626617
ASSERT_TRUE(CompilerInvocation::CreateFromArgs(
627618
Clang->getInvocation(), {Filename.data()}, Clang->getDiagnostics(),
628619
"clang"));
629620

621+
// Create unnamed memory buffers for all the files.
622+
auto VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
623+
VFS->addFile(Filename, /*ModificationTime=*/0,
624+
llvm::MemoryBuffer::getMemBufferCopy(Code, /*BufferName=*/""));
625+
for (const auto &Extra : Inputs.ExtraFiles)
626+
VFS->addFile(Extra.getKey(), /*ModificationTime=*/0,
627+
llvm::MemoryBuffer::getMemBufferCopy(Extra.getValue(),
628+
/*BufferName=*/""));
630629
auto *FM = Clang->createFileManager(VFS);
631630
ASSERT_TRUE(Clang->ExecuteAction(*Inputs.MakeAction()));
632631
EXPECT_THAT(

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -675,17 +675,13 @@ class CompilerInstance : public ModuleLoader {
675675
/// Note that this routine also replaces the diagnostic client,
676676
/// allocating one if one is not provided.
677677
///
678-
/// \param VFS is used for any IO needed when creating DiagnosticsEngine. It
679-
/// doesn't replace VFS in the CompilerInstance (if any).
680-
///
681678
/// \param Client If non-NULL, a diagnostic client that will be
682679
/// attached to (and, then, owned by) the DiagnosticsEngine inside this AST
683680
/// unit.
684681
///
685682
/// \param ShouldOwnClient If Client is non-NULL, specifies whether
686683
/// the diagnostic object should take ownership of the client.
687-
void createDiagnostics(llvm::vfs::FileSystem &VFS,
688-
DiagnosticConsumer *Client = nullptr,
684+
void createDiagnostics(DiagnosticConsumer *Client = nullptr,
689685
bool ShouldOwnClient = true);
690686

691687
/// Create a DiagnosticsEngine object with a the TextDiagnosticPrinter.
@@ -706,11 +702,10 @@ class CompilerInstance : public ModuleLoader {
706702
/// used by some diagnostics printers (for logging purposes only).
707703
///
708704
/// \return The new object on success, or null on failure.
709-
static IntrusiveRefCntPtr<DiagnosticsEngine>
710-
createDiagnostics(llvm::vfs::FileSystem &VFS, DiagnosticOptions *Opts,
711-
DiagnosticConsumer *Client = nullptr,
712-
bool ShouldOwnClient = true,
713-
const CodeGenOptions *CodeGenOpts = nullptr);
705+
static IntrusiveRefCntPtr<DiagnosticsEngine> createDiagnostics(
706+
DiagnosticOptions *Opts, DiagnosticConsumer *Client = nullptr,
707+
bool ShouldOwnClient = true, const CodeGenOptions *CodeGenOpts = nullptr,
708+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr);
714709

715710
/// Create the file manager and replace any existing one with it.
716711
///

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -332,20 +332,23 @@ static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts,
332332
}
333333
}
334334

335-
void CompilerInstance::createDiagnostics(llvm::vfs::FileSystem &VFS,
336-
DiagnosticConsumer *Client,
335+
void CompilerInstance::createDiagnostics(DiagnosticConsumer *Client,
337336
bool ShouldOwnClient) {
338-
Diagnostics = createDiagnostics(VFS, &getDiagnosticOpts(), Client,
339-
ShouldOwnClient, &getCodeGenOpts());
337+
Diagnostics = createDiagnostics(
338+
&getDiagnosticOpts(), Client, ShouldOwnClient, &getCodeGenOpts(),
339+
FileMgr ? FileMgr->getVirtualFileSystemPtr() : nullptr);
340340
}
341341

342342
IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(
343-
llvm::vfs::FileSystem &VFS, DiagnosticOptions *Opts,
344-
DiagnosticConsumer *Client, bool ShouldOwnClient,
345-
const CodeGenOptions *CodeGenOpts) {
343+
DiagnosticOptions *Opts, DiagnosticConsumer *Client, bool ShouldOwnClient,
344+
const CodeGenOptions *CodeGenOpts,
345+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
346346
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
347-
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
348-
new DiagnosticsEngine(DiagID, Opts));
347+
IntrusiveRefCntPtr<DiagnosticsEngine>
348+
Diags(new DiagnosticsEngine(DiagID, Opts));
349+
350+
if (!VFS)
351+
VFS = llvm::vfs::getRealFileSystem();
349352

350353
// Create the diagnostic client for reporting errors or for
351354
// implementing -verify.
@@ -369,7 +372,7 @@ IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(
369372
Opts->DiagnosticSerializationFile);
370373

371374
// Configure our handling of diagnostics.
372-
ProcessWarningOptions(*Diags, *Opts, VFS);
375+
ProcessWarningOptions(*Diags, *Opts, *VFS);
373376

374377
return Diags;
375378
}
@@ -1237,10 +1240,9 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc,
12371240
auto &Inv = *Invocation;
12381241
Instance.setInvocation(std::move(Invocation));
12391242

1240-
Instance.createDiagnostics(
1241-
ImportingInstance.getVirtualFileSystem(),
1242-
new ForwardingDiagnosticConsumer(ImportingInstance.getDiagnosticClient()),
1243-
/*ShouldOwnClient=*/true);
1243+
Instance.createDiagnostics(new ForwardingDiagnosticConsumer(
1244+
ImportingInstance.getDiagnosticClient()),
1245+
/*ShouldOwnClient=*/true);
12441246

12451247
if (llvm::is_contained(DiagOpts.SystemHeaderWarningsModules, ModuleName))
12461248
Instance.getDiagnostics().setSuppressSystemWarnings(false);

clang/lib/Frontend/CreateInvocationFromCommandLine.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "llvm/ADT/STLExtras.h"
2323
#include "llvm/ADT/StringRef.h"
2424
#include "llvm/Option/ArgList.h"
25-
#include "llvm/Support/VirtualFileSystem.h"
2625
#include "llvm/TargetParser/Host.h"
2726
using namespace clang;
2827
using namespace llvm::opt;
@@ -33,9 +32,7 @@ clang::createInvocation(ArrayRef<const char *> ArgList,
3332
assert(!ArgList.empty());
3433
auto Diags = Opts.Diags
3534
? std::move(Opts.Diags)
36-
: CompilerInstance::createDiagnostics(
37-
Opts.VFS ? *Opts.VFS : *llvm::vfs::getRealFileSystem(),
38-
new DiagnosticOptions);
35+
: CompilerInstance::createDiagnostics(new DiagnosticOptions);
3936

4037
SmallVector<const char *, 16> Args(ArgList);
4138

clang/lib/Frontend/Rewrite/FrontendActions.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ class RewriteIncludesAction::RewriteImportsListener : public ASTReaderListener {
247247
Instance.setInvocation(
248248
std::make_shared<CompilerInvocation>(CI.getInvocation()));
249249
Instance.createDiagnostics(
250-
CI.getVirtualFileSystem(),
251250
new ForwardingDiagnosticConsumer(CI.getDiagnosticClient()),
252251
/*ShouldOwnClient=*/true);
253252
Instance.getFrontendOpts().DisableFree = false;

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "IncrementalExecutor.h"
1616
#include "IncrementalParser.h"
1717
#include "InterpreterUtils.h"
18-
#include "llvm/Support/VirtualFileSystem.h"
1918
#ifdef __EMSCRIPTEN__
2019
#include "Wasm.h"
2120
#endif // __EMSCRIPTEN__
@@ -107,7 +106,7 @@ CreateCI(const llvm::opt::ArgStringList &Argv) {
107106
CompilerInvocation::GetResourcesPath(Argv[0], nullptr);
108107

109108
// Create the actual diagnostics engine.
110-
Clang->createDiagnostics(*llvm::vfs::getRealFileSystem());
109+
Clang->createDiagnostics();
111110
if (!Clang->hasDiagnostics())
112111
return llvm::createStringError(llvm::errc::not_supported,
113112
"Initialization failed. "

0 commit comments

Comments
 (0)