]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2012-04-10 Manuel López-Ibáñez <manu@gcc.gnu.org>
authormanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 10 Apr 2012 16:33:47 +0000 (16:33 +0000)
committermanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 10 Apr 2012 16:33:47 +0000 (16:33 +0000)
* c-family/c-common.c (warn_if_unused_value): Move definition to here.
* tree.h (warn_if_unused_value): Move declaration from here.
* c-family/c-common.h (warn_if_unused_value): Move declaration to here.
* cp/cvt.c (convert_to_void): Update comment.
* stmt.c (warn_if_unused_value): Move definition from here.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@186287 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/c-family/c-common.h
gcc/cp/ChangeLog
gcc/cp/cvt.c
gcc/stmt.c
gcc/tree.h

index dfb564c85c8ae2dd1f0938066b9b113c872d749c..cc84f50f3db819ec893ad0c35468b04f81a830bf 100644 (file)
@@ -1,3 +1,8 @@
+2012-04-10  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       * tree.h (warn_if_unused_value): Move declaration from here.
+       * stmt.c (warn_if_unused_value): Move definition from here.
+
 2010-04-10  Michael Matz  <matz@suse.de>
 
        * tree-vectorizer.h (_loop_vec_info.strided_stores): Rename to
index 6c4ac8b1edbc768a97e25db0921dae28fcac6df9..558c6a736e97ca7d38b82fbf5ba1442e9edd5d1e 100644 (file)
@@ -1,3 +1,8 @@
+2012-04-10  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       * c-common.c (warn_if_unused_value): Move definition to here.
+       * c-common.h (warn_if_unused_value): Move declaration to here.
+
 2012-03-23  William Bader  <williambader@hotmail.com>
 
        * c-lex.c (c_lex_with_flags): Avoid declarations after stmts.
index fc83b04c8a141ccb0320fb9d90795b0b43a290ac..a9e7ec1d14dcf352bef7bd12da2743cc8bf6f411 100644 (file)
@@ -1649,6 +1649,102 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
 }
 
 
+/* Warn if EXP contains any computations whose results are not used.
+   Return true if a warning is printed; false otherwise.  LOCUS is the
+   (potential) location of the expression.  */
+
+bool
+warn_if_unused_value (const_tree exp, location_t locus)
+{
+ restart:
+  if (TREE_USED (exp) || TREE_NO_WARNING (exp))
+    return false;
+
+  /* Don't warn about void constructs.  This includes casting to void,
+     void function calls, and statement expressions with a final cast
+     to void.  */
+  if (VOID_TYPE_P (TREE_TYPE (exp)))
+    return false;
+
+  if (EXPR_HAS_LOCATION (exp))
+    locus = EXPR_LOCATION (exp);
+
+  switch (TREE_CODE (exp))
+    {
+    case PREINCREMENT_EXPR:
+    case POSTINCREMENT_EXPR:
+    case PREDECREMENT_EXPR:
+    case POSTDECREMENT_EXPR:
+    case MODIFY_EXPR:
+    case INIT_EXPR:
+    case TARGET_EXPR:
+    case CALL_EXPR:
+    case TRY_CATCH_EXPR:
+    case WITH_CLEANUP_EXPR:
+    case EXIT_EXPR:
+    case VA_ARG_EXPR:
+      return false;
+
+    case BIND_EXPR:
+      /* For a binding, warn if no side effect within it.  */
+      exp = BIND_EXPR_BODY (exp);
+      goto restart;
+
+    case SAVE_EXPR:
+    case NON_LVALUE_EXPR:
+      exp = TREE_OPERAND (exp, 0);
+      goto restart;
+
+    case TRUTH_ORIF_EXPR:
+    case TRUTH_ANDIF_EXPR:
+      /* In && or ||, warn if 2nd operand has no side effect.  */
+      exp = TREE_OPERAND (exp, 1);
+      goto restart;
+
+    case COMPOUND_EXPR:
+      if (warn_if_unused_value (TREE_OPERAND (exp, 0), locus))
+       return true;
+      /* Let people do `(foo (), 0)' without a warning.  */
+      if (TREE_CONSTANT (TREE_OPERAND (exp, 1)))
+       return false;
+      exp = TREE_OPERAND (exp, 1);
+      goto restart;
+
+    case COND_EXPR:
+      /* If this is an expression with side effects, don't warn; this
+        case commonly appears in macro expansions.  */
+      if (TREE_SIDE_EFFECTS (exp))
+       return false;
+      goto warn;
+
+    case INDIRECT_REF:
+      /* Don't warn about automatic dereferencing of references, since
+        the user cannot control it.  */
+      if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == REFERENCE_TYPE)
+       {
+         exp = TREE_OPERAND (exp, 0);
+         goto restart;
+       }
+      /* Fall through.  */
+
+    default:
+      /* Referencing a volatile value is a side effect, so don't warn.  */
+      if ((DECL_P (exp) || REFERENCE_CLASS_P (exp))
+         && TREE_THIS_VOLATILE (exp))
+       return false;
+
+      /* If this is an expression which has no operands, there is no value
+        to be unused.  There are no such language-independent codes,
+        but front ends may define such.  */
+      if (EXPRESSION_CLASS_P (exp) && TREE_OPERAND_LENGTH (exp) == 0)
+       return false;
+
+    warn:
+      return warning_at (locus, OPT_Wunused_value, "value computed is not used");
+    }
+}
+
+
 /* Print a warning about casts that might indicate violation
    of strict aliasing rules if -Wstrict-aliasing is used and
    strict aliasing mode is in effect. OTYPE is the original
index 8552f0c92e981bd391844ccf38da8b79b80ab56d..cab7b43966191c5c916d49ac25e11b91433dc938 100644 (file)
@@ -772,6 +772,7 @@ extern bool strict_aliasing_warning (tree, tree, tree);
 extern void warnings_for_convert_and_check (tree, tree, tree);
 extern tree convert_and_check (tree, tree);
 extern void overflow_warning (location_t, tree);
+extern bool warn_if_unused_value (const_tree, location_t);
 extern void warn_logical_operator (location_t, enum tree_code, tree,
                                   enum tree_code, tree, enum tree_code, tree);
 extern void check_main_parameter_types (tree decl);
index 78c43691d45557b61590f6c707db909b35ce2722..3397470777ada9807ced9433320f68666dc63d1b 100644 (file)
@@ -1,3 +1,7 @@
+2012-04-10  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       * cvt.c (convert_to_void): Update comment.
+
 2012-04-05  Jason Merrill  <jason@redhat.com>
 
        PR c++/52596
index c411a47f0a8f6960b59f92f431d42d208dea9042..5694abede459ab2c66e01d26a52938fa33abe9e6 100644 (file)
@@ -1108,7 +1108,7 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
                - an expression with TREE_NO_WARNING set. (For an example of
                  such expressions, see build_over_call in call.c.)
                - automatic dereferencing of references, since the user cannot
-                 control it. (See also warn_if_unused_value() in stmt.c.)  */
+                 control it. (See also warn_if_unused_value() in c-common.c.)  */
             if (warn_unused_value
                && implicit != ICV_CAST
                 && (complain & tf_warning)
index 93d643a7bf0a8bdfa53fc627cad0c4c58ffc266a..0589bfd1bb88529228c446cb6593cf630a5eccb2 100644 (file)
@@ -1472,102 +1472,6 @@ expand_expr_stmt (tree exp)
   free_temp_slots ();
 }
 
-/* Warn if EXP contains any computations whose results are not used.
-   Return 1 if a warning is printed; 0 otherwise.  LOCUS is the
-   (potential) location of the expression.  */
-
-int
-warn_if_unused_value (const_tree exp, location_t locus)
-{
- restart:
-  if (TREE_USED (exp) || TREE_NO_WARNING (exp))
-    return 0;
-
-  /* Don't warn about void constructs.  This includes casting to void,
-     void function calls, and statement expressions with a final cast
-     to void.  */
-  if (VOID_TYPE_P (TREE_TYPE (exp)))
-    return 0;
-
-  if (EXPR_HAS_LOCATION (exp))
-    locus = EXPR_LOCATION (exp);
-
-  switch (TREE_CODE (exp))
-    {
-    case PREINCREMENT_EXPR:
-    case POSTINCREMENT_EXPR:
-    case PREDECREMENT_EXPR:
-    case POSTDECREMENT_EXPR:
-    case MODIFY_EXPR:
-    case INIT_EXPR:
-    case TARGET_EXPR:
-    case CALL_EXPR:
-    case TRY_CATCH_EXPR:
-    case WITH_CLEANUP_EXPR:
-    case EXIT_EXPR:
-    case VA_ARG_EXPR:
-      return 0;
-
-    case BIND_EXPR:
-      /* For a binding, warn if no side effect within it.  */
-      exp = BIND_EXPR_BODY (exp);
-      goto restart;
-
-    case SAVE_EXPR:
-    case NON_LVALUE_EXPR:
-      exp = TREE_OPERAND (exp, 0);
-      goto restart;
-
-    case TRUTH_ORIF_EXPR:
-    case TRUTH_ANDIF_EXPR:
-      /* In && or ||, warn if 2nd operand has no side effect.  */
-      exp = TREE_OPERAND (exp, 1);
-      goto restart;
-
-    case COMPOUND_EXPR:
-      if (warn_if_unused_value (TREE_OPERAND (exp, 0), locus))
-       return 1;
-      /* Let people do `(foo (), 0)' without a warning.  */
-      if (TREE_CONSTANT (TREE_OPERAND (exp, 1)))
-       return 0;
-      exp = TREE_OPERAND (exp, 1);
-      goto restart;
-
-    case COND_EXPR:
-      /* If this is an expression with side effects, don't warn; this
-        case commonly appears in macro expansions.  */
-      if (TREE_SIDE_EFFECTS (exp))
-       return 0;
-      goto warn;
-
-    case INDIRECT_REF:
-      /* Don't warn about automatic dereferencing of references, since
-        the user cannot control it.  */
-      if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == REFERENCE_TYPE)
-       {
-         exp = TREE_OPERAND (exp, 0);
-         goto restart;
-       }
-      /* Fall through.  */
-
-    default:
-      /* Referencing a volatile value is a side effect, so don't warn.  */
-      if ((DECL_P (exp) || REFERENCE_CLASS_P (exp))
-         && TREE_THIS_VOLATILE (exp))
-       return 0;
-
-      /* If this is an expression which has no operands, there is no value
-        to be unused.  There are no such language-independent codes,
-        but front ends may define such.  */
-      if (EXPRESSION_CLASS_P (exp) && TREE_OPERAND_LENGTH (exp) == 0)
-       return 0;
-
-    warn:
-      warning_at (locus, OPT_Wunused_value, "value computed is not used");
-      return 1;
-    }
-}
-
 \f
 /* Generate RTL to return from the current function, with no value.
    (That is, we do not do anything about returning any value.)  */
index da6be99805406869d5492ec2e3f3f8a4053723b1..c3fbde99b568fb45b053443ba8624cb8dc73a5c5 100644 (file)
@@ -5211,7 +5211,6 @@ extern tree unshare_expr (tree);
 /* In stmt.c */
 
 extern void expand_expr_stmt (tree);
-extern int warn_if_unused_value (const_tree, location_t);
 extern void expand_label (tree);
 extern void expand_goto (tree);