From 9d7fb3336049243a16ce20ba907946d1de9e1c0d Mon Sep 17 00:00:00 2001 From: grischka Date: Tue, 23 Sep 2014 12:30:08 +0200 Subject: [PATCH] tccgen: use lvalue as result from bitfield assignment test case: #include int main(int argc, char **argv) { struct _s { unsigned a:9, b:5, c:7; } _s, *s = &_s; int n = 250; s->a = s->b = s->c = n + 4; printf("--> %d / %d / %d\n", s->a, s->b, s->c); return 0; } before: --> 254 / 30 / 126 now: --> 30 / 30 / 126 --- tccgen.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tccgen.c b/tccgen.c index 5fd127fa..d456a2aa 100644 --- a/tccgen.c +++ b/tccgen.c @@ -2520,16 +2520,15 @@ ST_FUNC void vstore(void) /* leave source on stack */ } else if (ft & VT_BITFIELD) { /* bitfield store handling */ + + /* save lvalue as expression result (example: s.b = s.a = n;) */ + vdup(), vtop[-1] = vtop[-2]; + bit_pos = (ft >> VT_STRUCT_SHIFT) & 0x3f; bit_size = (ft >> (VT_STRUCT_SHIFT + 6)) & 0x3f; /* remove bit field info to avoid loops */ vtop[-1].type.t = ft & ~(VT_BITFIELD | (-1 << VT_STRUCT_SHIFT)); - /* duplicate source into other register */ - gv_dup(); - vswap(); - vrott(3); - if((ft & VT_BTYPE) == VT_BOOL) { gen_cast(&vtop[-1].type); vtop[-1].type.t = (vtop[-1].type.t & ~VT_BTYPE) | (VT_BYTE | VT_UNSIGNED); @@ -2561,8 +2560,7 @@ ST_FUNC void vstore(void) gen_op('|'); /* store result */ vstore(); - - /* pop off shifted source from "duplicate source..." above */ + /* ... and discard */ vpop(); } else {