From: Jakub Jelinek Date: Fri, 8 Mar 2019 10:46:39 +0000 (+0100) Subject: re PR tree-optimization/89550 (Spurious array-bounds warning when using __PRETTY_FUNC... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1db01ff96aa5ce5c4ad78313d342cf70f923b40c;p=gcc.git re PR tree-optimization/89550 (Spurious array-bounds warning when using __PRETTY_FUNCTION__ as a string_view) PR tree-optimization/89550 * builtins.c (c_strlen): Only set TREE_NO_WARNING if warning_at returned true. Formatting fixes. (expand_builtin_strnlen): Formatting fixes. * tree-vrp.c (vrp_prop::check_mem_ref): Only set TREE_NO_WARNING if warning_at returned true. * tree-cfg.c (pass_warn_function_return::execute): Likewise. c-family/ * c-common.c (c_common_truthvalue_conversion): Only set TREE_NO_WARNING if warning_at returned true. * c-warn.c (overflow_warning, warn_logical_operator): Likewise. c/ * c-decl.c (finish_function): Only set TREE_NO_WARNING if warning_at returned true. (c_write_global_declarations_1): Only set TREE_NO_WARNING if pedwarn or warning returned true. cp/ * semantics.c (maybe_convert_cond): Only set TREE_NO_WARNING if warning_at returned true. * decl2.c (c_parse_final_cleanups): Likewise. * typeck.c (convert_for_assignment): Likewise. * decl.c (finish_function): Likewise. From-SVN: r269485 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b46c5aff266..5ce59076868 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2019-03-08 Jakub Jelinek + + PR tree-optimization/89550 + * builtins.c (c_strlen): Only set TREE_NO_WARNING if warning_at + returned true. Formatting fixes. + (expand_builtin_strnlen): Formatting fixes. + * tree-vrp.c (vrp_prop::check_mem_ref): Only set TREE_NO_WARNING + if warning_at returned true. + * tree-cfg.c (pass_warn_function_return::execute): Likewise. + 2019-03-08 Richard Biener PR middle-end/89578 diff --git a/gcc/builtins.c b/gcc/builtins.c index d216d6fb881..0910c725ecb 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -760,15 +760,13 @@ c_strlen (tree src, int only_value, c_strlen_data *data, unsigned eltsize) runtime. */ if (eltoff < 0 || eltoff >= maxelts) { - /* Suppress multiple warnings for propagated constant strings. */ + /* Suppress multiple warnings for propagated constant strings. */ if (only_value != 2 - && !TREE_NO_WARNING (src)) - { - warning_at (loc, OPT_Warray_bounds, - "offset %qwi outside bounds of constant string", - eltoff); - TREE_NO_WARNING (src) = 1; - } + && !TREE_NO_WARNING (src) + && warning_at (loc, OPT_Warray_bounds, + "offset %qwi outside bounds of constant string", + eltoff)) + TREE_NO_WARNING (src) = 1; return NULL_TREE; } @@ -3099,7 +3097,7 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode) "%K%qD specified bound %E " "exceeds maximum object size %E", exp, func, bound, maxobjsize)) - TREE_NO_WARNING (exp) = true; + TREE_NO_WARNING (exp) = true; bool exact = true; if (!len || TREE_CODE (len) != INTEGER_CST) @@ -3158,7 +3156,7 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode) "%K%qD specified bound [%wu, %wu] " "exceeds maximum object size %E", exp, func, min.to_uhwi (), max.to_uhwi (), maxobjsize)) - TREE_NO_WARNING (exp) = true; + TREE_NO_WARNING (exp) = true; bool exact = true; if (!len || TREE_CODE (len) != INTEGER_CST) diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index da8918c5801..55006e68bc6 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,10 @@ +2019-03-08 Jakub Jelinek + + PR tree-optimization/89550 + * c-common.c (c_common_truthvalue_conversion): Only set + TREE_NO_WARNING if warning_at returned true. + * c-warn.c (overflow_warning, warn_logical_operator): Likewise. + 2019-02-25 Sandra Loosemore Martin Sebor diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index e5a5ea803d7..e5a19ccb8fe 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -3546,13 +3546,11 @@ c_common_truthvalue_conversion (location_t location, tree expr) case MODIFY_EXPR: if (!TREE_NO_WARNING (expr) - && warn_parentheses) - { - warning_at (location, OPT_Wparentheses, - "suggest parentheses around assignment used as " - "truth value"); - TREE_NO_WARNING (expr) = 1; - } + && warn_parentheses + && warning_at (location, OPT_Wparentheses, + "suggest parentheses around assignment used as " + "truth value")) + TREE_NO_WARNING (expr) = 1; break; case CONST_DECL: diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c index e2f3449e694..d775ff80b45 100644 --- a/gcc/c-family/c-warn.c +++ b/gcc/c-family/c-warn.c @@ -143,12 +143,16 @@ overflow_warning (location_t loc, tree value, tree expr) return; } + bool warned; if (expr) - warning_at (loc, OPT_Woverflow, warnfmt, expr, TREE_TYPE (expr), value); + warned = warning_at (loc, OPT_Woverflow, warnfmt, expr, TREE_TYPE (expr), + value); else - warning_at (loc, OPT_Woverflow, warnfmt, TREE_TYPE (value), value); + warned = warning_at (loc, OPT_Woverflow, warnfmt, TREE_TYPE (value), + value); - TREE_NO_WARNING (value) = 1; + if (warned) + TREE_NO_WARNING (value) = 1; } /* Helper function for walk_tree. Unwrap C_MAYBE_CONST_EXPRs in an expression @@ -216,13 +220,17 @@ warn_logical_operator (location_t location, enum tree_code code, tree type, && !integer_zerop (folded_op_right) && !integer_onep (folded_op_right)) { + bool warned; if (or_op) - warning_at (location, OPT_Wlogical_op, "logical %" - " applied to non-boolean constant"); + warned + = warning_at (location, OPT_Wlogical_op, + "logical % applied to non-boolean constant"); else - warning_at (location, OPT_Wlogical_op, "logical %" - " applied to non-boolean constant"); - TREE_NO_WARNING (op_left) = true; + warned + = warning_at (location, OPT_Wlogical_op, + "logical % applied to non-boolean constant"); + if (warned) + TREE_NO_WARNING (op_left) = true; return; } } diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index ec60ed3b81a..b59be5e062a 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,11 @@ +2019-03-08 Jakub Jelinek + + PR tree-optimization/89550 + * c-decl.c (finish_function): Only set TREE_NO_WARNING if warning_at + returned true. + (c_write_global_declarations_1): Only set TREE_NO_WARNING if pedwarn + or warning returned true. + 2019-02-28 Jakub Jelinek PR c/89525 diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 69c04d54de9..32ec183336c 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -9664,12 +9664,10 @@ finish_function (void) && !C_FUNCTION_IMPLICIT_INT (fndecl) /* Normally, with -Wreturn-type, flow will complain, but we might optimize out static functions. */ - && !TREE_PUBLIC (fndecl)) - { - warning (OPT_Wreturn_type, - "no return statement in function returning non-void"); - TREE_NO_WARNING (fndecl) = 1; - } + && !TREE_PUBLIC (fndecl) + && warning (OPT_Wreturn_type, + "no return statement in function returning non-void")) + TREE_NO_WARNING (fndecl) = 1; /* Complain about parameters that are only set, but never otherwise used. */ if (warn_unused_but_set_parameter) @@ -11486,17 +11484,19 @@ c_write_global_declarations_1 (tree globals) { if (C_DECL_USED (decl)) { - pedwarn (input_location, 0, "%q+F used but never defined", decl); - TREE_NO_WARNING (decl) = 1; + if (pedwarn (input_location, 0, "%q+F used but never defined", + decl)) + TREE_NO_WARNING (decl) = 1; } /* For -Wunused-function warn about unused static prototypes. */ else if (warn_unused_function && ! DECL_ARTIFICIAL (decl) && ! TREE_NO_WARNING (decl)) { - warning (OPT_Wunused_function, - "%q+F declared % but never defined", decl); - TREE_NO_WARNING (decl) = 1; + if (warning (OPT_Wunused_function, + "%q+F declared % but never defined", + decl)) + TREE_NO_WARNING (decl) = 1; } } diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5faebe5e007..43184b08cd3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,12 @@ 2019-03-08 Jakub Jelinek + PR tree-optimization/89550 + * semantics.c (maybe_convert_cond): Only set TREE_NO_WARNING if + warning_at returned true. + * decl2.c (c_parse_final_cleanups): Likewise. + * typeck.c (convert_for_assignment): Likewise. + * decl.c (finish_function): Likewise. + PR c++/89585 * parser.c (cp_parser_asm_definition): Just warn instead of error on volatile qualifier outside of function body. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 0187db5ff1c..081f37cd26a 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -16171,9 +16171,9 @@ finish_function (bool inline_p) global_dc->option_state)) add_return_star_this_fixit (&richloc, fndecl); } - warning_at (&richloc, OPT_Wreturn_type, - "no return statement in function returning non-void"); - TREE_NO_WARNING (fndecl) = 1; + if (warning_at (&richloc, OPT_Wreturn_type, + "no return statement in function returning non-void")) + TREE_NO_WARNING (fndecl) = 1; } /* Store the end of the function, so that we get good line number diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index b60110a2865..4e4746e2ca0 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -5022,13 +5022,11 @@ c_parse_final_cleanups (void) /* Don't complain if the template was defined. */ && !(DECL_TEMPLATE_INSTANTIATION (decl) && DECL_INITIAL (DECL_TEMPLATE_RESULT - (template_for_substitution (decl))))) - { - warning_at (DECL_SOURCE_LOCATION (decl), 0, - "inline function %qD used but never defined", decl); - /* Avoid a duplicate warning from check_global_declaration. */ - TREE_NO_WARNING (decl) = 1; - } + (template_for_substitution (decl)))) + && warning_at (DECL_SOURCE_LOCATION (decl), 0, + "inline function %qD used but never defined", decl)) + /* Avoid a duplicate warning from check_global_declaration. */ + TREE_NO_WARNING (decl) = 1; } /* So must decls that use a type with no linkage. */ diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 2573b77f6d6..798a2b3bb30 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -657,12 +657,11 @@ maybe_convert_cond (tree cond) if (TREE_CODE (cond) == MODIFY_EXPR && !TREE_NO_WARNING (cond) - && warn_parentheses) - { - warning_at (cp_expr_loc_or_loc (cond, input_location), OPT_Wparentheses, - "suggest parentheses around assignment used as truth value"); - TREE_NO_WARNING (cond) = 1; - } + && warn_parentheses + && warning_at (cp_expr_loc_or_loc (cond, input_location), + OPT_Wparentheses, "suggest parentheses around " + "assignment used as truth value")) + TREE_NO_WARNING (cond) = 1; return condition_conversion (cond); } diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 8d9224b668e..51f47814acd 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -9071,12 +9071,11 @@ convert_for_assignment (tree type, tree rhs, && TREE_CODE (rhs) == MODIFY_EXPR && !TREE_NO_WARNING (rhs) && TREE_CODE (TREE_TYPE (rhs)) != BOOLEAN_TYPE - && (complain & tf_warning)) - { - warning_at (rhs_loc, OPT_Wparentheses, - "suggest parentheses around assignment used as truth value"); - TREE_NO_WARNING (rhs) = 1; - } + && (complain & tf_warning) + && warning_at (rhs_loc, OPT_Wparentheses, + "suggest parentheses around assignment used as " + "truth value")) + TREE_NO_WARNING (rhs) = 1; if (complain & tf_warning) warn_for_address_or_pointer_of_packed_member (type, rhs); diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index f433efc89c0..71966147880 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -9329,9 +9329,9 @@ pass_warn_function_return::execute (function *fun) location = gimple_location (last); if (LOCATION_LOCUS (location) == UNKNOWN_LOCATION) location = fun->function_end_locus; - warning_at (location, OPT_Wreturn_type, - "control reaches end of non-void function"); - TREE_NO_WARNING (fun->decl) = 1; + if (warning_at (location, OPT_Wreturn_type, + "control reaches end of non-void function")) + TREE_NO_WARNING (fun->decl) = 1; break; } } @@ -9361,9 +9361,9 @@ pass_warn_function_return::execute (function *fun) location = gimple_location (prev); if (LOCATION_LOCUS (location) == UNKNOWN_LOCATION) location = fun->function_end_locus; - warning_at (location, OPT_Wreturn_type, - "control reaches end of non-void function"); - TREE_NO_WARNING (fun->decl) = 1; + if (warning_at (location, OPT_Wreturn_type, + "control reaches end of non-void function")) + TREE_NO_WARNING (fun->decl) = 1; break; } } diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index bde0751ec1e..bf1d947fbf7 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -4749,7 +4749,8 @@ vrp_prop::check_mem_ref (location_t location, tree ref, if (warned && DECL_P (arg)) inform (DECL_SOURCE_LOCATION (arg), "while referencing %qD", arg); - TREE_NO_WARNING (ref) = 1; + if (warned) + TREE_NO_WARNING (ref) = 1; return; } @@ -4762,11 +4763,10 @@ vrp_prop::check_mem_ref (location_t location, tree ref, { HOST_WIDE_INT tmpidx = extrema[i].to_shwi () / eltsize.to_shwi (); - warning_at (location, OPT_Warray_bounds, - "intermediate array offset %wi is outside array bounds " - "of %qT", - tmpidx, reftype); - TREE_NO_WARNING (ref) = 1; + if (warning_at (location, OPT_Warray_bounds, + "intermediate array offset %wi is outside array bounds " + "of %qT", tmpidx, reftype)) + TREE_NO_WARNING (ref) = 1; } }