diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index b97d0c636806a..cce91862ae3d0 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -225,6 +225,9 @@ class CompilerInstance : public ModuleLoader { // of the context or else not CompilerInstance specific. bool ExecuteAction(FrontendAction &Act); + /// At the end of a compilation, print the number of warnings/errors. + void printDiagnosticStats(); + /// Load the list of plugins requested in the \c FrontendOptions. void LoadRequestedPlugins(); diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index a25aa88bd85ef..444ffff307377 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1061,30 +1061,7 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) { } } - if (getDiagnosticOpts().ShowCarets) { - // We can have multiple diagnostics sharing one diagnostic client. - // Get the total number of warnings/errors from the client. - unsigned NumWarnings = getDiagnostics().getClient()->getNumWarnings(); - unsigned NumErrors = getDiagnostics().getClient()->getNumErrors(); - - if (NumWarnings) - OS << NumWarnings << " warning" << (NumWarnings == 1 ? "" : "s"); - if (NumWarnings && NumErrors) - OS << " and "; - if (NumErrors) - OS << NumErrors << " error" << (NumErrors == 1 ? "" : "s"); - if (NumWarnings || NumErrors) { - OS << " generated"; - if (getLangOpts().CUDA) { - if (!getLangOpts().CUDAIsDevice) { - OS << " when compiling for host"; - } else { - OS << " when compiling for " << getTargetOpts().CPU; - } - } - OS << ".\n"; - } - } + printDiagnosticStats(); if (getFrontendOpts().ShowStats) { if (hasFileManager()) { @@ -1112,6 +1089,36 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) { return !getDiagnostics().getClient()->getNumErrors(); } +void CompilerInstance::printDiagnosticStats() { + if (!getDiagnosticOpts().ShowCarets) + return; + + raw_ostream &OS = getVerboseOutputStream(); + + // We can have multiple diagnostics sharing one diagnostic client. + // Get the total number of warnings/errors from the client. + unsigned NumWarnings = getDiagnostics().getClient()->getNumWarnings(); + unsigned NumErrors = getDiagnostics().getClient()->getNumErrors(); + + if (NumWarnings) + OS << NumWarnings << " warning" << (NumWarnings == 1 ? "" : "s"); + if (NumWarnings && NumErrors) + OS << " and "; + if (NumErrors) + OS << NumErrors << " error" << (NumErrors == 1 ? "" : "s"); + if (NumWarnings || NumErrors) { + OS << " generated"; + if (getLangOpts().CUDA) { + if (!getLangOpts().CUDAIsDevice) { + OS << " when compiling for host"; + } else { + OS << " when compiling for " << getTargetOpts().CPU; + } + } + OS << ".\n"; + } +} + void CompilerInstance::LoadRequestedPlugins() { // Load any requested plugins. for (const std::string &Path : getFrontendOpts().Plugins) {