Commit c0b9d4c8 by Richard Kenner

(optimize_bit_field_compare): Correct bogus use of types in expressions...

(optimize_bit_field_compare): Correct bogus use of types in
expressions; always do computation in a type wide enough for the
result.

From-SVN: r1743
parent fde9637e
...@@ -2178,13 +2178,13 @@ optimize_bit_field_compare (code, compare_type, lhs, rhs) ...@@ -2178,13 +2178,13 @@ optimize_bit_field_compare (code, compare_type, lhs, rhs)
/* If not comparing with constant, just rework the comparison /* If not comparing with constant, just rework the comparison
and return. */ and return. */
return build (code, compare_type, return build (code, compare_type,
build (BIT_AND_EXPR, type, build (BIT_AND_EXPR, unsigned_type,
make_bit_field_ref (linner, type, make_bit_field_ref (linner, unsigned_type,
lnbitsize, lnbitpos, lunsignedp), lnbitsize, lnbitpos, 1),
mask), mask),
build (BIT_AND_EXPR, type, build (BIT_AND_EXPR, unsigned_type,
make_bit_field_ref (rinner, type, make_bit_field_ref (rinner, unsigned_type,
rnbitsize, rnbitpos, runsignedp), rnbitsize, rnbitpos, 1),
mask)); mask));
/* Otherwise, we are handling the constant case. See if the constant is too /* Otherwise, we are handling the constant case. See if the constant is too
...@@ -2233,17 +2233,16 @@ optimize_bit_field_compare (code, compare_type, lhs, rhs) ...@@ -2233,17 +2233,16 @@ optimize_bit_field_compare (code, compare_type, lhs, rhs)
/* Make a new bitfield reference, shift the constant over the /* Make a new bitfield reference, shift the constant over the
appropriate number of bits and mask it with the computed mask appropriate number of bits and mask it with the computed mask
(in case this was a signed field). If we changed it, make a new one. */ (in case this was a signed field). If we changed it, make a new one. */
lhs = make_bit_field_ref (linner, TREE_TYPE (lhs), lnbitsize, lnbitpos, lhs = make_bit_field_ref (linner, unsigned_type, lnbitsize, lnbitpos, 1);
lunsignedp);
rhs = fold (build1 (NOP_EXPR, type, rhs = fold (const_binop (BIT_AND_EXPR,
const_binop (BIT_AND_EXPR, const_binop (LSHIFT_EXPR,
const_binop (LSHIFT_EXPR, convert (unsigned_type, rhs),
convert (unsigned_type, rhs), size_int (lbitpos)),
size_int (lbitpos)), mask))); mask));
return build (code, compare_type, return build (code, compare_type,
build (BIT_AND_EXPR, type, lhs, mask), build (BIT_AND_EXPR, unsigned_type, lhs, mask),
rhs); rhs);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment