changeset 439:025b81f7e70b

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.
author Rob Landley <rob@landley.net>
date Thu, 03 May 2007 15:29:49 -0400
parents 31171653b1ee
children bbcb7f4bafe5
files tcc.c tests/tcctest.c
diffstat 2 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tcc.c	Thu May 03 13:13:20 2007 -0400
+++ b/tcc.c	Thu May 03 15:29:49 2007 -0400
@@ -5507,6 +5507,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];
@@ -5523,6 +5528,10 @@
         gen_op('|');
         /* store result */
         vstore();
+
+        /* pop off shifted source from "duplicate source..." above */
+        vpop();
+
     } else {
 #ifdef CONFIG_TCC_BCHECK
         /* bound check case */
@@ -7674,7 +7683,7 @@
         }
         vtop--;
     } else {
-        vset(&dtype, VT_LOCAL, c);
+        vset(&dtype, VT_LOCAL|VT_LVAL, c);
         vswap();
         vstore();
         vpop();
--- a/tests/tcctest.c	Thu May 03 13:13:20 2007 -0400
+++ b/tests/tcctest.c	Thu May 03 15:29:49 2007 -0400
@@ -1397,6 +1397,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)\