re PR tree-optimization/89550 (Spurious array-bounds warning when using __PRETTY_FUNC...
authorJakub Jelinek <jakub@redhat.com>
Fri, 8 Mar 2019 10:46:39 +0000 (11:46 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 8 Mar 2019 10:46:39 +0000 (11:46 +0100)
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

14 files changed:
gcc/ChangeLog
gcc/builtins.c
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/c-family/c-warn.c
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/cp/semantics.c
gcc/cp/typeck.c
gcc/tree-cfg.c
gcc/tree-vrp.c

index b46c5aff26618b4a5d7c6ac19f6de09decb8962f..5ce59076868177b8cf88bcc51b5c1cf1b15a6deb 100644 (file)
@@ -1,3 +1,13 @@
+2019-03-08  Jakub Jelinek  <jakub@redhat.com>
+
+       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  <rguenther@suse.de>
 
        PR middle-end/89578
index d216d6fb88172747cf8016e7a1ed0683b14e1628..0910c725ecbdd108408b57bd062b0737affe3f60 100644 (file)
@@ -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)
index da8918c58016874b124c73f78e9ed981b74a1092..55006e68bc6897ae2169e5612d501339b24e9f6a 100644 (file)
@@ -1,3 +1,10 @@
+2019-03-08  Jakub Jelinek  <jakub@redhat.com>
+
+       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  <sandra@codesourcery.com>
            Martin Sebor  <msebor@gmail.com>
 
index e5a5ea803d725895c569d213639995228f27653b..e5a19ccb8fe378234d37fe9e72c414e4f063598f 100644 (file)
@@ -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:
index e2f3449e69420364361766d524f9030dbf70ba82..d775ff80b452327af52326a7161487bd68e1a217 100644 (file)
@@ -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 %<or%>"
-                       " applied to non-boolean constant");
+           warned
+             = warning_at (location, OPT_Wlogical_op,
+                           "logical %<or%> applied to non-boolean constant");
          else
-           warning_at (location, OPT_Wlogical_op, "logical %<and%>"
-                       " applied to non-boolean constant");
-         TREE_NO_WARNING (op_left) = true;
+           warned
+             = warning_at (location, OPT_Wlogical_op,
+                           "logical %<and%> applied to non-boolean constant");
+         if (warned)
+           TREE_NO_WARNING (op_left) = true;
          return;
        }
     }
index ec60ed3b81a55225cfdd3cb989c1758de47a699e..b59be5e062ab9ace17e566921506f9b685877d12 100644 (file)
@@ -1,3 +1,11 @@
+2019-03-08  Jakub Jelinek  <jakub@redhat.com>
+
+       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  <jakub@redhat.com>
 
        PR c/89525
index 69c04d54de98e666ca3593466ef6556c13b545ad..32ec183336c45c3a3bd23688e7304d41eb07cc35 100644 (file)
@@ -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 %<static%> but never defined", decl);
-             TREE_NO_WARNING (decl) = 1;
+             if (warning (OPT_Wunused_function,
+                          "%q+F declared %<static%> but never defined",
+                          decl))
+               TREE_NO_WARNING (decl) = 1;
            }
        }
 
index 5faebe5e007a729a3600889c7cf749f975c2bdb7..43184b08cd3719b2bf1a2a50d8837bd494e48591 100644 (file)
@@ -1,5 +1,12 @@
 2019-03-08  Jakub Jelinek  <jakub@redhat.com>
 
+       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.
index 0187db5ff1c1d4b170f9b3dd584debf404dd9f29..081f37cd26a0544c9ab76811d5015632af3db2e8 100644 (file)
@@ -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
index b60110a28652608e01b2edec3d3559f81ba54550..4e4746e2ca0ce1b0bcfbdb0c63dc29832ce1fcbb 100644 (file)
@@ -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.  */
index 2573b77f6d6e4bd6525a1214fe46fd5428cfbe1e..798a2b3bb30f70d8ad830904cfd4c50908b5244b 100644 (file)
@@ -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);
 }
index 8d9224b668e2ad74949d08ab7fcf29dd31dca7fd..51f47814acd98bf1d8131924e6291e1b3cd7b56d 100644 (file)
@@ -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);
index f433efc89c0fc53c8a038773d238314543d983ac..71966147880c83017f36ee46df38e35d0581da9a 100644 (file)
@@ -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;
                }
            }
index bde0751ec1e6cd19ea8b52702f86ce9ec3a641f1..bf1d947fbf7e80edd2195aee42f9236255e565f9 100644 (file)
@@ -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;
     }
 }