Reapply "[clang] Remove intrusive reference count from DiagnosticOptions
(#139584)"
This reverts commit e2a885537f11f8d9ced1c80c2c90069ab5adeb1d. Build failures were fixed right away and reverting the original commit without the fixes breaks the build again.
This commit is contained in:
parent
45f6036533
commit
13e1a2cb22
@ -96,9 +96,9 @@ int main(int argc, char **argv) {
|
||||
cl::SetVersionPrinter(printVersion);
|
||||
cl::ParseCommandLineOptions(argc, argv);
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diagnostics(
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts.get());
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts);
|
||||
|
||||
// Determine a formatting style from options.
|
||||
auto FormatStyleOrError = format::getStyle(FormatStyleOpt, FormatStyleConfig,
|
||||
|
@ -126,10 +126,10 @@ int main(int argc, const char **argv) {
|
||||
if (int Result = Tool.run(Factory.get()))
|
||||
return Result;
|
||||
LangOptions DefaultLangOptions;
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
clang::TextDiagnosticPrinter DiagnosticPrinter(errs(), &*DiagOpts);
|
||||
DiagnosticOptions DiagOpts;
|
||||
clang::TextDiagnosticPrinter DiagnosticPrinter(errs(), DiagOpts);
|
||||
DiagnosticsEngine Diagnostics(
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts,
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts,
|
||||
&DiagnosticPrinter, false);
|
||||
auto &FileMgr = Tool.getFiles();
|
||||
SourceManager Sources(Diagnostics, FileMgr);
|
||||
|
@ -455,9 +455,9 @@ int includeFixerMain(int argc, const char **argv) {
|
||||
}
|
||||
|
||||
// Set up a new source manager for applying the resulting replacements.
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions);
|
||||
DiagnosticsEngine Diagnostics(new DiagnosticIDs, &*DiagOpts);
|
||||
TextDiagnosticPrinter DiagnosticPrinter(outs(), &*DiagOpts);
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diagnostics(new DiagnosticIDs, DiagOpts);
|
||||
TextDiagnosticPrinter DiagnosticPrinter(outs(), DiagOpts);
|
||||
SourceManager SM(Diagnostics, tool.getFiles());
|
||||
Diagnostics.setClient(&DiagnosticPrinter, false);
|
||||
|
||||
|
@ -176,10 +176,10 @@ int main(int argc, const char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
|
||||
clang::TextDiagnosticPrinter DiagnosticPrinter(errs(), &*DiagOpts);
|
||||
DiagnosticOptions DiagOpts;
|
||||
clang::TextDiagnosticPrinter DiagnosticPrinter(errs(), DiagOpts);
|
||||
DiagnosticsEngine Diagnostics(
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts,
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts,
|
||||
&DiagnosticPrinter, false);
|
||||
auto &FileMgr = Tool.getFiles();
|
||||
SourceManager SM(Diagnostics, FileMgr);
|
||||
|
@ -172,7 +172,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
|
||||
clang::SourceRange R = BI->second.getSourceRange();
|
||||
if (R.isValid()) {
|
||||
TextDiagnostic TD(OS, AST->getASTContext().getLangOpts(),
|
||||
&AST->getDiagnostics().getDiagnosticOptions());
|
||||
AST->getDiagnostics().getDiagnosticOptions());
|
||||
TD.emitDiagnostic(
|
||||
FullSourceLoc(R.getBegin(), AST->getSourceManager()),
|
||||
DiagnosticsEngine::Note, "\"" + BI->first + "\" binds here",
|
||||
|
@ -72,10 +72,10 @@ int main(int argc, const char **argv) {
|
||||
|
||||
int ExitCode = Tool.run(Factory.get());
|
||||
LangOptions DefaultLangOptions;
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
|
||||
TextDiagnosticPrinter DiagnosticPrinter(errs(), &*DiagOpts);
|
||||
DiagnosticOptions DiagOpts;
|
||||
TextDiagnosticPrinter DiagnosticPrinter(errs(), DiagOpts);
|
||||
DiagnosticsEngine Diagnostics(
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts,
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts,
|
||||
&DiagnosticPrinter, false);
|
||||
|
||||
auto &FileMgr = Tool.getFiles();
|
||||
|
@ -97,15 +97,14 @@ public:
|
||||
ErrorReporter(ClangTidyContext &Context, FixBehaviour ApplyFixes,
|
||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS)
|
||||
: Files(FileSystemOptions(), std::move(BaseFS)),
|
||||
DiagOpts(new DiagnosticOptions()),
|
||||
DiagPrinter(new TextDiagnosticPrinter(llvm::outs(), &*DiagOpts)),
|
||||
Diags(IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), &*DiagOpts,
|
||||
DiagPrinter(new TextDiagnosticPrinter(llvm::outs(), DiagOpts)),
|
||||
Diags(IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), DiagOpts,
|
||||
DiagPrinter),
|
||||
SourceMgr(Diags, Files), Context(Context), ApplyFixes(ApplyFixes) {
|
||||
DiagOpts->ShowColors = Context.getOptions().UseColor.value_or(
|
||||
DiagOpts.ShowColors = Context.getOptions().UseColor.value_or(
|
||||
llvm::sys::Process::StandardOutHasColors());
|
||||
DiagPrinter->BeginSourceFile(LangOpts);
|
||||
if (DiagOpts->ShowColors && !llvm::sys::Process::StandardOutIsDisplayed()) {
|
||||
if (DiagOpts.ShowColors && !llvm::sys::Process::StandardOutIsDisplayed()) {
|
||||
llvm::sys::Process::UseANSIEscapeCodes(true);
|
||||
}
|
||||
}
|
||||
@ -308,7 +307,7 @@ private:
|
||||
|
||||
FileManager Files;
|
||||
LangOptions LangOpts; // FIXME: use langopts from each original file
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticConsumer *DiagPrinter;
|
||||
DiagnosticsEngine Diags;
|
||||
SourceManager SourceMgr;
|
||||
@ -516,10 +515,10 @@ getCheckOptions(const ClangTidyOptions &Options,
|
||||
Options),
|
||||
AllowEnablingAnalyzerAlphaCheckers);
|
||||
ClangTidyDiagnosticConsumer DiagConsumer(Context);
|
||||
DiagnosticsEngine DE(llvm::makeIntrusiveRefCnt<DiagnosticIDs>(),
|
||||
llvm::makeIntrusiveRefCnt<DiagnosticOptions>(),
|
||||
auto DiagOpts = std::make_unique<DiagnosticOptions>();
|
||||
DiagnosticsEngine DE(llvm::makeIntrusiveRefCnt<DiagnosticIDs>(), *DiagOpts,
|
||||
&DiagConsumer, /*ShouldOwnClient=*/false);
|
||||
Context.setDiagnosticsEngine(&DE);
|
||||
Context.setDiagnosticsEngine(std::move(DiagOpts), &DE);
|
||||
ClangTidyASTConsumerFactory Factory(Context);
|
||||
return Factory.getCheckOptions();
|
||||
}
|
||||
@ -558,9 +557,10 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
|
||||
Context.setProfileStoragePrefix(StoreCheckProfile);
|
||||
|
||||
ClangTidyDiagnosticConsumer DiagConsumer(Context, nullptr, true, ApplyAnyFix);
|
||||
DiagnosticsEngine DE(new DiagnosticIDs(), new DiagnosticOptions(),
|
||||
&DiagConsumer, /*ShouldOwnClient=*/false);
|
||||
Context.setDiagnosticsEngine(&DE);
|
||||
auto DiagOpts = std::make_unique<DiagnosticOptions>();
|
||||
DiagnosticsEngine DE(new DiagnosticIDs(), *DiagOpts, &DiagConsumer,
|
||||
/*ShouldOwnClient=*/false);
|
||||
Context.setDiagnosticsEngine(std::move(DiagOpts), &DE);
|
||||
Tool.setDiagnosticConsumer(&DiagConsumer);
|
||||
|
||||
class ActionFactory : public FrontendActionFactory {
|
||||
|
@ -49,7 +49,7 @@ namespace {
|
||||
class ClangTidyDiagnosticRenderer : public DiagnosticRenderer {
|
||||
public:
|
||||
ClangTidyDiagnosticRenderer(const LangOptions &LangOpts,
|
||||
DiagnosticOptions *DiagOpts,
|
||||
DiagnosticOptions &DiagOpts,
|
||||
ClangTidyError &Error)
|
||||
: DiagnosticRenderer(LangOpts, DiagOpts), Error(Error) {}
|
||||
|
||||
@ -429,7 +429,7 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
|
||||
forwardDiagnostic(Info);
|
||||
} else {
|
||||
ClangTidyDiagnosticRenderer Converter(
|
||||
Context.getLangOpts(), &Context.DiagEngine->getDiagnosticOptions(),
|
||||
Context.getLangOpts(), Context.DiagEngine->getDiagnosticOptions(),
|
||||
Errors.back());
|
||||
SmallString<100> Message;
|
||||
Info.FormatDiagnostic(Message);
|
||||
|
@ -75,7 +75,9 @@ public:
|
||||
/// Sets the DiagnosticsEngine that diag() will emit diagnostics to.
|
||||
// FIXME: this is required initialization, and should be a constructor param.
|
||||
// Fix the context -> diag engine -> consumer -> context initialization cycle.
|
||||
void setDiagnosticsEngine(DiagnosticsEngine *DiagEngine) {
|
||||
void setDiagnosticsEngine(std::unique_ptr<DiagnosticOptions> DiagOpts,
|
||||
DiagnosticsEngine *DiagEngine) {
|
||||
this->DiagOpts = std::move(DiagOpts);
|
||||
this->DiagEngine = DiagEngine;
|
||||
}
|
||||
|
||||
@ -231,6 +233,7 @@ private:
|
||||
// Writes to Stats.
|
||||
friend class ClangTidyDiagnosticConsumer;
|
||||
|
||||
std::unique_ptr<DiagnosticOptions> DiagOpts = nullptr;
|
||||
DiagnosticsEngine *DiagEngine = nullptr;
|
||||
std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
|
||||
|
||||
|
@ -71,7 +71,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
|
||||
InMemoryFs(new llvm::vfs::InMemoryFileSystem),
|
||||
Sources(Compiler.getSourceManager()),
|
||||
// Forward the new diagnostics to the original DiagnosticConsumer.
|
||||
Diags(new DiagnosticIDs, new DiagnosticOptions,
|
||||
Diags(new DiagnosticIDs, DiagOpts,
|
||||
new ForwardingDiagnosticConsumer(Compiler.getDiagnosticClient())),
|
||||
LangOpts(Compiler.getLangOpts()), HSOpts(Compiler.getHeaderSearchOpts()) {
|
||||
// Add a FileSystem containing the extra files needed in place of modular
|
||||
|
@ -128,6 +128,7 @@ private:
|
||||
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFs;
|
||||
|
||||
SourceManager &Sources;
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags;
|
||||
LangOptions LangOpts;
|
||||
HeaderSearchOptions HSOpts;
|
||||
|
@ -110,8 +110,9 @@ buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
|
||||
CIOpts.VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory);
|
||||
CIOpts.CC1Args = CC1Args;
|
||||
CIOpts.RecoverOnError = true;
|
||||
CIOpts.Diags = CompilerInstance::createDiagnostics(
|
||||
*CIOpts.VFS, new DiagnosticOptions, &D, false);
|
||||
DiagnosticOptions DiagOpts;
|
||||
CIOpts.Diags =
|
||||
CompilerInstance::createDiagnostics(*CIOpts.VFS, DiagOpts, &D, false);
|
||||
CIOpts.ProbePrecompiled = false;
|
||||
std::unique_ptr<CompilerInvocation> CI = createInvocation(ArgStrs, CIOpts);
|
||||
if (!CI)
|
||||
|
@ -187,9 +187,9 @@ bool IsModuleFileUpToDate(PathRef ModuleFilePath,
|
||||
HSOpts.ValidateASTInputFilesContent = true;
|
||||
|
||||
clang::clangd::IgnoreDiagnostics IgnoreDiags;
|
||||
DiagnosticOptions DiagOpts;
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
|
||||
CompilerInstance::createDiagnostics(*VFS, new DiagnosticOptions,
|
||||
&IgnoreDiags,
|
||||
CompilerInstance::createDiagnostics(*VFS, DiagOpts, &IgnoreDiags,
|
||||
/*ShouldOwnClient=*/false);
|
||||
|
||||
LangOptions LangOpts;
|
||||
|
@ -556,7 +556,8 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
|
||||
*AllCTFactories, Cfg.Diagnostics.ClangTidy.FastCheckFilter);
|
||||
CTContext.emplace(std::make_unique<tidy::DefaultOptionsProvider>(
|
||||
tidy::ClangTidyGlobalOptions(), ClangTidyOpts));
|
||||
CTContext->setDiagnosticsEngine(&Clang->getDiagnostics());
|
||||
// The lifetime of DiagnosticOptions is managed by \c Clang.
|
||||
CTContext->setDiagnosticsEngine(nullptr, &Clang->getDiagnostics());
|
||||
CTContext->setASTContext(&Clang->getASTContext());
|
||||
CTContext->setCurrentFile(Filename);
|
||||
CTContext->setSelfContainedDiags(true);
|
||||
|
@ -615,7 +615,7 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
|
||||
});
|
||||
auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory);
|
||||
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> PreambleDiagsEngine =
|
||||
CompilerInstance::createDiagnostics(*VFS, &CI.getDiagnosticOpts(),
|
||||
CompilerInstance::createDiagnostics(*VFS, CI.getDiagnosticOpts(),
|
||||
&PreambleDiagnostics,
|
||||
/*ShouldOwnClient=*/false);
|
||||
const Config &Cfg = Config::current();
|
||||
|
@ -253,7 +253,8 @@ namespace {
|
||||
bool isValidTarget(llvm::StringRef Triple) {
|
||||
std::shared_ptr<TargetOptions> TargetOpts(new TargetOptions);
|
||||
TargetOpts->Triple = Triple.str();
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs, new DiagnosticOptions,
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs, DiagOpts,
|
||||
new IgnoringDiagConsumer);
|
||||
llvm::IntrusiveRefCntPtr<TargetInfo> Target =
|
||||
TargetInfo::CreateTargetInfo(Diags, *TargetOpts);
|
||||
|
@ -298,7 +298,8 @@ TEST_F(ConfigCompileTests, DiagnosticSuppression) {
|
||||
"unreachable-code", "unused-variable",
|
||||
"typecheck_bool_condition",
|
||||
"unexpected_friend", "warn_alloca"));
|
||||
clang::DiagnosticsEngine DiagEngine(new DiagnosticIDs, nullptr,
|
||||
clang::DiagnosticOptions DiagOpts;
|
||||
clang::DiagnosticsEngine DiagEngine(new DiagnosticIDs, DiagOpts,
|
||||
new clang::IgnoringDiagConsumer);
|
||||
|
||||
using Diag = clang::Diagnostic;
|
||||
|
@ -44,7 +44,8 @@ TEST(FileEdits, AbsolutePath) {
|
||||
for (const auto *Path : RelPaths)
|
||||
MemFS->addFile(Path, 0, llvm::MemoryBuffer::getMemBuffer("", Path));
|
||||
FileManager FM(FileSystemOptions(), MemFS);
|
||||
DiagnosticsEngine DE(new DiagnosticIDs, new DiagnosticOptions);
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine DE(new DiagnosticIDs, DiagOpts);
|
||||
SourceManager SM(DE, FM);
|
||||
|
||||
for (const auto *Path : RelPaths) {
|
||||
|
@ -618,8 +618,8 @@ TEST_F(PragmaIncludeTest, ExportInUnnamedBuffer) {
|
||||
llvm::MemoryBuffer::getMemBufferCopy(Extra.getValue(),
|
||||
/*BufferName=*/""));
|
||||
|
||||
auto DiagOpts = llvm::makeIntrusiveRefCnt<DiagnosticOptions>();
|
||||
auto Diags = CompilerInstance::createDiagnostics(*VFS, DiagOpts.get());
|
||||
DiagnosticOptions DiagOpts;
|
||||
auto Diags = CompilerInstance::createDiagnostics(*VFS, DiagOpts);
|
||||
auto Invocation = std::make_unique<CompilerInvocation>();
|
||||
ASSERT_TRUE(CompilerInvocation::CreateFromArgs(*Invocation, {Filename.data()},
|
||||
*Diags, "clang"));
|
||||
|
@ -85,9 +85,9 @@ std::vector<Decl::Kind> testWalk(llvm::StringRef TargetCode,
|
||||
// For each difference, show the target point in context, like a diagnostic.
|
||||
std::string DiagBuf;
|
||||
llvm::raw_string_ostream DiagOS(DiagBuf);
|
||||
auto *DiagOpts = new DiagnosticOptions();
|
||||
DiagOpts->ShowLevel = 0;
|
||||
DiagOpts->ShowNoteIncludeStack = 0;
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagOpts.ShowLevel = 0;
|
||||
DiagOpts.ShowNoteIncludeStack = 0;
|
||||
TextDiagnostic Diag(DiagOS, AST.context().getLangOpts(), DiagOpts);
|
||||
auto DiagnosePoint = [&](llvm::StringRef Message, unsigned Offset) {
|
||||
Diag.emitDiagnostic(
|
||||
|
@ -48,10 +48,8 @@ ModularizeUtilities::ModularizeUtilities(std::vector<std::string> &InputPaths,
|
||||
MissingHeaderCount(0),
|
||||
// Init clang stuff needed for loading the module map and preprocessing.
|
||||
LangOpts(new LangOptions()), DiagIDs(new DiagnosticIDs()),
|
||||
DiagnosticOpts(new DiagnosticOptions()),
|
||||
DC(llvm::errs(), DiagnosticOpts.get()),
|
||||
Diagnostics(
|
||||
new DiagnosticsEngine(DiagIDs, DiagnosticOpts.get(), &DC, false)),
|
||||
DC(llvm::errs(), DiagnosticOpts),
|
||||
Diagnostics(new DiagnosticsEngine(DiagIDs, DiagnosticOpts, &DC, false)),
|
||||
TargetOpts(new ModuleMapTargetOptions()),
|
||||
Target(TargetInfo::CreateTargetInfo(*Diagnostics, *TargetOpts)),
|
||||
FileMgr(new FileManager(FileSystemOpts)),
|
||||
|
@ -198,7 +198,7 @@ public:
|
||||
/// Diagnostic IDs.
|
||||
const llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagIDs;
|
||||
/// Options controlling the diagnostic engine.
|
||||
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagnosticOpts;
|
||||
clang::DiagnosticOptions DiagnosticOpts;
|
||||
/// Diagnostic consumer.
|
||||
clang::TextDiagnosticPrinter DC;
|
||||
/// Diagnostic engine.
|
||||
|
@ -32,9 +32,9 @@ makeTUDiagnostics(const std::string &MainSourceFile, StringRef DiagnosticName,
|
||||
// Test to ensure diagnostics with no fixes, will be merged correctly
|
||||
// before applying.
|
||||
TEST(ApplyReplacementsTest, mergeDiagnosticsWithNoFixes) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diagnostics(
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts.get());
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts);
|
||||
FileManager Files((FileSystemOptions()));
|
||||
SourceManager SM(Diagnostics, Files);
|
||||
TUReplacements TURs;
|
||||
|
@ -317,9 +317,9 @@ TEST(CheckOptionsValidation, MissingOptions) {
|
||||
ClangTidyContext Context(std::make_unique<DefaultOptionsProvider>(
|
||||
ClangTidyGlobalOptions(), Options));
|
||||
ClangTidyDiagnosticConsumer DiagConsumer(Context);
|
||||
DiagnosticsEngine DE(new DiagnosticIDs(), new DiagnosticOptions,
|
||||
&DiagConsumer, false);
|
||||
Context.setDiagnosticsEngine(&DE);
|
||||
auto DiagOpts = std::make_unique<DiagnosticOptions>();
|
||||
DiagnosticsEngine DE(new DiagnosticIDs(), *DiagOpts, &DiagConsumer, false);
|
||||
Context.setDiagnosticsEngine(std::move(DiagOpts), &DE);
|
||||
TestCheck TestCheck(&Context);
|
||||
EXPECT_FALSE(TestCheck.getLocal("Opt"));
|
||||
EXPECT_EQ(TestCheck.getLocal("Opt", "Unknown"), "Unknown");
|
||||
@ -347,9 +347,9 @@ TEST(CheckOptionsValidation, ValidIntOptions) {
|
||||
ClangTidyContext Context(std::make_unique<DefaultOptionsProvider>(
|
||||
ClangTidyGlobalOptions(), Options));
|
||||
ClangTidyDiagnosticConsumer DiagConsumer(Context);
|
||||
DiagnosticsEngine DE(new DiagnosticIDs(), new DiagnosticOptions,
|
||||
&DiagConsumer, false);
|
||||
Context.setDiagnosticsEngine(&DE);
|
||||
auto DiagOpts = std::make_unique<DiagnosticOptions>();
|
||||
DiagnosticsEngine DE(new DiagnosticIDs(), *DiagOpts, &DiagConsumer, false);
|
||||
Context.setDiagnosticsEngine(std::move(DiagOpts), &DE);
|
||||
TestCheck TestCheck(&Context);
|
||||
|
||||
CHECK_VAL(TestCheck.getIntLocal("IntExpected"), 1);
|
||||
@ -409,9 +409,9 @@ TEST(ValidConfiguration, ValidEnumOptions) {
|
||||
ClangTidyContext Context(std::make_unique<DefaultOptionsProvider>(
|
||||
ClangTidyGlobalOptions(), Options));
|
||||
ClangTidyDiagnosticConsumer DiagConsumer(Context);
|
||||
DiagnosticsEngine DE(new DiagnosticIDs(), new DiagnosticOptions,
|
||||
&DiagConsumer, false);
|
||||
Context.setDiagnosticsEngine(&DE);
|
||||
auto DiagOpts = std::make_unique<DiagnosticOptions>();
|
||||
DiagnosticsEngine DE(new DiagnosticIDs(), *DiagOpts, &DiagConsumer, false);
|
||||
Context.setDiagnosticsEngine(std::move(DiagOpts), &DE);
|
||||
TestCheck TestCheck(&Context);
|
||||
|
||||
CHECK_VAL(TestCheck.getIntLocal<Colours>("Valid"), Colours::Red);
|
||||
|
@ -96,9 +96,9 @@ runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr,
|
||||
ClangTidyContext Context(std::make_unique<DefaultOptionsProvider>(
|
||||
ClangTidyGlobalOptions(), Options));
|
||||
ClangTidyDiagnosticConsumer DiagConsumer(Context);
|
||||
DiagnosticsEngine DE(new DiagnosticIDs(), new DiagnosticOptions,
|
||||
&DiagConsumer, false);
|
||||
Context.setDiagnosticsEngine(&DE);
|
||||
auto DiagOpts = std::make_unique<DiagnosticOptions>();
|
||||
DiagnosticsEngine DE(new DiagnosticIDs(), *DiagOpts, &DiagConsumer, false);
|
||||
Context.setDiagnosticsEngine(std::move(DiagOpts), &DE);
|
||||
|
||||
std::vector<std::string> Args(1, "clang-tidy");
|
||||
Args.push_back("-fsyntax-only");
|
||||
|
@ -330,7 +330,7 @@ private:
|
||||
unsigned ConstexprBacktraceLimit = 0;
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> Diags;
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
|
||||
DiagnosticOptions &DiagOpts;
|
||||
DiagnosticConsumer *Client = nullptr;
|
||||
std::unique_ptr<DiagnosticConsumer> Owner;
|
||||
SourceManager *SourceMgr = nullptr;
|
||||
@ -566,7 +566,7 @@ private:
|
||||
|
||||
public:
|
||||
explicit DiagnosticsEngine(IntrusiveRefCntPtr<DiagnosticIDs> Diags,
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
|
||||
DiagnosticOptions &DiagOpts,
|
||||
DiagnosticConsumer *client = nullptr,
|
||||
bool ShouldOwnClient = true);
|
||||
DiagnosticsEngine(const DiagnosticsEngine &) = delete;
|
||||
@ -582,7 +582,7 @@ public:
|
||||
}
|
||||
|
||||
/// Retrieve the diagnostic options.
|
||||
DiagnosticOptions &getDiagnosticOptions() const { return *DiagOpts; }
|
||||
DiagnosticOptions &getDiagnosticOptions() const { return DiagOpts; }
|
||||
|
||||
using diag_mapping_range = llvm::iterator_range<DiagState::const_iterator>;
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
#define LLVM_CLANG_BASIC_DIAGNOSTICOPTIONS_H
|
||||
|
||||
#include "clang/Basic/LLVM.h"
|
||||
#include "llvm/ADT/IntrusiveRefCntPtr.h"
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
@ -67,8 +66,7 @@ inline DiagnosticLevelMask operator&(DiagnosticLevelMask LHS,
|
||||
raw_ostream& operator<<(raw_ostream& Out, DiagnosticLevelMask M);
|
||||
|
||||
/// Options for controlling the compiler diagnostics engine.
|
||||
class DiagnosticOptions
|
||||
: public llvm::ThreadSafeRefCountedBase<DiagnosticOptions> {
|
||||
class DiagnosticOptions {
|
||||
friend bool ParseDiagnosticArgs(DiagnosticOptions &, llvm::opt::ArgList &,
|
||||
clang::DiagnosticsEngine *, bool);
|
||||
|
||||
|
@ -2041,6 +2041,7 @@ private:
|
||||
// as they are created in `createSourceManagerForFile` so that they can be
|
||||
// deleted in the reverse order as they are created.
|
||||
std::unique_ptr<FileManager> FileMgr;
|
||||
std::unique_ptr<DiagnosticOptions> DiagOpts;
|
||||
std::unique_ptr<DiagnosticsEngine> Diagnostics;
|
||||
std::unique_ptr<SourceManager> SourceMgr;
|
||||
};
|
||||
|
@ -107,6 +107,11 @@ public:
|
||||
|
||||
private:
|
||||
std::unique_ptr<LangOptions> LangOpts;
|
||||
// FIXME: The documentation on \c LoadFrom* member functions states that the
|
||||
// DiagnosticsEngine (and therefore DiagnosticOptions) must outlive the
|
||||
// returned ASTUnit. This is not the case. Enfore it by storing non-owning
|
||||
// pointers here.
|
||||
std::shared_ptr<DiagnosticOptions> DiagOpts;
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics;
|
||||
IntrusiveRefCntPtr<FileManager> FileMgr;
|
||||
IntrusiveRefCntPtr<SourceManager> SourceMgr;
|
||||
@ -674,6 +679,7 @@ public:
|
||||
/// Create a ASTUnit. Gets ownership of the passed CompilerInvocation.
|
||||
static std::unique_ptr<ASTUnit>
|
||||
create(std::shared_ptr<CompilerInvocation> CI,
|
||||
std::shared_ptr<DiagnosticOptions> DiagOpts,
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
|
||||
CaptureDiagsKind CaptureDiagnostics, bool UserFilesAreVolatile);
|
||||
|
||||
@ -700,7 +706,8 @@ public:
|
||||
/// \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, IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
|
||||
WhatToLoad ToLoad, std::shared_ptr<DiagnosticOptions> DiagOpts,
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
|
||||
const FileSystemOptions &FileSystemOpts,
|
||||
const HeaderSearchOptions &HSOpts, const LangOptions *LangOpts = nullptr,
|
||||
bool OnlyLocalDecls = false,
|
||||
@ -762,6 +769,7 @@ public:
|
||||
static ASTUnit *LoadFromCompilerInvocationAction(
|
||||
std::shared_ptr<CompilerInvocation> CI,
|
||||
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
|
||||
std::shared_ptr<DiagnosticOptions> DiagOpts,
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
|
||||
FrontendAction *Action = nullptr, ASTUnit *Unit = nullptr,
|
||||
bool Persistent = true, StringRef ResourceFilesPath = StringRef(),
|
||||
@ -789,6 +797,7 @@ public:
|
||||
static std::unique_ptr<ASTUnit> LoadFromCompilerInvocation(
|
||||
std::shared_ptr<CompilerInvocation> CI,
|
||||
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
|
||||
std::shared_ptr<DiagnosticOptions> DiagOpts,
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FileManager *FileMgr,
|
||||
bool OnlyLocalDecls = false,
|
||||
CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
|
||||
@ -837,6 +846,7 @@ public:
|
||||
static std::unique_ptr<ASTUnit> LoadFromCommandLine(
|
||||
const char **ArgBegin, const char **ArgEnd,
|
||||
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
|
||||
std::shared_ptr<DiagnosticOptions> DiagOpts,
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags, StringRef ResourceFilesPath,
|
||||
bool StorePreamblesInMemory = false,
|
||||
StringRef PreambleStoragePath = StringRef(), bool OnlyLocalDecls = false,
|
||||
|
@ -674,7 +674,7 @@ public:
|
||||
///
|
||||
/// \return The new object on success, or null on failure.
|
||||
static IntrusiveRefCntPtr<DiagnosticsEngine>
|
||||
createDiagnostics(llvm::vfs::FileSystem &VFS, DiagnosticOptions *Opts,
|
||||
createDiagnostics(llvm::vfs::FileSystem &VFS, DiagnosticOptions &Opts,
|
||||
DiagnosticConsumer *Client = nullptr,
|
||||
bool ShouldOwnClient = true,
|
||||
const CodeGenOptions *CodeGenOpts = nullptr);
|
||||
|
@ -80,7 +80,7 @@ protected:
|
||||
std::shared_ptr<TargetOptions> TargetOpts;
|
||||
|
||||
/// Options controlling the diagnostic engine.
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagnosticOpts;
|
||||
std::shared_ptr<DiagnosticOptions> DiagnosticOpts;
|
||||
|
||||
/// Options controlling the \#include directive.
|
||||
std::shared_ptr<HeaderSearchOptions> HSOpts;
|
||||
|
@ -47,7 +47,7 @@ using DiagOrStoredDiag =
|
||||
class DiagnosticRenderer {
|
||||
protected:
|
||||
const LangOptions &LangOpts;
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
|
||||
DiagnosticOptions &DiagOpts;
|
||||
|
||||
/// The location of the previous diagnostic if known.
|
||||
///
|
||||
@ -68,8 +68,7 @@ protected:
|
||||
/// which change the amount of information displayed.
|
||||
DiagnosticsEngine::Level LastLevel = DiagnosticsEngine::Ignored;
|
||||
|
||||
DiagnosticRenderer(const LangOptions &LangOpts,
|
||||
DiagnosticOptions *DiagOpts);
|
||||
DiagnosticRenderer(const LangOptions &LangOpts, DiagnosticOptions &DiagOpts);
|
||||
|
||||
virtual ~DiagnosticRenderer();
|
||||
|
||||
@ -142,7 +141,7 @@ public:
|
||||
class DiagnosticNoteRenderer : public DiagnosticRenderer {
|
||||
public:
|
||||
DiagnosticNoteRenderer(const LangOptions &LangOpts,
|
||||
DiagnosticOptions *DiagOpts)
|
||||
DiagnosticOptions &DiagOpts)
|
||||
: DiagnosticRenderer(LangOpts, DiagOpts) {}
|
||||
|
||||
~DiagnosticNoteRenderer() override;
|
||||
|
@ -51,7 +51,7 @@ class LogDiagnosticPrinter : public DiagnosticConsumer {
|
||||
raw_ostream &OS;
|
||||
std::unique_ptr<raw_ostream> StreamOwner;
|
||||
const LangOptions *LangOpts;
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
|
||||
DiagnosticOptions &DiagOpts;
|
||||
|
||||
SourceLocation LastWarningLoc;
|
||||
FullSourceLoc LastLoc;
|
||||
@ -62,7 +62,7 @@ class LogDiagnosticPrinter : public DiagnosticConsumer {
|
||||
std::string DwarfDebugFlags;
|
||||
|
||||
public:
|
||||
LogDiagnosticPrinter(raw_ostream &OS, DiagnosticOptions *Diags,
|
||||
LogDiagnosticPrinter(raw_ostream &OS, DiagnosticOptions &DiagOpts,
|
||||
std::unique_ptr<raw_ostream> StreamOwner);
|
||||
|
||||
void setDwarfDebugFlags(StringRef Value) {
|
||||
|
@ -23,7 +23,7 @@ namespace clang {
|
||||
class SARIFDiagnostic : public DiagnosticRenderer {
|
||||
public:
|
||||
SARIFDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
|
||||
DiagnosticOptions *DiagOpts, SarifDocumentWriter *Writer);
|
||||
DiagnosticOptions &DiagOpts, SarifDocumentWriter *Writer);
|
||||
|
||||
~SARIFDiagnostic() = default;
|
||||
|
||||
|
@ -29,7 +29,7 @@ class SarifDocumentWriter;
|
||||
|
||||
class SARIFDiagnosticPrinter : public DiagnosticConsumer {
|
||||
public:
|
||||
SARIFDiagnosticPrinter(raw_ostream &OS, DiagnosticOptions *Diags);
|
||||
SARIFDiagnosticPrinter(raw_ostream &OS, DiagnosticOptions &DiagOpts);
|
||||
~SARIFDiagnosticPrinter() = default;
|
||||
|
||||
SARIFDiagnosticPrinter &operator=(const SARIFDiagnosticPrinter &&) = delete;
|
||||
@ -60,7 +60,7 @@ public:
|
||||
|
||||
private:
|
||||
raw_ostream &OS;
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
|
||||
DiagnosticOptions &DiagOpts;
|
||||
|
||||
/// Handle to the currently active SARIF diagnostic emitter.
|
||||
std::unique_ptr<SARIFDiagnostic> SARIFDiag;
|
||||
|
@ -32,7 +32,7 @@ namespace serialized_diags {
|
||||
/// (via libclang) without needing to parse Clang's command line output.
|
||||
///
|
||||
std::unique_ptr<DiagnosticConsumer> create(StringRef OutputFile,
|
||||
DiagnosticOptions *Diags,
|
||||
DiagnosticOptions &DiagOpts,
|
||||
bool MergeChildRecords = false);
|
||||
|
||||
} // end serialized_diags namespace
|
||||
|
@ -38,7 +38,7 @@ class TextDiagnostic : public DiagnosticRenderer {
|
||||
|
||||
public:
|
||||
TextDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
|
||||
DiagnosticOptions *DiagOpts, const Preprocessor *PP = nullptr);
|
||||
DiagnosticOptions &DiagOpts, const Preprocessor *PP = nullptr);
|
||||
|
||||
~TextDiagnostic() override;
|
||||
|
||||
|
@ -26,7 +26,7 @@ class TextDiagnostic;
|
||||
|
||||
class TextDiagnosticPrinter : public DiagnosticConsumer {
|
||||
raw_ostream &OS;
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
|
||||
DiagnosticOptions &DiagOpts;
|
||||
|
||||
/// Handle to the currently active text diagnostic emitter.
|
||||
std::unique_ptr<TextDiagnostic> TextDiag;
|
||||
@ -38,7 +38,7 @@ class TextDiagnosticPrinter : public DiagnosticConsumer {
|
||||
unsigned OwnsOutputStream : 1;
|
||||
|
||||
public:
|
||||
TextDiagnosticPrinter(raw_ostream &os, DiagnosticOptions *diags,
|
||||
TextDiagnosticPrinter(raw_ostream &os, DiagnosticOptions &DiagOpts,
|
||||
bool OwnsOutputStream = false);
|
||||
~TextDiagnosticPrinter() override;
|
||||
|
||||
|
@ -151,9 +151,8 @@ public:
|
||||
///
|
||||
/// \returns true to indicate the diagnostic options are invalid, or false
|
||||
/// otherwise.
|
||||
virtual bool
|
||||
ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
|
||||
StringRef ModuleFilename, bool Complain) {
|
||||
virtual bool ReadDiagnosticOptions(DiagnosticOptions &DiagOpts,
|
||||
StringRef ModuleFilename, bool Complain) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -285,7 +284,7 @@ public:
|
||||
bool ReadTargetOptions(const TargetOptions &TargetOpts,
|
||||
StringRef ModuleFilename, bool Complain,
|
||||
bool AllowCompatibleDifferences) override;
|
||||
bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
|
||||
bool ReadDiagnosticOptions(DiagnosticOptions &DiagOpts,
|
||||
StringRef ModuleFilename, bool Complain) override;
|
||||
bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
|
||||
bool Complain) override;
|
||||
@ -326,7 +325,7 @@ public:
|
||||
bool ReadTargetOptions(const TargetOptions &TargetOpts,
|
||||
StringRef ModuleFilename, bool Complain,
|
||||
bool AllowCompatibleDifferences) override;
|
||||
bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
|
||||
bool ReadDiagnosticOptions(DiagnosticOptions &DiagOpts,
|
||||
StringRef ModuleFilename, bool Complain) override;
|
||||
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
|
||||
StringRef ModuleFilename, bool ReadMacros,
|
||||
|
@ -77,11 +77,11 @@ DummyArgToStringFn(DiagnosticsEngine::ArgumentKind AK, intptr_t QT,
|
||||
Output.append(Str.begin(), Str.end());
|
||||
}
|
||||
|
||||
DiagnosticsEngine::DiagnosticsEngine(
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> diags,
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, DiagnosticConsumer *client,
|
||||
bool ShouldOwnClient)
|
||||
: Diags(std::move(diags)), DiagOpts(std::move(DiagOpts)) {
|
||||
DiagnosticsEngine::DiagnosticsEngine(IntrusiveRefCntPtr<DiagnosticIDs> diags,
|
||||
DiagnosticOptions &DiagOpts,
|
||||
DiagnosticConsumer *client,
|
||||
bool ShouldOwnClient)
|
||||
: Diags(std::move(diags)), DiagOpts(DiagOpts) {
|
||||
setClient(client, ShouldOwnClient);
|
||||
ArgToStringFn = DummyArgToStringFn;
|
||||
|
||||
|
@ -2391,11 +2391,11 @@ SourceManagerForFile::SourceManagerForFile(StringRef FileName,
|
||||
// in `Environment` so that `FileMgr` can out-live this function scope.
|
||||
FileMgr =
|
||||
std::make_unique<FileManager>(FileSystemOptions(), InMemoryFileSystem);
|
||||
DiagOpts = std::make_unique<DiagnosticOptions>();
|
||||
// This is passed to `SM` as reference, so the pointer has to be referenced
|
||||
// by `Environment` due to the same reason above.
|
||||
Diagnostics = std::make_unique<DiagnosticsEngine>(
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),
|
||||
new DiagnosticOptions);
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), *DiagOpts);
|
||||
SourceMgr = std::make_unique<SourceManager>(*Diagnostics, *FileMgr);
|
||||
FileEntryRef FE = llvm::cantFail(FileMgr->getFileRef(FileName));
|
||||
FileID ID =
|
||||
|
@ -560,15 +560,15 @@ CrossTranslationUnitContext::ASTLoader::load(StringRef Identifier) {
|
||||
|
||||
CrossTranslationUnitContext::LoadResultTy
|
||||
CrossTranslationUnitContext::ASTLoader::loadFromDump(StringRef ASTDumpPath) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
auto DiagOpts = std::make_shared<DiagnosticOptions>();
|
||||
TextDiagnosticPrinter *DiagClient =
|
||||
new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
|
||||
new TextDiagnosticPrinter(llvm::errs(), *DiagOpts);
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
|
||||
new DiagnosticsEngine(DiagID, &*DiagOpts, DiagClient));
|
||||
new DiagnosticsEngine(DiagID, *DiagOpts, DiagClient));
|
||||
return ASTUnit::LoadFromASTFile(
|
||||
ASTDumpPath, CI.getPCHContainerOperations()->getRawReader(),
|
||||
ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts(),
|
||||
ASTUnit::LoadEverything, DiagOpts, Diags, CI.getFileSystemOpts(),
|
||||
CI.getHeaderSearchOpts());
|
||||
}
|
||||
|
||||
@ -603,17 +603,17 @@ CrossTranslationUnitContext::ASTLoader::loadFromSource(
|
||||
CommandLineArgs.begin(),
|
||||
[](auto &&CmdPart) { return CmdPart.c_str(); });
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts{&CI.getDiagnosticOpts()};
|
||||
auto DiagOpts = std::make_shared<DiagnosticOptions>(CI.getDiagnosticOpts());
|
||||
auto *DiagClient = new ForwardingDiagnosticConsumer{CI.getDiagnosticClient()};
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID{
|
||||
CI.getDiagnostics().getDiagnosticIDs()};
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
|
||||
new DiagnosticsEngine{DiagID, &*DiagOpts, DiagClient});
|
||||
new DiagnosticsEngine{DiagID, *DiagOpts, DiagClient});
|
||||
|
||||
return ASTUnit::LoadFromCommandLine(CommandLineArgs.begin(),
|
||||
(CommandLineArgs.end()),
|
||||
CI.getPCHContainerOperations(), Diags,
|
||||
CI.getHeaderSearchOpts().ResourceDir);
|
||||
return ASTUnit::LoadFromCommandLine(
|
||||
CommandLineArgs.begin(), (CommandLineArgs.end()),
|
||||
CI.getPCHContainerOperations(), DiagOpts, Diags,
|
||||
CI.getHeaderSearchOpts().ResourceDir);
|
||||
}
|
||||
|
||||
llvm::Expected<InvocationListTy>
|
||||
|
@ -41,14 +41,13 @@ void ASTMergeAction::ExecuteAction() {
|
||||
auto SharedState = std::make_shared<ASTImporterSharedState>(
|
||||
*CI.getASTContext().getTranslationUnitDecl());
|
||||
for (unsigned I = 0, N = ASTFiles.size(); I != N; ++I) {
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine>
|
||||
Diags(new DiagnosticsEngine(DiagIDs, &CI.getDiagnosticOpts(),
|
||||
new ForwardingDiagnosticConsumer(
|
||||
*CI.getDiagnostics().getClient()),
|
||||
/*ShouldOwnClient=*/true));
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(new DiagnosticsEngine(
|
||||
DiagIDs, CI.getDiagnosticOpts(),
|
||||
new ForwardingDiagnosticConsumer(*CI.getDiagnostics().getClient()),
|
||||
/*ShouldOwnClient=*/true));
|
||||
std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromASTFile(
|
||||
ASTFiles[I], CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags,
|
||||
CI.getFileSystemOpts(), CI.getHeaderSearchOpts());
|
||||
ASTFiles[I], CI.getPCHContainerReader(), ASTUnit::LoadEverything,
|
||||
nullptr, Diags, CI.getFileSystemOpts(), CI.getHeaderSearchOpts());
|
||||
|
||||
if (!Unit)
|
||||
continue;
|
||||
|
@ -803,7 +803,8 @@ void ASTUnit::ConfigureDiags(IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
|
||||
|
||||
std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
|
||||
StringRef Filename, const PCHContainerReader &PCHContainerRdr,
|
||||
WhatToLoad ToLoad, IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
|
||||
WhatToLoad ToLoad, std::shared_ptr<DiagnosticOptions> DiagOpts,
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
|
||||
const FileSystemOptions &FileSystemOpts, const HeaderSearchOptions &HSOpts,
|
||||
const LangOptions *LangOpts, bool OnlyLocalDecls,
|
||||
CaptureDiagsKind CaptureDiagnostics, bool AllowASTWithCompilerErrors,
|
||||
@ -823,6 +824,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
|
||||
: std::make_unique<LangOptions>();
|
||||
AST->OnlyLocalDecls = OnlyLocalDecls;
|
||||
AST->CaptureDiagnostics = CaptureDiagnostics;
|
||||
AST->DiagOpts = DiagOpts;
|
||||
AST->Diagnostics = Diags;
|
||||
AST->FileMgr = new FileManager(FileSystemOpts, VFS);
|
||||
AST->UserFilesAreVolatile = UserFilesAreVolatile;
|
||||
@ -1534,6 +1536,7 @@ StringRef ASTUnit::getASTFileName() const {
|
||||
|
||||
std::unique_ptr<ASTUnit>
|
||||
ASTUnit::create(std::shared_ptr<CompilerInvocation> CI,
|
||||
std::shared_ptr<DiagnosticOptions> DiagOpts,
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
|
||||
CaptureDiagsKind CaptureDiagnostics,
|
||||
bool UserFilesAreVolatile) {
|
||||
@ -1541,6 +1544,7 @@ ASTUnit::create(std::shared_ptr<CompilerInvocation> CI,
|
||||
ConfigureDiags(Diags, *AST, CaptureDiagnostics);
|
||||
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
|
||||
createVFSFromCompilerInvocation(*CI, *Diags);
|
||||
AST->DiagOpts = DiagOpts;
|
||||
AST->Diagnostics = Diags;
|
||||
AST->FileSystemOpts = CI->getFileSystemOpts();
|
||||
AST->Invocation = std::move(CI);
|
||||
@ -1556,6 +1560,7 @@ ASTUnit::create(std::shared_ptr<CompilerInvocation> CI,
|
||||
ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
|
||||
std::shared_ptr<CompilerInvocation> CI,
|
||||
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
|
||||
std::shared_ptr<DiagnosticOptions> DiagOpts,
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FrontendAction *Action,
|
||||
ASTUnit *Unit, bool Persistent, StringRef ResourceFilesPath,
|
||||
bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
|
||||
@ -1567,7 +1572,8 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
|
||||
ASTUnit *AST = Unit;
|
||||
if (!AST) {
|
||||
// Create the AST unit.
|
||||
OwnAST = create(CI, Diags, CaptureDiagnostics, UserFilesAreVolatile);
|
||||
OwnAST =
|
||||
create(CI, DiagOpts, Diags, CaptureDiagnostics, UserFilesAreVolatile);
|
||||
AST = OwnAST.get();
|
||||
if (!AST)
|
||||
return nullptr;
|
||||
@ -1729,6 +1735,7 @@ bool ASTUnit::LoadFromCompilerInvocation(
|
||||
std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation(
|
||||
std::shared_ptr<CompilerInvocation> CI,
|
||||
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
|
||||
std::shared_ptr<DiagnosticOptions> DiagOpts,
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FileManager *FileMgr,
|
||||
bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
|
||||
unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind,
|
||||
@ -1737,6 +1744,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation(
|
||||
// Create the AST unit.
|
||||
std::unique_ptr<ASTUnit> AST(new ASTUnit(false));
|
||||
ConfigureDiags(Diags, *AST, CaptureDiagnostics);
|
||||
AST->DiagOpts = DiagOpts;
|
||||
AST->Diagnostics = Diags;
|
||||
AST->OnlyLocalDecls = OnlyLocalDecls;
|
||||
AST->CaptureDiagnostics = CaptureDiagnostics;
|
||||
@ -1766,6 +1774,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation(
|
||||
std::unique_ptr<ASTUnit> ASTUnit::LoadFromCommandLine(
|
||||
const char **ArgBegin, const char **ArgEnd,
|
||||
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
|
||||
std::shared_ptr<DiagnosticOptions> DiagOpts,
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags, StringRef ResourceFilesPath,
|
||||
bool StorePreamblesInMemory, StringRef PreambleStoragePath,
|
||||
bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
|
||||
@ -1828,6 +1837,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCommandLine(
|
||||
AST->NumStoredDiagnosticsFromDriver = StoredDiagnostics.size();
|
||||
AST->StoredDiagnostics.swap(StoredDiagnostics);
|
||||
ConfigureDiags(Diags, *AST, CaptureDiagnostics);
|
||||
AST->DiagOpts = DiagOpts;
|
||||
AST->Diagnostics = Diags;
|
||||
AST->FileSystemOpts = CI->getFileSystemOpts();
|
||||
VFS = createVFSFromCompilerInvocation(*CI, *Diags, VFS);
|
||||
|
@ -117,10 +117,10 @@ IntrusiveRefCntPtr<ExternalSemaSource> clang::createChainedIncludesSource(
|
||||
CInvok->getFrontendOpts().Inputs.push_back(InputFile);
|
||||
|
||||
TextDiagnosticPrinter *DiagClient =
|
||||
new TextDiagnosticPrinter(llvm::errs(), new DiagnosticOptions());
|
||||
new TextDiagnosticPrinter(llvm::errs(), CI.getDiagnosticOpts());
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
|
||||
new DiagnosticsEngine(DiagID, &CI.getDiagnosticOpts(), DiagClient));
|
||||
new DiagnosticsEngine(DiagID, CI.getDiagnosticOpts(), DiagClient));
|
||||
|
||||
auto Clang = std::make_unique<CompilerInstance>(
|
||||
std::move(CInvok), CI.getPCHContainerOperations());
|
||||
|
@ -280,20 +280,20 @@ static void collectVFSEntries(CompilerInstance &CI,
|
||||
}
|
||||
|
||||
// Diagnostics
|
||||
static void SetUpDiagnosticLog(DiagnosticOptions *DiagOpts,
|
||||
static void SetUpDiagnosticLog(DiagnosticOptions &DiagOpts,
|
||||
const CodeGenOptions *CodeGenOpts,
|
||||
DiagnosticsEngine &Diags) {
|
||||
std::error_code EC;
|
||||
std::unique_ptr<raw_ostream> StreamOwner;
|
||||
raw_ostream *OS = &llvm::errs();
|
||||
if (DiagOpts->DiagnosticLogFile != "-") {
|
||||
if (DiagOpts.DiagnosticLogFile != "-") {
|
||||
// Create the output stream.
|
||||
auto FileOS = std::make_unique<llvm::raw_fd_ostream>(
|
||||
DiagOpts->DiagnosticLogFile, EC,
|
||||
DiagOpts.DiagnosticLogFile, EC,
|
||||
llvm::sys::fs::OF_Append | llvm::sys::fs::OF_TextWithCRLF);
|
||||
if (EC) {
|
||||
Diags.Report(diag::warn_fe_cc_log_diagnostics_failure)
|
||||
<< DiagOpts->DiagnosticLogFile << EC.message();
|
||||
<< DiagOpts.DiagnosticLogFile << EC.message();
|
||||
} else {
|
||||
FileOS->SetUnbuffered();
|
||||
OS = FileOS.get();
|
||||
@ -315,7 +315,7 @@ static void SetUpDiagnosticLog(DiagnosticOptions *DiagOpts,
|
||||
}
|
||||
}
|
||||
|
||||
static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts,
|
||||
static void SetupSerializedDiagnostics(DiagnosticOptions &DiagOpts,
|
||||
DiagnosticsEngine &Diags,
|
||||
StringRef OutputFile) {
|
||||
auto SerializedConsumer =
|
||||
@ -333,12 +333,12 @@ static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts,
|
||||
void CompilerInstance::createDiagnostics(llvm::vfs::FileSystem &VFS,
|
||||
DiagnosticConsumer *Client,
|
||||
bool ShouldOwnClient) {
|
||||
Diagnostics = createDiagnostics(VFS, &getDiagnosticOpts(), Client,
|
||||
Diagnostics = createDiagnostics(VFS, getDiagnosticOpts(), Client,
|
||||
ShouldOwnClient, &getCodeGenOpts());
|
||||
}
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(
|
||||
llvm::vfs::FileSystem &VFS, DiagnosticOptions *Opts,
|
||||
llvm::vfs::FileSystem &VFS, DiagnosticOptions &Opts,
|
||||
DiagnosticConsumer *Client, bool ShouldOwnClient,
|
||||
const CodeGenOptions *CodeGenOpts) {
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
@ -349,25 +349,24 @@ IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(
|
||||
// implementing -verify.
|
||||
if (Client) {
|
||||
Diags->setClient(Client, ShouldOwnClient);
|
||||
} else if (Opts->getFormat() == DiagnosticOptions::SARIF) {
|
||||
} else if (Opts.getFormat() == DiagnosticOptions::SARIF) {
|
||||
Diags->setClient(new SARIFDiagnosticPrinter(llvm::errs(), Opts));
|
||||
} else
|
||||
Diags->setClient(new TextDiagnosticPrinter(llvm::errs(), Opts));
|
||||
|
||||
// Chain in -verify checker, if requested.
|
||||
if (Opts->VerifyDiagnostics)
|
||||
if (Opts.VerifyDiagnostics)
|
||||
Diags->setClient(new VerifyDiagnosticConsumer(*Diags));
|
||||
|
||||
// Chain in -diagnostic-log-file dumper, if requested.
|
||||
if (!Opts->DiagnosticLogFile.empty())
|
||||
if (!Opts.DiagnosticLogFile.empty())
|
||||
SetUpDiagnosticLog(Opts, CodeGenOpts, *Diags);
|
||||
|
||||
if (!Opts->DiagnosticSerializationFile.empty())
|
||||
SetupSerializedDiagnostics(Opts, *Diags,
|
||||
Opts->DiagnosticSerializationFile);
|
||||
if (!Opts.DiagnosticSerializationFile.empty())
|
||||
SetupSerializedDiagnostics(Opts, *Diags, Opts.DiagnosticSerializationFile);
|
||||
|
||||
// Configure our handling of diagnostics.
|
||||
ProcessWarningOptions(*Diags, *Opts, VFS);
|
||||
ProcessWarningOptions(*Diags, Opts, VFS);
|
||||
|
||||
return Diags;
|
||||
}
|
||||
|
@ -125,21 +125,14 @@ static Expected<std::optional<uint32_t>> parseToleranceOption(StringRef Arg) {
|
||||
// Initialization.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
namespace {
|
||||
template <class T> std::shared_ptr<T> make_shared_copy(const T &X) {
|
||||
return std::make_shared<T>(X);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
llvm::IntrusiveRefCntPtr<T> makeIntrusiveRefCntCopy(const T &X) {
|
||||
return llvm::makeIntrusiveRefCnt<T>(X);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
CompilerInvocationBase::CompilerInvocationBase()
|
||||
: LangOpts(std::make_shared<LangOptions>()),
|
||||
TargetOpts(std::make_shared<TargetOptions>()),
|
||||
DiagnosticOpts(llvm::makeIntrusiveRefCnt<DiagnosticOptions>()),
|
||||
DiagnosticOpts(std::make_shared<DiagnosticOptions>()),
|
||||
HSOpts(std::make_shared<HeaderSearchOptions>()),
|
||||
PPOpts(std::make_shared<PreprocessorOptions>()),
|
||||
AnalyzerOpts(std::make_shared<AnalyzerOptions>()),
|
||||
@ -156,7 +149,7 @@ CompilerInvocationBase::deep_copy_assign(const CompilerInvocationBase &X) {
|
||||
if (this != &X) {
|
||||
LangOpts = make_shared_copy(X.getLangOpts());
|
||||
TargetOpts = make_shared_copy(X.getTargetOpts());
|
||||
DiagnosticOpts = makeIntrusiveRefCntCopy(X.getDiagnosticOpts());
|
||||
DiagnosticOpts = make_shared_copy(X.getDiagnosticOpts());
|
||||
HSOpts = make_shared_copy(X.getHeaderSearchOpts());
|
||||
PPOpts = make_shared_copy(X.getPreprocessorOpts());
|
||||
AnalyzerOpts = make_shared_copy(X.getAnalyzerOpts());
|
||||
@ -202,7 +195,6 @@ CompilerInvocation::operator=(const CowCompilerInvocation &X) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
namespace {
|
||||
template <typename T>
|
||||
T &ensureOwned(std::shared_ptr<T> &Storage) {
|
||||
if (Storage.use_count() > 1)
|
||||
@ -210,14 +202,6 @@ T &ensureOwned(std::shared_ptr<T> &Storage) {
|
||||
return *Storage;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &ensureOwned(llvm::IntrusiveRefCntPtr<T> &Storage) {
|
||||
if (Storage.useCount() > 1)
|
||||
Storage = llvm::makeIntrusiveRefCnt<T>(*Storage);
|
||||
return *Storage;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
LangOptions &CowCompilerInvocation::getMutLangOpts() {
|
||||
return ensureOwned(LangOpts);
|
||||
}
|
||||
@ -844,7 +828,8 @@ static bool RoundTrip(ParseFn Parse, GenerateFn Generate,
|
||||
};
|
||||
|
||||
// Setup a dummy DiagnosticsEngine.
|
||||
DiagnosticsEngine DummyDiags(new DiagnosticIDs(), new DiagnosticOptions());
|
||||
DiagnosticOptions DummyDiagOpts;
|
||||
DiagnosticsEngine DummyDiags(new DiagnosticIDs(), DummyDiagOpts);
|
||||
DummyDiags.setClient(new TextDiagnosticBuffer());
|
||||
|
||||
// Run the first parse on the original arguments with the dummy invocation and
|
||||
@ -2663,9 +2648,11 @@ clang::CreateAndPopulateDiagOpts(ArrayRef<const char *> Argv) {
|
||||
bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
|
||||
DiagnosticsEngine *Diags,
|
||||
bool DefaultDiagColor) {
|
||||
std::optional<DiagnosticOptions> IgnoringDiagOpts;
|
||||
std::optional<DiagnosticsEngine> IgnoringDiags;
|
||||
if (!Diags) {
|
||||
IgnoringDiags.emplace(new DiagnosticIDs(), new DiagnosticOptions(),
|
||||
IgnoringDiagOpts.emplace();
|
||||
IgnoringDiags.emplace(new DiagnosticIDs(), *IgnoringDiagOpts,
|
||||
new IgnoringDiagConsumer());
|
||||
Diags = &*IgnoringDiags;
|
||||
}
|
||||
|
@ -31,11 +31,15 @@ std::unique_ptr<CompilerInvocation>
|
||||
clang::createInvocation(ArrayRef<const char *> ArgList,
|
||||
CreateInvocationOptions Opts) {
|
||||
assert(!ArgList.empty());
|
||||
auto Diags = Opts.Diags
|
||||
? std::move(Opts.Diags)
|
||||
: CompilerInstance::createDiagnostics(
|
||||
Opts.VFS ? *Opts.VFS : *llvm::vfs::getRealFileSystem(),
|
||||
new DiagnosticOptions);
|
||||
std::optional<DiagnosticOptions> LocalDiagOpts;
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags;
|
||||
if (Opts.Diags) {
|
||||
Diags = std::move(Opts.Diags);
|
||||
} else {
|
||||
LocalDiagOpts.emplace();
|
||||
Diags = CompilerInstance::createDiagnostics(
|
||||
Opts.VFS ? *Opts.VFS : *llvm::vfs::getRealFileSystem(), *LocalDiagOpts);
|
||||
}
|
||||
|
||||
SmallVector<const char *, 16> Args(ArgList);
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
using namespace clang;
|
||||
|
||||
DiagnosticRenderer::DiagnosticRenderer(const LangOptions &LangOpts,
|
||||
DiagnosticOptions *DiagOpts)
|
||||
DiagnosticOptions &DiagOpts)
|
||||
: LangOpts(LangOpts), DiagOpts(DiagOpts), LastLevel() {}
|
||||
|
||||
DiagnosticRenderer::~DiagnosticRenderer() = default;
|
||||
@ -115,7 +115,7 @@ void DiagnosticRenderer::emitDiagnostic(FullSourceLoc Loc,
|
||||
// Find the ultimate expansion location for the diagnostic.
|
||||
Loc = Loc.getFileLoc();
|
||||
|
||||
PresumedLoc PLoc = Loc.getPresumedLoc(DiagOpts->ShowPresumedLoc);
|
||||
PresumedLoc PLoc = Loc.getPresumedLoc(DiagOpts.ShowPresumedLoc);
|
||||
|
||||
// First, if this diagnostic is not in the main file, print out the
|
||||
// "included from" lines.
|
||||
@ -172,7 +172,7 @@ void DiagnosticRenderer::emitIncludeStack(FullSourceLoc Loc, PresumedLoc PLoc,
|
||||
|
||||
LastIncludeLoc = IncludeLoc;
|
||||
|
||||
if (!DiagOpts->ShowNoteIncludeStack && Level == DiagnosticsEngine::Note)
|
||||
if (!DiagOpts.ShowNoteIncludeStack && Level == DiagnosticsEngine::Note)
|
||||
return;
|
||||
|
||||
if (IncludeLoc.isValid())
|
||||
@ -191,7 +191,7 @@ void DiagnosticRenderer::emitIncludeStackRecursively(FullSourceLoc Loc) {
|
||||
return;
|
||||
}
|
||||
|
||||
PresumedLoc PLoc = Loc.getPresumedLoc(DiagOpts->ShowPresumedLoc);
|
||||
PresumedLoc PLoc = Loc.getPresumedLoc(DiagOpts.ShowPresumedLoc);
|
||||
if (PLoc.isInvalid())
|
||||
return;
|
||||
|
||||
@ -232,7 +232,7 @@ void DiagnosticRenderer::emitImportStackRecursively(FullSourceLoc Loc,
|
||||
return;
|
||||
}
|
||||
|
||||
PresumedLoc PLoc = Loc.getPresumedLoc(DiagOpts->ShowPresumedLoc);
|
||||
PresumedLoc PLoc = Loc.getPresumedLoc(DiagOpts.ShowPresumedLoc);
|
||||
|
||||
// Emit the other import frames first.
|
||||
std::pair<FullSourceLoc, StringRef> NextImportLoc = Loc.getModuleImportLoc();
|
||||
@ -247,9 +247,8 @@ void DiagnosticRenderer::emitImportStackRecursively(FullSourceLoc Loc,
|
||||
void DiagnosticRenderer::emitModuleBuildStack(const SourceManager &SM) {
|
||||
ModuleBuildStack Stack = SM.getModuleBuildStack();
|
||||
for (const auto &I : Stack) {
|
||||
emitBuildingModuleLocation(I.second, I.second.getPresumedLoc(
|
||||
DiagOpts->ShowPresumedLoc),
|
||||
I.first);
|
||||
emitBuildingModuleLocation(
|
||||
I.second, I.second.getPresumedLoc(DiagOpts.ShowPresumedLoc), I.first);
|
||||
}
|
||||
}
|
||||
|
||||
@ -539,7 +538,7 @@ void DiagnosticRenderer::emitMacroExpansions(FullSourceLoc Loc,
|
||||
LocationStack.begin() + IgnoredEnd);
|
||||
|
||||
unsigned MacroDepth = LocationStack.size();
|
||||
unsigned MacroLimit = DiagOpts->MacroBacktraceLimit;
|
||||
unsigned MacroLimit = DiagOpts.MacroBacktraceLimit;
|
||||
if (MacroDepth <= MacroLimit || MacroLimit == 0) {
|
||||
for (auto I = LocationStack.rbegin(), E = LocationStack.rend();
|
||||
I != E; ++I)
|
||||
|
@ -766,9 +766,8 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(&CI.getDiagnostics());
|
||||
|
||||
// The AST unit populates its own diagnostics engine rather than ours.
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> ASTDiags(
|
||||
new DiagnosticsEngine(Diags->getDiagnosticIDs(),
|
||||
&Diags->getDiagnosticOptions()));
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> ASTDiags(new DiagnosticsEngine(
|
||||
Diags->getDiagnosticIDs(), Diags->getDiagnosticOptions()));
|
||||
ASTDiags->setClient(Diags->getClient(), /*OwnsClient*/false);
|
||||
|
||||
// FIXME: What if the input is a memory buffer?
|
||||
@ -776,7 +775,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
|
||||
|
||||
std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(
|
||||
InputFile, CI.getPCHContainerReader(), ASTUnit::LoadPreprocessorOnly,
|
||||
ASTDiags, CI.getFileSystemOpts(), CI.getHeaderSearchOpts());
|
||||
nullptr, ASTDiags, CI.getFileSystemOpts(), CI.getHeaderSearchOpts());
|
||||
if (!AST)
|
||||
return false;
|
||||
|
||||
@ -842,8 +841,9 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
|
||||
StringRef InputFile = Input.getFile();
|
||||
|
||||
std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(
|
||||
InputFile, CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags,
|
||||
CI.getFileSystemOpts(), CI.getHeaderSearchOpts(), &CI.getLangOpts());
|
||||
InputFile, CI.getPCHContainerReader(), ASTUnit::LoadEverything, nullptr,
|
||||
Diags, CI.getFileSystemOpts(), CI.getHeaderSearchOpts(),
|
||||
&CI.getLangOpts());
|
||||
|
||||
if (!AST)
|
||||
return false;
|
||||
|
@ -685,21 +685,21 @@ namespace {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
|
||||
bool ReadDiagnosticOptions(DiagnosticOptions &DiagOpts,
|
||||
StringRef ModuleFilename,
|
||||
bool Complain) override {
|
||||
Out.indent(2) << "Diagnostic options:\n";
|
||||
#define DIAGOPT(Name, Bits, Default) DUMP_BOOLEAN(DiagOpts->Name, #Name);
|
||||
#define ENUM_DIAGOPT(Name, Type, Bits, Default) \
|
||||
Out.indent(4) << #Name << ": " << DiagOpts->get##Name() << "\n";
|
||||
#define VALUE_DIAGOPT(Name, Bits, Default) \
|
||||
Out.indent(4) << #Name << ": " << DiagOpts->Name << "\n";
|
||||
#define DIAGOPT(Name, Bits, Default) DUMP_BOOLEAN(DiagOpts.Name, #Name);
|
||||
#define ENUM_DIAGOPT(Name, Type, Bits, Default) \
|
||||
Out.indent(4) << #Name << ": " << DiagOpts.get##Name() << "\n";
|
||||
#define VALUE_DIAGOPT(Name, Bits, Default) \
|
||||
Out.indent(4) << #Name << ": " << DiagOpts.Name << "\n";
|
||||
#include "clang/Basic/DiagnosticOptions.def"
|
||||
|
||||
Out.indent(4) << "Diagnostic flags:\n";
|
||||
for (const std::string &Warning : DiagOpts->Warnings)
|
||||
for (const std::string &Warning : DiagOpts.Warnings)
|
||||
Out.indent(6) << "-W" << Warning << "\n";
|
||||
for (const std::string &Remark : DiagOpts->Remarks)
|
||||
for (const std::string &Remark : DiagOpts.Remarks)
|
||||
Out.indent(6) << "-R" << Remark << "\n";
|
||||
|
||||
return false;
|
||||
|
@ -18,10 +18,10 @@ using namespace clang;
|
||||
using namespace markup;
|
||||
|
||||
LogDiagnosticPrinter::LogDiagnosticPrinter(
|
||||
raw_ostream &os, DiagnosticOptions *diags,
|
||||
raw_ostream &os, DiagnosticOptions &DiagOpts,
|
||||
std::unique_ptr<raw_ostream> StreamOwner)
|
||||
: OS(os), StreamOwner(std::move(StreamOwner)), LangOpts(nullptr),
|
||||
DiagOpts(diags) {}
|
||||
DiagOpts(DiagOpts) {}
|
||||
|
||||
static StringRef getLevelName(DiagnosticsEngine::Level Level) {
|
||||
switch (Level) {
|
||||
|
@ -31,7 +31,7 @@
|
||||
namespace clang {
|
||||
|
||||
SARIFDiagnostic::SARIFDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
|
||||
DiagnosticOptions *DiagOpts,
|
||||
DiagnosticOptions &DiagOpts,
|
||||
SarifDocumentWriter *Writer)
|
||||
: DiagnosticRenderer(LangOpts, DiagOpts), Writer(Writer) {}
|
||||
|
||||
@ -163,7 +163,7 @@ SARIFDiagnostic::addDiagnosticLevelToRule(SarifRule Rule,
|
||||
|
||||
llvm::StringRef SARIFDiagnostic::emitFilename(StringRef Filename,
|
||||
const SourceManager &SM) {
|
||||
if (DiagOpts->AbsolutePath) {
|
||||
if (DiagOpts.AbsolutePath) {
|
||||
auto File = SM.getFileManager().getOptionalFileRef(Filename);
|
||||
if (File) {
|
||||
// We want to print a simplified absolute path, i. e. without "dots".
|
||||
|
@ -26,15 +26,15 @@
|
||||
namespace clang {
|
||||
|
||||
SARIFDiagnosticPrinter::SARIFDiagnosticPrinter(raw_ostream &OS,
|
||||
DiagnosticOptions *Diags)
|
||||
: OS(OS), DiagOpts(Diags) {}
|
||||
DiagnosticOptions &DiagOpts)
|
||||
: OS(OS), DiagOpts(DiagOpts) {}
|
||||
|
||||
void SARIFDiagnosticPrinter::BeginSourceFile(const LangOptions &LO,
|
||||
const Preprocessor *PP) {
|
||||
// Build the SARIFDiagnostic utility.
|
||||
assert(hasSarifWriter() && "Writer not set!");
|
||||
assert(!SARIFDiag && "SARIFDiagnostic already set.");
|
||||
SARIFDiag = std::make_unique<SARIFDiagnostic>(OS, LO, &*DiagOpts, &*Writer);
|
||||
SARIFDiag = std::make_unique<SARIFDiagnostic>(OS, LO, DiagOpts, &*Writer);
|
||||
// Initialize the SARIF object.
|
||||
Writer->createRun("clang", Prefix);
|
||||
}
|
||||
@ -72,7 +72,6 @@ void SARIFDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
|
||||
}
|
||||
|
||||
// Assert that the rest of our infrastructure is setup properly.
|
||||
assert(DiagOpts && "Unexpected diagnostic without options set");
|
||||
assert(Info.hasSourceManager() &&
|
||||
"Unexpected diagnostic with no source manager");
|
||||
|
||||
|
@ -57,8 +57,8 @@ class SDiagsRenderer : public DiagnosticNoteRenderer {
|
||||
SDiagsWriter &Writer;
|
||||
public:
|
||||
SDiagsRenderer(SDiagsWriter &Writer, const LangOptions &LangOpts,
|
||||
DiagnosticOptions *DiagOpts)
|
||||
: DiagnosticNoteRenderer(LangOpts, DiagOpts), Writer(Writer) {}
|
||||
DiagnosticOptions &DiagOpts)
|
||||
: DiagnosticNoteRenderer(LangOpts, DiagOpts), Writer(Writer) {}
|
||||
|
||||
~SDiagsRenderer() override {}
|
||||
|
||||
@ -140,7 +140,7 @@ class SDiagsWriter : public DiagnosticConsumer {
|
||||
State(std::move(State)) {}
|
||||
|
||||
public:
|
||||
SDiagsWriter(StringRef File, DiagnosticOptions *Diags, bool MergeChildRecords)
|
||||
SDiagsWriter(StringRef File, DiagnosticOptions &Diags, bool MergeChildRecords)
|
||||
: LangOpts(nullptr), OriginalInstance(true),
|
||||
MergeChildRecords(MergeChildRecords),
|
||||
State(std::make_shared<SharedState>(File, Diags)) {
|
||||
@ -242,12 +242,12 @@ private:
|
||||
/// State that is shared among the various clones of this diagnostic
|
||||
/// consumer.
|
||||
struct SharedState {
|
||||
SharedState(StringRef File, DiagnosticOptions *Diags)
|
||||
: DiagOpts(Diags), Stream(Buffer), OutputFile(File.str()),
|
||||
SharedState(StringRef File, DiagnosticOptions &DiagOpts)
|
||||
: DiagOpts(DiagOpts), Stream(Buffer), OutputFile(File.str()),
|
||||
EmittedAnyDiagBlocks(false) {}
|
||||
|
||||
/// Diagnostic options.
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
|
||||
DiagnosticOptions DiagOpts;
|
||||
|
||||
/// The byte buffer for the serialized content.
|
||||
SmallString<1024> Buffer;
|
||||
@ -295,9 +295,11 @@ private:
|
||||
|
||||
namespace clang {
|
||||
namespace serialized_diags {
|
||||
std::unique_ptr<DiagnosticConsumer>
|
||||
create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords) {
|
||||
return std::make_unique<SDiagsWriter>(OutputFile, Diags, MergeChildRecords);
|
||||
std::unique_ptr<DiagnosticConsumer> create(StringRef OutputFile,
|
||||
DiagnosticOptions &DiagOpts,
|
||||
bool MergeChildRecords) {
|
||||
return std::make_unique<SDiagsWriter>(OutputFile, DiagOpts,
|
||||
MergeChildRecords);
|
||||
}
|
||||
|
||||
} // end namespace serialized_diags
|
||||
@ -617,7 +619,7 @@ void SDiagsWriter::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
|
||||
|
||||
assert(Info.hasSourceManager() && LangOpts &&
|
||||
"Unexpected diagnostic with valid location outside of a source file");
|
||||
SDiagsRenderer Renderer(*this, *LangOpts, &*State->DiagOpts);
|
||||
SDiagsRenderer Renderer(*this, *LangOpts, State->DiagOpts);
|
||||
Renderer.emitDiagnostic(
|
||||
FullSourceLoc(Info.getLocation(), Info.getSourceManager()), DiagLevel,
|
||||
State->diagBuf, Info.getRanges(), Info.getFixItHints(), &Info);
|
||||
@ -755,10 +757,9 @@ DiagnosticsEngine *SDiagsWriter::getMetaDiags() {
|
||||
// normally not be used.
|
||||
if (!State->MetaDiagnostics) {
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> IDs(new DiagnosticIDs());
|
||||
auto Client =
|
||||
new TextDiagnosticPrinter(llvm::errs(), State->DiagOpts.get());
|
||||
State->MetaDiagnostics = std::make_unique<DiagnosticsEngine>(
|
||||
IDs, State->DiagOpts.get(), Client);
|
||||
auto Client = new TextDiagnosticPrinter(llvm::errs(), State->DiagOpts);
|
||||
State->MetaDiagnostics =
|
||||
std::make_unique<DiagnosticsEngine>(IDs, State->DiagOpts, Client);
|
||||
}
|
||||
return State->MetaDiagnostics.get();
|
||||
}
|
||||
|
@ -654,7 +654,7 @@ static bool printWordWrapped(raw_ostream &OS, StringRef Str, unsigned Columns,
|
||||
}
|
||||
|
||||
TextDiagnostic::TextDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
|
||||
DiagnosticOptions *DiagOpts,
|
||||
DiagnosticOptions &DiagOpts,
|
||||
const Preprocessor *PP)
|
||||
: DiagnosticRenderer(LangOpts, DiagOpts), OS(OS), PP(PP) {}
|
||||
|
||||
@ -670,15 +670,15 @@ void TextDiagnostic::emitDiagnosticMessage(
|
||||
if (Loc.isValid())
|
||||
emitDiagnosticLoc(Loc, PLoc, Level, Ranges);
|
||||
|
||||
if (DiagOpts->ShowColors)
|
||||
if (DiagOpts.ShowColors)
|
||||
OS.resetColor();
|
||||
|
||||
if (DiagOpts->ShowLevel)
|
||||
printDiagnosticLevel(OS, Level, DiagOpts->ShowColors);
|
||||
if (DiagOpts.ShowLevel)
|
||||
printDiagnosticLevel(OS, Level, DiagOpts.ShowColors);
|
||||
printDiagnosticMessage(OS,
|
||||
/*IsSupplemental*/ Level == DiagnosticsEngine::Note,
|
||||
Message, OS.tell() - StartOfLocationInfo,
|
||||
DiagOpts->MessageLength, DiagOpts->ShowColors);
|
||||
DiagOpts.MessageLength, DiagOpts.ShowColors);
|
||||
}
|
||||
|
||||
/*static*/ void
|
||||
@ -743,7 +743,7 @@ void TextDiagnostic::emitFilename(StringRef Filename, const SourceManager &SM) {
|
||||
#ifdef _WIN32
|
||||
SmallString<4096> TmpFilename;
|
||||
#endif
|
||||
if (DiagOpts->AbsolutePath) {
|
||||
if (DiagOpts.AbsolutePath) {
|
||||
auto File = SM.getFileManager().getOptionalFileRef(Filename);
|
||||
if (File) {
|
||||
// We want to print a simplified absolute path, i. e. without "dots".
|
||||
@ -796,27 +796,27 @@ void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
|
||||
}
|
||||
unsigned LineNo = PLoc.getLine();
|
||||
|
||||
if (!DiagOpts->ShowLocation)
|
||||
if (!DiagOpts.ShowLocation)
|
||||
return;
|
||||
|
||||
if (DiagOpts->ShowColors)
|
||||
if (DiagOpts.ShowColors)
|
||||
OS.changeColor(savedColor, true);
|
||||
|
||||
emitFilename(PLoc.getFilename(), Loc.getManager());
|
||||
switch (DiagOpts->getFormat()) {
|
||||
switch (DiagOpts.getFormat()) {
|
||||
case DiagnosticOptions::SARIF:
|
||||
case DiagnosticOptions::Clang:
|
||||
if (DiagOpts->ShowLine)
|
||||
if (DiagOpts.ShowLine)
|
||||
OS << ':' << LineNo;
|
||||
break;
|
||||
case DiagnosticOptions::MSVC: OS << '(' << LineNo; break;
|
||||
case DiagnosticOptions::Vi: OS << " +" << LineNo; break;
|
||||
}
|
||||
|
||||
if (DiagOpts->ShowColumn)
|
||||
if (DiagOpts.ShowColumn)
|
||||
// Compute the column number.
|
||||
if (unsigned ColNo = PLoc.getColumn()) {
|
||||
if (DiagOpts->getFormat() == DiagnosticOptions::MSVC) {
|
||||
if (DiagOpts.getFormat() == DiagnosticOptions::MSVC) {
|
||||
OS << ',';
|
||||
// Visual Studio 2010 or earlier expects column number to be off by one
|
||||
if (LangOpts.MSCompatibilityVersion &&
|
||||
@ -826,7 +826,7 @@ void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
|
||||
OS << ':';
|
||||
OS << ColNo;
|
||||
}
|
||||
switch (DiagOpts->getFormat()) {
|
||||
switch (DiagOpts.getFormat()) {
|
||||
case DiagnosticOptions::SARIF:
|
||||
case DiagnosticOptions::Clang:
|
||||
case DiagnosticOptions::Vi: OS << ':'; break;
|
||||
@ -841,7 +841,7 @@ void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
|
||||
break;
|
||||
}
|
||||
|
||||
if (DiagOpts->ShowSourceRanges && !Ranges.empty()) {
|
||||
if (DiagOpts.ShowSourceRanges && !Ranges.empty()) {
|
||||
FileID CaretFileID = Loc.getExpansionLoc().getFileID();
|
||||
bool PrintedRange = false;
|
||||
const SourceManager &SM = Loc.getManager();
|
||||
@ -881,7 +881,7 @@ void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
|
||||
}
|
||||
|
||||
void TextDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) {
|
||||
if (DiagOpts->ShowLocation && PLoc.isValid()) {
|
||||
if (DiagOpts.ShowLocation && PLoc.isValid()) {
|
||||
OS << "In file included from ";
|
||||
emitFilename(PLoc.getFilename(), Loc.getManager());
|
||||
OS << ':' << PLoc.getLine() << ":\n";
|
||||
@ -891,7 +891,7 @@ void TextDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) {
|
||||
|
||||
void TextDiagnostic::emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
|
||||
StringRef ModuleName) {
|
||||
if (DiagOpts->ShowLocation && PLoc.isValid())
|
||||
if (DiagOpts.ShowLocation && PLoc.isValid())
|
||||
OS << "In module '" << ModuleName << "' imported from "
|
||||
<< PLoc.getFilename() << ':' << PLoc.getLine() << ":\n";
|
||||
else
|
||||
@ -901,7 +901,7 @@ void TextDiagnostic::emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
|
||||
void TextDiagnostic::emitBuildingModuleLocation(FullSourceLoc Loc,
|
||||
PresumedLoc PLoc,
|
||||
StringRef ModuleName) {
|
||||
if (DiagOpts->ShowLocation && PLoc.isValid())
|
||||
if (DiagOpts.ShowLocation && PLoc.isValid())
|
||||
OS << "While building module '" << ModuleName << "' imported from "
|
||||
<< PLoc.getFilename() << ':' << PLoc.getLine() << ":\n";
|
||||
else
|
||||
@ -998,14 +998,13 @@ static void highlightRange(const LineRange &R, const SourceColumnMap &Map,
|
||||
std::fill(CaretLine.begin() + StartColNo, CaretLine.begin() + EndColNo, '~');
|
||||
}
|
||||
|
||||
static std::string buildFixItInsertionLine(FileID FID,
|
||||
unsigned LineNo,
|
||||
static std::string buildFixItInsertionLine(FileID FID, unsigned LineNo,
|
||||
const SourceColumnMap &map,
|
||||
ArrayRef<FixItHint> Hints,
|
||||
const SourceManager &SM,
|
||||
const DiagnosticOptions *DiagOpts) {
|
||||
const DiagnosticOptions &DiagOpts) {
|
||||
std::string FixItInsertionLine;
|
||||
if (Hints.empty() || !DiagOpts->ShowFixits)
|
||||
if (Hints.empty() || !DiagOpts.ShowFixits)
|
||||
return FixItInsertionLine;
|
||||
unsigned PrevHintEndCol = 0;
|
||||
|
||||
@ -1057,7 +1056,7 @@ static std::string buildFixItInsertionLine(FileID FID,
|
||||
}
|
||||
}
|
||||
|
||||
expandTabs(FixItInsertionLine, DiagOpts->TabStop);
|
||||
expandTabs(FixItInsertionLine, DiagOpts.TabStop);
|
||||
|
||||
return FixItInsertionLine;
|
||||
}
|
||||
@ -1296,7 +1295,7 @@ void TextDiagnostic::emitSnippetAndCaret(
|
||||
// was part of a different warning or error diagnostic, or if the
|
||||
// diagnostic has ranges. We don't want to emit the same caret
|
||||
// multiple times if one loc has multiple diagnostics.
|
||||
if (!DiagOpts->ShowCarets)
|
||||
if (!DiagOpts.ShowCarets)
|
||||
return;
|
||||
if (Loc == LastLoc && Ranges.empty() && Hints.empty() &&
|
||||
(LastLevel != DiagnosticsEngine::Note || Level == LastLevel))
|
||||
@ -1322,7 +1321,7 @@ void TextDiagnostic::emitSnippetAndCaret(
|
||||
return;
|
||||
|
||||
// Find the set of lines to include.
|
||||
const unsigned MaxLines = DiagOpts->SnippetLineLimit;
|
||||
const unsigned MaxLines = DiagOpts.SnippetLineLimit;
|
||||
std::pair<unsigned, unsigned> Lines = {CaretLineNo, CaretLineNo};
|
||||
unsigned DisplayLineNo = Loc.getPresumedLoc().getLine();
|
||||
for (const auto &I : Ranges) {
|
||||
@ -1338,7 +1337,7 @@ void TextDiagnostic::emitSnippetAndCaret(
|
||||
// Where [number] is MaxLineNoDisplayWidth columns
|
||||
// and the full thing is therefore MaxLineNoDisplayWidth + 4 columns.
|
||||
unsigned MaxLineNoDisplayWidth =
|
||||
DiagOpts->ShowLineNumbers
|
||||
DiagOpts.ShowLineNumbers
|
||||
? std::max(4u, getNumDisplayWidth(DisplayLineNo + MaxLines))
|
||||
: 0;
|
||||
auto indentForLineNumbers = [&] {
|
||||
@ -1350,7 +1349,7 @@ void TextDiagnostic::emitSnippetAndCaret(
|
||||
// emit, starting from the first line.
|
||||
std::unique_ptr<SmallVector<StyleRange>[]> SourceStyles =
|
||||
highlightLines(BufData, Lines.first, Lines.second, PP, LangOpts,
|
||||
DiagOpts->ShowColors, FID, SM);
|
||||
DiagOpts.ShowColors, FID, SM);
|
||||
|
||||
SmallVector<LineRange> LineRanges =
|
||||
prepareAndFilterRanges(Ranges, SM, Lines, FID, LangOpts);
|
||||
@ -1382,7 +1381,7 @@ void TextDiagnostic::emitSnippetAndCaret(
|
||||
SourceLine.pop_back();
|
||||
|
||||
// Build the byte to column map.
|
||||
const SourceColumnMap sourceColMap(SourceLine, DiagOpts->TabStop);
|
||||
const SourceColumnMap sourceColMap(SourceLine, DiagOpts.TabStop);
|
||||
|
||||
std::string CaretLine;
|
||||
// Highlight all of the characters covered by Ranges with ~ characters.
|
||||
@ -1398,12 +1397,12 @@ void TextDiagnostic::emitSnippetAndCaret(
|
||||
CaretLine[Col] = '^';
|
||||
}
|
||||
|
||||
std::string FixItInsertionLine = buildFixItInsertionLine(
|
||||
FID, LineNo, sourceColMap, Hints, SM, DiagOpts.get());
|
||||
std::string FixItInsertionLine =
|
||||
buildFixItInsertionLine(FID, LineNo, sourceColMap, Hints, SM, DiagOpts);
|
||||
|
||||
// If the source line is too long for our terminal, select only the
|
||||
// "interesting" source region within that line.
|
||||
unsigned Columns = DiagOpts->MessageLength;
|
||||
unsigned Columns = DiagOpts.MessageLength;
|
||||
if (Columns)
|
||||
selectInterestingSourceRegion(SourceLine, CaretLine, FixItInsertionLine,
|
||||
Columns, sourceColMap);
|
||||
@ -1412,7 +1411,7 @@ void TextDiagnostic::emitSnippetAndCaret(
|
||||
// to produce easily machine parsable output. Add a space before the
|
||||
// source line and the caret to make it trivial to tell the main diagnostic
|
||||
// line from what the user is intended to see.
|
||||
if (DiagOpts->ShowSourceRanges && !SourceLine.empty()) {
|
||||
if (DiagOpts.ShowSourceRanges && !SourceLine.empty()) {
|
||||
SourceLine = ' ' + SourceLine;
|
||||
CaretLine = ' ' + CaretLine;
|
||||
}
|
||||
@ -1423,22 +1422,22 @@ void TextDiagnostic::emitSnippetAndCaret(
|
||||
|
||||
if (!CaretLine.empty()) {
|
||||
indentForLineNumbers();
|
||||
if (DiagOpts->ShowColors)
|
||||
if (DiagOpts.ShowColors)
|
||||
OS.changeColor(caretColor, true);
|
||||
OS << CaretLine << '\n';
|
||||
if (DiagOpts->ShowColors)
|
||||
if (DiagOpts.ShowColors)
|
||||
OS.resetColor();
|
||||
}
|
||||
|
||||
if (!FixItInsertionLine.empty()) {
|
||||
indentForLineNumbers();
|
||||
if (DiagOpts->ShowColors)
|
||||
if (DiagOpts.ShowColors)
|
||||
// Print fixit line in color
|
||||
OS.changeColor(fixitColor, false);
|
||||
if (DiagOpts->ShowSourceRanges)
|
||||
if (DiagOpts.ShowSourceRanges)
|
||||
OS << ' ';
|
||||
OS << FixItInsertionLine << '\n';
|
||||
if (DiagOpts->ShowColors)
|
||||
if (DiagOpts.ShowColors)
|
||||
OS.resetColor();
|
||||
}
|
||||
}
|
||||
@ -1464,10 +1463,10 @@ void TextDiagnostic::emitSnippet(StringRef SourceLine,
|
||||
size_t I = 0;
|
||||
while (I < SourceLine.size()) {
|
||||
auto [Str, WasPrintable] =
|
||||
printableTextForNextCharacter(SourceLine, &I, DiagOpts->TabStop);
|
||||
printableTextForNextCharacter(SourceLine, &I, DiagOpts.TabStop);
|
||||
|
||||
// Toggle inverted colors on or off for this character.
|
||||
if (DiagOpts->ShowColors) {
|
||||
if (DiagOpts.ShowColors) {
|
||||
if (WasPrintable == PrintReversed) {
|
||||
PrintReversed = !PrintReversed;
|
||||
if (PrintReversed)
|
||||
@ -1498,7 +1497,7 @@ void TextDiagnostic::emitSnippet(StringRef SourceLine,
|
||||
OS << Str;
|
||||
}
|
||||
|
||||
if (DiagOpts->ShowColors)
|
||||
if (DiagOpts.ShowColors)
|
||||
OS.resetColor();
|
||||
|
||||
OS << '\n';
|
||||
@ -1506,7 +1505,7 @@ void TextDiagnostic::emitSnippet(StringRef SourceLine,
|
||||
|
||||
void TextDiagnostic::emitParseableFixits(ArrayRef<FixItHint> Hints,
|
||||
const SourceManager &SM) {
|
||||
if (!DiagOpts->ShowParseableFixits)
|
||||
if (!DiagOpts.ShowParseableFixits)
|
||||
return;
|
||||
|
||||
// We follow FixItRewriter's example in not (yet) handling
|
||||
|
@ -22,11 +22,9 @@
|
||||
using namespace clang;
|
||||
|
||||
TextDiagnosticPrinter::TextDiagnosticPrinter(raw_ostream &os,
|
||||
DiagnosticOptions *diags,
|
||||
DiagnosticOptions &DiagOpts,
|
||||
bool _OwnsOutputStream)
|
||||
: OS(os), DiagOpts(diags),
|
||||
OwnsOutputStream(_OwnsOutputStream) {
|
||||
}
|
||||
: OS(os), DiagOpts(DiagOpts), OwnsOutputStream(_OwnsOutputStream) {}
|
||||
|
||||
TextDiagnosticPrinter::~TextDiagnosticPrinter() {
|
||||
if (OwnsOutputStream)
|
||||
@ -36,7 +34,7 @@ TextDiagnosticPrinter::~TextDiagnosticPrinter() {
|
||||
void TextDiagnosticPrinter::BeginSourceFile(const LangOptions &LO,
|
||||
const Preprocessor *PP) {
|
||||
// Build the TextDiagnostic utility.
|
||||
TextDiag.reset(new TextDiagnostic(OS, LO, &*DiagOpts, PP));
|
||||
TextDiag.reset(new TextDiagnostic(OS, LO, DiagOpts, PP));
|
||||
}
|
||||
|
||||
void TextDiagnosticPrinter::EndSourceFile() {
|
||||
@ -121,7 +119,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
|
||||
Info.FormatDiagnostic(OutStr);
|
||||
|
||||
llvm::raw_svector_ostream DiagMessageStream(OutStr);
|
||||
printDiagnosticOptions(DiagMessageStream, Level, Info, *DiagOpts);
|
||||
printDiagnosticOptions(DiagMessageStream, Level, Info, DiagOpts);
|
||||
|
||||
// Keeps track of the starting position of the location
|
||||
// information (e.g., "foo.c:10:4:") that precedes the error
|
||||
@ -137,17 +135,16 @@ void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
|
||||
// diagnostics in a context that lacks language options, a source manager, or
|
||||
// other infrastructure necessary when emitting more rich diagnostics.
|
||||
if (!Info.getLocation().isValid()) {
|
||||
TextDiagnostic::printDiagnosticLevel(OS, Level, DiagOpts->ShowColors);
|
||||
TextDiagnostic::printDiagnosticLevel(OS, Level, DiagOpts.ShowColors);
|
||||
TextDiagnostic::printDiagnosticMessage(
|
||||
OS, /*IsSupplemental=*/Level == DiagnosticsEngine::Note,
|
||||
DiagMessageStream.str(), OS.tell() - StartOfLocationInfo,
|
||||
DiagOpts->MessageLength, DiagOpts->ShowColors);
|
||||
DiagOpts.MessageLength, DiagOpts.ShowColors);
|
||||
OS.flush();
|
||||
return;
|
||||
}
|
||||
|
||||
// Assert that the rest of our infrastructure is setup properly.
|
||||
assert(DiagOpts && "Unexpected diagnostic without options set");
|
||||
assert(Info.hasSourceManager() &&
|
||||
"Unexpected diagnostic with no source manager");
|
||||
assert(TextDiag && "Unexpected diagnostic outside source file processing");
|
||||
|
@ -359,13 +359,12 @@ void ReplCodeCompleter::codeComplete(CompilerInstance *InterpCI,
|
||||
unsigned Col,
|
||||
const CompilerInstance *ParentCI,
|
||||
std::vector<std::string> &CCResults) {
|
||||
auto DiagOpts = DiagnosticOptions();
|
||||
auto consumer = ReplCompletionConsumer(CCResults, *this);
|
||||
|
||||
auto diag = InterpCI->getDiagnosticsPtr();
|
||||
std::unique_ptr<ASTUnit> AU(ASTUnit::LoadFromCompilerInvocationAction(
|
||||
InterpCI->getInvocationPtr(), std::make_shared<PCHContainerOperations>(),
|
||||
diag));
|
||||
nullptr, diag));
|
||||
llvm::SmallVector<clang::StoredDiagnostic, 8> sd = {};
|
||||
llvm::SmallVector<const llvm::MemoryBuffer *, 1> tb = {};
|
||||
InterpCI->getFrontendOpts().Inputs[0] = FrontendInputFile(
|
||||
|
@ -95,9 +95,9 @@ CreateCI(const llvm::opt::ArgStringList &Argv) {
|
||||
|
||||
// Buffer diagnostics from argument parsing so that we can output them using
|
||||
// a well formed diagnostic object.
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, DiagsBuffer);
|
||||
bool Success = CompilerInvocation::CreateFromArgs(
|
||||
Clang->getInvocation(), llvm::ArrayRef(Argv.begin(), Argv.size()), Diags);
|
||||
|
||||
@ -173,10 +173,10 @@ IncrementalCompilerBuilder::create(std::string TT,
|
||||
// Buffer diagnostics from argument parsing so that we can output them using a
|
||||
// well formed diagnostic object.
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts =
|
||||
std::unique_ptr<DiagnosticOptions> DiagOpts =
|
||||
CreateAndPopulateDiagOpts(ClangArgv);
|
||||
TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer);
|
||||
DiagnosticsEngine Diags(DiagID, *DiagOpts, DiagsBuffer);
|
||||
|
||||
driver::Driver Driver(/*MainBinaryName=*/ClangArgv[0], TT, Diags);
|
||||
Driver.setCheckInputsExist(false); // the input comes from mem buffers
|
||||
|
@ -636,8 +636,8 @@ static void HighlightMacrosImpl(
|
||||
// Temporarily change the diagnostics object so that we ignore any generated
|
||||
// diagnostics from this pass.
|
||||
DiagnosticsEngine TmpDiags(PP.getDiagnostics().getDiagnosticIDs(),
|
||||
&PP.getDiagnostics().getDiagnosticOptions(),
|
||||
new IgnoringDiagConsumer);
|
||||
PP.getDiagnostics().getDiagnosticOptions(),
|
||||
new IgnoringDiagConsumer);
|
||||
|
||||
// FIXME: This is a huge hack; we reuse the input preprocessor because we want
|
||||
// its state, but we aren't actually changing it (we hope). This should really
|
||||
|
@ -193,8 +193,7 @@ bool ChainedASTReaderListener::ReadTargetOptions(
|
||||
}
|
||||
|
||||
bool ChainedASTReaderListener::ReadDiagnosticOptions(
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, StringRef ModuleFilename,
|
||||
bool Complain) {
|
||||
DiagnosticOptions &DiagOpts, StringRef ModuleFilename, bool Complain) {
|
||||
return First->ReadDiagnosticOptions(DiagOpts, ModuleFilename, Complain) ||
|
||||
Second->ReadDiagnosticOptions(DiagOpts, ModuleFilename, Complain);
|
||||
}
|
||||
@ -595,16 +594,16 @@ static Module *getTopImportImplicitModule(ModuleManager &ModuleMgr,
|
||||
return M;
|
||||
}
|
||||
|
||||
bool PCHValidator::ReadDiagnosticOptions(
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, StringRef ModuleFilename,
|
||||
bool Complain) {
|
||||
bool PCHValidator::ReadDiagnosticOptions(DiagnosticOptions &DiagOpts,
|
||||
StringRef ModuleFilename,
|
||||
bool Complain) {
|
||||
DiagnosticsEngine &ExistingDiags = PP.getDiagnostics();
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(ExistingDiags.getDiagnosticIDs());
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
|
||||
new DiagnosticsEngine(DiagIDs, DiagOpts.get()));
|
||||
new DiagnosticsEngine(DiagIDs, DiagOpts));
|
||||
// This should never fail, because we would have processed these options
|
||||
// before writing them to an ASTFile.
|
||||
ProcessWarningOptions(*Diags, *DiagOpts,
|
||||
ProcessWarningOptions(*Diags, DiagOpts,
|
||||
PP.getFileManager().getVirtualFileSystem(),
|
||||
/*Report*/ false);
|
||||
|
||||
@ -6422,17 +6421,17 @@ bool ASTReader::ParseTargetOptions(const RecordData &Record,
|
||||
bool ASTReader::ParseDiagnosticOptions(const RecordData &Record,
|
||||
StringRef ModuleFilename, bool Complain,
|
||||
ASTReaderListener &Listener) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions);
|
||||
DiagnosticOptions DiagOpts;
|
||||
unsigned Idx = 0;
|
||||
#define DIAGOPT(Name, Bits, Default) DiagOpts->Name = Record[Idx++];
|
||||
#define ENUM_DIAGOPT(Name, Type, Bits, Default) \
|
||||
DiagOpts->set##Name(static_cast<Type>(Record[Idx++]));
|
||||
#define DIAGOPT(Name, Bits, Default) DiagOpts.Name = Record[Idx++];
|
||||
#define ENUM_DIAGOPT(Name, Type, Bits, Default) \
|
||||
DiagOpts.set##Name(static_cast<Type>(Record[Idx++]));
|
||||
#include "clang/Basic/DiagnosticOptions.def"
|
||||
|
||||
for (unsigned N = Record[Idx++]; N; --N)
|
||||
DiagOpts->Warnings.push_back(ReadString(Record, Idx));
|
||||
DiagOpts.Warnings.push_back(ReadString(Record, Idx));
|
||||
for (unsigned N = Record[Idx++]; N; --N)
|
||||
DiagOpts->Remarks.push_back(ReadString(Record, Idx));
|
||||
DiagOpts.Remarks.push_back(ReadString(Record, Idx));
|
||||
|
||||
return Listener.ReadDiagnosticOptions(DiagOpts, ModuleFilename, Complain);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
std::string Text;
|
||||
llvm::raw_string_ostream OS(Text);
|
||||
TextDiagnostic Renderer(OS, LangOpts,
|
||||
&Info.getDiags()->getDiagnosticOptions());
|
||||
Info.getDiags()->getDiagnosticOptions());
|
||||
Renderer.emitStoredDiagnostic(Out.back());
|
||||
ADD_FAILURE() << Text;
|
||||
}
|
||||
|
@ -243,13 +243,13 @@ std::string GetClangToolCommand() {
|
||||
static bool stripPositionalArgs(std::vector<const char *> Args,
|
||||
std::vector<std::string> &Result,
|
||||
std::string &ErrorMsg) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
llvm::raw_string_ostream Output(ErrorMsg);
|
||||
TextDiagnosticPrinter DiagnosticPrinter(Output, &*DiagOpts);
|
||||
TextDiagnosticPrinter DiagnosticPrinter(Output, DiagOpts);
|
||||
UnusedInputDiagConsumer DiagClient(DiagnosticPrinter);
|
||||
DiagnosticsEngine Diagnostics(
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()),
|
||||
&*DiagOpts, &DiagClient, false);
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts,
|
||||
&DiagClient, false);
|
||||
|
||||
// The clang executable path isn't required since the jobs the driver builds
|
||||
// will not be executed.
|
||||
|
@ -585,9 +585,9 @@ llvm::Expected<std::string> applyAllReplacements(StringRef Code,
|
||||
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
|
||||
new llvm::vfs::InMemoryFileSystem);
|
||||
FileManager Files(FileSystemOptions(), InMemoryFileSystem);
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diagnostics(
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),
|
||||
new DiagnosticOptions);
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), DiagOpts);
|
||||
SourceManager SourceMgr(Diagnostics, Files);
|
||||
Rewriter Rewrite(SourceMgr, LangOptions());
|
||||
InMemoryFileSystem->addFile(
|
||||
|
@ -642,7 +642,7 @@ llvm::Error DependencyScanningWorker::computeDependencies(
|
||||
std::string DiagnosticOutput;
|
||||
llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
|
||||
auto DiagOpts = createDiagOptions(CommandLine);
|
||||
TextDiagnosticPrinter DiagPrinter(DiagnosticsOS, DiagOpts.release());
|
||||
TextDiagnosticPrinter DiagPrinter(DiagnosticsOS, *DiagOpts);
|
||||
|
||||
if (computeDependencies(WorkingDirectory, CommandLine, Consumer, Controller,
|
||||
DiagPrinter, TUBuffer))
|
||||
@ -660,7 +660,7 @@ llvm::Error DependencyScanningWorker::computeDependencies(
|
||||
std::string DiagnosticOutput;
|
||||
llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
|
||||
auto DiagOpts = createDiagOptions(CommandLine);
|
||||
TextDiagnosticPrinter DiagPrinter(DiagnosticsOS, DiagOpts.release());
|
||||
TextDiagnosticPrinter DiagPrinter(DiagnosticsOS, *DiagOpts);
|
||||
|
||||
if (computeDependencies(WorkingDirectory, CommandLine, Consumer, Controller,
|
||||
DiagPrinter, ModuleName))
|
||||
@ -744,7 +744,7 @@ bool DependencyScanningWorker::scanDependencies(
|
||||
sanitizeDiagOpts(*DiagOpts);
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
|
||||
CompilerInstance::createDiagnostics(FileMgr->getVirtualFileSystem(),
|
||||
DiagOpts.release(), &DC,
|
||||
*DiagOpts, &DC,
|
||||
/*ShouldOwnClient=*/false);
|
||||
|
||||
// Although `Diagnostics` are used only for command-line parsing, the
|
||||
|
@ -39,11 +39,11 @@ int RefactoringTool::runAndSave(FrontendActionFactory *ActionFactory) {
|
||||
}
|
||||
|
||||
LangOptions DefaultLangOptions;
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), &*DiagOpts);
|
||||
DiagnosticOptions DiagOpts;
|
||||
TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), DiagOpts);
|
||||
DiagnosticsEngine Diagnostics(
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()),
|
||||
&*DiagOpts, &DiagnosticPrinter, false);
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts,
|
||||
&DiagnosticPrinter, false);
|
||||
SourceManager Sources(Diagnostics, getFiles());
|
||||
Rewriter Rewrite(Sources, DefaultLangOptions);
|
||||
|
||||
|
@ -377,17 +377,17 @@ bool ToolInvocation::run() {
|
||||
|
||||
// Parse diagnostic options from the driver command-line only if none were
|
||||
// explicitly set.
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> ParsedDiagOpts;
|
||||
std::unique_ptr<DiagnosticOptions> ParsedDiagOpts;
|
||||
DiagnosticOptions *DiagOpts = this->DiagOpts;
|
||||
if (!DiagOpts) {
|
||||
ParsedDiagOpts = CreateAndPopulateDiagOpts(Argv);
|
||||
DiagOpts = &*ParsedDiagOpts;
|
||||
}
|
||||
|
||||
TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), DiagOpts);
|
||||
TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), *DiagOpts);
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics =
|
||||
CompilerInstance::createDiagnostics(
|
||||
Files->getVirtualFileSystem(), &*DiagOpts,
|
||||
Files->getVirtualFileSystem(), *DiagOpts,
|
||||
DiagConsumer ? DiagConsumer : &DiagnosticPrinter, false);
|
||||
// Although `Diagnostics` are used only for command-line parsing, the custom
|
||||
// `DiagConsumer` might expect a `SourceManager` to be present.
|
||||
@ -652,9 +652,9 @@ public:
|
||||
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
|
||||
DiagnosticConsumer *DiagConsumer) override {
|
||||
std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromCompilerInvocation(
|
||||
Invocation, std::move(PCHContainerOps),
|
||||
Invocation, std::move(PCHContainerOps), nullptr,
|
||||
CompilerInstance::createDiagnostics(Files->getVirtualFileSystem(),
|
||||
&Invocation->getDiagnosticOpts(),
|
||||
Invocation->getDiagnosticOpts(),
|
||||
DiagConsumer,
|
||||
/*ShouldOwnClient=*/false),
|
||||
Files);
|
||||
|
@ -220,9 +220,10 @@ static bool printSourceSymbols(const char *Executable,
|
||||
SmallVector<const char *, 4> ArgsWithProgName;
|
||||
ArgsWithProgName.push_back(Executable);
|
||||
ArgsWithProgName.append(Args.begin(), Args.end());
|
||||
auto DiagOpts = std::make_shared<DiagnosticOptions>();
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
|
||||
CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(),
|
||||
new DiagnosticOptions));
|
||||
*DiagOpts));
|
||||
CreateInvocationOptions CIOpts;
|
||||
CIOpts.Diags = Diags;
|
||||
CIOpts.ProbePrecompiled = true; // FIXME: historical default. Needed?
|
||||
@ -241,7 +242,7 @@ static bool printSourceSymbols(const char *Executable,
|
||||
|
||||
auto PCHContainerOps = std::make_shared<PCHContainerOperations>();
|
||||
std::unique_ptr<ASTUnit> Unit(ASTUnit::LoadFromCompilerInvocationAction(
|
||||
std::move(CInvok), PCHContainerOps, Diags, IndexAction.get()));
|
||||
std::move(CInvok), PCHContainerOps, DiagOpts, Diags, IndexAction.get()));
|
||||
|
||||
if (!Unit)
|
||||
return true;
|
||||
@ -274,15 +275,16 @@ static bool printSourceSymbolsFromModule(StringRef modulePath,
|
||||
|
||||
HeaderSearchOptions HSOpts;
|
||||
|
||||
auto DiagOpts = std::make_shared<DiagnosticOptions>();
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
|
||||
CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(),
|
||||
new DiagnosticOptions());
|
||||
std::unique_ptr<ASTUnit> AU =
|
||||
ASTUnit::LoadFromASTFile(modulePath, *pchRdr, ASTUnit::LoadASTOnly, Diags,
|
||||
FileSystemOpts, HSOpts, /*LangOpts=*/nullptr,
|
||||
/*OnlyLocalDecls=*/true, CaptureDiagsKind::None,
|
||||
/*AllowASTWithCompilerErrors=*/true,
|
||||
/*UserFilesAreVolatile=*/false);
|
||||
*DiagOpts);
|
||||
std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
|
||||
modulePath, *pchRdr, ASTUnit::LoadASTOnly, DiagOpts, Diags,
|
||||
FileSystemOpts, HSOpts, /*LangOpts=*/nullptr,
|
||||
/*OnlyLocalDecls=*/true, CaptureDiagsKind::None,
|
||||
/*AllowASTWithCompilerErrors=*/true,
|
||||
/*UserFilesAreVolatile=*/false);
|
||||
if (!AU) {
|
||||
errs() << "failed to create TU for: " << modulePath << '\n';
|
||||
return true;
|
||||
|
@ -123,21 +123,21 @@ static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
|
||||
|
||||
static IntrusiveRefCntPtr<DiagnosticsEngine> Diags;
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> GetDiagnosticsEngine() {
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine>
|
||||
GetDiagnosticsEngine(DiagnosticOptions &DiagOpts) {
|
||||
if (Diags) {
|
||||
// Call reset to make sure we don't mix errors
|
||||
Diags->Reset(false);
|
||||
return Diags;
|
||||
}
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
TextDiagnosticPrinter *DiagClient =
|
||||
new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
|
||||
new TextDiagnosticPrinter(llvm::errs(), DiagOpts);
|
||||
DiagClient->setPrefix("clang-extdef-mappping");
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> DiagEngine(
|
||||
new DiagnosticsEngine(DiagID, &*DiagOpts, DiagClient));
|
||||
new DiagnosticsEngine(DiagID, DiagOpts, DiagClient));
|
||||
Diags.swap(DiagEngine);
|
||||
|
||||
// Retain this one time so it's not destroyed by ASTUnit::LoadFromASTFile
|
||||
@ -152,11 +152,13 @@ static bool HandleAST(StringRef AstPath) {
|
||||
if (!CI)
|
||||
CI = new CompilerInstance();
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> DiagEngine = GetDiagnosticsEngine();
|
||||
auto DiagOpts = std::make_shared<DiagnosticOptions>();
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> DiagEngine =
|
||||
GetDiagnosticsEngine(*DiagOpts);
|
||||
|
||||
std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromASTFile(
|
||||
AstPath, CI->getPCHContainerOperations()->getRawReader(),
|
||||
ASTUnit::LoadASTOnly, DiagEngine, CI->getFileSystemOpts(),
|
||||
ASTUnit::LoadASTOnly, DiagOpts, DiagEngine, CI->getFileSystemOpts(),
|
||||
CI->getHeaderSearchOpts());
|
||||
|
||||
if (!Unit)
|
||||
|
@ -240,9 +240,9 @@ static bool fillRanges(MemoryBuffer *Code,
|
||||
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
|
||||
new llvm::vfs::InMemoryFileSystem);
|
||||
FileManager Files(FileSystemOptions(), InMemoryFileSystem);
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diagnostics(
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),
|
||||
new DiagnosticOptions);
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), DiagOpts);
|
||||
SourceManager Sources(Diagnostics, Files);
|
||||
FileID ID = createInMemoryFile("<irrelevant>", *Code, Sources, Files,
|
||||
InMemoryFileSystem.get());
|
||||
@ -519,10 +519,10 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
|
||||
new llvm::vfs::InMemoryFileSystem);
|
||||
FileManager Files(FileSystemOptions(), InMemoryFileSystem);
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
|
||||
DiagnosticOptions DiagOpts;
|
||||
ClangFormatDiagConsumer IgnoreDiagnostics;
|
||||
DiagnosticsEngine Diagnostics(
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), &*DiagOpts,
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), DiagOpts,
|
||||
&IgnoreDiagnostics, false);
|
||||
SourceManager Sources(Diagnostics, Files);
|
||||
FileID ID = createInMemoryFile(AssumedFileName, *Code, Sources, Files,
|
||||
|
@ -162,10 +162,10 @@ private:
|
||||
};
|
||||
|
||||
std::unique_ptr<CompilerInstance> BuildCompilerInstance() {
|
||||
auto DiagOpts = llvm::makeIntrusiveRefCnt<DiagnosticOptions>();
|
||||
DiagnosticOptions DiagOpts;
|
||||
auto DC = std::make_unique<TestDiagnosticConsumer>();
|
||||
auto Diags = CompilerInstance::createDiagnostics(
|
||||
*llvm::vfs::getRealFileSystem(), DiagOpts.get(), DC.get(),
|
||||
*llvm::vfs::getRealFileSystem(), DiagOpts, DC.get(),
|
||||
/*ShouldOwnClient=*/false);
|
||||
|
||||
auto Inv = std::make_unique<CompilerInvocation>();
|
||||
|
@ -70,16 +70,16 @@ static bool runFrontend(StringRef ProgName, Twine Label, bool Verbose,
|
||||
|
||||
static bool run(ArrayRef<const char *> Args, const char *ProgName) {
|
||||
// Setup Diagnostics engine.
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
const llvm::opt::OptTable &ClangOpts = clang::driver::getDriverOptTable();
|
||||
unsigned MissingArgIndex, MissingArgCount;
|
||||
llvm::opt::InputArgList ParsedArgs = ClangOpts.ParseArgs(
|
||||
ArrayRef(Args).slice(1), MissingArgIndex, MissingArgCount);
|
||||
ParseDiagnosticArgs(*DiagOpts, ParsedArgs);
|
||||
ParseDiagnosticArgs(DiagOpts, ParsedArgs);
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diag = new clang::DiagnosticsEngine(
|
||||
new clang::DiagnosticIDs(), DiagOpts.get(),
|
||||
new clang::TextDiagnosticPrinter(llvm::errs(), DiagOpts.get()));
|
||||
new clang::DiagnosticIDs(), DiagOpts,
|
||||
new clang::TextDiagnosticPrinter(llvm::errs(), DiagOpts));
|
||||
|
||||
// Create file manager for all file operations and holding in-memory generated
|
||||
// inputs.
|
||||
|
@ -452,11 +452,11 @@ public:
|
||||
// Returns \c true if any command lines fail to round-trip. We expect
|
||||
// commands already be canonical when output by the scanner.
|
||||
bool roundTripCommands(raw_ostream &ErrOS) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions{};
|
||||
TextDiagnosticPrinter DiagConsumer(ErrOS, &*DiagOpts);
|
||||
DiagnosticOptions DiagOpts;
|
||||
TextDiagnosticPrinter DiagConsumer(ErrOS, DiagOpts);
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
|
||||
CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(),
|
||||
&*DiagOpts, &DiagConsumer,
|
||||
DiagOpts, &DiagConsumer,
|
||||
/*ShouldOwnClient=*/false);
|
||||
|
||||
for (auto &&M : Modules)
|
||||
@ -779,9 +779,10 @@ getCompilationDatabase(int argc, char **argv, std::string &ErrorMessage) {
|
||||
CompilationDB, ErrorMessage,
|
||||
tooling::JSONCommandLineSyntax::AutoDetect);
|
||||
|
||||
DiagnosticOptions DiagOpts;
|
||||
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
|
||||
CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(),
|
||||
new DiagnosticOptions);
|
||||
DiagOpts);
|
||||
driver::Driver TheDriver(CommandLine[0], llvm::sys::getDefaultTargetTriple(),
|
||||
*Diags);
|
||||
TheDriver.setCheckInputsExist(false);
|
||||
|
@ -56,6 +56,7 @@ static char getCharForLevel(DiagnosticsEngine::Level Level) {
|
||||
static IntrusiveRefCntPtr<DiagnosticsEngine>
|
||||
createDiagnostics(unsigned int argc, char **argv) {
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(new DiagnosticIDs());
|
||||
DiagnosticOptions DiagOpts;
|
||||
|
||||
// Buffer diagnostics from argument parsing so that we can output them using a
|
||||
// well formed diagnostic object.
|
||||
@ -66,8 +67,7 @@ createDiagnostics(unsigned int argc, char **argv) {
|
||||
Args.push_back("diagtool");
|
||||
Args.append(argv, argv + argc);
|
||||
CreateInvocationOptions CIOpts;
|
||||
CIOpts.Diags =
|
||||
new DiagnosticsEngine(DiagIDs, new DiagnosticOptions(), DiagsBuffer);
|
||||
CIOpts.Diags = new DiagnosticsEngine(DiagIDs, DiagOpts, DiagsBuffer);
|
||||
std::unique_ptr<CompilerInvocation> Invocation =
|
||||
createInvocation(Args, CIOpts);
|
||||
if (!Invocation)
|
||||
@ -76,7 +76,7 @@ createDiagnostics(unsigned int argc, char **argv) {
|
||||
// Build the diagnostics parser
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> FinalDiags =
|
||||
CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(),
|
||||
&Invocation->getDiagnosticOpts());
|
||||
Invocation->getDiagnosticOpts());
|
||||
if (!FinalDiags)
|
||||
return nullptr;
|
||||
|
||||
|
@ -31,8 +31,8 @@ public:
|
||||
|
||||
static bool isIgnored(unsigned DiagID) {
|
||||
// FIXME: This feels like a hack.
|
||||
static clang::DiagnosticsEngine Diags(new DiagnosticIDs,
|
||||
new DiagnosticOptions);
|
||||
static DiagnosticOptions DiagOpts;
|
||||
static clang::DiagnosticsEngine Diags(new DiagnosticIDs, DiagOpts);
|
||||
return Diags.isIgnored(DiagID, SourceLocation());
|
||||
}
|
||||
|
||||
|
@ -232,9 +232,9 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
||||
|
||||
// Buffer diagnostics from argument parsing so that we can output them using a
|
||||
// well formed diagnostic object.
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, DiagsBuffer);
|
||||
|
||||
// Setup round-trip remarks for the DiagnosticsEngine used in CreateFromArgs.
|
||||
if (find(Argv, StringRef("-Rround-trip-cc1-args")) != Argv.end())
|
||||
|
@ -658,12 +658,12 @@ int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
||||
InitializeAllAsmParsers();
|
||||
|
||||
// Construct our diagnostic client.
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
TextDiagnosticPrinter *DiagClient
|
||||
= new TextDiagnosticPrinter(errs(), &*DiagOpts);
|
||||
DiagnosticOptions DiagOpts;
|
||||
TextDiagnosticPrinter *DiagClient =
|
||||
new TextDiagnosticPrinter(errs(), DiagOpts);
|
||||
DiagClient->setPrefix("clang -cc1as");
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, DiagClient);
|
||||
|
||||
// Set an error handler, so that any LLVM backend diagnostics go through our
|
||||
// error handler.
|
||||
|
@ -117,12 +117,12 @@ generateReproducerForInvocationArguments(ArrayRef<const char *> Argv,
|
||||
using namespace driver;
|
||||
auto TargetAndMode = ToolChain::getTargetAndModeFromProgramName(Argv[0]);
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions;
|
||||
DiagnosticOptions DiagOpts;
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new IgnoringDiagConsumer());
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new IgnoringDiagConsumer());
|
||||
auto VFS = llvm::vfs::getRealFileSystem();
|
||||
ProcessWarningOptions(Diags, *DiagOpts, *VFS, /*ReportDiags=*/false);
|
||||
ProcessWarningOptions(Diags, DiagOpts, *VFS, /*ReportDiags=*/false);
|
||||
Driver TheDriver(ToolContext.Path, llvm::sys::getDefaultTargetTriple(), Diags,
|
||||
/*Title=*/"clang LLVM compiler", VFS);
|
||||
TheDriver.setTargetAndMode(TargetAndMode);
|
||||
|
@ -321,25 +321,24 @@ int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContext) {
|
||||
.Case("-fintegrated-cc1", false)
|
||||
.Default(UseNewCC1Process);
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts =
|
||||
CreateAndPopulateDiagOpts(Args);
|
||||
std::unique_ptr<DiagnosticOptions> DiagOpts = CreateAndPopulateDiagOpts(Args);
|
||||
// Driver's diagnostics don't use suppression mappings, so don't bother
|
||||
// parsing them. CC1 still receives full args, so this doesn't impact other
|
||||
// actions.
|
||||
DiagOpts->DiagnosticSuppressionMappingsFile.clear();
|
||||
|
||||
TextDiagnosticPrinter *DiagClient
|
||||
= new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
|
||||
TextDiagnosticPrinter *DiagClient =
|
||||
new TextDiagnosticPrinter(llvm::errs(), *DiagOpts);
|
||||
FixupDiagPrefixExeName(DiagClient, ProgName);
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
|
||||
DiagnosticsEngine Diags(DiagID, *DiagOpts, DiagClient);
|
||||
|
||||
if (!DiagOpts->DiagnosticSerializationFile.empty()) {
|
||||
auto SerializedConsumer =
|
||||
clang::serialized_diags::create(DiagOpts->DiagnosticSerializationFile,
|
||||
&*DiagOpts, /*MergeChildRecords=*/true);
|
||||
*DiagOpts, /*MergeChildRecords=*/true);
|
||||
Diags.setClient(new ChainedDiagnosticConsumer(
|
||||
Diags.takeClient(), std::move(SerializedConsumer)));
|
||||
}
|
||||
|
@ -4227,12 +4227,13 @@ enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx,
|
||||
FileSystemOptions FileSystemOpts;
|
||||
HeaderSearchOptions HSOpts;
|
||||
|
||||
auto DiagOpts = std::make_shared<DiagnosticOptions>();
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
|
||||
CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(),
|
||||
new DiagnosticOptions());
|
||||
*DiagOpts);
|
||||
std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
|
||||
ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(),
|
||||
ASTUnit::LoadEverything, Diags, FileSystemOpts, HSOpts,
|
||||
ASTUnit::LoadEverything, DiagOpts, Diags, FileSystemOpts, HSOpts,
|
||||
/*LangOpts=*/nullptr, CXXIdx->getOnlyLocalDecls(), CaptureDiagsKind::All,
|
||||
/*AllowASTWithCompilerErrors=*/true,
|
||||
/*UserFilesAreVolatile=*/true);
|
||||
@ -4299,11 +4300,11 @@ clang_parseTranslationUnit_Impl(CXIndex CIdx, const char *source_filename,
|
||||
}
|
||||
|
||||
// Configure the diagnostics.
|
||||
std::unique_ptr<DiagnosticOptions> DiagOpts = CreateAndPopulateDiagOpts(
|
||||
std::shared_ptr<DiagnosticOptions> DiagOpts = CreateAndPopulateDiagOpts(
|
||||
llvm::ArrayRef(command_line_args, num_command_line_args));
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
|
||||
CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(),
|
||||
DiagOpts.release()));
|
||||
*DiagOpts));
|
||||
|
||||
if (options & CXTranslationUnit_KeepGoing)
|
||||
Diags->setFatalsAsError(true);
|
||||
@ -4387,7 +4388,7 @@ clang_parseTranslationUnit_Impl(CXIndex CIdx, const char *source_filename,
|
||||
options, llvm::ArrayRef(*Args), /*InvocationArgs=*/{}, unsaved_files);
|
||||
std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromCommandLine(
|
||||
Args->data(), Args->data() + Args->size(),
|
||||
CXXIdx->getPCHContainerOperations(), Diags,
|
||||
CXXIdx->getPCHContainerOperations(), DiagOpts, Diags,
|
||||
CXXIdx->getClangResourcesPath(), CXXIdx->getStorePreamblesInMemory(),
|
||||
CXXIdx->getPreambleStoragePath(), CXXIdx->getOnlyLocalDecls(),
|
||||
CaptureDiagnostics, *RemappedFiles,
|
||||
|
@ -256,8 +256,8 @@ struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults {
|
||||
/// Allocated API-exposed wrappters for Diagnostics.
|
||||
SmallVector<std::unique_ptr<CXStoredDiagnostic>, 8> DiagnosticsWrappers;
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
|
||||
|
||||
DiagnosticOptions DiagOpts;
|
||||
|
||||
/// Diag object
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diag;
|
||||
|
||||
@ -356,9 +356,9 @@ static std::atomic<unsigned> CodeCompletionResultObjects;
|
||||
|
||||
AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults(
|
||||
IntrusiveRefCntPtr<FileManager> FileMgr)
|
||||
: CXCodeCompleteResults(), DiagOpts(new DiagnosticOptions),
|
||||
: CXCodeCompleteResults(),
|
||||
Diag(new DiagnosticsEngine(
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), &*DiagOpts)),
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), DiagOpts)),
|
||||
FileMgr(std::move(FileMgr)),
|
||||
SourceMgr(new SourceManager(*Diag, *this->FileMgr)),
|
||||
CodeCompletionAllocator(
|
||||
@ -369,7 +369,7 @@ AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults(
|
||||
fprintf(stderr, "+++ %u completion results\n",
|
||||
++CodeCompletionResultObjects);
|
||||
}
|
||||
|
||||
|
||||
AllocatedCXCodeCompleteResults::~AllocatedCXCodeCompleteResults() {
|
||||
delete [] Results;
|
||||
|
||||
|
@ -80,12 +80,11 @@ public:
|
||||
};
|
||||
|
||||
class CXDiagnosticRenderer : public DiagnosticNoteRenderer {
|
||||
public:
|
||||
CXDiagnosticRenderer(const LangOptions &LangOpts,
|
||||
DiagnosticOptions *DiagOpts,
|
||||
public:
|
||||
CXDiagnosticRenderer(const LangOptions &LangOpts, DiagnosticOptions &DiagOpts,
|
||||
CXDiagnosticSetImpl *mainSet)
|
||||
: DiagnosticNoteRenderer(LangOpts, DiagOpts),
|
||||
CurrentSet(mainSet), MainSet(mainSet) {}
|
||||
: DiagnosticNoteRenderer(LangOpts, DiagOpts), CurrentSet(mainSet),
|
||||
MainSet(mainSet) {}
|
||||
|
||||
~CXDiagnosticRenderer() override {}
|
||||
|
||||
@ -182,10 +181,10 @@ CXDiagnosticSetImpl *cxdiag::lazyCreateDiags(CXTranslationUnit TU,
|
||||
if (!TU->Diagnostics) {
|
||||
CXDiagnosticSetImpl *Set = new CXDiagnosticSetImpl();
|
||||
TU->Diagnostics = Set;
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DOpts = new DiagnosticOptions;
|
||||
CXDiagnosticRenderer Renderer(AU->getASTContext().getLangOpts(),
|
||||
&*DOpts, Set);
|
||||
|
||||
DiagnosticOptions DOpts;
|
||||
CXDiagnosticRenderer Renderer(AU->getASTContext().getLangOpts(), DOpts,
|
||||
Set);
|
||||
|
||||
for (ASTUnit::stored_diag_iterator it = AU->stored_diag_begin(),
|
||||
ei = AU->stored_diag_end(); it != ei; ++it) {
|
||||
Renderer.emitStoredDiagnostic(*it);
|
||||
|
@ -480,9 +480,10 @@ static CXErrorCode clang_indexSourceFile_Impl(
|
||||
CaptureDiag = new CaptureDiagnosticConsumer();
|
||||
|
||||
// Configure the diagnostics.
|
||||
auto DiagOpts = std::make_shared<DiagnosticOptions>();
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
|
||||
CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(),
|
||||
new DiagnosticOptions, CaptureDiag,
|
||||
*DiagOpts, CaptureDiag,
|
||||
/*ShouldOwnClient=*/true));
|
||||
|
||||
// Recover resources if we crash before exiting this function.
|
||||
@ -554,7 +555,7 @@ static CXErrorCode clang_indexSourceFile_Impl(
|
||||
CInvok->getHeaderSearchOpts().ModuleFormat = std::string(
|
||||
CXXIdx->getPCHContainerOperations()->getRawReader().getFormats().front());
|
||||
|
||||
auto Unit = ASTUnit::create(CInvok, Diags, CaptureDiagnostics,
|
||||
auto Unit = ASTUnit::create(CInvok, DiagOpts, Diags, CaptureDiagnostics,
|
||||
/*UserFilesAreVolatile=*/true);
|
||||
if (!Unit)
|
||||
return CXError_InvalidArguments;
|
||||
@ -617,7 +618,7 @@ static CXErrorCode clang_indexSourceFile_Impl(
|
||||
!PrecompilePreamble ? 0 : 2 - CreatePreambleOnFirstParse;
|
||||
DiagnosticErrorTrap DiagTrap(*Diags);
|
||||
bool Success = ASTUnit::LoadFromCompilerInvocationAction(
|
||||
std::move(CInvok), CXXIdx->getPCHContainerOperations(), Diags,
|
||||
std::move(CInvok), CXXIdx->getPCHContainerOperations(), DiagOpts, Diags,
|
||||
IndexAction.get(), UPtr, Persistent, CXXIdx->getClangResourcesPath(),
|
||||
OnlyLocalDecls, CaptureDiagnostics, PrecompilePreambleAfterNParses,
|
||||
CacheCodeCompletionResults, /*UserFilesAreVolatile=*/true);
|
||||
|
@ -27,13 +27,14 @@ class ASTVectorTest : public ::testing::Test {
|
||||
protected:
|
||||
ASTVectorTest()
|
||||
: FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
|
||||
Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
|
||||
Diags(DiagID, DiagOpts, new IgnoringDiagConsumer()),
|
||||
SourceMgr(Diags, FileMgr), Idents(LangOpts, nullptr),
|
||||
Ctxt(LangOpts, SourceMgr, Idents, Sels, Builtins, TU_Complete) {}
|
||||
|
||||
FileSystemOptions FileMgrOpts;
|
||||
FileManager FileMgr;
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags;
|
||||
SourceManager SourceMgr;
|
||||
LangOptions LangOpts;
|
||||
|
@ -27,16 +27,14 @@ namespace {
|
||||
class CommentLexerTest : public ::testing::Test {
|
||||
protected:
|
||||
CommentLexerTest()
|
||||
: FileMgr(FileMgrOpts),
|
||||
DiagID(new DiagnosticIDs()),
|
||||
Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
|
||||
SourceMgr(Diags, FileMgr),
|
||||
Traits(Allocator, CommentOptions()) {
|
||||
}
|
||||
: FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
|
||||
Diags(DiagID, DiagOpts, new IgnoringDiagConsumer()),
|
||||
SourceMgr(Diags, FileMgr), Traits(Allocator, CommentOptions()) {}
|
||||
|
||||
FileSystemOptions FileMgrOpts;
|
||||
FileManager FileMgr;
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags;
|
||||
SourceManager SourceMgr;
|
||||
llvm::BumpPtrAllocator Allocator;
|
||||
|
@ -33,16 +33,14 @@ const bool MY_DEBUG = true;
|
||||
class CommentParserTest : public ::testing::Test {
|
||||
protected:
|
||||
CommentParserTest()
|
||||
: FileMgr(FileMgrOpts),
|
||||
DiagID(new DiagnosticIDs()),
|
||||
Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
|
||||
SourceMgr(Diags, FileMgr),
|
||||
Traits(Allocator, CommentOptions()) {
|
||||
}
|
||||
: FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
|
||||
Diags(DiagID, DiagOpts, new IgnoringDiagConsumer()),
|
||||
SourceMgr(Diags, FileMgr), Traits(Allocator, CommentOptions()) {}
|
||||
|
||||
FileSystemOptions FileMgrOpts;
|
||||
FileManager FileMgr;
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags;
|
||||
SourceManager SourceMgr;
|
||||
llvm::BumpPtrAllocator Allocator;
|
||||
|
@ -43,7 +43,8 @@ protected:
|
||||
// FIXME: technically, merged that we set here is incorrect, but that
|
||||
// shouldn't matter.
|
||||
RawComment Comment(SourceMgr, CommentRange, EmptyOpts, /*Merged=*/true);
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs, new DiagnosticOptions);
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs, DiagOpts);
|
||||
return Comment.getFormattedText(SourceMgr, Diags);
|
||||
}
|
||||
};
|
||||
|
@ -51,9 +51,9 @@ bool testExternalASTSource(ExternalASTSource *Source, StringRef FileContents) {
|
||||
"test.cc", MemoryBuffer::getMemBuffer(FileContents).release());
|
||||
const char *Args[] = { "test.cc" };
|
||||
|
||||
auto InvocationDiagOpts = llvm::makeIntrusiveRefCnt<DiagnosticOptions>();
|
||||
DiagnosticOptions InvocationDiagOpts;
|
||||
auto InvocationDiags = CompilerInstance::createDiagnostics(
|
||||
*llvm::vfs::getRealFileSystem(), InvocationDiagOpts.get());
|
||||
*llvm::vfs::getRealFileSystem(), InvocationDiagOpts);
|
||||
CompilerInvocation::CreateFromArgs(*Invocation, Args, *InvocationDiags);
|
||||
|
||||
CompilerInstance Compiler(std::move(Invocation));
|
||||
|
@ -1388,10 +1388,9 @@ protected:
|
||||
unsigned Line = SrcMgr.getPresumedLineNumber(Diag.Range.getBegin());
|
||||
DiagnosticLines.insert(Line);
|
||||
if (!AnnotationLines.contains(Line)) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(
|
||||
new DiagnosticOptions());
|
||||
DiagnosticOptions DiagOpts;
|
||||
TextDiagnostic TD(llvm::errs(), AO.ASTCtx.getLangOpts(),
|
||||
DiagOpts.get());
|
||||
DiagOpts);
|
||||
TD.emitDiagnostic(FullSourceLoc(Diag.Range.getBegin(), SrcMgr),
|
||||
DiagnosticsEngine::Error,
|
||||
"unexpected diagnostic", {Diag.Range}, {});
|
||||
|
@ -35,8 +35,8 @@ protected:
|
||||
MacroExpansionContextTest()
|
||||
: InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem),
|
||||
FileMgr(FileSystemOptions(), InMemoryFileSystem),
|
||||
DiagID(new DiagnosticIDs()), DiagOpts(new DiagnosticOptions()),
|
||||
Diags(DiagID, DiagOpts.get(), new IgnoringDiagConsumer()),
|
||||
DiagID(new DiagnosticIDs()),
|
||||
Diags(DiagID, DiagOpts, new IgnoringDiagConsumer()),
|
||||
SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions()) {
|
||||
TargetOpts->Triple = "x86_64-pc-linux-unknown";
|
||||
Target = TargetInfo::CreateTargetInfo(Diags, *TargetOpts);
|
||||
@ -46,7 +46,7 @@ protected:
|
||||
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem;
|
||||
FileManager FileMgr;
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags;
|
||||
SourceManager SourceMgr;
|
||||
LangOptions LangOpts;
|
||||
|
@ -13,12 +13,13 @@ class UnsafeBufferUsageTest : public ::testing::Test {
|
||||
protected:
|
||||
UnsafeBufferUsageTest()
|
||||
: FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
|
||||
Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
|
||||
Diags(DiagID, DiagOpts, new IgnoringDiagConsumer()),
|
||||
SourceMgr(Diags, FileMgr) {}
|
||||
|
||||
FileSystemOptions FileMgrOpts;
|
||||
FileManager FileMgr;
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags;
|
||||
SourceManager SourceMgr;
|
||||
};
|
||||
|
@ -46,8 +46,8 @@ using testing::IsEmpty;
|
||||
|
||||
// Check that DiagnosticErrorTrap works with SuppressAllDiagnostics.
|
||||
TEST(DiagnosticTest, suppressAndTrap) {
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs(),
|
||||
new DiagnosticOptions,
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs(), DiagOpts,
|
||||
new IgnoringDiagConsumer());
|
||||
Diags.setSuppressAllDiagnostics(true);
|
||||
|
||||
@ -77,8 +77,8 @@ TEST(DiagnosticTest, suppressAndTrap) {
|
||||
// Check that FatalsAsError works as intended
|
||||
TEST(DiagnosticTest, fatalsAsError) {
|
||||
for (unsigned FatalsAsError = 0; FatalsAsError != 2; ++FatalsAsError) {
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs(),
|
||||
new DiagnosticOptions,
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs(), DiagOpts,
|
||||
new IgnoringDiagConsumer());
|
||||
Diags.setFatalsAsError(FatalsAsError);
|
||||
|
||||
@ -101,7 +101,8 @@ TEST(DiagnosticTest, fatalsAsError) {
|
||||
}
|
||||
|
||||
TEST(DiagnosticTest, tooManyErrorsIsAlwaysFatal) {
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs(), DiagOpts,
|
||||
new IgnoringDiagConsumer());
|
||||
Diags.setFatalsAsError(true);
|
||||
|
||||
@ -117,7 +118,8 @@ TEST(DiagnosticTest, tooManyErrorsIsAlwaysFatal) {
|
||||
|
||||
// Check that soft RESET works as intended
|
||||
TEST(DiagnosticTest, softReset) {
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs(), DiagOpts,
|
||||
new IgnoringDiagConsumer());
|
||||
|
||||
unsigned numWarnings = 0U, numErrors = 0U;
|
||||
@ -140,7 +142,8 @@ TEST(DiagnosticTest, softReset) {
|
||||
}
|
||||
|
||||
TEST(DiagnosticTest, diagnosticError) {
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs(), DiagOpts,
|
||||
new IgnoringDiagConsumer());
|
||||
PartialDiagnostic::DiagStorageAllocator Alloc;
|
||||
llvm::Expected<std::pair<int, int>> Value = DiagnosticError::create(
|
||||
@ -162,7 +165,8 @@ TEST(DiagnosticTest, diagnosticError) {
|
||||
}
|
||||
|
||||
TEST(DiagnosticTest, storedDiagEmptyWarning) {
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions);
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs(), DiagOpts);
|
||||
|
||||
class CaptureDiagnosticConsumer : public DiagnosticConsumer {
|
||||
public:
|
||||
@ -192,7 +196,8 @@ public:
|
||||
protected:
|
||||
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS =
|
||||
llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
|
||||
DiagnosticsEngine Diags{new DiagnosticIDs(), new DiagnosticOptions};
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags{new DiagnosticIDs(), DiagOpts};
|
||||
|
||||
llvm::ArrayRef<StoredDiagnostic> diags() {
|
||||
return CaptureConsumer.StoredDiags;
|
||||
|
@ -43,14 +43,14 @@ protected:
|
||||
SarifDocumentWriterTest()
|
||||
: InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem),
|
||||
FileMgr(FileSystemOptions(), InMemoryFileSystem),
|
||||
DiagID(new DiagnosticIDs()), DiagOpts(new DiagnosticOptions()),
|
||||
Diags(DiagID, DiagOpts.get(), new IgnoringDiagConsumer()),
|
||||
DiagID(new DiagnosticIDs()),
|
||||
Diags(DiagID, DiagOpts, new IgnoringDiagConsumer()),
|
||||
SourceMgr(Diags, FileMgr) {}
|
||||
|
||||
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem;
|
||||
FileManager FileMgr;
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags;
|
||||
SourceManager SourceMgr;
|
||||
LangOptions LangOpts;
|
||||
|
@ -40,11 +40,9 @@ namespace {
|
||||
class SourceManagerTest : public ::testing::Test {
|
||||
protected:
|
||||
SourceManagerTest()
|
||||
: FileMgr(FileMgrOpts),
|
||||
DiagID(new DiagnosticIDs()),
|
||||
Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
|
||||
SourceMgr(Diags, FileMgr),
|
||||
TargetOpts(new TargetOptions) {
|
||||
: FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
|
||||
Diags(DiagID, DiagOpts, new IgnoringDiagConsumer()),
|
||||
SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) {
|
||||
TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
|
||||
Target = TargetInfo::CreateTargetInfo(Diags, *TargetOpts);
|
||||
}
|
||||
@ -52,6 +50,7 @@ protected:
|
||||
FileSystemOptions FileMgrOpts;
|
||||
FileManager FileMgr;
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags;
|
||||
SourceManager SourceMgr;
|
||||
LangOptions LangOpts;
|
||||
|
@ -64,8 +64,8 @@ TEST(DxcModeTest, TargetProfileValidation) {
|
||||
llvm::MemoryBuffer::getMemBuffer("\n"));
|
||||
|
||||
auto *DiagConsumer = new SimpleDiagnosticConsumer;
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagConsumer);
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, DiagConsumer);
|
||||
|
||||
validateTargetProfile("-Tvs_6_0", "dxilv1.0--shadermodel6.0-vertex",
|
||||
InMemoryFileSystem, Diags);
|
||||
@ -114,8 +114,8 @@ TEST(DxcModeTest, ValidatorVersionValidation) {
|
||||
llvm::MemoryBuffer::getMemBuffer("\n"));
|
||||
|
||||
auto *DiagConsumer = new SimpleDiagnosticConsumer;
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagConsumer);
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, DiagConsumer);
|
||||
Driver TheDriver("/bin/clang", "", Diags, "", InMemoryFileSystem);
|
||||
std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(
|
||||
{"clang", "--driver-mode=dxc", "-Tlib_6_7", "foo.hlsl"}));
|
||||
@ -218,9 +218,9 @@ TEST(DxcModeTest, DefaultEntry) {
|
||||
|
||||
const char *Args[] = {"clang", "--driver-mode=dxc", "-Tcs_6_7", "foo.hlsl"};
|
||||
|
||||
DiagnosticOptions DiagOpts;
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
|
||||
CompilerInstance::createDiagnostics(*InMemoryFileSystem,
|
||||
new DiagnosticOptions());
|
||||
CompilerInstance::createDiagnostics(*InMemoryFileSystem, DiagOpts);
|
||||
|
||||
CreateInvocationOptions CIOpts;
|
||||
CIOpts.Diags = Diags;
|
||||
|
@ -52,10 +52,9 @@ protected:
|
||||
std::vector<std::string> ExtraFiles) {
|
||||
assert(!DriverInstance && "Running twice is not allowed");
|
||||
|
||||
llvm::IntrusiveRefCntPtr<DiagnosticOptions> Opts = new DiagnosticOptions;
|
||||
DiagnosticsEngine Diags(
|
||||
new DiagnosticIDs, Opts,
|
||||
new TextDiagnosticPrinter(llvm::errs(), Opts.get()));
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags(new DiagnosticIDs, DiagOpts,
|
||||
new TextDiagnosticPrinter(llvm::errs(), DiagOpts));
|
||||
DriverInstance.emplace(ClangBinary, "x86_64-unknown-linux-gnu", Diags,
|
||||
"clang LLVM compiler", prepareFS(ExtraFiles));
|
||||
|
||||
|
@ -47,9 +47,8 @@ inline clang::driver::Driver diagnostic_test_driver() {
|
||||
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
|
||||
new llvm::vfs::InMemoryFileSystem);
|
||||
auto *DiagConsumer = new SimpleDiagnosticConsumer;
|
||||
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts =
|
||||
new clang::DiagnosticOptions();
|
||||
clang::DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagConsumer);
|
||||
clang::DiagnosticOptions DiagOpts;
|
||||
clang::DiagnosticsEngine Diags(DiagID, DiagOpts, DiagConsumer);
|
||||
return clang::driver::Driver("/bin/clang", "", Diags, "", InMemoryFileSystem);
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ using namespace clang::driver;
|
||||
namespace {
|
||||
|
||||
TEST(ToolChainTest, VFSGCCInstallation) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
struct TestDiagnosticConsumer : public DiagnosticConsumer {};
|
||||
@ -84,7 +84,7 @@ TEST(ToolChainTest, VFSGCCInstallation) {
|
||||
llvm::MemoryBuffer::getMemBuffer("\n"));
|
||||
|
||||
{
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
Driver TheDriver("/bin/clang", "arm-linux-gnueabihf", Diags,
|
||||
"clang LLVM compiler", InMemoryFileSystem);
|
||||
std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(
|
||||
@ -107,7 +107,8 @@ TEST(ToolChainTest, VFSGCCInstallation) {
|
||||
}
|
||||
|
||||
{
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
Driver TheDriver("/bin/clang", "arm-linux-gnueabihf", Diags,
|
||||
"clang LLVM compiler", InMemoryFileSystem);
|
||||
std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(
|
||||
@ -134,11 +135,11 @@ TEST(ToolChainTest, VFSGCCInstallation) {
|
||||
}
|
||||
|
||||
TEST(ToolChainTest, VFSGCCInstallationRelativeDir) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
struct TestDiagnosticConsumer : public DiagnosticConsumer {};
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
|
||||
new llvm::vfs::InMemoryFileSystem);
|
||||
Driver TheDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
|
||||
@ -173,7 +174,7 @@ TEST(ToolChainTest, VFSGCCInstallationRelativeDir) {
|
||||
}
|
||||
|
||||
TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
struct TestDiagnosticConsumer : public DiagnosticConsumer {};
|
||||
@ -201,7 +202,7 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
|
||||
llvm::MemoryBuffer::getMemBuffer("\n"));
|
||||
|
||||
{
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
Driver TheDriver("/bin/clang", "i386-pc-solaris2.11", Diags,
|
||||
"clang LLVM compiler", InMemoryFileSystem);
|
||||
std::unique_ptr<Compilation> C(
|
||||
@ -225,7 +226,7 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
|
||||
}
|
||||
|
||||
{
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
Driver TheDriver("/bin/clang", "amd64-pc-solaris2.11", Diags,
|
||||
"clang LLVM compiler", InMemoryFileSystem);
|
||||
std::unique_ptr<Compilation> C(
|
||||
@ -249,7 +250,7 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
|
||||
}
|
||||
|
||||
{
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
Driver TheDriver("/bin/clang", "x86_64-pc-solaris2.11", Diags,
|
||||
"clang LLVM compiler", InMemoryFileSystem);
|
||||
std::unique_ptr<Compilation> C(
|
||||
@ -273,7 +274,7 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
|
||||
}
|
||||
|
||||
{
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
Driver TheDriver("/bin/clang", "sparc-sun-solaris2.11", Diags,
|
||||
"clang LLVM compiler", InMemoryFileSystem);
|
||||
std::unique_ptr<Compilation> C(
|
||||
@ -296,7 +297,7 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
|
||||
S);
|
||||
}
|
||||
{
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
Driver TheDriver("/bin/clang", "sparcv9-sun-solaris2.11", Diags,
|
||||
"clang LLVM compiler", InMemoryFileSystem);
|
||||
std::unique_ptr<Compilation> C(
|
||||
@ -337,7 +338,7 @@ MATCHER_P(jobHasArgs, Substr, "") {
|
||||
}
|
||||
|
||||
TEST(ToolChainTest, VFSGnuLibcxxPathNoSysroot) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
struct TestDiagnosticConsumer : public DiagnosticConsumer {};
|
||||
@ -355,7 +356,7 @@ TEST(ToolChainTest, VFSGnuLibcxxPathNoSysroot) {
|
||||
llvm::MemoryBuffer::getMemBuffer("\n"));
|
||||
|
||||
{
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
Driver TheDriver("/bin/clang", "x86_64-unknown-linux-gnu", Diags,
|
||||
"clang LLVM compiler", InMemoryFileSystem);
|
||||
std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(
|
||||
@ -368,11 +369,11 @@ TEST(ToolChainTest, VFSGnuLibcxxPathNoSysroot) {
|
||||
}
|
||||
|
||||
TEST(ToolChainTest, DefaultDriverMode) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
struct TestDiagnosticConsumer : public DiagnosticConsumer {};
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
|
||||
new llvm::vfs::InMemoryFileSystem);
|
||||
|
||||
@ -403,8 +404,8 @@ TEST(ToolChainTest, DefaultDriverMode) {
|
||||
TEST(ToolChainTest, InvalidArgument) {
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
struct TestDiagnosticConsumer : public DiagnosticConsumer {};
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticOptions DiagOpts;
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
Driver TheDriver("/bin/clang", "arm-linux-gnueabihf", Diags);
|
||||
std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(
|
||||
{"-fsyntax-only", "-fan-unknown-option", "foo.cpp"}));
|
||||
@ -514,11 +515,11 @@ TEST(ToolChainTest, GetTargetAndMode) {
|
||||
}
|
||||
|
||||
TEST(ToolChainTest, CommandOutput) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
struct TestDiagnosticConsumer : public DiagnosticConsumer {};
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
|
||||
new llvm::vfs::InMemoryFileSystem);
|
||||
|
||||
@ -543,10 +544,10 @@ TEST(ToolChainTest, CommandOutput) {
|
||||
}
|
||||
|
||||
TEST(ToolChainTest, PostCallback) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
struct TestDiagnosticConsumer : public DiagnosticConsumer {};
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
|
||||
new llvm::vfs::InMemoryFileSystem);
|
||||
|
||||
@ -596,10 +597,10 @@ TEST(ToolChainTest, UEFICallingConventionTest) {
|
||||
}
|
||||
|
||||
TEST(ToolChainTest, UEFIDefaultDebugFormatTest) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
struct TestDiagnosticConsumer : public DiagnosticConsumer {};
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
|
||||
new llvm::vfs::InMemoryFileSystem);
|
||||
Driver CCDriver("/home/test/bin/clang", "x86_64-unknown-uefi", Diags,
|
||||
@ -638,10 +639,10 @@ struct SimpleDiagnosticConsumer : public DiagnosticConsumer {
|
||||
};
|
||||
|
||||
TEST(ToolChainTest, ConfigFileSearch) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
struct TestDiagnosticConsumer : public DiagnosticConsumer {};
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS(
|
||||
new llvm::vfs::InMemoryFileSystem);
|
||||
|
||||
@ -715,11 +716,11 @@ struct FileSystemWithError : public llvm::vfs::FileSystem {
|
||||
};
|
||||
|
||||
TEST(ToolChainTest, ConfigFileError) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
std::unique_ptr<SimpleDiagnosticConsumer> DiagConsumer(
|
||||
new SimpleDiagnosticConsumer());
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagConsumer.get(), false);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, DiagConsumer.get(), false);
|
||||
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS(new FileSystemWithError);
|
||||
|
||||
Driver TheDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
|
||||
@ -736,11 +737,11 @@ TEST(ToolChainTest, ConfigFileError) {
|
||||
}
|
||||
|
||||
TEST(ToolChainTest, BadConfigFile) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
std::unique_ptr<SimpleDiagnosticConsumer> DiagConsumer(
|
||||
new SimpleDiagnosticConsumer());
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagConsumer.get(), false);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, DiagConsumer.get(), false);
|
||||
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS(
|
||||
new llvm::vfs::InMemoryFileSystem);
|
||||
|
||||
@ -810,11 +811,11 @@ TEST(ToolChainTest, BadConfigFile) {
|
||||
}
|
||||
|
||||
TEST(ToolChainTest, ConfigInexistentInclude) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
std::unique_ptr<SimpleDiagnosticConsumer> DiagConsumer(
|
||||
new SimpleDiagnosticConsumer());
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagConsumer.get(), false);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, DiagConsumer.get(), false);
|
||||
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS(
|
||||
new llvm::vfs::InMemoryFileSystem);
|
||||
|
||||
@ -851,11 +852,11 @@ TEST(ToolChainTest, ConfigInexistentInclude) {
|
||||
}
|
||||
|
||||
TEST(ToolChainTest, ConfigRecursiveInclude) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
std::unique_ptr<SimpleDiagnosticConsumer> DiagConsumer(
|
||||
new SimpleDiagnosticConsumer());
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagConsumer.get(), false);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, DiagConsumer.get(), false);
|
||||
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS(
|
||||
new llvm::vfs::InMemoryFileSystem);
|
||||
|
||||
@ -897,10 +898,10 @@ TEST(ToolChainTest, ConfigRecursiveInclude) {
|
||||
}
|
||||
|
||||
TEST(ToolChainTest, NestedConfigFile) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
struct TestDiagnosticConsumer : public DiagnosticConsumer {};
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer);
|
||||
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS(
|
||||
new llvm::vfs::InMemoryFileSystem);
|
||||
|
||||
|
@ -30,6 +30,8 @@ protected:
|
||||
int FD;
|
||||
llvm::SmallString<256> InputFileName;
|
||||
std::unique_ptr<ToolOutputFile> input_file;
|
||||
std::shared_ptr<DiagnosticOptions> DiagOpts =
|
||||
std::make_shared<DiagnosticOptions>();
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags;
|
||||
std::shared_ptr<CompilerInvocation> CInvok;
|
||||
std::shared_ptr<PCHContainerOperations> PCHContainerOps;
|
||||
@ -43,7 +45,7 @@ protected:
|
||||
const char *Args[] = {"clang", "-xc++", InputFileName.c_str()};
|
||||
|
||||
auto VFS = llvm::vfs::getRealFileSystem();
|
||||
Diags = CompilerInstance::createDiagnostics(*VFS, new DiagnosticOptions());
|
||||
Diags = CompilerInstance::createDiagnostics(*VFS, *DiagOpts);
|
||||
|
||||
CreateInvocationOptions CIOpts;
|
||||
CIOpts.Diags = Diags;
|
||||
@ -57,8 +59,8 @@ protected:
|
||||
PCHContainerOps = std::make_shared<PCHContainerOperations>();
|
||||
|
||||
return ASTUnit::LoadFromCompilerInvocation(
|
||||
CInvok, PCHContainerOps, Diags, FileMgr, false, CaptureDiagsKind::None,
|
||||
0, TU_Complete, false, false, isVolatile);
|
||||
CInvok, PCHContainerOps, DiagOpts, Diags, FileMgr, false,
|
||||
CaptureDiagsKind::None, 0, TU_Complete, false, false, isVolatile);
|
||||
}
|
||||
};
|
||||
|
||||
@ -95,7 +97,7 @@ TEST_F(ASTUnitTest, SaveLoadPreservesLangOptionsInPrintingPolicy) {
|
||||
|
||||
std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
|
||||
ASTFileName, PCHContainerOps->getRawReader(), ASTUnit::LoadEverything,
|
||||
Diags, FileSystemOptions(), HSOpts);
|
||||
DiagOpts, Diags, FileSystemOptions(), HSOpts);
|
||||
|
||||
if (!AU)
|
||||
FAIL() << "failed to load ASTUnit";
|
||||
@ -136,8 +138,7 @@ TEST_F(ASTUnitTest, ModuleTextualHeader) {
|
||||
|
||||
const char *Args[] = {"clang", "test.cpp", "-fmodule-map-file=m.modulemap",
|
||||
"-fmodule-name=M"};
|
||||
Diags =
|
||||
CompilerInstance::createDiagnostics(*InMemoryFs, new DiagnosticOptions());
|
||||
Diags = CompilerInstance::createDiagnostics(*InMemoryFs, *DiagOpts);
|
||||
CreateInvocationOptions CIOpts;
|
||||
CIOpts.Diags = Diags;
|
||||
CInvok = createInvocation(Args, std::move(CIOpts));
|
||||
@ -147,8 +148,8 @@ TEST_F(ASTUnitTest, ModuleTextualHeader) {
|
||||
PCHContainerOps = std::make_shared<PCHContainerOperations>();
|
||||
|
||||
auto AU = ASTUnit::LoadFromCompilerInvocation(
|
||||
CInvok, PCHContainerOps, Diags, FileMgr, false, CaptureDiagsKind::None, 1,
|
||||
TU_Complete, false, false, false);
|
||||
CInvok, PCHContainerOps, DiagOpts, Diags, FileMgr, false,
|
||||
CaptureDiagsKind::None, 1, TU_Complete, false, false, false);
|
||||
ASSERT_TRUE(AU);
|
||||
auto File = AU->getFileManager().getFileRef("Textual.h", false, false);
|
||||
ASSERT_TRUE(bool(File));
|
||||
@ -166,15 +167,15 @@ TEST_F(ASTUnitTest, LoadFromCommandLineEarlyError) {
|
||||
const char *Args[] = {"clang", "-target", "foobar", InputFileName.c_str()};
|
||||
|
||||
auto Diags = CompilerInstance::createDiagnostics(
|
||||
*llvm::vfs::getRealFileSystem(), new DiagnosticOptions());
|
||||
*llvm::vfs::getRealFileSystem(), *DiagOpts);
|
||||
auto PCHContainerOps = std::make_shared<PCHContainerOperations>();
|
||||
std::unique_ptr<clang::ASTUnit> ErrUnit;
|
||||
|
||||
std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromCommandLine(
|
||||
&Args[0], &Args[4], PCHContainerOps, Diags, "", false, "", false,
|
||||
CaptureDiagsKind::All, {}, true, 0, TU_Complete, false, false, false,
|
||||
SkipFunctionBodiesScope::None, false, true, false, false, std::nullopt,
|
||||
&ErrUnit, nullptr);
|
||||
&Args[0], &Args[4], PCHContainerOps, DiagOpts, Diags, "", false, "",
|
||||
false, CaptureDiagsKind::All, {}, true, 0, TU_Complete, false, false,
|
||||
false, SkipFunctionBodiesScope::None, false, true, false, false,
|
||||
std::nullopt, &ErrUnit, nullptr);
|
||||
|
||||
ASSERT_EQ(AST, nullptr);
|
||||
ASSERT_NE(ErrUnit, nullptr);
|
||||
@ -194,15 +195,15 @@ TEST_F(ASTUnitTest, LoadFromCommandLineWorkingDirectory) {
|
||||
InputFileName.c_str()};
|
||||
|
||||
auto Diags = CompilerInstance::createDiagnostics(
|
||||
*llvm::vfs::getRealFileSystem(), new DiagnosticOptions());
|
||||
*llvm::vfs::getRealFileSystem(), *DiagOpts);
|
||||
auto PCHContainerOps = std::make_shared<PCHContainerOperations>();
|
||||
std::unique_ptr<clang::ASTUnit> ErrUnit;
|
||||
|
||||
std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromCommandLine(
|
||||
&Args[0], &Args[4], PCHContainerOps, Diags, "", false, "", false,
|
||||
CaptureDiagsKind::All, {}, true, 0, TU_Complete, false, false, false,
|
||||
SkipFunctionBodiesScope::None, false, true, false, false, std::nullopt,
|
||||
&ErrUnit, nullptr);
|
||||
&Args[0], &Args[4], PCHContainerOps, DiagOpts, Diags, "", false, "",
|
||||
false, CaptureDiagsKind::All, {}, true, 0, TU_Complete, false, false,
|
||||
false, SkipFunctionBodiesScope::None, false, true, false, false,
|
||||
std::nullopt, &ErrUnit, nullptr);
|
||||
|
||||
ASSERT_NE(AST, nullptr);
|
||||
ASSERT_FALSE(Diags->hasErrorOccurred());
|
||||
|
@ -53,9 +53,10 @@ TEST(CompilerInstance, DefaultVFSOverlayFromInvocation) {
|
||||
const std::string VFSArg = "-ivfsoverlay" + FileNameStr;
|
||||
const char *Args[] = {"clang", VFSArg.c_str(), "-xc++", "-"};
|
||||
|
||||
DiagnosticOptions DiagOpts;
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
|
||||
CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(),
|
||||
new DiagnosticOptions());
|
||||
DiagOpts);
|
||||
|
||||
CreateInvocationOptions CIOpts;
|
||||
CIOpts.Diags = Diags;
|
||||
@ -76,17 +77,17 @@ TEST(CompilerInstance, DefaultVFSOverlayFromInvocation) {
|
||||
}
|
||||
|
||||
TEST(CompilerInstance, AllowDiagnosticLogWithUnownedDiagnosticConsumer) {
|
||||
auto DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
// Tell the diagnostics engine to emit the diagnostic log to STDERR. This
|
||||
// ensures that a chained diagnostic consumer is created so that the test can
|
||||
// exercise the unowned diagnostic consumer in a chained consumer.
|
||||
DiagOpts->DiagnosticLogFile = "-";
|
||||
DiagOpts.DiagnosticLogFile = "-";
|
||||
|
||||
// Create the diagnostic engine with unowned consumer.
|
||||
std::string DiagnosticOutput;
|
||||
llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
|
||||
auto DiagPrinter = std::make_unique<TextDiagnosticPrinter>(
|
||||
DiagnosticsOS, new DiagnosticOptions());
|
||||
auto DiagPrinter =
|
||||
std::make_unique<TextDiagnosticPrinter>(DiagnosticsOS, DiagOpts);
|
||||
CompilerInstance Instance;
|
||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
|
||||
Instance.createDiagnostics(*llvm::vfs::getRealFileSystem(), DiagOpts,
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user