diff options
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 31 | ||||
-rw-r--r-- | gcc/c/c-decl.cc | 5 | ||||
-rw-r--r-- | gcc/c/c-parser.cc | 44 | ||||
-rw-r--r-- | gcc/c/c-tree.h | 1 | ||||
-rw-r--r-- | gcc/c/c-typeck.cc | 54 |
5 files changed, 82 insertions, 53 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index d771923..f75a0f6 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,34 @@ +2025-04-15 Qing Zhao <qing.zhao@oracle.com> + + PR c/119717 + * c-typeck.cc (build_access_with_size_for_counted_by): Fully fold the + parameters for call to .ACCESS_WITH_SIZE. + +2025-04-08 Martin Uecker <uecker@tugraz.at> + + PR c/119612 + * c-tree.h (c_type_tag): Add prototype. + * c-typeck.cc (c_type_tag): New function. + (tagged_types_tu_compatible_p, composite_type_internal): Use + c_type_tag. + * c-decl.cc (c_struct_hasher::hash, previous_tag): Use c_type_tag. + +2025-04-02 Jakub Jelinek <jakub@redhat.com> + + PR c/119582 + * c-typeck.cc (pointer_diff, build_binary_op): Call c_fully_fold on + __sanitizer_ptr_sub or __sanitizer_ptr_cmp arguments. + +2025-04-02 Sandra Loosemore <sloosemore@baylibre.com> + + PR middle-end/118965 + * c-parser.cc (c_parser_omp_clause_init_modifiers): Adjust + error message. + (c_parser_omp_clause_init): Remove code for recognizing clauses + without modifiers. Diagnose missing target/targetsync modifier. + (c_finish_omp_declare_variant): Diagnose missing target/targetsync + modifier. + 2025-03-28 Jakub Jelinek <jakub@redhat.com> * Make-lang.in (c.srcextra): Don't depend on anything and don't copy diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index c778c7f..8c420f2 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -659,7 +659,8 @@ c_struct_hasher::hash (tree type) inchash::hash hstate; hstate.add_int (TREE_CODE (type)); - hstate.add_object (TYPE_NAME (type)); + tree tag = c_type_tag (type); + hstate.add_object (tag); return hstate.end (); } @@ -2073,7 +2074,7 @@ static tree previous_tag (tree type) { struct c_binding *b = NULL; - tree name = TYPE_NAME (type); + tree name = c_type_tag (type); if (name) b = I_TAG_BINDING (name); diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index cfb1f60..22ec0f8 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -20837,8 +20837,8 @@ c_parser_omp_clause_init_modifiers (c_parser *parser, bool *target, while (true); fail: - c_parser_error (parser, "%<init%> clause with modifier other than " - "%<prefer_type%>, %<target%> or %<targetsync%>"); + c_parser_error (parser, + "expected %<prefer_type%>, %<target%>, or %<targetsync%>"); return false; } @@ -20859,45 +20859,23 @@ c_parser_omp_clause_init (c_parser *parser, tree list) if (!parens.require_open (parser)) return list; - unsigned raw_pos = 1; - while (c_parser_peek_nth_token_raw (parser, raw_pos)->type == CPP_NAME) - { - raw_pos++; - if (c_parser_peek_nth_token_raw (parser, raw_pos)->type == CPP_OPEN_PAREN) - { - raw_pos++; - c_parser_check_balanced_raw_token_sequence (parser, &raw_pos); - if (c_parser_peek_nth_token_raw (parser, raw_pos)->type != CPP_CLOSE_PAREN) - { - raw_pos = 0; - break; - } - raw_pos++; - } - if (c_parser_peek_nth_token_raw (parser, raw_pos)->type == CPP_COLON) - break; - if (c_parser_peek_nth_token_raw (parser, raw_pos)->type != CPP_COMMA) - { - raw_pos = 0; - break; - } - raw_pos++; - } - bool target = false; bool targetsync = false; tree prefer_type_tree = NULL_TREE; - if (raw_pos > 1 - && (!c_parser_omp_clause_init_modifiers (parser, &target, &targetsync, - &prefer_type_tree) - || !c_parser_require (parser, CPP_COLON, "expected %<:%>"))) + if (!c_parser_omp_clause_init_modifiers (parser, &target, &targetsync, + &prefer_type_tree) + || !c_parser_require (parser, CPP_COLON, "expected %<:%>")) { if (prefer_type_tree != error_mark_node) parens.skip_until_found_close (parser); return list; } + if (!target && !targetsync) + error_at (loc, + "missing required %<target%> and/or %<targetsync%> modifier"); + tree nl = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_INIT, list, false); parens.skip_until_found_close (parser); @@ -27166,6 +27144,10 @@ c_finish_omp_declare_variant (c_parser *parser, tree fndecl, tree parms) || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%> or %<,%>")) goto fail; + if (!target && !targetsync) + error_at (loc, + "missing required %<target%> and/or " + "%<targetsync%> modifier"); tree t = build_tree_list (target ? boolean_true_node : boolean_false_node, targetsync ? boolean_true_node diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 743ec5c..2098120 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -795,6 +795,7 @@ c_type_unspecified_p (tree t) } extern bool char_type_p (tree); +extern tree c_type_tag (const_tree t); extern tree c_objc_common_truthvalue_conversion (location_t, tree, tree = integer_type_node); extern tree require_complete_type (location_t, tree); diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index aaf8e54..55d896e 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -577,7 +577,7 @@ c_build_functype_attribute_variant (tree ntype, tree otype, tree attrs) } /* Given a type which could be a typedef name, make sure to return the - original type. */ + original type. See set_underlying_type. */ static const_tree c_type_original (const_tree t) { @@ -591,6 +591,26 @@ c_type_original (const_tree t) return t; } +/* Return the tag for a tagged type. */ +tree +c_type_tag (const_tree t) +{ + gcc_assert (RECORD_OR_UNION_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE); + const_tree orig = c_type_original (t); + tree name = TYPE_NAME (orig); + if (!name) + return NULL_TREE; + if (TREE_CODE (name) == TYPE_DECL) + { + /* A TYPE_DECL added by add_decl_expr. */ + gcc_checking_assert (!DECL_NAME (name)); + return NULL_TREE; + } + gcc_checking_assert (TREE_CODE (name) == IDENTIFIER_NODE); + return name; +} + + /* Return the composite type of two compatible types. @@ -744,7 +764,7 @@ composite_type_internal (tree t1, tree t2, struct composite_cache* cache) if (flag_isoc23 && !comptypes_same_p (t1, t2)) { /* Go to the original type to get the right tag. */ - tree tag = TYPE_NAME (c_type_original (const_cast<tree> (t1))); + tree tag = c_type_tag (t1); gcc_checking_assert (COMPLETE_TYPE_P (t1) && COMPLETE_TYPE_P (t2)); gcc_checking_assert (!tag || comptypes (t1, t2)); @@ -1807,17 +1827,7 @@ tagged_types_tu_compatible_p (const_tree t1, const_tree t2, { tree s1, s2; - /* We have to verify that the tags of the types are the same. This - is harder than it looks because this may be a typedef, so we have - to go look at the original type. */ - t1 = c_type_original (t1); - t2 = c_type_original (t2); - gcc_checking_assert (!TYPE_NAME (t1) - || TREE_CODE (TYPE_NAME (t1)) == IDENTIFIER_NODE); - gcc_checking_assert (!TYPE_NAME (t2) - || TREE_CODE (TYPE_NAME (t2)) == IDENTIFIER_NODE); - - if (TYPE_NAME (t1) != TYPE_NAME (t2)) + if (c_type_tag (t1) != c_type_tag (t2)) return false; /* When forming equivalence classes for TYPE_CANONICAL in C23, we treat @@ -1828,7 +1838,7 @@ tagged_types_tu_compatible_p (const_tree t1, const_tree t2, /* Different types without tag are incompatible except as an anonymous field or when forming equivalence classes for TYPE_CANONICAL. */ - if (!data->anon_field && !data->equiv && NULL_TREE == TYPE_NAME (t1)) + if (!data->anon_field && !data->equiv && NULL_TREE == c_type_tag (t1)) return false; if (!data->anon_field && TYPE_STUB_DECL (t1) != TYPE_STUB_DECL (t2)) @@ -3003,12 +3013,16 @@ build_access_with_size_for_counted_by (location_t loc, tree ref, gcc_assert (c_flexible_array_member_type_p (TREE_TYPE (ref))); /* The result type of the call is a pointer to the flexible array type. */ tree result_type = c_build_pointer_type (TREE_TYPE (ref)); + tree first_param + = c_fully_fold (array_to_pointer_conversion (loc, ref), false, NULL); + tree second_param + = c_fully_fold (counted_by_ref, false, NULL); tree call = build_call_expr_internal_loc (loc, IFN_ACCESS_WITH_SIZE, result_type, 6, - array_to_pointer_conversion (loc, ref), - counted_by_ref, + first_param, + second_param, build_int_cst (integer_type_node, 1), build_int_cst (counted_by_type, 0), build_int_cst (integer_type_node, -1), @@ -4824,8 +4838,8 @@ pointer_diff (location_t loc, tree op0, tree op1, tree *instrument_expr) if (current_function_decl != NULL_TREE && sanitize_flags_p (SANITIZE_POINTER_SUBTRACT)) { - op0 = save_expr (op0); - op1 = save_expr (op1); + op0 = save_expr (c_fully_fold (op0, false, NULL)); + op1 = save_expr (c_fully_fold (op1, false, NULL)); tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT); *instrument_expr = build_call_expr_loc (loc, tt, 2, op0, op1); @@ -14455,8 +14469,8 @@ build_binary_op (location_t location, enum tree_code code, && current_function_decl != NULL_TREE && sanitize_flags_p (SANITIZE_POINTER_COMPARE)) { - op0 = save_expr (op0); - op1 = save_expr (op1); + op0 = save_expr (c_fully_fold (op0, false, NULL)); + op1 = save_expr (c_fully_fold (op1, false, NULL)); tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_COMPARE); instrument_expr = build_call_expr_loc (location, tt, 2, op0, op1); |