https://gcc.gnu.org/g:ccbcde5ec0e481e1ea775649d59691b6f5fcc5a1
commit r15-1556-gccbcde5ec0e481e1ea775649d59691b6f5fcc5a1 Author: David Malcolm <dmalc...@redhat.com> Date: Fri Jun 21 18:20:38 2024 -0400 diagnostics: remove duplicate copies of diagnostic_kind_text No functional change intended. gcc/ChangeLog: * diagnostic-format-json.cc (json_output_format::on_end_diagnostic): Use get_diagnostic_kind_text rather than embedding a duplicate copy of the table. * diagnostic-format-sarif.cc (make_rule_id_for_diagnostic_kind): Likewise. * diagnostic.cc (get_diagnostic_kind_text): New. * diagnostic.h (get_diagnostic_kind_text): New decl. Signed-off-by: David Malcolm <dmalc...@redhat.com> Diff: --- gcc/diagnostic-format-json.cc | 8 +------- gcc/diagnostic-format-sarif.cc | 8 +------- gcc/diagnostic.cc | 8 ++++++++ gcc/diagnostic.h | 2 ++ 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc index ec03ac15aeb..8f2ff6cfde2 100644 --- a/gcc/diagnostic-format-json.cc +++ b/gcc/diagnostic-format-json.cc @@ -231,14 +231,8 @@ json_output_format::on_end_diagnostic (const diagnostic_info &diagnostic, /* Get "kind" of diagnostic. */ { - static const char *const diagnostic_kind_text[] = { -#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T), -#include "diagnostic.def" -#undef DEFINE_DIAGNOSTIC_KIND - "must-not-happen" - }; /* Lose the trailing ": ". */ - const char *kind_text = diagnostic_kind_text[diagnostic.kind]; + const char *kind_text = get_diagnostic_kind_text (diagnostic.kind); size_t len = strlen (kind_text); gcc_assert (len > 2); gcc_assert (kind_text[len - 2] == ':'); diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc index 5581aa1579e..2745c72ea3e 100644 --- a/gcc/diagnostic-format-sarif.cc +++ b/gcc/diagnostic-format-sarif.cc @@ -662,14 +662,8 @@ maybe_get_sarif_level (diagnostic_t diag_kind) static char * make_rule_id_for_diagnostic_kind (diagnostic_t diag_kind) { - static const char *const diagnostic_kind_text[] = { -#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T), -#include "diagnostic.def" -#undef DEFINE_DIAGNOSTIC_KIND - "must-not-happen" - }; /* Lose the trailing ": ". */ - const char *kind_text = diagnostic_kind_text[diag_kind]; + const char *kind_text = get_diagnostic_kind_text (diag_kind); size_t len = strlen (kind_text); gcc_assert (len > 2); gcc_assert (kind_text[len - 2] == ':'); diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index c66aa5af5ff..8fc22466b92 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -590,6 +590,14 @@ static const char *const diagnostic_kind_text[] = { "must-not-happen" }; +/* Get unlocalized string describing KIND. */ + +const char * +get_diagnostic_kind_text (diagnostic_t kind) +{ + return diagnostic_kind_text[kind]; +} + /* Return a malloc'd string describing a location and the severity of the diagnostic, e.g. "foo.c:42:10: error: ". The caller is responsible for freeing the memory. */ diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index c6846525da3..4969f07836c 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -1121,4 +1121,6 @@ option_unspecified_p (int opt) extern char *get_cwe_url (int cwe); +extern const char *get_diagnostic_kind_text (diagnostic_t kind); + #endif /* ! GCC_DIAGNOSTIC_H */