aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Kenner <kenner@gcc.gnu.org>1994-08-25 17:43:46 -0400
committerRichard Kenner <kenner@gcc.gnu.org>1994-08-25 17:43:46 -0400
commit5af6001b5e2e82b47fd38552d62e3b643adcff0a (patch)
tree410c07bafde7ee82f7f27923c712276019b270da
parent96a31ab889aca2a00133a92a5692e748fc7b6f0e (diff)
downloadgcc-5af6001b5e2e82b47fd38552d62e3b643adcff0a.zip
gcc-5af6001b5e2e82b47fd38552d62e3b643adcff0a.tar.gz
gcc-5af6001b5e2e82b47fd38552d62e3b643adcff0a.tar.bz2
(shorten_compare): Don't issue warning if both operands constants and the...
(shorten_compare): Don't issue warning if both operands constants and the signedness doesn't affect the comparison results. From-SVN: r7981
-rw-r--r--gcc/c-common.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 8109fc0..0d9184f 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -1457,9 +1457,11 @@ shorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr)
real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE;
/* If first arg is constant, swap the args (changing operation
- so value is preserved), for canonicalization. */
+ so value is preserved), for canonicalization. Don't do this if
+ the second arg is 0. */
- if (TREE_CONSTANT (primop0))
+ if (TREE_CONSTANT (primop0)
+ && ! integer_zerop (primop1) && ! real_zerop (primop1))
{
register tree tem = primop0;
register int temi = unsignedp0;
@@ -1698,13 +1700,23 @@ shorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr)
switch (code)
{
case GE_EXPR:
- if (extra_warnings)
+ /* All unsigned values are >= 0, so we warn if extra warnings
+ are requested. However, if OP0 is a constant that is
+ >= 0, the signedness of the comparison isn't an issue,
+ so suppress the warning. */
+ if (extra_warnings
+ && ! (TREE_CODE (primop0) == INTEGER_CST
+ && ! TREE_OVERFLOW (convert (signed_type (type),
+ primop0))))
warning ("unsigned value >= 0 is always 1");
value = integer_one_node;
break;
case LT_EXPR:
- if (extra_warnings)
+ if (extra_warnings
+ && ! (TREE_CODE (primop0) == INTEGER_CST
+ && ! TREE_OVERFLOW (convert (signed_type (type),
+ primop0))))
warning ("unsigned value < 0 is always 0");
value = integer_zero_node;
}