* src/hc08/gen.c (genPointerGetSetOfs): disabled optimization if
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 1 Jun 2004 04:46:09 +0000 (04:46 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 1 Jun 2004 04:46:09 +0000 (04:46 +0000)
computed address is reused
* src/hc08/gen.c (genPackBits): fixed offsets in assignments to
multi-byte bitfields
* support/regression/tests/zeropad.c: disabled the declarations
and tests associated with struct z nestedstruct

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3334 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/hc08/gen.c
support/regression/tests/zeropad.c

index de90e142ed559077833e28fcfdad4fdce9e9965d..2e2744a0d792dae3683d70dc96e870828cf7d893 100644 (file)
@@ -4263,6 +4263,10 @@ genPointerGetSetOfs (iCode *ic)
   if (!pset && !pget)
     return FALSE;
 
+  /* Make sure this is the only use of the pointer */
+  if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) > 1)
+    return FALSE;
+    
   D(emitcode("", "; checking pset operandsEqu"));
   if (pset & !operandsEqu (IC_RESULT (ic), IC_RESULT (lic)))
     return FALSE;
@@ -6749,6 +6753,7 @@ genPackBits (sym_link * etype,
   int bstr;            /* bitfield starting bit within byte */
   int litval;          /* source literal value (if AOP_LIT) */
   unsigned char mask;  /* bitmask within current byte */
+  int xoffset = 0;
 
   D(emitcode (";     genPackBits",""));
 
@@ -6807,6 +6812,7 @@ genPackBits (sym_link * etype,
       if (AOP (right)->type == AOP_DIR)
         {
           emitcode ("mov", "%s,x+", aopAdrStr(AOP (right), offset, FALSE));
+         xoffset++;
         }
       else
         {
@@ -6828,13 +6834,13 @@ genPackBits (sym_link * etype,
           litval = (int) floatFromVal (AOP (right)->aopu.aop_lit);
           litval >>= (blen-rlen);
           litval &= (~mask) & 0xff;
-          emitcode ("lda", "%d,x", offset);
+          emitcode ("lda", "%d,x", offset - xoffset);
           hc08_dirtyReg (hc08_reg_a, FALSE);
           if ((mask|litval)!=0xff)
             emitcode ("and","#0x%02x", mask);
           if (litval)
             emitcode ("ora","#0x%02x", litval);
-          emitcode ("sta", "%d,x", offset);
+          emitcode ("sta", "%d,x", offset - xoffset);
           hc08_dirtyReg (hc08_reg_a, FALSE);
           hc08_freeReg (hc08_reg_a);
           return;
@@ -6842,15 +6848,15 @@ genPackBits (sym_link * etype,
       
       /* Case with partial byte and arbitrary source
       */
-      loadRegFromAop (hc08_reg_a, AOP (right), offset++);
+      loadRegFromAop (hc08_reg_a, AOP (right), offset);
       emitcode ("and", "#0x%02x", (~mask) & 0xff);
       hc08_dirtyReg (hc08_reg_a, FALSE);
       pushReg (hc08_reg_a, TRUE);
 
-      emitcode ("lda", ",x");
+      emitcode ("lda", "%d,x", offset - xoffset);
       emitcode ("and", "#0x%02x", mask);
       emitcode ("ora", "1,s");
-      emitcode ("sta", ",x");
+      emitcode ("sta", "%d,x", offset - xoffset);
       pullReg (hc08_reg_a);
     }
 
index a3049bcf3b00809e7624ce706636c8d11908fea2..dbec36a224f8620e9a8d9b3f7e3c94eebc184584 100644 (file)
@@ -38,10 +38,15 @@ struct y {
   char  b[];
 };
 
+/* I think section 6.7.2.1 paragraph 2 of ISO/IEC 9899:1999 prohibits */
+/* nesting a structure ending in a flexible array inside another      */
+/* struct/union. In any case, my gcc (3.2.2) chokes on this. -- EEP   */
+#ifdef NESTED_FLEX_ARRAY
 struct z {
   char     c;
   struct y s;
 };
+#endif
 
 struct x STORAGE teststruct[5] = {
   { 10, {  1, 2, 3, 4, 5} },
@@ -53,10 +58,12 @@ struct y STORAGE incompletestruct = {
   10, {1, 2, 3, 4, 5}
 };
 
+#ifdef NESTED_FLEX_ARRAY
 struct z STORAGE nestedstruct = {
   16,
   {20, {6, 7, 8} }
 };
+#endif
 
 void
 testZeropad(void)
@@ -87,7 +94,9 @@ testZeropad(void)
   ASSERT(sizeof(incompletestruct) == offsetof(struct y, b));
   ASSERT(sizeof(incompletestruct) == offsetof(struct x, b));
 
+#ifdef NESTED_FLEX_ARRAY
   ASSERT(nestedstruct.c      == 16);
   ASSERT(nestedstruct.s.a    == 20);
   ASSERT(nestedstruct.s.b[2] ==  8);
+#endif
 }