re PR middle-end/21085 (Virtual memory exhausted with g++)
authorJames A. Morrison <phython@gcc.gnu.org>
Tue, 19 Apr 2005 02:36:04 +0000 (02:36 +0000)
committerJames A. Morrison <phython@gcc.gnu.org>
Tue, 19 Apr 2005 02:36:04 +0000 (02:36 +0000)
2005-04-18  James A. Morrison  <phython@gcc.gnu.org>

        PR tree-optimization/21085
        * fold-const (fold_binary): Don't change X % -C to X % C if C has
        overflowed.

From-SVN: r98365

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr21085.c [new file with mode: 0644]

index a6c212d..dd19840 100644 (file)
@@ -1,3 +1,9 @@
+2005-04-18  James A. Morrison  <phython@gcc.gnu.org>
+
+       PR tree-optimization/21085
+       * fold-const (fold_binary): Don't change X % -C to X % C if C has
+       overflowed.
+
 2005-04-19  Ben Elliston  <bje@au.ibm.com>
 
        * doc/invoke.texi (Optimize Options): Refer to the correct
index 1e1ecc1..bbd14c0 100644 (file)
@@ -8504,6 +8504,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
       if (code == TRUNC_MOD_EXPR
          && !TYPE_UNSIGNED (type)
          && TREE_CODE (arg1) == INTEGER_CST
+         && !TREE_CONSTANT_OVERFLOW (arg1)
          && TREE_INT_CST_HIGH (arg1) < 0
          && !flag_trapv
          /* Avoid this transformation if C is INT_MIN, i.e. C == -C.  */
index 28dfc14..57dc0fe 100644 (file)
@@ -1,3 +1,7 @@
+2005-04-18  James A. Morrison  <phython@gcc.gnu.org>
+
+       * gcc.dg/pr21085.c: New test.
+
 2005-04-18  Richard Sandiford  <rsandifo@redhat.com>
 
        * gcc.target/mips/mips.exp: Minor formatting.  Call setup_mips_tests.
diff --git a/gcc/testsuite/gcc.dg/pr21085.c b/gcc/testsuite/gcc.dg/pr21085.c
new file mode 100644 (file)
index 0000000..6a51adb
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* This used to cause excessive use, or a stack overflow, depending on which
+   came first.  */
+void foo (void)
+{
+  int maxstringlen = 1;
+  int limit = 0, maxblock = 0, maxblockrem = 0;
+  maxblockrem = (maxstringlen) % (2147483647 + 1); /* { dg-warning "overflow" } */
+}