This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch for c/16302
- From: "Thomas R. Truscott" <trt at cs dot duke dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 1 Jul 2004 10:48:21 -0400 (EDT)
- Subject: Patch for c/16302
This patch adds a warning for some boolean-logic errors
which are rare but easily overlooked (there are some in gcc itself).
Bootstrapped on i686-pc-linux-gnu.
2004-07-01 Tom Truscott <trt@acm.org>
PR c/16302
* fold-const.c (fold_range_test): add warning.
(nondestructive_fold_binary_to_constant): fix bug exposed
by the warning so that gcc will bootstrap
diff -rupN fold-const.c.orig fold-const.c
--- fold-const.c.orig 2004-06-27 11:23:44.000000000 -0400
+++ fold-const.c 2004-06-30 13:01:59.000000000 -0400
@@ -4375,7 +4375,16 @@ fold_range_test (tree exp)
lhs != 0 ? lhs
: rhs != 0 ? rhs : integer_zero_node,
in_p, low, high))))
- return or_op ? invert_truthvalue (tem) : tem;
+ {
+ if (TREE_CODE (tem) == INTEGER_CST && extra_warnings)
+ {
+ if (or_op)
+ warning ("sas: `or' of collectively exhaustive tests is always 1");
+ else
+ warning ("sas: `and' of mutually exclusive tests is always 0");
+ }
+ return or_op ? invert_truthvalue (tem) : tem;
+ }
/* On machines where the branch cost is expensive, if this is a
short-circuited branch and the underlying object on both sides
@@ -9996,7 +10005,7 @@ nondestructive_fold_binary_to_constant (
if ((TREE_CODE (op0) == INTEGER_CST
&& TREE_CODE (op1) != INTEGER_CST)
|| (TREE_CODE (op0) == REAL_CST
- && TREE_CODE (op0) != REAL_CST))
+ && TREE_CODE (op1) != REAL_CST))
{
tree temp;