diff options
author | Richard Guenther <rguenther@suse.de> | 2008-05-26 12:38:19 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2008-05-26 12:38:19 +0000 |
commit | fcb4587ef66e7d3d5b2e580b1a737e73ae78bb23 (patch) | |
tree | 7061c86d99df91be70148ec69b4696860a24b55b /gcc | |
parent | d6ca724ce2bf5d47d973d6231a80e6e83c244a92 (diff) | |
download | gcc-fcb4587ef66e7d3d5b2e580b1a737e73ae78bb23.zip gcc-fcb4587ef66e7d3d5b2e580b1a737e73ae78bb23.tar.gz gcc-fcb4587ef66e7d3d5b2e580b1a737e73ae78bb23.tar.bz2 |
re PR middle-end/36300 (Incorrect type used for inlined expression)
2008-05-26 Richard Guenther <rguenther@suse.de>
PR middle-end/36300
* fold-const.c (extract_muldiv_1): Use TYPE_OVERFLOW_WRAPS,
not TYPE_UNSIGNED. Use TYPE_PRECISION instead of GET_MODE_SIZE.
* gcc.dg/pr36300-1.c: New testcase.
* gcc.dg/pr36300-2.c: Likewise.
From-SVN: r135913
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fold-const.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr36300-1.c | 24 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr36300-2.c | 24 |
5 files changed, 67 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4e68ae5..25f86bc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2008-05-26 Richard Guenther <rguenther@suse.de> + + PR middle-end/36300 + * fold-const.c (extract_muldiv_1): Use TYPE_OVERFLOW_WRAPS, + not TYPE_UNSIGNED. Use TYPE_PRECISION instead of GET_MODE_SIZE. + 2008-05-26 Daniel Franke <franke.daniel@gmail.com> PR bootstrap/36331 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 4113dc4..25756bb 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -5736,17 +5736,17 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type, || BINARY_CLASS_P (op0) || VL_EXP_CLASS_P (op0) || EXPRESSION_CLASS_P (op0)) - /* ... and is unsigned, and its type is smaller than ctype, - then we cannot pass through as widening. */ - && ((TYPE_UNSIGNED (TREE_TYPE (op0)) + /* ... and has wrapping overflow, and its type is smaller + than ctype, then we cannot pass through as widening. */ + && ((TYPE_OVERFLOW_WRAPS (TREE_TYPE (op0)) && ! (TREE_CODE (TREE_TYPE (op0)) == INTEGER_TYPE && TYPE_IS_SIZETYPE (TREE_TYPE (op0))) - && (GET_MODE_SIZE (TYPE_MODE (ctype)) - > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0))))) + && (TYPE_PRECISION (ctype) + > TYPE_PRECISION (TREE_TYPE (op0)))) /* ... or this is a truncation (t is narrower than op0), then we cannot pass through this narrowing. */ - || (GET_MODE_SIZE (TYPE_MODE (type)) - < GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))) + || (TYPE_PRECISION (type) + < TYPE_PRECISION (TREE_TYPE (op0))) /* ... or signedness changes for division or modulus, then we cannot pass through this conversion. */ || (code != MULT_EXPR diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5060df6..867b297 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2008-05-26 Richard Guenther <rguenther@suse.de> + + PR middle-end/36300 + * gcc.dg/pr36300-1.c: New testcase. + * gcc.dg/pr36300-2.c: Likewise. + 2008-05-26 Arnaud Charlet <charlet@adacore.com> * gnat.dg/set_in_pproc.adb: New test. diff --git a/gcc/testsuite/gcc.dg/pr36300-1.c b/gcc/testsuite/gcc.dg/pr36300-1.c new file mode 100644 index 0000000..466522f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr36300-1.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fwrapv" } */ + +extern void abort (void); + +#define VALUE ((int)((long long)U1 * (long long)3) + 2) + +int main(void) +{ + int U1; + long long Y, Y2; + int t; + + U1 = -2147483647-1; + + Y = ((long long)(VALUE * VALUE) * 3); + + t = VALUE; + Y2 = ((long long)(t * t) * 3); + + if (Y != Y2) + abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pr36300-2.c b/gcc/testsuite/gcc.dg/pr36300-2.c new file mode 100644 index 0000000..7e7cfa2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr36300-2.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +extern void abort (void); + +#define VALUE (unsigned int)((int)((long long)U1 * (long long)3) + 2) + +int main(void) +{ + int U1; + long long Y, Y2; + unsigned int t; + + U1 = -2147483647-1; + + Y = ((long long)(int)(VALUE * VALUE) * 3); + + t = VALUE; + Y2 = ((long long)(int)(t * t) * 3); + + if (Y != Y2) + abort (); + return 0; +} |