diff options
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 13 | ||||
-rw-r--r-- | gcc/c/c-decl.c | 38 | ||||
-rw-r--r-- | gcc/c/c-parser.c | 18 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 8 |
4 files changed, 49 insertions, 28 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 9afa103..1fee3e7 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,16 @@ +2021-02-11 Marek Polacek <polacek@redhat.com> + + * c-parser.c (c_parser_if_statement): Use vec_free. + +2021-02-04 Martin Sebor <msebor@redhat.com> + + PR c/97882 + * c-decl.c (locate_old_decl): Add type to diagnostic output. + (diagnose_mismatched_decls): Same. + (start_function): Introduce temporaries for better readability. + * c-typeck.c (comptypes_internal): Only consider complete enum + types in comparisons with integers. + 2021-02-01 Martin Sebor <msebor@redhat.com> PR middle-end/97172 diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index be95643..a5852a3 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -1910,15 +1910,22 @@ validate_proto_after_old_defn (tree newdecl, tree newtype, tree oldtype) static void locate_old_decl (tree decl) { - if (TREE_CODE (decl) == FUNCTION_DECL && fndecl_built_in_p (decl) + if (TREE_CODE (decl) == FUNCTION_DECL + && fndecl_built_in_p (decl) && !C_DECL_DECLARED_BUILTIN (decl)) ; else if (DECL_INITIAL (decl)) - inform (input_location, "previous definition of %q+D was here", decl); + inform (input_location, + "previous definition of %q+D with type %qT", + decl, TREE_TYPE (decl)); else if (C_DECL_IMPLICIT (decl)) - inform (input_location, "previous implicit declaration of %q+D was here", decl); + inform (input_location, + "previous implicit declaration of %q+D with type %qT", + decl, TREE_TYPE (decl)); else - inform (input_location, "previous declaration of %q+D was here", decl); + inform (input_location, + "previous declaration of %q+D with type %qT", + decl, TREE_TYPE (decl)); } /* Subroutine of duplicate_decls. Compare NEWDECL to OLDDECL. @@ -2083,7 +2090,8 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl)) { pedwarned = pedwarn (input_location, 0, - "conflicting types for %q+D", newdecl); + "conflicting types for %q+D; have %qT", + newdecl, newtype); /* Make sure we keep void as the return type. */ TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype; } @@ -2119,7 +2127,7 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, error ("conflicting type qualifiers for %q+D", newdecl); } else - error ("conflicting types for %q+D", newdecl); + error ("conflicting types for %q+D; have %qT", newdecl, newtype); diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype); locate_old_decl (olddecl); return false; @@ -9457,27 +9465,29 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, current_function_prototype_locus = UNKNOWN_LOCATION; current_function_prototype_built_in = false; current_function_prototype_arg_types = NULL_TREE; - if (!prototype_p (TREE_TYPE (decl1))) + tree newtype = TREE_TYPE (decl1); + tree oldtype = old_decl ? TREE_TYPE (old_decl) : newtype; + if (!prototype_p (newtype)) { + tree oldrt = TREE_TYPE (oldtype); + tree newrt = TREE_TYPE (newtype); if (old_decl != NULL_TREE - && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE - && comptypes (TREE_TYPE (TREE_TYPE (decl1)), - TREE_TYPE (TREE_TYPE (old_decl)))) + && TREE_CODE (oldtype) == FUNCTION_TYPE + && comptypes (oldrt, newrt)) { - if (stdarg_p (TREE_TYPE (old_decl))) + if (stdarg_p (oldtype)) { auto_diagnostic_group d; warning_at (loc, 0, "%q+D defined as variadic function " "without prototype", decl1); locate_old_decl (old_decl); } - TREE_TYPE (decl1) = composite_type (TREE_TYPE (old_decl), - TREE_TYPE (decl1)); + TREE_TYPE (decl1) = composite_type (oldtype, newtype); current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl); current_function_prototype_built_in = C_DECL_BUILTIN_PROTOTYPE (old_decl); current_function_prototype_arg_types - = TYPE_ARG_TYPES (TREE_TYPE (decl1)); + = TYPE_ARG_TYPES (newtype); } if (TREE_PUBLIC (decl1)) { diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index a8df208..2a49d07 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -6499,12 +6499,9 @@ c_parser_if_statement (c_parser *parser, bool *if_p, vec<tree> *chain) chain->safe_push (cond); } else if (!c_parser_next_token_is_keyword (parser, RID_IF)) - { - /* This is if-else without subsequent if. Zap the condition - chain; we would have already warned at this point. */ - delete chain; - chain = NULL; - } + /* This is if-else without subsequent if. Zap the condition + chain; we would have already warned at this point. */ + vec_free (chain); } second_body = c_parser_else_body (parser, else_tinfo, chain); /* Set IF_P to true to indicate that this if statement has an @@ -6524,12 +6521,9 @@ c_parser_if_statement (c_parser *parser, bool *if_p, vec<tree> *chain) "suggest explicit braces to avoid ambiguous %<else%>"); if (warn_duplicated_cond) - { - /* This if statement does not have an else clause. We don't - need the condition chain anymore. */ - delete chain; - chain = NULL; - } + /* This if statement does not have an else clause. We don't + need the condition chain anymore. */ + vec_free (chain); } c_finish_if_stmt (loc, cond, first_body, second_body); add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 8ef0843..725dc51 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -1107,7 +1107,9 @@ comptypes_internal (const_tree type1, const_tree type2, bool *enum_and_int_p, not transitive: two enumerated types in the same translation unit are compatible with each other only if they are the same type. */ - if (TREE_CODE (t1) == ENUMERAL_TYPE && TREE_CODE (t2) != ENUMERAL_TYPE) + if (TREE_CODE (t1) == ENUMERAL_TYPE + && COMPLETE_TYPE_P (t1) + && TREE_CODE (t2) != ENUMERAL_TYPE) { t1 = c_common_type_for_size (TYPE_PRECISION (t1), TYPE_UNSIGNED (t1)); if (TREE_CODE (t2) != VOID_TYPE) @@ -1118,7 +1120,9 @@ comptypes_internal (const_tree type1, const_tree type2, bool *enum_and_int_p, *different_types_p = true; } } - else if (TREE_CODE (t2) == ENUMERAL_TYPE && TREE_CODE (t1) != ENUMERAL_TYPE) + else if (TREE_CODE (t2) == ENUMERAL_TYPE + && COMPLETE_TYPE_P (t2) + && TREE_CODE (t1) != ENUMERAL_TYPE) { t2 = c_common_type_for_size (TYPE_PRECISION (t2), TYPE_UNSIGNED (t2)); if (TREE_CODE (t1) != VOID_TYPE) |