diff options
author | Kaveh R. Ghazi <ghazi@caip.rutgers.edu> | 2000-04-08 04:45:18 +0000 |
---|---|---|
committer | Kaveh Ghazi <ghazi@gcc.gnu.org> | 2000-04-08 04:45:18 +0000 |
commit | 3facde269a04c33b91becb5cf4397fb69077895d (patch) | |
tree | ffab24c880d3a50de4e3ea9bfc57f63e27c41487 | |
parent | 155d8a473c79aa5a557ee37306f83b28353b06d4 (diff) | |
download | gcc-3facde269a04c33b91becb5cf4397fb69077895d.zip gcc-3facde269a04c33b91becb5cf4397fb69077895d.tar.gz gcc-3facde269a04c33b91becb5cf4397fb69077895d.tar.bz2 |
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
-rw-r--r-- | gcc/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/c-typeck.c | 17 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 7 | ||||
-rw-r--r-- | gcc/tree.c | 19 | ||||
-rw-r--r-- | gcc/tree.h | 1 |
6 files changed, 46 insertions, 13 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3ed3fff..3ff6707 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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. diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index f66d1b9..0d395a2 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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"); diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a23b48d..5759cb6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 522bc57..74f16b7 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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 @@ -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. */ @@ -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)); |