From b9a7d8179530c752f068487822281b8604d34614 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 1 Aug 2025 10:38:38 -0400 Subject: [PATCH 74/98] FIXME: WIP on error and warning counts (PR diagnostics/26061) --- gcc/diagnostics/context.h | 1 + gcc/diagnostics/text-sink.cc | 34 ++++++++++++++++++++++++++++++++++ gcc/diagnostics/text-sink.h | 2 ++ 3 files changed, 37 insertions(+) diff --git a/gcc/diagnostics/context.h b/gcc/diagnostics/context.h index ad1192e93a35..afb8e9e0b91b 100644 --- a/gcc/diagnostics/context.h +++ b/gcc/diagnostics/context.h @@ -476,6 +476,7 @@ public: { return m_diagnostic_counters.get_count (kind); } + const counters &get_counters () const { return m_diagnostic_counters; } /* Option-related member functions. */ inline bool option_enabled_p (option_id opt_id) const diff --git a/gcc/diagnostics/text-sink.cc b/gcc/diagnostics/text-sink.cc index 6f97ca54329c..3f9744cfac3e 100644 --- a/gcc/diagnostics/text-sink.cc +++ b/gcc/diagnostics/text-sink.cc @@ -132,6 +132,9 @@ text_sink_buffer::flush () text_sink::~text_sink () { + pp_set_prefix (get_printer (), nullptr); + report_error_and_warning_counts (m_context.get_counters ()); + /* Some of the errors may actually have been warnings. */ if (m_context.diagnostic_count (kind::werror)) { @@ -156,6 +159,37 @@ text_sink::~text_sink () } } +// FIXME: what about werror ? + +void +text_sink::report_error_and_warning_counts (const counters &c) +{ + const int num_errors + = (c.get_count (kind::error) + + c.get_count (kind::werror)); + const int num_warnings = c.get_count (kind::warning); + if (num_errors || num_warnings) + { + pretty_printer *pp = get_printer (); + if (num_errors) + { + pp_printf_n (pp, num_errors, + "%s: %r%i error%R generated", + "%s: %r%i errors%R generated", + progname, "error", num_errors); + pp_newline_and_flush (pp); + } + if (num_warnings) + { + pp_printf_n (pp, num_warnings, + "%s: %r%i warning%R generated", + "%s: %r%i warnings%R generated", + progname, "warning", num_warnings); + pp_newline_and_flush (pp); + } + } +} + void text_sink::dump (FILE *outfile, int indent) const { diff --git a/gcc/diagnostics/text-sink.h b/gcc/diagnostics/text-sink.h index b756a49d0471..250e10d677e9 100644 --- a/gcc/diagnostics/text-sink.h +++ b/gcc/diagnostics/text-sink.h @@ -142,6 +142,8 @@ public: static const char *maybe_line_and_column (int line, int col); + void report_error_and_warning_counts (const counters &); + protected: void print_any_cwe (const diagnostic_info &diagnostic); void print_any_rules (const diagnostic_info &diagnostic); -- 2.49.0