From 6ddaa100f3fb6e330bce20314c548a789fcbc62a Mon Sep 17 00:00:00 2001 From: phython Date: Tue, 19 Apr 2005 02:36:04 +0000 Subject: [PATCH] 2005-04-18 James A. Morrison PR tree-optimization/21085 * fold-const (fold_binary): Don't change X % -C to X % C if C has overflowed. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@98365 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 1 + gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/pr21085.c | 9 +++++++++ 4 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr21085.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a6c212d..dd19840 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2005-04-18 James A. Morrison + + 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 * doc/invoke.texi (Optimize Options): Refer to the correct diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 1e1ecc1..bbd14c0 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 28dfc14..57dc0fe 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2005-04-18 James A. Morrison + + * gcc.dg/pr21085.c: New test. + 2005-04-18 Richard Sandiford * 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 index 0000000..6a51adb --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr21085.c @@ -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" } */ +} -- 2.7.4