diff options
author | Joseph Myers <jsm@polyomino.org.uk> | 2004-07-11 10:45:39 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2004-07-11 10:45:39 +0100 |
commit | fae1b38dc82248b70271f42647fa92b82ca6e200 (patch) | |
tree | 1b02a4649bd7dcfe9f9116eb1060eb0d1e1d01b3 | |
parent | 7d3998a4453d9aa086113cb353eebda4c0a87563 (diff) | |
download | gcc-fae1b38dc82248b70271f42647fa92b82ca6e200.zip gcc-fae1b38dc82248b70271f42647fa92b82ca6e200.tar.gz gcc-fae1b38dc82248b70271f42647fa92b82ca6e200.tar.bz2 |
re PR tree-optimization/16437 (New c-torture failures after bitfield patch)
PR tree-optimization/16437
* c-common.c (shorten_compare): Don't mark result of conversion to
narrower signed type as overflowing.
* fold-const.c (decode_field_reference): Determine whether
signedness comes from outer type using precision rather than size.
testsuite:
* gcc.c-torture/execute/bitfld-4.c: New test.
From-SVN: r84498
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/c-common.c | 7 | ||||
-rw-r--r-- | gcc/fold-const.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/bitfld-4.c | 21 |
5 files changed, 41 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b3dec3e..efd1f24 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2004-07-11 Joseph S. Myers <jsm@polyomino.org.uk> + + PR tree-optimization/16437 + * c-common.c (shorten_compare): Don't mark result of conversion to + narrower signed type as overflowing. + * fold-const.c (decode_field_reference): Determine whether + signedness comes from outer type using precision rather than size. + 2004-07-11 Phil Edwards <phil@codesourcery.com> * configure.ac: Alphabetize --enable-checking list, add diff --git a/gcc/c-common.c b/gcc/c-common.c index ebb5e65..e177d88 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -1924,7 +1924,12 @@ shorten_compare (tree *op0_ptr, tree *op1_ptr, tree *restype_ptr, *restype_ptr = c_common_signed_type (*restype_ptr); if (TREE_TYPE (primop1) != *restype_ptr) - primop1 = convert (*restype_ptr, primop1); + { + tree tmp = convert (*restype_ptr, primop1); + TREE_OVERFLOW (tmp) = TREE_OVERFLOW (primop1); + TREE_CONSTANT_OVERFLOW (tmp) = TREE_CONSTANT_OVERFLOW (primop1); + primop1 = tmp; + } if (type != *restype_ptr) { minval = convert (*restype_ptr, minval); diff --git a/gcc/fold-const.c b/gcc/fold-const.c index a1efab1..b35dfbf 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -3296,7 +3296,7 @@ decode_field_reference (tree exp, HOST_WIDE_INT *pbitsize, /* If the number of bits in the reference is the same as the bitsize of the outer type, then the outer type gives the signedness. Otherwise (in case of a small bitfield) the signedness is unchanged. */ - if (outer_type && *pbitsize == tree_low_cst (TYPE_SIZE (outer_type), 1)) + if (outer_type && *pbitsize == TYPE_PRECISION (outer_type)) *punsignedp = TYPE_UNSIGNED (outer_type); /* Compute the mask to access the bitfield. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 99083c2..20104dd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-07-11 Joseph S. Myers <jsm@polyomino.org.uk> + + PR tree-optimization/16437 + * gcc.c-torture/execute/bitfld-4.c: New test. + 2004-07-10 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de> * gfortran.fortran-torture/execute/common_2.f90: Add check for diff --git a/gcc/testsuite/gcc.c-torture/execute/bitfld-4.c b/gcc/testsuite/gcc.c-torture/execute/bitfld-4.c new file mode 100644 index 0000000..6f7d7e2 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/bitfld-4.c @@ -0,0 +1,21 @@ +/* When comparisons of bit-fields to unsigned constants got shortened, + the shortened signed constant was wrongly marked as overflowing, + leading to a later integer_zerop failure and misoptimization. + + Related to bug tree-optimization/16437 but shows the problem on + 32-bit systems. */ +/* Origin: Joseph Myers <jsm@polyomino.org.uk> */ + +extern void abort (void); + +struct s { int a:12, b:20; }; + +struct s x = { -123, -456 }; + +int +main (void) +{ + if (x.a != -123U || x.b != -456U) + abort (); + return 0; +} |