aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorJeff Law <law@redhat.com>2005-01-31 20:48:52 -0700
committerJeff Law <law@gcc.gnu.org>2005-01-31 20:48:52 -0700
commitdc5d4efbce3e6587b31da8d6d1c502aea80acfcc (patch)
tree156482e0e2154f02927d2baaf5e214e13f2ba2d8 /gcc/fold-const.c
parent3dcec1e9e797af50ef38718cf19e0742e1c6a96a (diff)
downloadgcc-dc5d4efbce3e6587b31da8d6d1c502aea80acfcc.zip
gcc-dc5d4efbce3e6587b31da8d6d1c502aea80acfcc.tar.gz
gcc-dc5d4efbce3e6587b31da8d6d1c502aea80acfcc.tar.bz2
fold-const.c (fold, [...]): Do not lose side effects when optimizing 0 % X.
* fold-const.c (fold, case CEIL_MOD_EXPR): Do not lose side effects when optimizing 0 % X. Do not try to optimize X % 0. * gcc.c-torture/execute/20050131-1.c: New test. * gcc.dg/wcaselabel.c: New test. From-SVN: r94516
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 13c57e0..2285742 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -7938,12 +7938,21 @@ fold (tree expr)
case FLOOR_MOD_EXPR:
case ROUND_MOD_EXPR:
case TRUNC_MOD_EXPR:
- /* 0 % X is always zero as is X % 1. */
- if (integer_zerop (arg0) || integer_onep (arg1))
+ /* X % 1 is always zero, but be sure to preserve any side
+ effects in X. */
+ if (integer_onep (arg1))
return omit_one_operand (type, integer_zero_node, arg0);
+
+ /* X % 0, return X % 0 unchanged so that we can get the
+ proper warnings and errors. */
if (integer_zerop (arg1))
return t;
+ /* 0 % X is always zero, but be sure to preserve any side
+ effects in X. Place this after checking for X == 0. */
+ if (integer_zerop (arg0))
+ return omit_one_operand (type, integer_zero_node, arg1);
+
/* X % -1 is zero. */
if (!TYPE_UNSIGNED (type)
&& TREE_CODE (arg1) == INTEGER_CST