Keep rvalue of bitfield assignment: bit1=bit2=1, grischka-2005-09-25 case_3 This patch was originally posted in grischka's 2005-09-25 email as required fix case_3 to compile gcc 2.95. This fixes bitfield assignment so that when assignments are chained the rvalue is correctly passed to later assignments. The tests were tweaked by David A. Wheeler to merge the test cases into the standard tcc test suite. diff -ur tinycc-rl-1.0.0-orig/tcc.c tinycc-rl-1.0.0-grischka3/tcc.c --- tinycc-rl-1.0.0-orig/tcc.c 2007-04-18 14:52:22.000000000 -0400 +++ tinycc-rl-1.0.0-grischka3/tcc.c 2007-05-03 14:03:06.000000000 -0400 @@ -5503,6 +5503,11 @@ /* 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); + /* duplicate destination */ vdup(); vtop[-1] = vtop[-2]; @@ -5519,6 +5524,10 @@ gen_op('|'); /* store result */ vstore(); + + /* pop off shifted source from "duplicate source..." above */ + vpop(); + } else { #ifdef CONFIG_TCC_BCHECK /* bound check case */ @@ -7666,7 +7675,7 @@ } vtop--; } else { - vset(&dtype, VT_LOCAL, c); + vset(&dtype, VT_LOCAL|VT_LVAL, c); vswap(); vstore(); vpop(); diff -ur tinycc-rl-1.0.0-orig/tests/tcctest.c tinycc-rl-1.0.0-grischka3/tests/tcctest.c --- tinycc-rl-1.0.0-orig/tests/tcctest.c 2007-04-18 14:52:22.000000000 -0400 +++ tinycc-rl-1.0.0-grischka3/tests/tcctest.c 2007-05-03 13:55:17.000000000 -0400 @@ -1349,6 +1349,20 @@ printf("st1.f2 == -1\n"); else printf("st1.f2 != -1\n"); + + /* Do bitfield assignments return correct rvalue? This is bug + * grischka-2005-09-29 case_3 */ + { + struct test1 { unsigned a:1, b:1, c:1, d:1; }; + struct test1 t1 = {0, 1, 0, 1}; + struct test1 *p = &t1; + + printf("case_3.1: 0101 -> %d%d%d%d\n", p->a, p->b, p->c, p->d); + p->b = p->d = 0; + p->a = p->c = 1; + printf("case_3.2: 1010 -> %d%d%d%d\n", p->a, p->b, p->c, p->d); + } + } #define FTEST(prefix, type, fmt)\