Use a new struct diagnostic_option_id rather than just "int" when referring to command-line options controlling warnings in the diagnostic subsystem.
No functional change intended, but better documents the meaning of the code. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r15-3556-g89991f31c5ded2. gcc/c-family/ChangeLog: * c-common.cc (c_option_controlling_cpp_diagnostic): Return diagnostic_option_id rather than int. (c_cpp_diagnostic): Update for renaming of diagnostic_override_option_index to diagnostic_set_option_id. gcc/c/ChangeLog: * c-errors.cc (pedwarn_c23): Use "diagnostic_option_id option_id" rather than "int opt". Update for renaming of diagnostic_info field. (pedwarn_c11): Likewise. (pedwarn_c99): Likewise. (pedwarn_c90): Likewise. * c-tree.h (pedwarn_c90): Likewise for decl. (pedwarn_c99): Likewise. (pedwarn_c11): Likewise. (pedwarn_c23): Likewise. gcc/cp/ChangeLog: * constexpr.cc (constexpr_error): Update for renaming of diagnostic_info field. * cp-tree.h (pedwarn_cxx98): Use "diagnostic_option_id" rather than "int". * error.cc (cp_adjust_diagnostic_info): Update for renaming of diagnostic_info field. (pedwarn_cxx98): Use "diagnostic_option_id option_id" rather than "int opt". Update for renaming of diagnostic_info field. (diagnostic_set_info): Likewise. gcc/d/ChangeLog: * d-diagnostic.cc (d_diagnostic_report_diagnostic): Update for renaming of diagnostic_info field. gcc/ChangeLog: * diagnostic-core.h (struct diagnostic_option_id): New. (warning): Use it rather than "int" for param. (warning_n): Likewise. (warning_at): Likewise. (warning_meta): Likewise. (pedwarn): Likewise. (permerror_opt): Likewise. (emit_diagnostic): Likewise. (emit_diagnostic_valist): Likewise. (emit_diagnostic_valist_meta): Likewise. * diagnostic-format-json.cc (json_output_format::on_report_diagnostic): Update for renaming of diagnostic_info field. * diagnostic-format-sarif.cc (sarif_builder::make_result_object): Likewise. (make_reporting_descriptor_object_for_warning): Likewise. * diagnostic-format-text.cc (print_option_information): Likewise. * diagnostic-global-context.cc (emit_diagnostic): Use "diagnostic_option_id option_id" rather than "int opt". (emit_diagnostic_valist): Likewise. (emit_diagnostic_valist_meta): Likewise. (warning): Likewise. (warning_at): Likewise. (warning_meta): Likewise. (warning_n): Likewise. (pedwarn): Likewise. (permerror_opt): Likewise. * diagnostic.cc (diagnostic_set_info_translated): Update for renaming of diagnostic_info field. (diagnostic_option_classifier::classify_diagnostic): Use "diagnostic_option_id option_id" rather than "int opt". (update_effective_level_from_pragmas): Update for renaming of diagnostic_info field. (diagnostic_context::diagnostic_enabled): Likewise. (diagnostic_context::warning_enabled_at): Use "diagnostic_option_id option_id" rather than "int opt". (diagnostic_context::diagnostic_impl): Likewise. (diagnostic_context::diagnostic_n_impl): Likewise. * diagnostic.h (diagnostic_info::diagnostic_info): Update for... (diagnostic_info::option_index): Rename... (diagnostic_info::option_id): ...to this. (class diagnostic_option_manager): Use "diagnostic_option_id option_id" rather than "int opt" for vfuncs. (diagnostic_option_classifier): Likewise for member funcs. (diagnostic_classification_change_t::option): Add comment. (diagnostic_context::warning_enabled_at): Use "diagnostic_option_id option_id" rather than "int option_index". (diagnostic_context::option_unspecified_p): Likewise. (diagnostic_context::classify_diagnostic): Likewise. (diagnostic_context::option_enabled_p): Likewise. (diagnostic_context::make_option_name): Likewise. (diagnostic_context::make_option_url): Likewise. (diagnostic_context::diagnostic_impl): Likewise. (diagnostic_context::diagnostic_n_impl): Likewise. (diagnostic_override_option_index): Rename... (diagnostic_set_option_id): ...to this, and update for diagnostic_info field renaming. (diagnostic_classify_diagnostic): Use "diagnostic_option_id" rather than "int". (warning_enabled_at): Likewise. (option_unspecified_p): Likewise. gcc/fortran/ChangeLog: * cpp.cc (cb_cpp_diagnostic_cpp_option): Convert return type from "int" to "diagnostic_option_id". (cb_cpp_diagnostic): Update for renaming of diagnostic_override_option_index to diagnostic_set_option_id. * error.cc (gfc_warning): Update for renaming of diagnostic_info field. (gfc_warning_now_at): Likewise. (gfc_warning_now): Likewise. (gfc_warning_internal): Likewise. gcc/ChangeLog: * ipa-pure-const.cc: Replace include of "opts.h" with "opts-diagnostic.h". (suggest_attribute): Convert param from int to diagnostic_option_id. * lto-wrapper.cc (class lto_diagnostic_option_manager): Use diagnostic_option_id rather than "int". * opts-common.cc (compiler_diagnostic_option_manager::option_enabled_p): Likewise. * opts-diagnostic.h (class gcc_diagnostic_option_manager): Likewise. (class compiler_diagnostic_option_manager): Likewise. * opts.cc (compiler_diagnostic_option_manager::make_option_name): Likewise. (gcc_diagnostic_option_manager::make_option_url): Likewise. * substring-locations.cc (format_string_diagnostic_t::emit_warning_n_va): Likewise. (format_string_diagnostic_t::emit_warning_va): Likewise. (format_string_diagnostic_t::emit_warning): Likewise. (format_string_diagnostic_t::emit_warning_n): Likewise. * substring-locations.h (format_string_diagnostic_t::emit_warning_va): Likewise. (format_string_diagnostic_t::emit_warning_n_va): Likewise. (format_string_diagnostic_t::emit_warning): Likewise. (format_string_diagnostic_t::emit_warning_n): Likewise. Signed-off-by: David Malcolm <dmalc...@redhat.com> --- gcc/c-family/c-common.cc | 7 +-- gcc/c/c-errors.cc | 38 +++++++----- gcc/c/c-tree.h | 8 +-- gcc/cp/constexpr.cc | 2 +- gcc/cp/cp-tree.h | 4 +- gcc/cp/error.cc | 10 +-- gcc/d/d-diagnostic.cc | 2 +- gcc/diagnostic-core.h | 78 +++++++++++++++++++----- gcc/diagnostic-format-json.cc | 4 +- gcc/diagnostic-format-sarif.cc | 4 +- gcc/diagnostic-format-text.cc | 4 +- gcc/diagnostic-global-context.cc | 101 +++++++++++++++++++------------ gcc/diagnostic.cc | 55 +++++++++-------- gcc/diagnostic.h | 78 +++++++++++++----------- gcc/fortran/cpp.cc | 6 +- gcc/fortran/error.cc | 8 +-- gcc/ipa-pure-const.cc | 5 +- gcc/lto-wrapper.cc | 6 +- gcc/opts-common.cc | 5 +- gcc/opts-diagnostic.h | 6 +- gcc/opts.cc | 16 ++--- gcc/substring-locations.cc | 21 ++++--- gcc/substring-locations.h | 16 +++-- 23 files changed, 295 insertions(+), 189 deletions(-) diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index e7e371fd26f6..ec6a5da892dd 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -6787,7 +6787,7 @@ c_parse_error (const char *gmsgid, enum cpp_ttype token_type, /* Return the gcc option code associated with the reason for a cpp message, or 0 if none. */ -static int +static diagnostic_option_id c_option_controlling_cpp_diagnostic (enum cpp_warning_reason reason) { const struct cpp_reason_option_codes_t *entry; @@ -6870,9 +6870,8 @@ c_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED, richloc->set_range (0, input_location, SHOW_RANGE_WITH_CARET); diagnostic_set_info_translated (&diagnostic, msg, ap, richloc, dlevel); - diagnostic_override_option_index - (&diagnostic, - c_option_controlling_cpp_diagnostic (reason)); + diagnostic_set_option_id (&diagnostic, + c_option_controlling_cpp_diagnostic (reason)); ret = diagnostic_report_diagnostic (global_dc, &diagnostic); if (level == CPP_DL_WARNING_SYSHDR) global_dc->m_warn_system_headers = save_warn_system_headers; diff --git a/gcc/c/c-errors.cc b/gcc/c/c-errors.cc index f36e7f9780a3..c6b7c108354b 100644 --- a/gcc/c/c-errors.cc +++ b/gcc/c/c-errors.cc @@ -32,7 +32,9 @@ along with GCC; see the file COPYING3. If not see when C2Y is specified. */ bool -pedwarn_c23 (location_t location, int opt, const char *gmsgid, ...) +pedwarn_c23 (location_t location, + diagnostic_option_id option_id, + const char *gmsgid, ...) { diagnostic_info diagnostic; va_list ap; @@ -47,7 +49,7 @@ pedwarn_c23 (location_t location, int opt, const char *gmsgid, ...) diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, (pedantic && !flag_isoc2y) ? DK_PEDWARN : DK_WARNING); - diagnostic.option_index = OPT_Wc23_c2y_compat; + diagnostic.option_id = OPT_Wc23_c2y_compat; warned = diagnostic_report_diagnostic (global_dc, &diagnostic); } /* -Wno-c23-c2y-compat suppresses even the pedwarns. */ @@ -57,7 +59,7 @@ pedwarn_c23 (location_t location, int opt, const char *gmsgid, ...) else if (pedantic && !flag_isoc2y) { diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN); - diagnostic.option_index = opt; + diagnostic.option_id = option_id; warned = diagnostic_report_diagnostic (global_dc, &diagnostic); } va_end (ap); @@ -71,7 +73,9 @@ pedwarn_c23 (location_t location, int opt, const char *gmsgid, ...) when C23 is specified. */ bool -pedwarn_c11 (location_t location, int opt, const char *gmsgid, ...) +pedwarn_c11 (location_t location, + diagnostic_option_id option_id, + const char *gmsgid, ...) { diagnostic_info diagnostic; va_list ap; @@ -86,7 +90,7 @@ pedwarn_c11 (location_t location, int opt, const char *gmsgid, ...) diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, (pedantic && !flag_isoc23) ? DK_PEDWARN : DK_WARNING); - diagnostic.option_index = OPT_Wc11_c23_compat; + diagnostic.option_id = OPT_Wc11_c23_compat; warned = diagnostic_report_diagnostic (global_dc, &diagnostic); } /* -Wno-c11-c23-compat suppresses even the pedwarns. */ @@ -96,7 +100,7 @@ pedwarn_c11 (location_t location, int opt, const char *gmsgid, ...) else if (pedantic && !flag_isoc23) { diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN); - diagnostic.option_index = opt; + diagnostic.option_id = option_id; warned = diagnostic_report_diagnostic (global_dc, &diagnostic); } va_end (ap); @@ -110,7 +114,9 @@ pedwarn_c11 (location_t location, int opt, const char *gmsgid, ...) when C11 is specified. */ bool -pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...) +pedwarn_c99 (location_t location, + diagnostic_option_id option_id, + const char *gmsgid, ...) { diagnostic_info diagnostic; va_list ap; @@ -125,7 +131,7 @@ pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...) diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, (pedantic && !flag_isoc11) ? DK_PEDWARN : DK_WARNING); - diagnostic.option_index = OPT_Wc99_c11_compat; + diagnostic.option_id = OPT_Wc99_c11_compat; warned = diagnostic_report_diagnostic (global_dc, &diagnostic); } /* -Wno-c99-c11-compat suppresses even the pedwarns. */ @@ -135,7 +141,7 @@ pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...) else if (pedantic && !flag_isoc11) { diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN); - diagnostic.option_index = opt; + diagnostic.option_id = option_id; warned = diagnostic_report_diagnostic (global_dc, &diagnostic); } va_end (ap); @@ -150,7 +156,9 @@ pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...) when C99 is specified. (There is no flag_c90.) */ bool -pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...) +pedwarn_c90 (location_t location, + diagnostic_option_id option_id, + const char *gmsgid, ...) { diagnostic_info diagnostic; va_list ap; @@ -159,9 +167,9 @@ pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...) va_start (ap, gmsgid); /* Warnings such as -Wvla are the most specific ones. */ - if (opt != OPT_Wpedantic) + if (option_id.m_idx != OPT_Wpedantic) { - int opt_var = *(int *) option_flag_var (opt, &global_options); + int opt_var = *(int *) option_flag_var (option_id.m_idx, &global_options); if (opt_var == 0) goto out; else if (opt_var > 0) @@ -169,7 +177,7 @@ pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...) diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, (pedantic && !flag_isoc99) ? DK_PEDWARN : DK_WARNING); - diagnostic.option_index = opt; + diagnostic.option_id = option_id; diagnostic_report_diagnostic (global_dc, &diagnostic); warned = true; goto out; @@ -182,7 +190,7 @@ pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...) diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, (pedantic && !flag_isoc99) ? DK_PEDWARN : DK_WARNING); - diagnostic.option_index = OPT_Wc90_c99_compat; + diagnostic.option_id = OPT_Wc90_c99_compat; diagnostic_report_diagnostic (global_dc, &diagnostic); } /* -Wno-c90-c99-compat suppresses the pedwarns. */ @@ -192,7 +200,7 @@ pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...) else if (pedantic && !flag_isoc99) { diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN); - diagnostic.option_index = opt; + diagnostic.option_id = option_id; diagnostic_report_diagnostic (global_dc, &diagnostic); warned = true; } diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 57befb94c083..b3e7bb013b6a 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -899,13 +899,13 @@ extern void c_bind (location_t, tree, bool); extern bool tag_exists_p (enum tree_code, tree); /* In c-errors.cc */ -extern bool pedwarn_c90 (location_t, int opt, const char *, ...) +extern bool pedwarn_c90 (location_t, diagnostic_option_id, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); -extern bool pedwarn_c99 (location_t, int opt, const char *, ...) +extern bool pedwarn_c99 (location_t, diagnostic_option_id, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); -extern bool pedwarn_c11 (location_t, int opt, const char *, ...) +extern bool pedwarn_c11 (location_t, diagnostic_option_id, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); -extern bool pedwarn_c23 (location_t, int opt, const char *, ...) +extern bool pedwarn_c23 (location_t, diagnostic_option_id, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); extern void diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index b0adbb9036d9..db2a9c1543e1 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -168,7 +168,7 @@ constexpr_error (location_t location, bool constexpr_fundef_p, { diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, cxx_dialect < cxx23 ? DK_PEDWARN : DK_WARNING); - diagnostic.option_index = OPT_Winvalid_constexpr; + diagnostic.option_id = OPT_Winvalid_constexpr; ret = diagnostic_report_diagnostic (global_dc, &diagnostic); } else diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 2eeb5e3e8b16..307e802a9c47 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7185,7 +7185,9 @@ extern const char *class_key_or_enum_as_string (tree); extern void maybe_warn_variadic_templates (void); extern void maybe_warn_cpp0x (cpp0x_warn_str str, location_t = input_location); -extern bool pedwarn_cxx98 (location_t, int, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); +extern bool pedwarn_cxx98 (location_t, + diagnostic_option_id option_id, + const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); extern location_t location_of (tree); extern void qualified_name_lookup_error (tree, tree, tree, location_t); diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc index fbabf66376e1..f868325fac77 100644 --- a/gcc/cp/error.cc +++ b/gcc/cp/error.cc @@ -231,7 +231,7 @@ cp_adjust_diagnostic_info (diagnostic_context *context, if (diagnostic->kind == DK_ERROR) if (tree tmpl = get_current_template ()) { - diagnostic->option_index = OPT_Wtemplate_body; + diagnostic->option_id = OPT_Wtemplate_body; if (context->m_permissive) diagnostic->kind = DK_WARNING; @@ -4768,11 +4768,13 @@ maybe_warn_variadic_templates (void) /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on - option OPT with text GMSGID. Use this function to report + option OPTION_ID with text GMSGID. Use this function to report diagnostics for constructs that are invalid C++98, but valid C++0x. */ bool -pedwarn_cxx98 (location_t location, int opt, const char *gmsgid, ...) +pedwarn_cxx98 (location_t location, + diagnostic_option_id option_id, + const char *gmsgid, ...) { diagnostic_info diagnostic; va_list ap; @@ -4782,7 +4784,7 @@ pedwarn_cxx98 (location_t location, int opt, const char *gmsgid, ...) va_start (ap, gmsgid); diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, (cxx_dialect == cxx98) ? DK_PEDWARN : DK_WARNING); - diagnostic.option_index = opt; + diagnostic.option_id = option_id; ret = diagnostic_report_diagnostic (global_dc, &diagnostic); va_end (ap); return ret; diff --git a/gcc/d/d-diagnostic.cc b/gcc/d/d-diagnostic.cc index 5cf74ef964d4..373075ca54de 100644 --- a/gcc/d/d-diagnostic.cc +++ b/gcc/d/d-diagnostic.cc @@ -198,7 +198,7 @@ d_diagnostic_report_diagnostic (const Loc &loc, int opt, const char *format, diagnostic_set_info_translated (&diagnostic, xformat, &argp, &rich_loc, kind); if (opt != 0) - diagnostic.option_index = opt; + diagnostic.option_id = opt; diagnostic_report_diagnostic (global_dc, &diagnostic); } diff --git a/gcc/diagnostic-core.h b/gcc/diagnostic-core.h index 8071cc1f69b5..0fddf25403ce 100644 --- a/gcc/diagnostic-core.h +++ b/gcc/diagnostic-core.h @@ -51,6 +51,27 @@ class auto_diagnostic_group /* Forward decl. */ class diagnostic_metadata; /* See diagnostic-metadata.h. */ +/* A class to use for the ID of an option that controls + a particular diagnostic. + This is just a wrapper around "int", but better documents + the intent of the code. */ + +struct diagnostic_option_id +{ + diagnostic_option_id () : m_idx (0) {} + + diagnostic_option_id (int idx) : m_idx (idx) {} + /* Ideally we'd take an enum opt_code here, but we don't + want to depend on its decl. */ + + bool operator== (diagnostic_option_id other) const + { + return m_idx == other.m_idx; + } + + int m_idx; +}; + extern const char *progname; extern const char *trim_filename (const char *); @@ -73,19 +94,29 @@ extern void internal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2) extern void internal_error_no_backtrace (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2) ATTRIBUTE_NORETURN; /* Pass one of the OPT_W* from options.h as the first parameter. */ -extern bool warning (int, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); -extern bool warning_n (location_t, int, unsigned HOST_WIDE_INT, +extern bool warning (diagnostic_option_id, + const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); +extern bool warning_n (location_t, + diagnostic_option_id, + unsigned HOST_WIDE_INT, const char *, const char *, ...) ATTRIBUTE_GCC_DIAG(4,6) ATTRIBUTE_GCC_DIAG(5,6); -extern bool warning_n (rich_location *, int, unsigned HOST_WIDE_INT, +extern bool warning_n (rich_location *, + diagnostic_option_id, + unsigned HOST_WIDE_INT, const char *, const char *, ...) ATTRIBUTE_GCC_DIAG(4, 6) ATTRIBUTE_GCC_DIAG(5, 6); -extern bool warning_at (location_t, int, const char *, ...) +extern bool warning_at (location_t, + diagnostic_option_id, + const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); -extern bool warning_at (rich_location *, int, const char *, ...) +extern bool warning_at (rich_location *, + diagnostic_option_id, + const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); extern bool warning_meta (rich_location *, - const diagnostic_metadata &, int, + const diagnostic_metadata &, + diagnostic_option_id, const char *, ...) ATTRIBUTE_GCC_DIAG(4,5); extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); @@ -101,17 +132,25 @@ extern void error_meta (rich_location *, const diagnostic_metadata &, extern void fatal_error (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3) ATTRIBUTE_NORETURN; /* Pass one of the OPT_W* from options.h as the second parameter. */ -extern bool pedwarn (location_t, int, const char *, ...) +extern bool pedwarn (location_t, + diagnostic_option_id, + const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); -extern bool pedwarn (rich_location *, int, const char *, ...) +extern bool pedwarn (rich_location *, + diagnostic_option_id, + const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); extern bool permerror (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); extern bool permerror (rich_location *, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); -extern bool permerror_opt (location_t, int, const char *, ...) +extern bool permerror_opt (location_t, + diagnostic_option_id, + const char *, ...) + ATTRIBUTE_GCC_DIAG(3,4); +extern bool permerror_opt (rich_location *, + diagnostic_option_id, + const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); -extern bool permerror_opt (rich_location *, int, const char *, - ...) ATTRIBUTE_GCC_DIAG(3,4); extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); extern void sorry_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); extern void inform (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); @@ -120,16 +159,23 @@ extern void inform_n (location_t, unsigned HOST_WIDE_INT, const char *, const char *, ...) ATTRIBUTE_GCC_DIAG(3,5) ATTRIBUTE_GCC_DIAG(4,5); extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); -extern bool emit_diagnostic (diagnostic_t, location_t, int, +extern bool emit_diagnostic (diagnostic_t, + location_t, + diagnostic_option_id, const char *, ...) ATTRIBUTE_GCC_DIAG(4,5); -extern bool emit_diagnostic (diagnostic_t, rich_location *, int, +extern bool emit_diagnostic (diagnostic_t, + rich_location *, + diagnostic_option_id, const char *, ...) ATTRIBUTE_GCC_DIAG(4,5); -extern bool emit_diagnostic_valist (diagnostic_t, location_t, int, const char *, - va_list *) ATTRIBUTE_GCC_DIAG (4,0); +extern bool emit_diagnostic_valist (diagnostic_t, + location_t, + diagnostic_option_id, + const char *, va_list *) + ATTRIBUTE_GCC_DIAG (4,0); extern bool emit_diagnostic_valist_meta (diagnostic_t, rich_location *, const diagnostic_metadata *, - int, + diagnostic_option_id, const char *, va_list *) ATTRIBUTE_GCC_DIAG (5,0); extern bool seen_error (void); diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc index 3a7b07d1cb0c..a98269d5d48b 100644 --- a/gcc/diagnostic-format-json.cc +++ b/gcc/diagnostic-format-json.cc @@ -252,7 +252,7 @@ json_output_format::on_report_diagnostic (const diagnostic_info &diagnostic, diag_obj->set_string ("message", pp_formatted_text (pp)); pp_clear_output_area (pp); - if (char *option_text = m_context.make_option_name (diagnostic.option_index, + if (char *option_text = m_context.make_option_name (diagnostic.option_id, orig_diag_kind, diagnostic.kind)) { @@ -260,7 +260,7 @@ json_output_format::on_report_diagnostic (const diagnostic_info &diagnostic, free (option_text); } - if (char *option_url = m_context.make_option_url (diagnostic.option_index)) + if (char *option_url = m_context.make_option_url (diagnostic.option_id)) { diag_obj->set_string ("option_url", option_url); free (option_url); diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc index 1fa19ed08735..33d60a680beb 100644 --- a/gcc/diagnostic-format-sarif.cc +++ b/gcc/diagnostic-format-sarif.cc @@ -1642,7 +1642,7 @@ sarif_builder::make_result_object (diagnostic_context &context, /* "ruleId" property (SARIF v2.1.0 section 3.27.5). */ /* Ideally we'd have an option_name for these. */ if (char *option_text - = context.make_option_name (diagnostic.option_index, + = context.make_option_name (diagnostic.option_id, orig_diag_kind, diagnostic.kind)) { /* Lazily create reportingDescriptor objects for and add to m_rules_arr. @@ -1754,7 +1754,7 @@ make_reporting_descriptor_object_for_warning (diagnostic_context &context, it seems redundant compared to "id". */ /* "helpUri" property (SARIF v2.1.0 section 3.49.12). */ - if (char *option_url = context.make_option_url (diagnostic.option_index)) + if (char *option_url = context.make_option_url (diagnostic.option_id)) { reporting_desc->set_string ("helpUri", option_url); free (option_url); diff --git a/gcc/diagnostic-format-text.cc b/gcc/diagnostic-format-text.cc index fcca72a3b2b4..f87addc44b24 100644 --- a/gcc/diagnostic-format-text.cc +++ b/gcc/diagnostic-format-text.cc @@ -190,13 +190,13 @@ print_option_information (const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind) { if (char *option_text - = m_context.make_option_name (diagnostic.option_index, + = m_context.make_option_name (diagnostic.option_id, orig_diag_kind, diagnostic.kind)) { char *option_url = nullptr; pretty_printer * const pp = get_printer (); if (pp->supports_urls_p ()) - option_url = m_context.make_option_url (diagnostic.option_index); + option_url = m_context.make_option_url (diagnostic.option_id); pp_string (pp, " ["); const char *kind_color = diagnostic_get_color_for_kind (diagnostic.kind); pp_string (pp, colorize_start (pp_show_color (pp), kind_color)); diff --git a/gcc/diagnostic-global-context.cc b/gcc/diagnostic-global-context.cc index a329b2a045ba..9e151905a6bb 100644 --- a/gcc/diagnostic-global-context.cc +++ b/gcc/diagnostic-global-context.cc @@ -53,15 +53,17 @@ verbatim (const char *gmsgid, ...) implying global_dc and taking a variable argument list. */ bool -emit_diagnostic (diagnostic_t kind, location_t location, int opt, +emit_diagnostic (diagnostic_t kind, + location_t location, + diagnostic_option_id option_id, const char *gmsgid, ...) { auto_diagnostic_group d; va_list ap; va_start (ap, gmsgid); rich_location richloc (line_table, location); - bool ret = global_dc->diagnostic_impl (&richloc, nullptr, opt, gmsgid, &ap, - kind); + bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id, + gmsgid, &ap, kind); va_end (ap); return ret; } @@ -69,14 +71,16 @@ emit_diagnostic (diagnostic_t kind, location_t location, int opt, /* As above, but for rich_location *. */ bool -emit_diagnostic (diagnostic_t kind, rich_location *richloc, int opt, +emit_diagnostic (diagnostic_t kind, + rich_location *richloc, + diagnostic_option_id option_id, const char *gmsgid, ...) { auto_diagnostic_group d; va_list ap; va_start (ap, gmsgid); - bool ret = global_dc->diagnostic_impl (richloc, nullptr, opt, gmsgid, &ap, - kind); + bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id, + gmsgid, &ap, kind); va_end (ap); return ret; } @@ -84,11 +88,14 @@ emit_diagnostic (diagnostic_t kind, rich_location *richloc, int opt, /* As above, but taking a variable argument list. */ bool -emit_diagnostic_valist (diagnostic_t kind, location_t location, int opt, +emit_diagnostic_valist (diagnostic_t kind, + location_t location, + diagnostic_option_id option_id, const char *gmsgid, va_list *ap) { rich_location richloc (line_table, location); - return global_dc->diagnostic_impl (&richloc, nullptr, opt, gmsgid, ap, kind); + return global_dc->diagnostic_impl (&richloc, nullptr, option_id, + gmsgid, ap, kind); } /* As above, but with rich_location and metadata. */ @@ -97,10 +104,11 @@ bool emit_diagnostic_valist_meta (diagnostic_t kind, rich_location *richloc, const diagnostic_metadata *metadata, - int opt, + diagnostic_option_id option_id, const char *gmsgid, va_list *ap) { - return global_dc->diagnostic_impl (richloc, metadata, opt, gmsgid, ap, kind); + return global_dc->diagnostic_impl (richloc, metadata, option_id, + gmsgid, ap, kind); } /* An informative note at LOCATION. Use this for additional details on an error @@ -149,14 +157,14 @@ inform_n (location_t location, unsigned HOST_WIDE_INT n, to the relevant language specification but is likely to be buggy anyway. Returns true if the warning was printed, false if it was inhibited. */ bool -warning (int opt, const char *gmsgid, ...) +warning (diagnostic_option_id option_id, const char *gmsgid, ...) { auto_diagnostic_group d; va_list ap; va_start (ap, gmsgid); rich_location richloc (line_table, input_location); - bool ret = global_dc->diagnostic_impl (&richloc, nullptr, opt, gmsgid, &ap, - DK_WARNING); + bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id, + gmsgid, &ap, DK_WARNING); va_end (ap); return ret; } @@ -166,14 +174,16 @@ warning (int opt, const char *gmsgid, ...) Returns true if the warning was printed, false if it was inhibited. */ bool -warning_at (location_t location, int opt, const char *gmsgid, ...) +warning_at (location_t location, + diagnostic_option_id option_id, + const char *gmsgid, ...) { auto_diagnostic_group d; va_list ap; va_start (ap, gmsgid); rich_location richloc (line_table, location); - bool ret = global_dc->diagnostic_impl (&richloc, nullptr, opt, gmsgid, &ap, - DK_WARNING); + bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id, + gmsgid, &ap, DK_WARNING); va_end (ap); return ret; } @@ -181,15 +191,17 @@ warning_at (location_t location, int opt, const char *gmsgid, ...) /* Same as "warning at" above, but using RICHLOC. */ bool -warning_at (rich_location *richloc, int opt, const char *gmsgid, ...) +warning_at (rich_location *richloc, + diagnostic_option_id option_id, + const char *gmsgid, ...) { gcc_assert (richloc); auto_diagnostic_group d; va_list ap; va_start (ap, gmsgid); - bool ret = global_dc->diagnostic_impl (richloc, nullptr, opt, gmsgid, &ap, - DK_WARNING); + bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id, + gmsgid, &ap, DK_WARNING); va_end (ap); return ret; } @@ -199,15 +211,16 @@ warning_at (rich_location *richloc, int opt, const char *gmsgid, ...) bool warning_meta (rich_location *richloc, const diagnostic_metadata &metadata, - int opt, const char *gmsgid, ...) + diagnostic_option_id option_id, + const char *gmsgid, ...) { gcc_assert (richloc); auto_diagnostic_group d; va_list ap; va_start (ap, gmsgid); - bool ret = global_dc->diagnostic_impl (richloc, &metadata, opt, gmsgid, &ap, - DK_WARNING); + bool ret = global_dc->diagnostic_impl (richloc, &metadata, option_id, + gmsgid, &ap, DK_WARNING); va_end (ap); return ret; } @@ -215,7 +228,9 @@ warning_meta (rich_location *richloc, /* Same as warning_n plural variant below, but using RICHLOC. */ bool -warning_n (rich_location *richloc, int opt, unsigned HOST_WIDE_INT n, +warning_n (rich_location *richloc, + diagnostic_option_id option_id, + unsigned HOST_WIDE_INT n, const char *singular_gmsgid, const char *plural_gmsgid, ...) { gcc_assert (richloc); @@ -223,7 +238,7 @@ warning_n (rich_location *richloc, int opt, unsigned HOST_WIDE_INT n, auto_diagnostic_group d; va_list ap; va_start (ap, plural_gmsgid); - bool ret = global_dc->diagnostic_n_impl (richloc, nullptr, opt, n, + bool ret = global_dc->diagnostic_n_impl (richloc, nullptr, option_id, n, singular_gmsgid, plural_gmsgid, &ap, DK_WARNING); va_end (ap); @@ -235,14 +250,16 @@ warning_n (rich_location *richloc, int opt, unsigned HOST_WIDE_INT n, Returns true if the warning was printed, false if it was inhibited. */ bool -warning_n (location_t location, int opt, unsigned HOST_WIDE_INT n, +warning_n (location_t location, + diagnostic_option_id option_id, + unsigned HOST_WIDE_INT n, const char *singular_gmsgid, const char *plural_gmsgid, ...) { auto_diagnostic_group d; va_list ap; va_start (ap, plural_gmsgid); rich_location richloc (line_table, location); - bool ret = global_dc->diagnostic_n_impl (&richloc, nullptr, opt, n, + bool ret = global_dc->diagnostic_n_impl (&richloc, nullptr, option_id, n, singular_gmsgid, plural_gmsgid, &ap, DK_WARNING); va_end (ap); @@ -263,14 +280,16 @@ warning_n (location_t location, int opt, unsigned HOST_WIDE_INT n, Returns true if the warning was printed, false if it was inhibited. */ bool -pedwarn (location_t location, int opt, const char *gmsgid, ...) +pedwarn (location_t location, + diagnostic_option_id option_id, + const char *gmsgid, ...) { auto_diagnostic_group d; va_list ap; va_start (ap, gmsgid); rich_location richloc (line_table, location); - bool ret = global_dc->diagnostic_impl (&richloc, nullptr, opt, gmsgid, &ap, - DK_PEDWARN); + bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id, + gmsgid, &ap, DK_PEDWARN); va_end (ap); return ret; } @@ -278,15 +297,17 @@ pedwarn (location_t location, int opt, const char *gmsgid, ...) /* Same as pedwarn above, but using RICHLOC. */ bool -pedwarn (rich_location *richloc, int opt, const char *gmsgid, ...) +pedwarn (rich_location *richloc, + diagnostic_option_id option_id, + const char *gmsgid, ...) { gcc_assert (richloc); auto_diagnostic_group d; va_list ap; va_start (ap, gmsgid); - bool ret = global_dc->diagnostic_impl (richloc, nullptr, opt, gmsgid, &ap, - DK_PEDWARN); + bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id, + gmsgid, &ap, DK_PEDWARN); va_end (ap); return ret; } @@ -332,14 +353,16 @@ permerror (rich_location *richloc, const char *gmsgid, ...) diagnostic can also be downgraded by -Wno-error=opt. */ bool -permerror_opt (location_t location, int opt, const char *gmsgid, ...) +permerror_opt (location_t location, + diagnostic_option_id option_id, + const char *gmsgid, ...) { auto_diagnostic_group d; va_list ap; va_start (ap, gmsgid); rich_location richloc (line_table, location); - bool ret = global_dc->diagnostic_impl (&richloc, nullptr, opt, gmsgid, &ap, - DK_PERMERROR); + bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id, + gmsgid, &ap, DK_PERMERROR); va_end (ap); return ret; } @@ -347,15 +370,17 @@ permerror_opt (location_t location, int opt, const char *gmsgid, ...) /* Same as "permerror" above, but at RICHLOC. */ bool -permerror_opt (rich_location *richloc, int opt, const char *gmsgid, ...) +permerror_opt (rich_location *richloc, + diagnostic_option_id option_id, + const char *gmsgid, ...) { gcc_assert (richloc); auto_diagnostic_group d; va_list ap; va_start (ap, gmsgid); - bool ret = global_dc->diagnostic_impl (richloc, nullptr, opt, gmsgid, &ap, - DK_PERMERROR); + bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id, + gmsgid, &ap, DK_PERMERROR); va_end (ap); return ret; } diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index 0e0ab7aeb838..03fc346501e4 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -482,7 +482,7 @@ diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg, diagnostic->richloc = richloc; diagnostic->metadata = NULL; diagnostic->kind = kind; - diagnostic->option_index = 0; + diagnostic->option_id = 0; } /* Initialize DIAGNOSTIC, where the message GMSGID has not yet been @@ -1004,23 +1004,23 @@ default_diagnostic_finalizer (diagnostic_context *context, /* Interface to specify diagnostic kind overrides. Returns the previous setting, or DK_UNSPECIFIED if the parameters are out of - range. If OPTION_INDEX is zero, the new setting is for all the + range. If OPTION_ID is zero, the new setting is for all the diagnostics. */ diagnostic_t diagnostic_option_classifier:: classify_diagnostic (const diagnostic_context *context, - int option_index, + diagnostic_option_id option_id, diagnostic_t new_kind, location_t where) { diagnostic_t old_kind; - if (option_index < 0 - || option_index >= m_n_opts + if (option_id.m_idx < 0 + || option_id.m_idx >= m_n_opts || new_kind >= DK_LAST_DIAGNOSTIC_KIND) return DK_UNSPECIFIED; - old_kind = m_classify_diagnostic[option_index]; + old_kind = m_classify_diagnostic[option_id.m_idx]; /* Handle pragmas separately, since we need to keep track of *where* the pragmas were. */ @@ -1031,13 +1031,13 @@ classify_diagnostic (const diagnostic_context *context, /* Record the command-line status, so we can reset it back on DK_POP. */ if (old_kind == DK_UNSPECIFIED) { - old_kind = !context->option_enabled_p (option_index) + old_kind = !context->option_enabled_p (option_id) ? DK_IGNORED : DK_ANY; - m_classify_diagnostic[option_index] = old_kind; + m_classify_diagnostic[option_id.m_idx] = old_kind; } for (i = m_n_classification_history - 1; i >= 0; i --) - if (m_classification_history[i].option == option_index) + if (m_classification_history[i].option == option_id.m_idx) { old_kind = m_classification_history[i].kind; break; @@ -1048,12 +1048,12 @@ classify_diagnostic (const diagnostic_context *context, (diagnostic_classification_change_t *) xrealloc (m_classification_history, (i + 1) * sizeof (diagnostic_classification_change_t)); m_classification_history[i].location = where; - m_classification_history[i].option = option_index; + m_classification_history[i].option = option_id.m_idx; m_classification_history[i].kind = new_kind; m_n_classification_history ++; } else - m_classify_diagnostic[option_index] = new_kind; + m_classify_diagnostic[option_id.m_idx] = new_kind; return old_kind; } @@ -1205,9 +1205,9 @@ update_effective_level_from_pragmas (diagnostic_info *diagnostic) const continue; } - int option = hist.option; + diagnostic_option_id option = hist.option; /* The option 0 is for all the diagnostics. */ - if (option == 0 || option == diagnostic->option_index) + if (option == 0 || option == diagnostic->option_id) { diagnostic_t kind = hist.kind; if (kind != DK_UNSPECIFIED) @@ -1239,13 +1239,13 @@ diagnostic_context::diagnostic_enabled (diagnostic_info *diagnostic) get_any_inlining_info (diagnostic); /* Diagnostics with no option or -fpermissive are always enabled. */ - if (!diagnostic->option_index - || diagnostic->option_index == m_opt_permissive) + if (!diagnostic->option_id.m_idx + || diagnostic->option_id == m_opt_permissive) return true; /* This tests if the user provided the appropriate -Wfoo or -Wno-foo option. */ - if (!option_enabled_p (diagnostic->option_index)) + if (!option_enabled_p (diagnostic->option_id)) return false; /* This tests for #pragma diagnostic changes. */ @@ -1255,10 +1255,10 @@ diagnostic_context::diagnostic_enabled (diagnostic_info *diagnostic) /* This tests if the user provided the appropriate -Werror=foo option. */ if (diag_class == DK_UNSPECIFIED - && !option_unspecified_p (diagnostic->option_index)) + && !option_unspecified_p (diagnostic->option_id)) { const diagnostic_t new_kind - = m_option_classifier.get_current_override (diagnostic->option_index); + = m_option_classifier.get_current_override (diagnostic->option_id); if (new_kind != DK_ANY) /* DK_ANY means the diagnostic is not to be ignored, but we don't want to change it specifically to DK_ERROR or DK_WARNING; we want to @@ -1274,17 +1274,18 @@ diagnostic_context::diagnostic_enabled (diagnostic_info *diagnostic) return true; } -/* Returns whether warning OPT is enabled at LOC. */ +/* Returns whether warning OPTION_ID is enabled at LOC. */ bool -diagnostic_context::warning_enabled_at (location_t loc, int opt) +diagnostic_context::warning_enabled_at (location_t loc, + diagnostic_option_id option_id) { if (!diagnostic_report_warnings_p (this, loc)) return false; rich_location richloc (line_table, loc); diagnostic_info diagnostic = {}; - diagnostic.option_index = opt; + diagnostic.option_id = option_id; diagnostic.richloc = &richloc; diagnostic.message.m_richloc = &richloc; diagnostic.kind = DK_WARNING; @@ -1527,7 +1528,8 @@ diagnostic_append_note (diagnostic_context *context, bool diagnostic_context::diagnostic_impl (rich_location *richloc, const diagnostic_metadata *metadata, - int opt, const char *gmsgid, + diagnostic_option_id option_id, + const char *gmsgid, va_list *ap, diagnostic_t kind) { diagnostic_info diagnostic; @@ -1535,13 +1537,13 @@ diagnostic_context::diagnostic_impl (rich_location *richloc, { diagnostic_set_info (&diagnostic, gmsgid, ap, richloc, m_permissive ? DK_WARNING : DK_ERROR); - diagnostic.option_index = (opt != -1 ? opt : m_opt_permissive); + diagnostic.option_id = (option_id.m_idx != -1 ? option_id : m_opt_permissive); } else { diagnostic_set_info (&diagnostic, gmsgid, ap, richloc, kind); if (kind == DK_WARNING || kind == DK_PEDWARN) - diagnostic.option_index = opt; + diagnostic.option_id = option_id; } diagnostic.metadata = metadata; return report_diagnostic (&diagnostic); @@ -1552,7 +1554,8 @@ diagnostic_context::diagnostic_impl (rich_location *richloc, bool diagnostic_context::diagnostic_n_impl (rich_location *richloc, const diagnostic_metadata *metadata, - int opt, unsigned HOST_WIDE_INT n, + diagnostic_option_id option_id, + unsigned HOST_WIDE_INT n, const char *singular_gmsgid, const char *plural_gmsgid, va_list *ap, diagnostic_t kind) @@ -1571,7 +1574,7 @@ diagnostic_context::diagnostic_n_impl (rich_location *richloc, const char *text = ngettext (singular_gmsgid, plural_gmsgid, gtn); diagnostic_set_info_translated (&diagnostic, text, ap, richloc, kind); if (kind == DK_WARNING) - diagnostic.option_index = opt; + diagnostic.option_id = option_id; diagnostic.metadata = metadata; return report_diagnostic (&diagnostic); } diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 7244f425936c..b7c38267bd08 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -136,7 +136,7 @@ enum diagnostic_text_art_charset struct diagnostic_info { diagnostic_info () - : message (), richloc (), metadata (), x_data (), kind (), option_index (), + : message (), richloc (), metadata (), x_data (), kind (), option_id (), m_iinfo () { } @@ -155,7 +155,7 @@ struct diagnostic_info /* The kind of diagnostic it is about. */ diagnostic_t kind; /* Which OPT_* directly controls this diagnostic. */ - int option_index; + diagnostic_option_id option_id; /* Inlining context containing locations for each call site along the inlining stack. */ @@ -189,17 +189,17 @@ class diagnostic_option_manager public: virtual ~diagnostic_option_manager () {} - /* Return 1 if option OPT_IDX is enabled, 0 if it is disabled, + /* Return 1 if option OPTION_ID is enabled, 0 if it is disabled, or -1 if it isn't a simple on-off switch (or if the value is unknown, typically set later in target). */ - virtual int option_enabled_p (int opt_idx) const = 0; + virtual int option_enabled_p (diagnostic_option_id option_id) const = 0; - /* Return malloced memory for the name of the option OPT_IDX + /* Return malloced memory for the name of the option OPTION_ID which enabled a diagnostic, originally of type ORIG_DIAG_KIND but possibly converted to DIAG_KIND by options such as -Werror. May return NULL if no name is to be printed. May be passed 0 as well as the index of a particular option. */ - virtual char *make_option_name (int opt_idx, + virtual char *make_option_name (diagnostic_option_id option_id, diagnostic_t orig_diag_kind, diagnostic_t diag_kind) const = 0; @@ -207,7 +207,7 @@ public: a diagnostic. May return NULL if no URL is available. May be passed 0 as well as the index of a particular option. */ - virtual char *make_option_url (int opt_idx) const = 0; + virtual char *make_option_url (diagnostic_option_id option_id) const = 0; }; class edit_context; @@ -236,20 +236,20 @@ public: is empty, revert to the state based on command line parameters. */ void pop (location_t where); - bool option_unspecified_p (int opt) const + bool option_unspecified_p (diagnostic_option_id option_id) const { - return get_current_override (opt) == DK_UNSPECIFIED; + return get_current_override (option_id) == DK_UNSPECIFIED; } - diagnostic_t get_current_override (int opt) const + diagnostic_t get_current_override (diagnostic_option_id option_id) const { - gcc_assert (opt < m_n_opts); - return m_classify_diagnostic[opt]; + gcc_assert (option_id.m_idx < m_n_opts); + return m_classify_diagnostic[option_id.m_idx]; } diagnostic_t classify_diagnostic (const diagnostic_context *context, - int option_index, + diagnostic_option_id option_id, diagnostic_t new_kind, location_t where); @@ -263,7 +263,12 @@ private: struct diagnostic_classification_change_t { location_t location; + + /* For DK_POP, this is the index of the corresponding push (as stored + in m_push_list). + Otherwise, this is an option index. */ int option; + diagnostic_t kind; }; @@ -386,11 +391,11 @@ public: void begin_group (); void end_group (); - bool warning_enabled_at (location_t loc, int opt); + bool warning_enabled_at (location_t loc, diagnostic_option_id option_id); - bool option_unspecified_p (int opt) const + bool option_unspecified_p (diagnostic_option_id option_id) const { - return m_option_classifier.option_unspecified_p (opt); + return m_option_classifier.option_unspecified_p (option_id); } bool report_diagnostic (diagnostic_info *); @@ -401,12 +406,12 @@ public: void action_after_output (diagnostic_t diag_kind); diagnostic_t - classify_diagnostic (int option_index, + classify_diagnostic (diagnostic_option_id option_id, diagnostic_t new_kind, location_t where) { return m_option_classifier.classify_diagnostic (this, - option_index, + option_id, new_kind, where); } @@ -507,29 +512,29 @@ public: } /* Option-related member functions. */ - inline bool option_enabled_p (int option_index) const + inline bool option_enabled_p (diagnostic_option_id option_id) const { if (!m_option_mgr) return true; - return m_option_mgr->option_enabled_p (option_index); + return m_option_mgr->option_enabled_p (option_id); } - inline char *make_option_name (int option_index, - diagnostic_t orig_diag_kind, - diagnostic_t diag_kind) const + inline char *make_option_name (diagnostic_option_id option_id, + diagnostic_t orig_diag_kind, + diagnostic_t diag_kind) const { if (!m_option_mgr) return nullptr; - return m_option_mgr->make_option_name (option_index, + return m_option_mgr->make_option_name (option_id, orig_diag_kind, diag_kind); } - inline char *make_option_url (int option_index) const + inline char *make_option_url (diagnostic_option_id option_id) const { if (!m_option_mgr) return nullptr; - return m_option_mgr->make_option_url (option_index); + return m_option_mgr->make_option_url (option_id); } void @@ -544,10 +549,10 @@ public: label_text get_location_text (const expanded_location &s) const; bool diagnostic_impl (rich_location *, const diagnostic_metadata *, - int, const char *, + diagnostic_option_id, const char *, va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(5,0); bool diagnostic_n_impl (rich_location *, const diagnostic_metadata *, - int, unsigned HOST_WIDE_INT, + diagnostic_option_id, unsigned HOST_WIDE_INT, const char *, const char *, va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(7,0); @@ -850,9 +855,10 @@ diagnostic_ready_p () diagnostic. */ inline void -diagnostic_override_option_index (diagnostic_info *info, int optidx) +diagnostic_set_option_id (diagnostic_info *info, + diagnostic_option_id option_id) { - info->option_index = optidx; + info->option_id = option_id; } /* Diagnostic related functions. */ @@ -925,11 +931,11 @@ diagnostic_initialize_input_context (diagnostic_context *context, /* Force diagnostics controlled by OPTIDX to be kind KIND. */ inline diagnostic_t diagnostic_classify_diagnostic (diagnostic_context *context, - int optidx, + diagnostic_option_id option_id, diagnostic_t kind, location_t where) { - return context->classify_diagnostic (optidx, kind, where); + return context->classify_diagnostic (option_id, kind, where); } inline void @@ -1052,15 +1058,15 @@ extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1; extern int num_digits (int); inline bool -warning_enabled_at (location_t loc, int opt) +warning_enabled_at (location_t loc, diagnostic_option_id option_id) { - return global_dc->warning_enabled_at (loc, opt); + return global_dc->warning_enabled_at (loc, option_id); } inline bool -option_unspecified_p (int opt) +option_unspecified_p (diagnostic_option_id option_id) { - return global_dc->option_unspecified_p (opt); + return global_dc->option_unspecified_p (option_id); } extern char *get_cwe_url (int cwe); diff --git a/gcc/fortran/cpp.cc b/gcc/fortran/cpp.cc index 3a6dbdc2003c..7c5f00cfd690 100644 --- a/gcc/fortran/cpp.cc +++ b/gcc/fortran/cpp.cc @@ -1057,7 +1057,7 @@ cb_used_define (cpp_reader *pfile, location_t line ATTRIBUTE_UNUSED, /* Return the gcc option code associated with the reason for a cpp message, or 0 if none. */ -static int +static diagnostic_option_id cb_cpp_diagnostic_cpp_option (enum cpp_warning_reason reason) { const struct cpp_reason_option_codes_t *entry; @@ -1115,8 +1115,8 @@ cb_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED, } diagnostic_set_info_translated (&diagnostic, msg, ap, richloc, dlevel); - diagnostic_override_option_index (&diagnostic, - cb_cpp_diagnostic_cpp_option (reason)); + diagnostic_set_option_id (&diagnostic, + cb_cpp_diagnostic_cpp_option (reason)); ret = diagnostic_report_diagnostic (global_dc, &diagnostic); if (level == CPP_DL_WARNING_SYSHDR) global_dc->m_warn_system_headers = save_warn_system_headers; diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc index e328dbd13fc5..6a7f0b052bc5 100644 --- a/gcc/fortran/error.cc +++ b/gcc/fortran/error.cc @@ -978,7 +978,7 @@ gfc_warning (int opt, const char *gmsgid, va_list ap) diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_WARNING); - diagnostic.option_index = opt; + diagnostic.option_id = opt; bool ret = gfc_report_diagnostic (&diagnostic); if (buffered_p) @@ -1367,7 +1367,7 @@ gfc_warning_now_at (location_t loc, int opt, const char *gmsgid, ...) va_start (argp, gmsgid); diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_WARNING); - diagnostic.option_index = opt; + diagnostic.option_id = opt; ret = gfc_report_diagnostic (&diagnostic); va_end (argp); return ret; @@ -1386,7 +1386,7 @@ gfc_warning_now (int opt, const char *gmsgid, ...) va_start (argp, gmsgid); diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_WARNING); - diagnostic.option_index = opt; + diagnostic.option_id = opt; ret = gfc_report_diagnostic (&diagnostic); va_end (argp); return ret; @@ -1405,7 +1405,7 @@ gfc_warning_internal (int opt, const char *gmsgid, ...) va_start (argp, gmsgid); diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_WARNING); - diagnostic.option_index = opt; + diagnostic.option_id = opt; ret = gfc_report_diagnostic (&diagnostic); va_end (argp); return ret; diff --git a/gcc/ipa-pure-const.cc b/gcc/ipa-pure-const.cc index d285462b6cf1..b5a1dcdc154f 100644 --- a/gcc/ipa-pure-const.cc +++ b/gcc/ipa-pure-const.cc @@ -199,11 +199,12 @@ function_always_visible_to_compiler_p (tree decl) by the function. */ static hash_set<tree> * -suggest_attribute (int option, tree decl, bool known_finite, +suggest_attribute (diagnostic_option_id option, tree decl, bool known_finite, hash_set<tree> *warned_about, const char * attrib_name) { - if (!option_enabled (option, lang_hooks.option_lang_mask (), &global_options)) + if (!option_enabled (option.m_idx, lang_hooks.option_lang_mask (), + &global_options)) return warned_about; if (TREE_THIS_VOLATILE (decl) || (known_finite && function_always_visible_to_compiler_p (decl))) diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc index 11eaa1f5f789..6d847e01a4ee 100644 --- a/gcc/lto-wrapper.cc +++ b/gcc/lto-wrapper.cc @@ -2148,11 +2148,13 @@ public: : gcc_diagnostic_option_manager (0 /* lang_mask */) { } - int option_enabled_p (int) const final override + int option_enabled_p (diagnostic_option_id) const final override { return true; } - char *make_option_name (int, diagnostic_t, diagnostic_t) const final override + char *make_option_name (diagnostic_option_id, + diagnostic_t, + diagnostic_t) const final override { return nullptr; } diff --git a/gcc/opts-common.cc b/gcc/opts-common.cc index 62d7bef552e0..70ac225e3968 100644 --- a/gcc/opts-common.cc +++ b/gcc/opts-common.cc @@ -1871,9 +1871,10 @@ option_enabled (int opt_idx, unsigned lang_mask, void *opts) } int -compiler_diagnostic_option_manager::option_enabled_p (int opt_idx) const +compiler_diagnostic_option_manager:: +option_enabled_p (diagnostic_option_id opt_id) const { - return option_enabled (opt_idx, m_lang_mask, m_opts); + return option_enabled (opt_id.m_idx, m_lang_mask, m_opts); } /* Fill STATE with the current state of option OPTION in OPTS. Return diff --git a/gcc/opts-diagnostic.h b/gcc/opts-diagnostic.h index 2b78ce73b1b3..48cc21e31a48 100644 --- a/gcc/opts-diagnostic.h +++ b/gcc/opts-diagnostic.h @@ -25,7 +25,7 @@ along with GCC; see the file COPYING3. If not see class gcc_diagnostic_option_manager : public diagnostic_option_manager { public: - char *make_option_url (int opt) const final override; + char *make_option_url (diagnostic_option_id option_id) const final override; protected: gcc_diagnostic_option_manager (unsigned lang_mask) @@ -49,8 +49,8 @@ public: { } - int option_enabled_p (int opt_idx) const final override; - char *make_option_name (int opt_idx, + int option_enabled_p (diagnostic_option_id option_id) const final override; + char *make_option_name (diagnostic_option_id option_id, diagnostic_t orig_diag_kind, diagnostic_t diag_kind) const final override; diff --git a/gcc/opts.cc b/gcc/opts.cc index 3e50933a0a94..d48a1ac6602c 100644 --- a/gcc/opts.cc +++ b/gcc/opts.cc @@ -3705,22 +3705,22 @@ enable_warning_as_error (const char *arg, int value, unsigned int lang_mask, char * compiler_diagnostic_option_manager:: -make_option_name (int option_index, +make_option_name (diagnostic_option_id option_id, diagnostic_t orig_diag_kind, diagnostic_t diag_kind) const { - if (option_index) + if (option_id.m_idx) { /* A warning classified as an error. */ if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN) && diag_kind == DK_ERROR) return concat (cl_options[OPT_Werror_].opt_text, /* Skip over "-W". */ - cl_options[option_index].opt_text + 2, + cl_options[option_id.m_idx].opt_text + 2, NULL); /* A warning with option. */ else - return xstrdup (cl_options[option_index].opt_text); + return xstrdup (cl_options[option_id.m_idx].opt_text); } /* A warning without option classified as an error. */ else if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN @@ -3781,11 +3781,13 @@ get_option_url_suffix (int option_index, unsigned lang_mask) which enabled a diagnostic. */ char * -gcc_diagnostic_option_manager::make_option_url (int option_index) const +gcc_diagnostic_option_manager:: +make_option_url (diagnostic_option_id option_id) const { - if (option_index) + if (option_id.m_idx) { - label_text url_suffix = get_option_url_suffix (option_index, m_lang_mask); + label_text url_suffix = get_option_url_suffix (option_id.m_idx, + m_lang_mask); if (url_suffix.get ()) return concat (DOCUMENTATION_ROOT_URL, url_suffix.get (), nullptr); } diff --git a/gcc/substring-locations.cc b/gcc/substring-locations.cc index 00ad8edd5869..156c12134baf 100644 --- a/gcc/substring-locations.cc +++ b/gcc/substring-locations.cc @@ -143,7 +143,7 @@ format_string_diagnostic_t (const substring_loc &fmt_loc, { } -/* Emit a warning governed by option OPT, using SINGULAR_GMSGID as the +/* Emit a warning governed by option OPTION_ID, using SINGULAR_GMSGID as the format string (or if PLURAL_GMSGID is different from SINGULAR_GMSGID, using SINGULAR_GMSGID, PLURAL_GMSGID and N as arguments to ngettext) and AP as its arguments. @@ -151,7 +151,7 @@ format_string_diagnostic_t (const substring_loc &fmt_loc, Return true if a warning was emitted, false otherwise. */ bool -format_string_diagnostic_t::emit_warning_n_va (int opt, +format_string_diagnostic_t::emit_warning_n_va (diagnostic_option_id option_id, unsigned HOST_WIDE_INT n, const char *singular_gmsgid, const char *plural_gmsgid, @@ -223,7 +223,7 @@ format_string_diagnostic_t::emit_warning_n_va (int opt, else diagnostic_set_info (&diagnostic, singular_gmsgid, ap, &richloc, DK_WARNING); - diagnostic.option_index = opt; + diagnostic.option_id = option_id; bool warned = diagnostic_report_diagnostic (global_dc, &diagnostic); if (!err && fmt_substring_loc && !substring_within_range) @@ -248,21 +248,23 @@ format_string_diagnostic_t::emit_warning_n_va (int opt, /* Singular-only version of the above. */ bool -format_string_diagnostic_t::emit_warning_va (int opt, const char *gmsgid, +format_string_diagnostic_t::emit_warning_va (diagnostic_option_id option_id, + const char *gmsgid, va_list *ap) const { - return emit_warning_n_va (opt, 0, gmsgid, gmsgid, ap); + return emit_warning_n_va (option_id, 0, gmsgid, gmsgid, ap); } /* Variadic version of the above (singular only). */ bool -format_string_diagnostic_t::emit_warning (int opt, const char *gmsgid, +format_string_diagnostic_t::emit_warning (diagnostic_option_id option_id, + const char *gmsgid, ...) const { va_list ap; va_start (ap, gmsgid); - bool warned = emit_warning_va (opt, gmsgid, &ap); + bool warned = emit_warning_va (option_id, gmsgid, &ap); va_end (ap); return warned; @@ -271,14 +273,15 @@ format_string_diagnostic_t::emit_warning (int opt, const char *gmsgid, /* Variadic version of the above (singular vs plural). */ bool -format_string_diagnostic_t::emit_warning_n (int opt, unsigned HOST_WIDE_INT n, +format_string_diagnostic_t::emit_warning_n (diagnostic_option_id option_id, + unsigned HOST_WIDE_INT n, const char *singular_gmsgid, const char *plural_gmsgid, ...) const { va_list ap; va_start (ap, plural_gmsgid); - bool warned = emit_warning_n_va (opt, n, singular_gmsgid, plural_gmsgid, + bool warned = emit_warning_n_va (option_id, n, singular_gmsgid, plural_gmsgid, &ap); va_end (ap); diff --git a/gcc/substring-locations.h b/gcc/substring-locations.h index b286ae8e3b5f..ef67d981aa94 100644 --- a/gcc/substring-locations.h +++ b/gcc/substring-locations.h @@ -90,18 +90,24 @@ class format_string_diagnostic_t /* Functions for emitting a warning about a format string. */ - bool emit_warning_va (int opt, const char *gmsgid, va_list *ap) const + bool emit_warning_va (diagnostic_option_id option_id, + const char *gmsgid, + va_list *ap) const ATTRIBUTE_GCC_DIAG (3, 0); - bool emit_warning_n_va (int opt, unsigned HOST_WIDE_INT n, + bool emit_warning_n_va (diagnostic_option_id option_id, + unsigned HOST_WIDE_INT n, const char *singular_gmsgid, - const char *plural_gmsgid, va_list *ap) const + const char *plural_gmsgid, + va_list *ap) const ATTRIBUTE_GCC_DIAG (4, 0) ATTRIBUTE_GCC_DIAG (5, 0); - bool emit_warning (int opt, const char *gmsgid, ...) const + bool emit_warning (diagnostic_option_id option_id, + const char *gmsgid, ...) const ATTRIBUTE_GCC_DIAG (3, 4); - bool emit_warning_n (int opt, unsigned HOST_WIDE_INT n, + bool emit_warning_n (diagnostic_option_id option_id, + unsigned HOST_WIDE_INT n, const char *singular_gmsgid, const char *plural_gmsgid, ...) const ATTRIBUTE_GCC_DIAG (4, 6) ATTRIBUTE_GCC_DIAG (5, 6); -- 2.26.3