Fix bitfield loads into char/short.

Removes a premature optimization of char/short loads
rewriting the source type.  It did so also for bitfield
loads, thereby removing all the shifts/maskings.
master
Michael Matz 2012-04-15 01:06:46 +02:00
parent 6471ec0a2b
commit 5c0a2366a3
2 changed files with 8 additions and 2 deletions

View File

@ -2320,8 +2320,9 @@ ST_FUNC void vstore(void)
ft = vtop[-1].type.t;
sbt = vtop->type.t & VT_BTYPE;
dbt = ft & VT_BTYPE;
if (((sbt == VT_INT || sbt == VT_SHORT) && dbt == VT_BYTE) ||
(sbt == VT_INT && dbt == VT_SHORT)) {
if ((((sbt == VT_INT || sbt == VT_SHORT) && dbt == VT_BYTE) ||
(sbt == VT_INT && dbt == VT_SHORT))
&& !(vtop->type.t & VT_BITFIELD)) {
/* optimize char/short casts */
delayed_cast = VT_MUSTCAST;
vtop->type.t = ft & (VT_TYPE & ~(VT_BITFIELD | (-1 << VT_STRUCT_SHIFT)));

View File

@ -1461,6 +1461,8 @@ void c99_bool_test(void)
void bitfield_test(void)
{
int a;
short sa;
unsigned char ca;
struct sbf1 {
int f1 : 3;
int : 2;
@ -1482,6 +1484,9 @@ void bitfield_test(void)
st1.f5++;
printf("%d %d %d %d %d\n",
st1.f1, st1.f2, st1.f3, st1.f4, st1.f5);
sa = st1.f5;
ca = st1.f5;
printf("%d %d\n", sa, ca);
st1.f1 = 7;
if (st1.f1 == -1)