summaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorzadeck <zadeck@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-27 15:42:02 +0000
committerzadeck <zadeck@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-27 15:42:02 +0000
commit15b8d58c97ed9c7cef6c7de79dc5e32fb455d3a4 (patch)
tree2550786536ef94f31fb46f8419d188392110b7c1 /gcc/fold-const.c
parent9978ce6d95c41b01acc06b98dc3379b0c4a6ff90 (diff)
downloadlinaro-gcc-15b8d58c97ed9c7cef6c7de79dc5e32fb455d3a4.tar.gz
linaro-gcc-15b8d58c97ed9c7cef6c7de79dc5e32fb455d3a4.tar.bz2
linaro-gcc-15b8d58c97ed9c7cef6c7de79dc5e32fb455d3a4.zip
2013-11-27 Kenneth Zadeck <zadeck@naturalbridge.com>
* gcc.dg/c90-const-expr-8.c: Look for overflow on INT_MIN % -1. * gcc.dg/c99-const-expr-8.c: Look for overflow on INT_MIN % -1. 2013-11-27 Kenneth Zadeck <zadeck@naturalbridge.com> * fold-const.c (int_const_binop_1): Make INT_MIN % -1 return 0 with the overflow bit set. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@205448 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index d56b35513f6..fcd7f087be8 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -1110,7 +1110,22 @@ int_const_binop_1 (enum tree_code code, const_tree arg1, const_tree arg2,
case ROUND_MOD_EXPR:
if (op2.is_zero ())
return NULL_TREE;
- tmp = op1.divmod_with_overflow (op2, uns, code, &res, &overflow);
+
+ /* Check for the case the case of INT_MIN % -1 and return
+ overflow and result = 0. The TImode case is handled properly
+ in double-int. */
+ if (TYPE_PRECISION (type) <= HOST_BITS_PER_WIDE_INT
+ && !uns
+ && op2.is_minus_one ()
+ && op1.high == (HOST_WIDE_INT) -1
+ && (HOST_WIDE_INT) op1.low
+ == (((HOST_WIDE_INT)-1) << (TYPE_PRECISION (type) - 1)))
+ {
+ overflow = 1;
+ res = double_int_zero;
+ }
+ else
+ tmp = op1.divmod_with_overflow (op2, uns, code, &res, &overflow);
break;
case MIN_EXPR: