diff options
Diffstat (limited to 'gcc/c-family')
-rw-r--r-- | gcc/c-family/ChangeLog | 83 | ||||
-rw-r--r-- | gcc/c-family/c-common.cc | 28 | ||||
-rw-r--r-- | gcc/c-family/c-common.h | 5 | ||||
-rw-r--r-- | gcc/c-family/c-cppbuiltin.cc | 2 | ||||
-rw-r--r-- | gcc/c-family/c-format.cc | 16 | ||||
-rw-r--r-- | gcc/c-family/c-indentation.cc | 19 | ||||
-rw-r--r-- | gcc/c-family/c-lex.cc | 2 | ||||
-rw-r--r-- | gcc/c-family/c-opts.cc | 20 | ||||
-rw-r--r-- | gcc/c-family/c-pragma.cc | 15 | ||||
-rw-r--r-- | gcc/c-family/c-warn.cc | 4 | ||||
-rw-r--r-- | gcc/c-family/known-headers.cc | 7 | ||||
-rw-r--r-- | gcc/c-family/known-headers.h | 4 |
12 files changed, 149 insertions, 56 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index fb40698..a754525 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,86 @@ +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * c-common.cc: Make diagnostics::context::m_source_printing + private. + * c-format.cc: Likewise. + * c-opts.cc: Likewise. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * c-common.cc: Update usage of "diagnostic_info" to explicitly + refer to "diagnostics::diagnostic_info". + * c-opts.cc: Likewise. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * c-format.cc: Update for file_cache and char_span moving from + input.h to diagnostics/file-cache.h and into the "diagnostics::" + namespace. + * c-indentation.cc: Likewise. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * c-common.cc (c_family_tests): Add include of + "diagnostics/diagnostics-selftests.h". Replace + c_diagnostic_cc_tests with + diagnostics::selftest::context_cc_tests. + * c-common.h: Drop c_diagnostic_cc_tests decl. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * c-common.cc: Update for diagnostic_t becoming + enum class diagnostics::kind. + * c-format.cc: Likewise. + * c-lex.cc: Likewise. + * c-opts.cc: Likewise. + * c-pragma.cc: Likewise. + * c-warn.cc: Likewise. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * c-common.cc: Update for renaming of diagnostic_option_id to + diagnostics::option_id. + * c-common.h: Likewise. + * c-cppbuiltin.cc: Likewise. + * known-headers.cc: Likewise. + * known-headers.h: Likewise. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * c-common.cc: Update comment for renaming of edit_context. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * c-format.cc (test_type_mismatch_range_labels): Update for + move of selftest::test_diagnostic_context to + diagnostics::selftest::test_context. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * c-format.cc: Update for move of selftest-diagnostic.h to + diagnostics/selftest-context.h. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * c-common.h: Update for diagnostic_context becoming + diagnostics::context. + * c-opts.cc: Likewise. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * c-opts.cc (c_diagnostic_text_finalizer): Add "m_" prefix to + fields of diagnostic_info. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * c-opts.cc: Update for move of "diagnostic-macro-unwinding.h" + to "diagnostics/macro-unwinding.h". + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * c-opts.cc: Update for move of diagnostics output formats into + namespace "diagnostics" as "sinks". + 2025-07-16 Kwok Cheung Yeung <kcyeung@baylibre.com> * c-omp.cc (c_finish_omp_depobj): Use OMP_ITERATOR_DECL_P. diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index 362dc50..e7dd460 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -56,6 +56,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-pretty-print-markup.h" #include "gcc-rich-location.h" #include "gcc-urlifier.h" +#include "diagnostics/diagnostics-selftests.h" cpp_reader *parse_in; /* Declared in c-pragma.h. */ @@ -7025,7 +7026,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 diagnostic_option_id +static diagnostics::option_id c_option_controlling_cpp_diagnostic (enum cpp_warning_reason reason) { const struct cpp_reason_option_codes_t *entry; @@ -7067,8 +7068,8 @@ c_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED, rich_location *richloc, const char *msg, va_list *ap) { - diagnostic_info diagnostic; - diagnostic_t dlevel; + diagnostics::diagnostic_info diagnostic; + enum diagnostics::kind dlevel; bool save_warn_system_headers = global_dc->m_warn_system_headers; bool ret; @@ -7082,24 +7083,24 @@ c_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED, case CPP_DL_WARNING: if (flag_no_output) return false; - dlevel = DK_WARNING; + dlevel = diagnostics::kind::warning; break; case CPP_DL_PEDWARN: if (flag_no_output && !flag_pedantic_errors) return false; - dlevel = DK_PEDWARN; + dlevel = diagnostics::kind::pedwarn; break; case CPP_DL_ERROR: - dlevel = DK_ERROR; + dlevel = diagnostics::kind::error; break; case CPP_DL_ICE: - dlevel = DK_ICE; + dlevel = diagnostics::kind::ice; break; case CPP_DL_NOTE: - dlevel = DK_NOTE; + dlevel = diagnostics::kind::note; break; case CPP_DL_FATAL: - dlevel = DK_FATAL; + dlevel = diagnostics::kind::fatal; break; default: gcc_unreachable (); @@ -9963,8 +9964,11 @@ c_family_tests (void) c_indentation_cc_tests (); c_pretty_print_cc_tests (); c_spellcheck_cc_tests (); - c_diagnostic_cc_tests (); c_opt_problem_cc_tests (); + + /* According to https://gcc.gnu.org/pipermail/gcc/2021-November/237703.html + this has some language-specific assumptions, so we run it here. */ + diagnostics::selftest::context_cc_tests (); } } // namespace selftest @@ -10046,7 +10050,7 @@ try_to_locate_new_include_insertion_point (const char *file, location_t loc) return UNKNOWN_LOCATION; /* The "start_location" is column 0, meaning "the whole line". - rich_location and edit_context can't cope with this, so use + rich_location and diagnostics::changes can't cope with this, so use column 1 instead. */ location_t col_0 = ord_map_for_insertion->start_location; return linemap_position_for_loc_and_offset (line_table, col_0, 1); @@ -10110,7 +10114,7 @@ maybe_add_include_fixit (rich_location *richloc, const char *header, richloc->add_fixit_insert_before (include_insert_loc, text); free (text); - if (override_location && global_dc->m_source_printing.enabled) + if (override_location && global_dc->get_source_printing_options ().enabled) { /* Replace the primary location with that of the insertion point for the fix-it hint. diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 675708d..7c7e21d 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -979,7 +979,7 @@ extern tree build_va_arg (location_t, tree, tree); extern const unsigned int c_family_lang_mask; extern unsigned int c_common_option_lang_mask (void); -extern void c_common_diagnostics_set_defaults (diagnostic_context *); +extern void c_common_diagnostics_set_defaults (diagnostics::context *); extern bool c_common_complain_wrong_lang_p (const struct cl_option *); extern void c_common_init_options_struct (struct gcc_options *); extern void c_common_init_options (unsigned int, struct cl_decoded_option *); @@ -1265,7 +1265,7 @@ extern void c_stddef_cpp_builtins (void); extern void fe_file_change (const line_map_ordinary *); extern void c_parse_error (const char *, enum cpp_ttype, tree, unsigned char, rich_location *richloc); -extern diagnostic_option_id get_option_for_builtin_define (const char *macro_name); +extern diagnostics::option_id get_option_for_builtin_define (const char *macro_name); /* In c-ppoutput.cc */ extern void init_pp_output (FILE *); @@ -1729,7 +1729,6 @@ extern tree braced_lists_to_strings (tree, tree); namespace selftest { /* Declarations for specific families of tests within c-family, by source file, in alphabetical order. */ - extern void c_diagnostic_cc_tests (void); extern void c_format_cc_tests (void); extern void c_indentation_cc_tests (void); extern void c_opt_problem_cc_tests (void); diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc index 2f86b1f..4aea902 100644 --- a/gcc/c-family/c-cppbuiltin.cc +++ b/gcc/c-family/c-cppbuiltin.cc @@ -1681,7 +1681,7 @@ c_cpp_builtins (cpp_reader *pfile) /* Given NAME, return the command-line option that would make it be a builtin define, or 0 if unrecognized. */ -diagnostic_option_id +diagnostics::option_id get_option_for_builtin_define (const char *name) { if (!strcmp (name, "_OPENACC")) diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc index 80430e9..bf144d0 100644 --- a/gcc/c-family/c-format.cc +++ b/gcc/c-family/c-format.cc @@ -32,7 +32,8 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic.h" #include "substring-locations.h" #include "selftest.h" -#include "selftest-diagnostic.h" +#include "diagnostics/selftest-context.h" +#include "diagnostics/file-cache.h" #include "builtins.h" #include "attribs.h" #include "c-family/c-type-mismatch.h" @@ -4634,7 +4635,7 @@ get_corrected_substring (const substring_loc &fmt_loc, if (caret.column > finish.column) return NULL; - char_span line + diagnostics::char_span line = global_dc->get_file_cache ().get_source_line (start.file, start.line); if (!line) return NULL; @@ -4646,7 +4647,8 @@ get_corrected_substring (const substring_loc &fmt_loc, specification, up to the (but not including) the length modifier. In the above example, this would be "%-+*.*". */ int length_up_to_type = caret.column - start.column; - char_span prefix_span = line.subspan (start.column - 1, length_up_to_type); + diagnostics::char_span prefix_span + = line.subspan (start.column - 1, length_up_to_type); char *prefix = prefix_span.xstrdup (); /* Now attempt to generate a suggestion for the rest of the specification @@ -5584,10 +5586,12 @@ test_type_mismatch_range_labels () gcc_rich_location richloc (fmt, &fmt_label, nullptr); richloc.add_range (param, SHOW_RANGE_WITHOUT_CARET, ¶m_label); - test_diagnostic_context dc; + diagnostics::selftest::test_context dc; diagnostic_show_locus (&dc, - dc.m_source_printing, - &richloc, DK_ERROR, dc.get_reference_printer ()); + dc.get_source_printing_options (), + &richloc, + diagnostics::kind::error, + dc.get_reference_printer ()); if (c_dialect_cxx ()) /* "char*", without a space. */ ASSERT_STREQ (" printf (\"msg: %i\\n\", msg);\n" diff --git a/gcc/c-family/c-indentation.cc b/gcc/c-family/c-indentation.cc index 2e8261d..bb214fc 100644 --- a/gcc/c-family/c-indentation.cc +++ b/gcc/c-family/c-indentation.cc @@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see #include "c-indentation.h" #include "selftest.h" #include "diagnostic.h" +#include "diagnostics/file-cache.h" /* Round up VIS_COLUMN to nearest tab stop. */ @@ -45,13 +46,13 @@ next_tab_stop (unsigned int vis_column, unsigned int tab_width) on the line (up to or before EXPLOC). */ static bool -get_visual_column (file_cache &fc, +get_visual_column (diagnostics::file_cache &fc, expanded_location exploc, unsigned int *out, unsigned int *first_nws, unsigned int tab_width) { - char_span line = fc.get_source_line (exploc.file, exploc.line); + diagnostics::char_span line = fc.get_source_line (exploc.file, exploc.line); if (!line) return false; if ((size_t)exploc.column > line.length ()) @@ -88,14 +89,14 @@ get_visual_column (file_cache &fc, Otherwise, return false, leaving *FIRST_NWS untouched. */ static bool -get_first_nws_vis_column (file_cache &fc, +get_first_nws_vis_column (diagnostics::file_cache &fc, const char *file, int line_num, unsigned int *first_nws, unsigned int tab_width) { gcc_assert (first_nws); - char_span line = fc.get_source_line (file, line_num); + diagnostics::char_span line = fc.get_source_line (file, line_num); if (!line) return false; unsigned int vis_column = 0; @@ -160,7 +161,7 @@ get_first_nws_vis_column (file_cache &fc, Return true if such an unindent/outdent is detected. */ static bool -detect_intervening_unindent (file_cache &fc, +detect_intervening_unindent (diagnostics::file_cache &fc, const char *file, int body_line, int next_stmt_line, @@ -335,7 +336,7 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo, if (next_stmt_exploc.file != body_exploc.file) return false; - file_cache &fc = global_dc->get_file_cache (); + diagnostics::file_cache &fc = global_dc->get_file_cache (); /* If NEXT_STMT_LOC and BODY_LOC are on the same line, consider the location of the guard. @@ -691,7 +692,7 @@ test_next_tab_stop () static void assert_get_visual_column_succeeds (const location &loc, - file_cache &fc, + diagnostics::file_cache &fc, const char *file, int line, int column, const unsigned int tab_width, unsigned int expected_visual_column, @@ -735,7 +736,7 @@ assert_get_visual_column_succeeds (const location &loc, static void assert_get_visual_column_fails (const location &loc, - file_cache &fc, + diagnostics::file_cache &fc, const char *file, int line, int column, const unsigned int tab_width) { @@ -783,7 +784,7 @@ test_get_visual_column () "\t line 2\n"); line_table_test ltt; temp_source_file tmp (SELFTEST_LOCATION, ".txt", content); - file_cache fc; + diagnostics::file_cache fc; const unsigned int tab_width = 8; const char *file = tmp.get_filename (); diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc index fef6ae6..b45d722 100644 --- a/gcc/c-family/c-lex.cc +++ b/gcc/c-family/c-lex.cc @@ -1176,7 +1176,7 @@ interpret_integer (const cpp_token *token, unsigned int flags, && (flags & CPP_N_WIDTH) != CPP_N_LARGE) emit_diagnostic ((c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99) - ? DK_PEDWARN : DK_WARNING, + ? diagnostics::kind::pedwarn : diagnostics::kind::warning, input_location, OPT_Wlong_long, (flags & CPP_N_UNSIGNED) ? "integer constant is too large for %<unsigned long%> type" diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index 795f5a3..c652e82 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -32,7 +32,7 @@ along with GCC; see the file COPYING3. If not see #include "flags.h" #include "toplev.h" #include "langhooks.h" -#include "diagnostic-macro-unwinding.h" /* for virt_loc_aware_diagnostic_finalizer */ +#include "diagnostics/macro-unwinding.h" /* for virt_loc_aware_diagnostic_finalizer */ #include "intl.h" #include "cppdefault.h" #include "incpath.h" @@ -43,7 +43,7 @@ along with GCC; see the file COPYING3. If not see #include "dumpfile.h" #include "file-prefix-map.h" /* add_*_prefix_map() */ #include "context.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" #ifndef DOLLARS_IN_IDENTIFIERS # define DOLLARS_IN_IDENTIFIERS true @@ -169,9 +169,9 @@ c_common_option_lang_mask (void) /* Diagnostic finalizer for C/C++/Objective-C/Objective-C++. */ static void -c_diagnostic_text_finalizer (diagnostic_text_output_format &text_output, - const diagnostic_info *diagnostic, - diagnostic_t) +c_diagnostic_text_finalizer (diagnostics::text_sink &text_output, + const diagnostics::diagnostic_info *diagnostic, + enum diagnostics::kind) { pretty_printer *const pp = text_output.get_printer (); char *saved_prefix = pp_take_prefix (pp); @@ -179,19 +179,19 @@ c_diagnostic_text_finalizer (diagnostic_text_output_format &text_output, pp_newline (pp); diagnostic_show_locus (&text_output.get_context (), text_output.get_source_printing_options (), - diagnostic->richloc, diagnostic->kind, pp); + diagnostic->m_richloc, diagnostic->m_kind, pp); /* By default print macro expansion contexts in the diagnostic finalizer -- for tokens resulting from macro expansion. */ - virt_loc_aware_diagnostic_finalizer (text_output, diagnostic); + diagnostics::virt_loc_aware_text_finalizer (text_output, diagnostic); pp_set_prefix (pp, saved_prefix); pp_flush (pp); } /* Common default settings for diagnostics. */ void -c_common_diagnostics_set_defaults (diagnostic_context *context) +c_common_diagnostics_set_defaults (diagnostics::context *context) { - diagnostic_text_finalizer (context) = c_diagnostic_text_finalizer; + diagnostics::text_finalizer (context) = c_diagnostic_text_finalizer; context->set_permissive_option (OPT_fpermissive); } @@ -278,7 +278,7 @@ c_common_init_options (unsigned int decoded_options_count, if (c_dialect_cxx ()) set_std_cxx17 (/*ISO*/false); - global_dc->m_source_printing.colorize_source_p = true; + global_dc->get_source_printing_options ().colorize_source_p = true; } /* Handle switch SCODE with argument ARG. VALUE is true, unless no- diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc index 137b83bf..8a1218b 100644 --- a/gcc/c-family/c-pragma.cc +++ b/gcc/c-family/c-pragma.cc @@ -781,7 +781,7 @@ public: PK_IGNORED_ATTRIBUTES, PK_DIAGNOSTIC, } pd_kind; - diagnostic_t diagnostic_kind; + enum diagnostics::kind diagnostic_kind; const char *kind_str; const char *option_str; bool own_option_str; @@ -792,7 +792,7 @@ public: valid = false; loc_kind = loc_option = UNKNOWN_LOCATION; pd_kind = PK_INVALID; - diagnostic_kind = DK_UNSPECIFIED; + diagnostic_kind = diagnostics::kind::unspecified; kind_str = option_str = nullptr; own_option_str = false; } @@ -808,7 +808,7 @@ public: kind_str = kind_string; pd_kind = PK_INVALID; - diagnostic_kind = DK_UNSPECIFIED; + diagnostic_kind = diagnostics::kind::unspecified; if (strcmp (kind_str, "push") == 0) pd_kind = PK_PUSH; else if (strcmp (kind_str, "pop") == 0) @@ -818,17 +818,17 @@ public: else if (strcmp (kind_str, "error") == 0) { pd_kind = PK_DIAGNOSTIC; - diagnostic_kind = DK_ERROR; + diagnostic_kind = diagnostics::kind::error; } else if (strcmp (kind_str, "warning") == 0) { pd_kind = PK_DIAGNOSTIC; - diagnostic_kind = DK_WARNING; + diagnostic_kind = diagnostics::kind::warning; } else if (strcmp (kind_str, "ignored") == 0) { pd_kind = PK_DIAGNOSTIC; - diagnostic_kind = DK_IGNORED; + diagnostic_kind = diagnostics::kind::ignored; } } @@ -1016,7 +1016,8 @@ handle_pragma_diagnostic_impl () what we used to do here before and changing it breaks e.g. PR69543 and PR69558. */ control_warning_option (option_index, (int) data.diagnostic_kind, - arg, data.diagnostic_kind != DK_IGNORED, + arg, + data.diagnostic_kind != diagnostics::kind::ignored, input_location, lang_mask, &handlers, &global_options, &global_options_set, global_dc); diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc index d547b08..09517d2 100644 --- a/gcc/c-family/c-warn.cc +++ b/gcc/c-family/c-warn.cc @@ -3835,7 +3835,7 @@ do_warn_array_compare (location_t location, tree_code code, tree op0, tree op1) op1 = TREE_OPERAND (op1, 0); auto_diagnostic_group d; - diagnostic_t kind = DK_WARNING; + enum diagnostics::kind kind = diagnostics::kind::warning; const char *msg; if (c_dialect_cxx () && cxx_dialect >= cxx20) { @@ -3843,7 +3843,7 @@ do_warn_array_compare (location_t location, tree_code code, tree op0, tree op1) if (cxx_dialect >= cxx26) { msg = G_("comparison between two arrays is not allowed in C++26"); - kind = DK_PERMERROR; + kind = diagnostics::kind::permerror; } else msg = G_("comparison between two arrays is deprecated in C++20"); diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc index 7e0fa95..e3c0113 100644 --- a/gcc/c-family/known-headers.cc +++ b/gcc/c-family/known-headers.cc @@ -329,9 +329,10 @@ suggest_missing_header::~suggest_missing_header () /* suggest_missing_option's ctor. */ -suggest_missing_option::suggest_missing_option (location_t loc, - const char *macro_name, - diagnostic_option_id option_id) +suggest_missing_option:: +suggest_missing_option (location_t loc, + const char *macro_name, + diagnostics::option_id option_id) : deferred_diagnostic (loc), m_name_str (macro_name), m_option_id (option_id) { gcc_assert (macro_name); diff --git a/gcc/c-family/known-headers.h b/gcc/c-family/known-headers.h index b1da757f..3ffe5f3 100644 --- a/gcc/c-family/known-headers.h +++ b/gcc/c-family/known-headers.h @@ -48,12 +48,12 @@ class suggest_missing_option : public deferred_diagnostic { public: suggest_missing_option (location_t loc, const char *name, - diagnostic_option_id option_id); + diagnostics::option_id option_id); ~suggest_missing_option (); private: const char *m_name_str; - diagnostic_option_id m_option_id; + diagnostics::option_id m_option_id; }; #endif /* GCC_KNOWN_HEADERS_H */ |