diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2025-05-22 12:51:28 -0700 |
---|---|---|
committer | Jan Svoboda <jan_svoboda@apple.com> | 2025-05-22 12:52:03 -0700 |
commit | 13e1a2cb2246dc5e9a4afcdacabed4d43154ec3f (patch) | |
tree | 44ef419d0d5533ac9464061a6801ed0db1c93a49 /clang/lib/Frontend | |
parent | 45f6036533bd30966f5e815568b792a7e293a0e8 (diff) | |
download | llvm-13e1a2cb2246dc5e9a4afcdacabed4d43154ec3f.zip llvm-13e1a2cb2246dc5e9a4afcdacabed4d43154ec3f.tar.gz llvm-13e1a2cb2246dc5e9a4afcdacabed4d43154ec3f.tar.bz2 |
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.
Diffstat (limited to 'clang/lib/Frontend')
-rw-r--r-- | clang/lib/Frontend/ASTMerge.cpp | 13 | ||||
-rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 14 | ||||
-rw-r--r-- | clang/lib/Frontend/ChainedIncludesSource.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 27 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 27 | ||||
-rw-r--r-- | clang/lib/Frontend/CreateInvocationFromCommandLine.cpp | 14 | ||||
-rw-r--r-- | clang/lib/Frontend/DiagnosticRenderer.cpp | 17 | ||||
-rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 12 | ||||
-rw-r--r-- | clang/lib/Frontend/FrontendActions.cpp | 16 | ||||
-rw-r--r-- | clang/lib/Frontend/LogDiagnosticPrinter.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Frontend/SARIFDiagnostic.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Frontend/SARIFDiagnosticPrinter.cpp | 7 | ||||
-rw-r--r-- | clang/lib/Frontend/SerializedDiagnosticPrinter.cpp | 29 | ||||
-rw-r--r-- | clang/lib/Frontend/TextDiagnostic.cpp | 79 | ||||
-rw-r--r-- | clang/lib/Frontend/TextDiagnosticPrinter.cpp | 15 |
15 files changed, 138 insertions, 144 deletions
diff --git a/clang/lib/Frontend/ASTMerge.cpp b/clang/lib/Frontend/ASTMerge.cpp index b6b0644..a4ce883 100644 --- a/clang/lib/Frontend/ASTMerge.cpp +++ b/clang/lib/Frontend/ASTMerge.cpp @@ -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; diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 5a79fe0..457043c 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -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); diff --git a/clang/lib/Frontend/ChainedIncludesSource.cpp b/clang/lib/Frontend/ChainedIncludesSource.cpp index 95b0ed2..f9a398d 100644 --- a/clang/lib/Frontend/ChainedIncludesSource.cpp +++ b/clang/lib/Frontend/ChainedIncludesSource.cpp @@ -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()); diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 503d364..cc39049 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -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; } diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 3c23073..9c33910 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -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; } diff --git a/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp b/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp index d0b855f..99212b8 100644 --- a/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp +++ b/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp @@ -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); diff --git a/clang/lib/Frontend/DiagnosticRenderer.cpp b/clang/lib/Frontend/DiagnosticRenderer.cpp index 3b120ab..1396b2b 100644 --- a/clang/lib/Frontend/DiagnosticRenderer.cpp +++ b/clang/lib/Frontend/DiagnosticRenderer.cpp @@ -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) diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 54a2e3e..af9d18a 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -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; diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 8c75e1a..d14d091 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -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; diff --git a/clang/lib/Frontend/LogDiagnosticPrinter.cpp b/clang/lib/Frontend/LogDiagnosticPrinter.cpp index 4e963af..2d18893 100644 --- a/clang/lib/Frontend/LogDiagnosticPrinter.cpp +++ b/clang/lib/Frontend/LogDiagnosticPrinter.cpp @@ -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) { diff --git a/clang/lib/Frontend/SARIFDiagnostic.cpp b/clang/lib/Frontend/SARIFDiagnostic.cpp index 4e36153..e2aec7f6 100644 --- a/clang/lib/Frontend/SARIFDiagnostic.cpp +++ b/clang/lib/Frontend/SARIFDiagnostic.cpp @@ -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". diff --git a/clang/lib/Frontend/SARIFDiagnosticPrinter.cpp b/clang/lib/Frontend/SARIFDiagnosticPrinter.cpp index 73928d1..23fbc3e 100644 --- a/clang/lib/Frontend/SARIFDiagnosticPrinter.cpp +++ b/clang/lib/Frontend/SARIFDiagnosticPrinter.cpp @@ -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"); diff --git a/clang/lib/Frontend/SerializedDiagnosticPrinter.cpp b/clang/lib/Frontend/SerializedDiagnosticPrinter.cpp index 02aa3e8..ee49cdd 100644 --- a/clang/lib/Frontend/SerializedDiagnosticPrinter.cpp +++ b/clang/lib/Frontend/SerializedDiagnosticPrinter.cpp @@ -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(); } diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp index 4119ce6..25ab13b 100644 --- a/clang/lib/Frontend/TextDiagnostic.cpp +++ b/clang/lib/Frontend/TextDiagnostic.cpp @@ -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 diff --git a/clang/lib/Frontend/TextDiagnosticPrinter.cpp b/clang/lib/Frontend/TextDiagnosticPrinter.cpp index 28f7218..e878c63 100644 --- a/clang/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/clang/lib/Frontend/TextDiagnosticPrinter.cpp @@ -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"); |