diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-10-04 15:49:13 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-10-04 15:49:13 +0000 |
commit | 7f719f690a1d5d5275273799677468d1ef1218e9 (patch) | |
tree | 7df63e3198b51ae14cadad518c7a763b15c9c179 /gcc | |
parent | f235fedee9919b7396c17f2a16f6b8d0f79ee87f (diff) | |
download | gcc-7f719f690a1d5d5275273799677468d1ef1218e9.tar.gz |
PR middle-end/45876
* fold-const.c (fold_binary_loc) <case BIT_AND_EXPR>: Use
arg0's type or its unsigned counterpart as utype. Convert
arg1 to utype unconditionally.
* gcc.c-torture/compile/pr45876.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@164943 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/fold-const.c | 17 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/compile/pr45876.c | 9 |
4 files changed, 26 insertions, 12 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2915c281a16..147fdd1fd02 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2010-10-04 Jakub Jelinek <jakub@redhat.com> + + PR middle-end/45876 + * fold-const.c (fold_binary_loc) <case BIT_AND_EXPR>: Use + arg0's type or its unsigned counterpart as utype. Convert + arg1 to utype unconditionally. + 2010-10-04 Julian Brown <julian@codesourcery.com> * expr.c (expand_assignment): Add assertion to prevent emitting diff --git a/gcc/fold-const.c b/gcc/fold-const.c index b2dbb981cfc..81469203553 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -11152,12 +11152,12 @@ fold_binary_loc (location_t loc, || (TREE_CODE (arg0) != NEGATE_EXPR && pmop[1] != TREE_OPERAND (arg0, 1))) { - tree utype = type; + tree utype = TREE_TYPE (arg0); if (! TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg0))) { /* Perform the operations in a type that has defined overflow behavior. */ - utype = unsigned_type_for (type); + utype = unsigned_type_for (TREE_TYPE (arg0)); if (pmop[0] != NULL) pmop[0] = fold_convert_loc (loc, utype, pmop[0]); if (pmop[1] != NULL) @@ -11184,16 +11184,9 @@ fold_binary_loc (location_t loc, tem = fold_build2_loc (loc, MINUS_EXPR, utype, pmop[0], pmop[1]); /* TEM is now the new binary +, - or unary - replacement. */ - if (utype == type) - return fold_build2_loc (loc, BIT_AND_EXPR, type, - tem, arg1); - else - { - tem = fold_build2_loc (loc, BIT_AND_EXPR, utype, tem, - fold_convert_loc (loc, utype, - arg1)); - return fold_convert_loc (loc, type, tem); - } + tem = fold_build2_loc (loc, BIT_AND_EXPR, utype, tem, + fold_convert_loc (loc, utype, arg1)); + return fold_convert_loc (loc, type, tem); } } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3f817263329..a8f6aae7af5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-10-04 Jakub Jelinek <jakub@redhat.com> + + PR middle-end/45876 + * gcc.c-torture/compile/pr45876.c: New test. + 2010-10-04 Julian Brown <julian@codesourcery.com> * gcc.dg/vect/vect-42.c: Use vect_element_align instead of diff --git a/gcc/testsuite/gcc.c-torture/compile/pr45876.c b/gcc/testsuite/gcc.c-torture/compile/pr45876.c new file mode 100644 index 00000000000..a71be5fa895 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr45876.c @@ -0,0 +1,9 @@ +/* PR middle-end/45876 */ + +unsigned +foo (unsigned x) +{ + short i = 0; + i = ((short) (((((unsigned) i) >> 1) & 16383) + x)) & 16383; + return i; +} |