diff options
author | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-03-23 22:57:26 +0000 |
---|---|---|
committer | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-03-23 22:57:26 +0000 |
commit | cee280efb4397b8c6e08a33b5000b42c885325fd (patch) | |
tree | e1c8674477700f6ed2edd93d67199d024ef407d1 | |
parent | 8df677b548f48904cd6374e32bbb5076fbf8b731 (diff) | |
download | gcc-cee280efb4397b8c6e08a33b5000b42c885325fd.tar.gz |
PR c/8224
* fold-const.c (extract_muldiv_1): Don't pass through type conversions
when signedness changes for division or modulus.
PR c/8224
* gcc.dg/20030323-1.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@64760 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fold-const.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/20030323-1.c | 24 |
4 files changed, 41 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index fc8f41838f7..596e91e0984 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2003-03-23 Glen Nakamura <glen@imodulo.com> + + PR c/8224 + * fold-const.c (extract_muldiv_1): Don't pass through type conversions + when signedness changes for division or modulus. + 2003-03-24 Alan Modra <amodra@bigpond.net.au> * config/rs6000/sysv4.h (ASM_OUTPUT_ALIGNED_BSS): Remove unnecessary diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 7b051fa8a6e..0f9f3d419a5 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4170,7 +4170,12 @@ extract_muldiv_1 (t, c, code, wide_type) /* ... or its type is larger than ctype, then we cannot pass through this truncation. */ || (GET_MODE_SIZE (TYPE_MODE (ctype)) - < GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))))) + < GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))) + /* ... or signedness changes for division or modulus, + then we cannot pass through this conversion. */ + || (code != MULT_EXPR + && (TREE_UNSIGNED (ctype) + != TREE_UNSIGNED (TREE_TYPE (op0)))))) break; /* Pass the constant down and see if we can make a simplification. If diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 05b170ca185..9db85358f04 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2003-03-23 Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz> + + PR c/8224 + * gcc.dg/20030323-1.c: New test. + 2003-03-23 Roger Sayle <roger@eyesopen.com> * gcc.c-torture/compile/20030323-1.c: New test case. diff --git a/gcc/testsuite/gcc.dg/20030323-1.c b/gcc/testsuite/gcc.dg/20030323-1.c new file mode 100644 index 00000000000..8a563ec5eb2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/20030323-1.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ + +/* PR c/8224 */ +/* Contributed by Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz> */ + +extern void abort (void); + +unsigned f (int x) +{ + return (unsigned) (x / 2) / 2; +} + +unsigned f1 (int x) +{ + unsigned xx = x / 2; + return xx / 2; +} + +int main () +{ + if (f1 (-5) != f (-5)) + abort (); + return 0; +} |