* src/mcs51/gen.c (adjustArithmeticResult): fixed bug 1839299
authorMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 22 Mar 2008 11:58:36 +0000 (11:58 +0000)
committerMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 22 Mar 2008 11:58:36 +0000 (11:58 +0000)
* support/regression/tests/bug1839277.c: added related testBug1839299

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

ChangeLog
src/mcs51/gen.c
support/regression/tests/bug1839277.c

index 86e619de84bb7725d341f7858fa116477b3c375b..923e2a98d18bfec3b84c675d84ba38da97bcb999 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-03-22 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * src/mcs51/gen.c (adjustArithmeticResult): fixed bug 1839299
+       * support/regression/tests/bug1839277.c: added related testBug1839299
+
 2008-03-21 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * src/ds390/gen.c (opIsGptr, adjustArithmeticResult, genAddrOf, genAssign),
index a8086d65a1726b9e9fdf7bdf85a236c2c5ac83f9..a5da703fa0e3dec3487f80268bae174fecb9e9e5 100644 (file)
@@ -4425,34 +4425,58 @@ adjustArithmeticResult (iCode * ic)
 static void
 adjustArithmeticResult (iCode * ic)
 {
-  if (opIsGptr (IC_RESULT (ic)) &&
-      opIsGptr (IC_LEFT (ic)) &&
-      !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))))
+  if (opIsGptr (IC_RESULT (ic)))
     {
-      aopPut (IC_RESULT (ic),
-              aopGet (IC_LEFT (ic), GPTRSIZE - 1, FALSE, FALSE),
-              GPTRSIZE - 1);
-    }
+      char buffer[10];
 
-  if (opIsGptr (IC_RESULT (ic)) &&
-      opIsGptr (IC_RIGHT (ic)) &&
-      !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
-    {
-      aopPut (IC_RESULT (ic),
-              aopGet (IC_RIGHT (ic), GPTRSIZE - 1, FALSE, FALSE),
-              GPTRSIZE - 1);
-    }
+      if (opIsGptr (IC_LEFT (ic)))
+        {
+          if (!sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))))
+            {
+              aopPut (IC_RESULT (ic),
+                      aopGet (IC_LEFT (ic), GPTRSIZE - 1, FALSE, FALSE),
+                      GPTRSIZE - 1);
+            }
+          return;
+        }
 
-  if (opIsGptr (IC_RESULT (ic)) &&
-      IC_LEFT (ic) && AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
-      IC_RIGHT (ic) && AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
-      !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))) &&
-      !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
-    {
-      char buffer[10];
-      SNPRINTF (buffer, sizeof(buffer),
-                "#0x%02x", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL));
-      aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1);
+      if (opIsGptr (IC_RIGHT (ic)))
+        {
+          if (!sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
+            {
+              aopPut (IC_RESULT (ic),
+                      aopGet (IC_RIGHT (ic), GPTRSIZE - 1, FALSE, FALSE),
+                      GPTRSIZE - 1);
+            }
+          return;
+        }
+
+      if (IC_LEFT (ic) && AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
+          IC_RIGHT (ic) && AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
+          !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))) &&
+          !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
+        {
+          SNPRINTF (buffer, sizeof(buffer),
+                    "#0x%02x", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL));
+          aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1);
+          return;
+        }
+      if (IC_LEFT (ic) && AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
+          !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))))
+        {
+          SNPRINTF (buffer, sizeof(buffer),
+                    "#0x%02x", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL));
+          aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1);
+          return;
+        }
+      if (IC_RIGHT (ic) && AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
+          !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
+        {
+          SNPRINTF (buffer, sizeof(buffer),
+                    "#0x%02x", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_RIGHT (ic)))), NULL, NULL));
+          aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1);
+          return;
+        }
     }
 }
 #endif
index 78dae846f22326b6f56eafdbcbe59e445f175875..4c4732840df71363da15b0fb6db6014fabe37bae 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    bug 1839277
+    bug 1839277 & 1839299
 */
 
 #include <testfwk.h>
@@ -11,7 +11,7 @@ code struct Value {
 char i=1;
 
 void
-testBug(void)
+testBug1839277(void)
 {
        volatile char code* * p;
        unsigned long v = 0;
@@ -48,3 +48,27 @@ testBug(void)
        ASSERT((unsigned char)(v>>16)==0x80);
 #endif
 }
+
+void
+testBug1839299(void)
+{
+       volatile char code* * p;
+       unsigned long v = 0;
+//'Values[0].Name' subexpression is evaluated as follows first:
+//mov     r2,#_Values
+//mov     r3,#(_Values >> 8)
+//mov     r4,#(_Values >> 16) ;this is wrong - see bug 1839277
+  p= i ? Values[0].Name : Values[1].Name;
+//this assignment has some sideeffect on the following one
+//in fact it is the evaluation of 'Values[0].Name' itself has the effect, not the assignment
+  p= Values[0].Name;
+//'Values[0].Name' subexpression is evaluated as follows second:
+//mov     r2,#_Values
+//mov     r3,#(_Values >> 8)
+//mov     r4,#0x00 ;this is different from first occurrence but also wrong
+  p= i ? Values[0].Name : Values[1].Name;
+#if defined(SDCC_mcs51)
+       v = (unsigned long)p;
+       ASSERT((unsigned char)(v>>16)==0x80);
+#endif
+}