tree.c (tree_expr_nonnegative_p): New function.
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>
Sat, 8 Apr 2000 04:45:18 +0000 (04:45 +0000)
committerKaveh Ghazi <ghazi@gcc.gnu.org>
Sat, 8 Apr 2000 04:45:18 +0000 (04:45 +0000)
        * tree.c (tree_expr_nonnegative_p): New function.

        * tree.h (tree_expr_nonnegative_p): Declare.

        * c-typeck.c (build_binary_op): Call `tree_expr_nonnegative_p' to
        elide some sign_compare warnings.
        (build_conditional_expr): Likewise.

cp:
        * typeck.c (build_binary_op): Call `tree_expr_nonnegative_p' to elide
        some sign_compare warnings.

From-SVN: r33019

gcc/ChangeLog
gcc/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/tree.c
gcc/tree.h

index 3ed3fff..3ff6707 100644 (file)
@@ -1,3 +1,13 @@
+2000-04-08  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+       * tree.c (tree_expr_nonnegative_p): New function.
+
+       * tree.h (tree_expr_nonnegative_p): Declare.
+
+       * c-typeck.c (build_binary_op): Call `tree_expr_nonnegative_p' to
+       elide some sign_compare warnings.
+       (build_conditional_expr): Likewise.
+
 Sat Apr  8 00:21:51 EDT 2000  John Wehle  (john@feith.com)
 
        * i386.md (ashrsi3, ashrhi3, ashrqi3): Fix typo.
index f66d1b9..0d395a2 100644 (file)
@@ -2416,11 +2416,12 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
                  else
                    sop = xop1, uop = xop0;
 
-                 /* Do not warn if the signed quantity is an unsuffixed
-                    integer literal (or some static constant expression
-                    involving such literals) and it is non-negative.  */
-                 if (TREE_CODE (sop) == INTEGER_CST
-                     && tree_int_cst_sgn (sop) >= 0)
+                 /* Do not warn if the signed quantity is an
+                    unsuffixed integer literal (or some static
+                    constant expression involving such literals or a
+                    conditional expression involving such literals)
+                    and it is non-negative.  */
+                 if (tree_expr_nonnegative_p (sop))
                    /* OK */;
                  /* Do not warn if the comparison is an equality operation,
                     the unsigned quantity is an integral constant, and it
@@ -3383,10 +3384,8 @@ build_conditional_expr (ifexp, op1, op2)
              /* Do not warn if the signed quantity is an unsuffixed
                 integer literal (or some static constant expression
                 involving such literals) and it is non-negative.  */
-             else if ((unsigned_op2 && TREE_CODE (op1) == INTEGER_CST
-                       && tree_int_cst_sgn (op1) >= 0)
-                      || (unsigned_op1 && TREE_CODE (op2) == INTEGER_CST
-                          && tree_int_cst_sgn (op2) >= 0))
+             else if ((unsigned_op2 && tree_expr_nonnegative_p (op1))
+                      || (unsigned_op1 && tree_expr_nonnegative_p (op2)))
                /* OK */;
              else
                warning ("signed and unsigned type in conditional expression");
index a23b48d..5759cb6 100644 (file)
@@ -1,3 +1,8 @@
+2000-04-08  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+       * typeck.c (build_binary_op): Call `tree_expr_nonnegative_p' to elide
+       some sign_compare warnings.
+
 2000-04-07  Nathan Sidwell  <nathan@codesourcery.com>
 
        Rename abi::__vmi_class_type_info members.
index 522bc57..74f16b7 100644 (file)
@@ -3960,11 +3960,10 @@ build_binary_op (code, orig_op0, orig_op1)
            /* OK */;
          /* Do not warn if the signed quantity is an unsuffixed
             integer literal (or some static constant expression
+            involving such literals or a conditional expression
             involving such literals) and it is non-negative.  */
-         else if ((op0_signed && TREE_CODE (orig_op0) == INTEGER_CST
-                   && tree_int_cst_sgn (orig_op0) >= 0)
-                  || (op1_signed && TREE_CODE (orig_op1) == INTEGER_CST
-                      && tree_int_cst_sgn (orig_op1) >= 0))
+         else if ((op0_signed && tree_expr_nonnegative_p (orig_op0))
+                  || (op1_signed && tree_expr_nonnegative_p (orig_op1)))
            /* OK */;
          /* Do not warn if the comparison is an equality operation,
             the unsigned quantity is an integral constant and it does
index 53ca207..66078e5 100644 (file)
@@ -4370,6 +4370,25 @@ tree_int_cst_sgn (t)
     return 1;
 }
 
+/* Return true if `t' is known to be non-negative.  */
+
+int
+tree_expr_nonnegative_p (t)
+     tree t;
+{
+  switch (TREE_CODE (t))
+    {
+    case INTEGER_CST:
+      return tree_int_cst_sgn (t) >= 0;
+    case COND_EXPR:
+      return tree_expr_nonnegative_p (TREE_OPERAND (t, 1))
+       && tree_expr_nonnegative_p (TREE_OPERAND (t, 2));
+    default:
+      /* We don't know sign of `t', so be safe and return false.  */
+      return 0;
+    }
+}
+
 /* Compare two constructor-element-type constants.  Return 1 if the lists
    are known to be equal; otherwise return 0.  */
 
index 0264ccc..0332102 100644 (file)
@@ -1697,6 +1697,7 @@ extern int host_integerp          PARAMS ((tree, int));
 extern HOST_WIDE_INT tree_low_cst      PARAMS ((tree, int));
 extern int tree_int_cst_msb            PARAMS ((tree));
 extern int tree_int_cst_sgn            PARAMS ((tree));
+extern int tree_expr_nonnegative_p             PARAMS ((tree));
 extern int index_type_equal            PARAMS ((tree, tree));
 extern tree get_inner_array_type       PARAMS ((tree));