aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
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