History

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.

Michael Matz committed 14 years ago

Commit 5c0a2361 parent 6471ec02 files · +8 −2Browse files

Unified · Split

2 files
  1. tccgen.c +3 −2
  2. tests/tcctest.c +5 −0
tccgen.c+3−2
@@ -2320,8 +2320,9 @@ ST_FUNC void vstore(void) · 2319 unmodified lines
2320 ft = vtop[-1].type.t;2320 ft = vtop[-1].type.t;
2321 sbt = vtop->type.t & VT_BTYPE;2321 sbt = vtop->type.t & VT_BTYPE;
2322 dbt = ft & VT_BTYPE;2322 dbt = ft & VT_BTYPE;
2323 if (((sbt == VT_INT || sbt == VT_SHORT) && dbt == VT_BYTE) ||2323 if ((((sbt == VT_INT || sbt == VT_SHORT) && dbt == VT_BYTE) ||
2324 (sbt == VT_INT && dbt == VT_SHORT)) {2324 (sbt == VT_INT && dbt == VT_SHORT))
2325 && !(vtop->type.t & VT_BITFIELD)) {
2325 /* optimize char/short casts */2326 /* optimize char/short casts */
2326 delayed_cast = VT_MUSTCAST;2327 delayed_cast = VT_MUSTCAST;
2327 vtop->type.t = ft & (VT_TYPE & ~(VT_BITFIELD | (-1 << VT_STRUCT_SHIFT)));2328 vtop->type.t = ft & (VT_TYPE & ~(VT_BITFIELD | (-1 << VT_STRUCT_SHIFT)));
tests/tcctest.c+5−0
@@ -1461,6 +1461,8 @@ void c99_bool_test(void) · 1460 unmodified lines
1461void bitfield_test(void)1461void bitfield_test(void)
1462{1462{
1463 int a;1463 int a;
1464 short sa;
1465 unsigned char ca;
1464 struct sbf1 {1466 struct sbf1 {
1465 int f1 : 3;1467 int f1 : 3;
1466 int : 2;1468 int : 2;
@@ -1482,6 +1484,9 @@ void bitfield_test(void) · 15 unmodified lines
1482 st1.f5++;1484 st1.f5++;
1483 printf("%d %d %d %d %d\n",1485 printf("%d %d %d %d %d\n",
1484 st1.f1, st1.f2, st1.f3, st1.f4, st1.f5);1486 st1.f1, st1.f2, st1.f3, st1.f4, st1.f5);
1487 sa = st1.f5;
1488 ca = st1.f5;
1489 printf("%d %d\n", sa, ca);
1485 1490
1486 st1.f1 = 7;1491 st1.f1 = 7;
1487 if (st1.f1 == -1) 1492 if (st1.f1 == -1)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t