Commit 3facde26 by Kaveh R. Ghazi Committed by Kaveh Ghazi

tree.c (tree_expr_nonnegative_p): New function.

        * 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
parent 155d8a47
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) Sat Apr 8 00:21:51 EDT 2000 John Wehle (john@feith.com)
* i386.md (ashrsi3, ashrhi3, ashrqi3): Fix typo. * i386.md (ashrsi3, ashrhi3, ashrqi3): Fix typo.
......
...@@ -2416,11 +2416,12 @@ build_binary_op (code, orig_op0, orig_op1, convert_p) ...@@ -2416,11 +2416,12 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
else else
sop = xop1, uop = xop0; sop = xop1, uop = xop0;
/* Do not warn if the signed quantity is an unsuffixed /* Do not warn if the signed quantity is an
integer literal (or some static constant expression unsuffixed integer literal (or some static
involving such literals) and it is non-negative. */ constant expression involving such literals or a
if (TREE_CODE (sop) == INTEGER_CST conditional expression involving such literals)
&& tree_int_cst_sgn (sop) >= 0) and it is non-negative. */
if (tree_expr_nonnegative_p (sop))
/* OK */; /* OK */;
/* Do not warn if the comparison is an equality operation, /* Do not warn if the comparison is an equality operation,
the unsigned quantity is an integral constant, and it the unsigned quantity is an integral constant, and it
...@@ -3383,10 +3384,8 @@ build_conditional_expr (ifexp, op1, op2) ...@@ -3383,10 +3384,8 @@ build_conditional_expr (ifexp, op1, op2)
/* Do not warn if the signed quantity is an unsuffixed /* Do not warn if the signed quantity is an unsuffixed
integer literal (or some static constant expression integer literal (or some static constant expression
involving such literals) and it is non-negative. */ involving such literals) and it is non-negative. */
else if ((unsigned_op2 && TREE_CODE (op1) == INTEGER_CST else if ((unsigned_op2 && tree_expr_nonnegative_p (op1))
&& tree_int_cst_sgn (op1) >= 0) || (unsigned_op1 && tree_expr_nonnegative_p (op2)))
|| (unsigned_op1 && TREE_CODE (op2) == INTEGER_CST
&& tree_int_cst_sgn (op2) >= 0))
/* OK */; /* OK */;
else else
warning ("signed and unsigned type in conditional expression"); warning ("signed and unsigned type in conditional expression");
......
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> 2000-04-07 Nathan Sidwell <nathan@codesourcery.com>
Rename abi::__vmi_class_type_info members. Rename abi::__vmi_class_type_info members.
......
...@@ -3960,11 +3960,10 @@ build_binary_op (code, orig_op0, orig_op1) ...@@ -3960,11 +3960,10 @@ build_binary_op (code, orig_op0, orig_op1)
/* OK */; /* OK */;
/* Do not warn if the signed quantity is an unsuffixed /* Do not warn if the signed quantity is an unsuffixed
integer literal (or some static constant expression integer literal (or some static constant expression
involving such literals or a conditional expression
involving such literals) and it is non-negative. */ involving such literals) and it is non-negative. */
else if ((op0_signed && TREE_CODE (orig_op0) == INTEGER_CST else if ((op0_signed && tree_expr_nonnegative_p (orig_op0))
&& tree_int_cst_sgn (orig_op0) >= 0) || (op1_signed && tree_expr_nonnegative_p (orig_op1)))
|| (op1_signed && TREE_CODE (orig_op1) == INTEGER_CST
&& tree_int_cst_sgn (orig_op1) >= 0))
/* OK */; /* OK */;
/* Do not warn if the comparison is an equality operation, /* Do not warn if the comparison is an equality operation,
the unsigned quantity is an integral constant and it does the unsigned quantity is an integral constant and it does
......
...@@ -4370,6 +4370,25 @@ tree_int_cst_sgn (t) ...@@ -4370,6 +4370,25 @@ tree_int_cst_sgn (t)
return 1; 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 /* Compare two constructor-element-type constants. Return 1 if the lists
are known to be equal; otherwise return 0. */ are known to be equal; otherwise return 0. */
......
...@@ -1697,6 +1697,7 @@ extern int host_integerp PARAMS ((tree, int)); ...@@ -1697,6 +1697,7 @@ extern int host_integerp PARAMS ((tree, int));
extern HOST_WIDE_INT tree_low_cst 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_msb PARAMS ((tree));
extern int tree_int_cst_sgn 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 int index_type_equal PARAMS ((tree, tree));
extern tree get_inner_array_type PARAMS ((tree)); extern tree get_inner_array_type PARAMS ((tree));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment