diff options
Diffstat (limited to 'gcc/c-family')
-rw-r--r-- | gcc/c-family/ChangeLog | 109 | ||||
-rw-r--r-- | gcc/c-family/c-attribs.cc | 139 | ||||
-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 | 23 | ||||
-rw-r--r-- | gcc/c-family/c-format.h | 1 | ||||
-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-omp.cc | 4 | ||||
-rw-r--r-- | gcc/c-family/c-opts.cc | 31 | ||||
-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 |
15 files changed, 314 insertions, 79 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index ed79d36..a754525 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,112 @@ +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. + +2025-07-16 Alfie Richards <alfie.richards@arm.com> + + * c-attribs.cc (handle_target_clones_attribute): Change to use + get_clone_versions. + +2025-07-16 Alfie Richards <alfie.richards@arm.com> + + * c-format.cc (local_string_slice_node): New node type. + (asm_fprintf_char_table): New entry. + (init_dynamic_diag_info): Add support for string_slice. + * c-format.h (T_STRING_SLICE): New node type. + +2025-07-15 Jakub Jelinek <jakub@redhat.com> + Jason Merrill <jason@redhat.com> + + PR c/44677 + * c-opts.cc (c_common_post_options): Change + warn_unused_but_set_parameter and warn_unused_but_set_variable + from 1 to 3 if they were set only implicitly. + * c-attribs.cc (build_attr_access_from_parms): Remove unused + but set variable nelts. + 2025-07-11 Jakub Jelinek <jakub@redhat.com> PR c++/119064 diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 5d7a31f..a0d832b 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -4120,10 +4120,11 @@ handle_argspec_attribute (tree *, tree, tree args, int, bool *) { /* Verify the attribute has one or two arguments and their kind. */ gcc_assert (args && TREE_CODE (TREE_VALUE (args)) == STRING_CST); - for (tree next = TREE_CHAIN (args); next; next = TREE_CHAIN (next)) + if (TREE_CHAIN (args)) { - tree val = TREE_VALUE (next); - gcc_assert (DECL_P (val) || EXPR_P (val)); + tree val = TREE_VALUE (TREE_CHAIN (args)); + gcc_assert (!TREE_CHAIN (TREE_CHAIN (args))); + gcc_assert (TYPE_P (val)); } return NULL_TREE; } @@ -5736,6 +5737,71 @@ handle_access_attribute (tree node[3], tree name, tree args, int flags, return NULL_TREE; } + +/* This function builds a string which is concatenated to SPEC and returns + list of variably bounds corresponding to an array/VLA parameter with + type TYPE. The string consists of one dollar symbol for each specified + variable bound, one asterisk for each unspecified variable bound, + a space for an array of unknown size (only possibly for the outermost), + and a zero for a zero-sized array. + + The chainof variable bounds starts with the most significant bound. + For example, the TYPE T[2][m][3][n] will produce "$$" and (m, (n, nil)). */ + +static tree +build_arg_spec (tree type, std::string *spec) +{ + while (POINTER_TYPE_P (type)) + type = TREE_TYPE (type); + + if (TREE_CODE (type) != ARRAY_TYPE) + return NULL_TREE; + + tree list = build_arg_spec (TREE_TYPE (type), spec); + + if (!COMPLETE_TYPE_P (type)) + { + (*spec) += ' '; + return list; + } + + tree mval = TYPE_MAX_VALUE (TYPE_DOMAIN (type)); + + if (!mval) + { + (*spec) += '0'; + return list; + } + + if (TREE_CODE (mval) == COMPOUND_EXPR + && integer_zerop (TREE_OPERAND (mval, 0)) + && integer_zerop (TREE_OPERAND (mval, 1))) + { + (*spec) += '*'; + return list; + } + + if (TREE_CODE (mval) == INTEGER_CST) + return list; + + /* A variable bound. */ + (*spec) += '$'; + + mval = array_type_nelts_top (type); + + /* Remove NOP_EXPR and SAVE_EXPR to uncover possible PARM_DECLS. */ + if (TREE_CODE (mval) == NOP_EXPR) + mval = TREE_OPERAND (mval, 0); + if (TREE_CODE (mval) == SAVE_EXPR) + { + mval = TREE_OPERAND (mval, 0); + if (TREE_CODE (mval) == NOP_EXPR) + mval = TREE_OPERAND (mval, 0); + } + + return tree_cons (NULL_TREE, mval, list); +} + /* Extract attribute "arg spec" from each FNDECL argument that has it, build a single attribute access corresponding to all the arguments, and return the result. SKIP_VOIDPTR set to ignore void* parameters @@ -5812,15 +5878,16 @@ build_attr_access_from_parms (tree parms, bool skip_voidptr) argspec = TREE_VALUE (argspec); /* The attribute arg spec string. */ - tree str = TREE_VALUE (argspec); - const char *s = TREE_STRING_POINTER (str); + const char *s = TREE_STRING_POINTER (TREE_VALUE (argspec)); + bool static_p = s && (0 == strcmp("static", s)); /* Collect the list of nonnull arguments which use "[static ..]". */ - if (s != NULL && s[0] == '[' && s[1] == 's') + if (static_p) nnlist = tree_cons (NULL_TREE, build_int_cst (integer_type_node, argpos + 1), nnlist); - /* Create the attribute access string from the arg spec string, + tree argvbs; + /* Create the attribute access string from the arg spec data, optionally followed by position of the VLA bound argument if it is one. */ { @@ -5831,21 +5898,52 @@ build_attr_access_from_parms (tree parms, bool skip_voidptr) specend = 1; } - /* Format the access string in place. */ - int len = snprintf (NULL, 0, "%c%u%s", - attr_access::mode_chars[access_deferred], - argpos, s); - spec.resize (specend + len + 1); - sprintf (&spec[specend], "%c%u%s", - attr_access::mode_chars[access_deferred], - argpos, s); + spec += attr_access::mode_chars[access_deferred]; + spec += std::to_string (argpos); + spec += '['; + tree type = TREE_VALUE (TREE_CHAIN (argspec)); + argvbs = build_arg_spec (type, &spec); + + /* Postprocess the string to bring it in the format expected + by the code handling the access attribute. First, we + add 's' if the array was declared as [static ...]. */ + if (static_p) + { + size_t send = spec.length(); + + if (spec[send - 1] == '[') + { + spec += 's'; + } + else + { + /* If there is a symbol, we need to swap the order. */ + spec += spec[send - 1]; + spec[send - 1] = 's'; + } + } + + /* If the outermost bound is an integer constant, we need to write + the size if it is constant. */ + if (type && TYPE_DOMAIN (type)) + { + tree mval = TYPE_MAX_VALUE (TYPE_DOMAIN (type)); + if (mval && TREE_CODE (mval) == INTEGER_CST) + { + char buf[40]; + unsigned HOST_WIDE_INT n = tree_to_uhwi (mval) + 1; + sprintf (buf, HOST_WIDE_INT_PRINT_UNSIGNED, n); + spec += buf; + } + } + spec += ']'; + /* Trim the trailing NUL. */ - spec.resize (specend + len); + spec.resize (spec.length ()); } /* The (optional) list of expressions denoting the VLA bounds N in ARGTYPE <arg>[Ni]...[Nj]...[Nk]. */ - tree argvbs = TREE_CHAIN (argspec); if (argvbs) { spec += ','; @@ -5858,8 +5956,7 @@ build_attr_access_from_parms (tree parms, bool skip_voidptr) order. */ vblist = tree_cons (NULL_TREE, argvbs, vblist); - unsigned nelts = 0; - for (tree vb = argvbs; vb; vb = TREE_CHAIN (vb), ++nelts) + for (tree vb = argvbs; vb; vb = TREE_CHAIN (vb)) { tree bound = TREE_VALUE (vb); if (const unsigned *psizpos = arg2pos.get (bound)) @@ -6141,7 +6238,9 @@ handle_target_clones_attribute (tree *node, tree name, tree ARG_UNUSED (args), } } - if (get_target_clone_attr_len (args) == -1) + auto_vec<string_slice> versions = get_clone_attr_versions (args, NULL); + + if (versions.length () == 1) { warning (OPT_Wattributes, "single %<target_clones%> attribute is ignored"); 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 a44249a..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" @@ -70,6 +71,7 @@ static GTY(()) tree local_event_ptr_node; static GTY(()) tree local_pp_element_ptr_node; static GTY(()) tree local_gimple_ptr_node; static GTY(()) tree local_cgraph_node_ptr_node; +static GTY(()) tree local_string_slice_node; static GTY(()) tree locus; static bool decode_format_attr (const_tree, tree, tree, function_format_info *, @@ -770,6 +772,7 @@ static const format_char_info asm_fprintf_char_table[] = { "p", 1, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "q", "c", NULL }, \ { "r", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "//cR", NULL }, \ { "@", 1, STD_C89, { T_EVENT_PTR, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "\"", NULL }, \ + { "B", 1, STD_C89, { T_STRING_SLICE, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "q", "", NULL }, \ { "e", 1, STD_C89, { T_PP_ELEMENT_PTR, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "\"", NULL }, \ { "<", 0, STD_C89, NOARGUMENTS, "", "<", NULL }, \ { ">", 0, STD_C89, NOARGUMENTS, "", ">", NULL }, \ @@ -4632,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; @@ -4644,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 @@ -5211,6 +5215,11 @@ init_dynamic_diag_info (void) || local_cgraph_node_ptr_node == void_type_node) local_cgraph_node_ptr_node = get_named_type ("cgraph_node"); + /* Similar to the above but for string_slice*. */ + if (!local_string_slice_node + || local_string_slice_node == void_type_node) + local_string_slice_node = get_named_type ("string_slice"); + /* Similar to the above but for diagnostic_event_id_t*. */ if (!local_event_ptr_node || local_event_ptr_node == void_type_node) @@ -5577,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-format.h b/gcc/c-family/c-format.h index 323338c..d44d386 100644 --- a/gcc/c-family/c-format.h +++ b/gcc/c-family/c-format.h @@ -317,6 +317,7 @@ struct format_kind_info #define T89_G { STD_C89, NULL, &local_gimple_ptr_node } #define T_CGRAPH_NODE { STD_C89, NULL, &local_cgraph_node_ptr_node } #define T_EVENT_PTR { STD_C89, NULL, &local_event_ptr_node } +#define T_STRING_SLICE { STD_C89, NULL, &local_string_slice_node } #define T_PP_ELEMENT_PTR { STD_C89, NULL, &local_pp_element_ptr_node } #define T89_T { STD_C89, NULL, &local_tree_type_node } #define T89_V { STD_C89, NULL, T_V } 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-omp.cc b/gcc/c-family/c-omp.cc index 4352214..fe272888 100644 --- a/gcc/c-family/c-omp.cc +++ b/gcc/c-family/c-omp.cc @@ -769,9 +769,7 @@ c_finish_omp_depobj (location_t loc, tree depobj, kind = OMP_CLAUSE_DEPEND_KIND (clause); t = OMP_CLAUSE_DECL (clause); gcc_assert (t); - if (TREE_CODE (t) == TREE_LIST - && TREE_PURPOSE (t) - && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC) + if (OMP_ITERATOR_DECL_P (t)) { error_at (OMP_CLAUSE_LOCATION (clause), "%<iterator%> modifier may not be specified on " diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index 872bdf4..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- @@ -1226,6 +1226,17 @@ c_common_post_options (const char **pfilename) SET_OPTION_IF_UNSET (&global_options, &global_options_set, flag_range_for_ext_temps, cxx_dialect >= cxx23); + /* EnabledBy unfortunately can't specify value to use if set and + LangEnabledBy can't specify multiple options with &&. For -Wunused + or -Wunused -Wextra we want these to default to 3 unless user specified + some other level explicitly. */ + if (warn_unused_but_set_parameter == 1) + SET_OPTION_IF_UNSET (&global_options, &global_options_set, + warn_unused_but_set_parameter, 3); + if (warn_unused_but_set_variable == 1) + SET_OPTION_IF_UNSET (&global_options, &global_options_set, + warn_unused_but_set_variable, 3); + /* -fimmediate-escalation has no effect when immediate functions are not supported. */ if (flag_immediate_escalation && cxx_dialect < cxx20) 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 */ |