]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c90-const-expr-8.c: Look for overflow on INT_MIN % -1.
authorKenneth Zadeck <zadeck@naturalbridge.com>
Wed, 27 Nov 2013 15:42:02 +0000 (15:42 +0000)
committerKenneth Zadeck <zadeck@gcc.gnu.org>
Wed, 27 Nov 2013 15:42:02 +0000 (15:42 +0000)
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.

From-SVN: r205448

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c90-const-expr-8.c
gcc/testsuite/gcc.dg/c99-const-expr-8.c

index 3899f7e40c5ca287e1f8d5c235b04442c72e07da..1ef702c50fee5c6255b32e396ef2ea06c2777864 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2013-11-27  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/58723
index d56b35513f6157faa27de623ef8054f49eab0420..fcd7f087be8d66c635f7d10ceaefada3ce1217c7 100644 (file)
@@ -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:
index 084e8128dcc5af3589310c92d795c2c62357049b..075e0b14d80f1e44d4ae16e3c06f1adcfb486c44 100644 (file)
@@ -1,3 +1,8 @@
+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  Marek Polacek  <polacek@redhat.com>
 
        PR sanitizer/59306
index 4923bc680468ab4a024f34987c1c82a823747cbf..b6aba7b1d87eab5ef03a2e553cbcdbc586158dcd 100644 (file)
@@ -23,5 +23,6 @@ enum e {
   /* { dg-error "3:overflow in constant expression" "constant" { target *-*-* } 22 } */
   E6 = 0 * !-INT_MIN, /* { dg-warning "13:integer overflow in expression" } */
   /* { dg-error "8:not an integer constant" "constant" { target *-*-* } 24 } */
-  E7 = INT_MIN % -1 /* Not an overflow.  */
+  E7 = INT_MIN % -1 /* { dg-warning "16:integer overflow in expression" } */
+  /* { dg-error "1:overflow in constant expression" "constant" { target *-*-* } 28 } */
 };
index e84fa7b4db055653784d789e0857d1564f57c5b5..1ddd9ed91ce0d6483b1cd3b80cb1215f6d1be3b7 100644 (file)
@@ -23,5 +23,6 @@ enum e {
   /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 22 } */
   E6 = 0 * !-INT_MIN, /* { dg-warning "integer overflow in expression" } */
   /* { dg-error "not an integer constant" "constant" { target *-*-* } 24 } */
-  E7 = INT_MIN % -1 /* Not an overflow.  */
+  E7 = INT_MIN % -1 /* { dg-warning "16:integer overflow in expression" } */
+  /* { dg-error "1:overflow in constant expression" "constant" { target *-*-* } 28 } */
 };