diff options
author | Richard Guenther <rguenther@suse.de> | 2007-10-31 12:33:05 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2007-10-31 12:33:05 +0000 |
commit | ac029795f3fde4f8cf6ea1b48b76a7c7f137bee9 (patch) | |
tree | 2035bbc1a2f604178b758bb8ac8aec2c7229d814 /gcc | |
parent | 182393f4f798c2ca212e2eba190e9a181f9787d8 (diff) | |
download | gcc-ac029795f3fde4f8cf6ea1b48b76a7c7f137bee9.zip gcc-ac029795f3fde4f8cf6ea1b48b76a7c7f137bee9.tar.gz gcc-ac029795f3fde4f8cf6ea1b48b76a7c7f137bee9.tar.bz2 |
re PR middle-end/33779 (folds unsigned multiplication == 0 to true)
2007-10-31 Richard Guenther <rguenther@suse.de>
PR middle-end/33779
* fold-const.c (extract_muldiv_1): Make sure to not introduce
new undefined integer overflow.
(fold_binary): Avoid useless conversion.
* gcc.c-torture/execute/pr33779-1.c: New testcase.
* gcc.c-torture/execute/pr33779-2.c: Likewise.
From-SVN: r129796
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/fold-const.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/pr33779-1.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/pr33779-2.c | 12 |
5 files changed, 46 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2808ae7..9e46938 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2007-10-31 Richard Guenther <rguenther@suse.de> + + PR middle-end/33779 + * fold-const.c (extract_muldiv_1): Make sure to not introduce + new undefined integer overflow. + (fold_binary): Avoid useless conversion. + 2007-10-31 Richard Sandiford <rsandifo@nildram.co.uk> PR target/33948 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 2598ec1..a7d2756 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6060,7 +6060,12 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type, then we cannot pass through this conversion. */ || (code != MULT_EXPR && (TYPE_UNSIGNED (ctype) - != TYPE_UNSIGNED (TREE_TYPE (op0)))))) + != TYPE_UNSIGNED (TREE_TYPE (op0)))) + /* ... or has undefined overflow while the converted to + type has not, we cannot do the operation in the inner type + as that would introduce undefined overflow. */ + || (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (op0)) + && !TYPE_OVERFLOW_UNDEFINED (type)))) break; /* Pass the constant down and see if we can make a simplification. If @@ -10266,9 +10271,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) strict_overflow_p = false; if (TREE_CODE (arg1) == INTEGER_CST - && 0 != (tem = extract_muldiv (op0, - fold_convert (type, arg1), - code, NULL_TREE, + && 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE, &strict_overflow_p))) { if (strict_overflow_p) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 59ae5ef..385b384e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2007-10-31 Richard Guenther <rguenther@suse.de> + + PR middle-end/33779 + * gcc.c-torture/execute/pr33779-1.c: New testcase. + * gcc.c-torture/execute/pr33779-2.c: Likewise. + 2007-10-31 Paul Thomas <pault@gcc.gnu.org> PR fortran/33897 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr33779-1.c b/gcc/testsuite/gcc.c-torture/execute/pr33779-1.c new file mode 100644 index 0000000..da08e01 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr33779-1.c @@ -0,0 +1,14 @@ +int foo(int i) +{ + if (((unsigned)(i + 1)) * 4 == 0) + return 1; + return 0; +} + +extern void abort(void); +int main() +{ + if (foo(0x3fffffff) == 0) + abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr33779-2.c b/gcc/testsuite/gcc.c-torture/execute/pr33779-2.c new file mode 100644 index 0000000..16c34b6 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr33779-2.c @@ -0,0 +1,12 @@ +int foo(int i) +{ + return ((int)((unsigned)(i + 1) * 4)) / 4; +} + +extern void abort(void); +int main() +{ + if (foo(0x3fffffff) != 0) + abort (); + return 0; +} |