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
23202320 ft = vtop[-1].type.t;
23212321 sbt = vtop->type.t & VT_BTYPE;
23222322 dbt = ft & VT_BTYPE;
2323− if (((sbt == VT_INT || sbt == VT_SHORT) && dbt == VT_BYTE) ||
2324− (sbt == VT_INT && dbt == VT_SHORT)) {
2323+ if ((((sbt == VT_INT || sbt == VT_SHORT) && dbt == VT_BYTE) ||
2324+ (sbt == VT_INT && dbt == VT_SHORT))
2325+ && !(vtop->type.t & VT_BITFIELD)) {
23252326 /* optimize char/short casts */
23262327 delayed_cast = VT_MUSTCAST;
23272328 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
14611461 void bitfield_test(void)
14621462 {
14631463 int a;
1464+ short sa;
1465+ unsigned char ca;
14641466 struct sbf1 {
14651467 int f1 : 3;
14661468 int : 2;
@@ -1482,6 +1484,9 @@ void bitfield_test(void) · 15 unmodified lines
14821484 st1.f5++;
14831485 printf("%d %d %d %d %d\n",
14841486 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);
14851490
14861491 st1.f1 = 7;
14871492 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