From 89991f31c5ded21179b12a9f4063c2b8fabc2e3b Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Mon, 9 Sep 2024 19:38:13 -0400 Subject: diagnostics: introduce struct diagnostic_option_id 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. 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 --- gcc/c/c-errors.cc | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'gcc/c/c-errors.cc') diff --git a/gcc/c/c-errors.cc b/gcc/c/c-errors.cc index f36e7f9..c6b7c10 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; } -- cgit v1.1