* src/z80/gen.c: fixed bug #1294691: nested ifs make compiler crash;
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 9 Jun 2007 15:59:28 +0000 (15:59 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 9 Jun 2007 15:59:28 +0000 (15:59 +0000)
  removed unused swap_sense; removed outBitCLong, replaced with outBitC
* support/regression/tests/bug-1294691.c: added

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

ChangeLog
src/z80/gen.c
support/regression/tests/bug-1294691.c [new file with mode: 0644]

index 39b149e4c5655a52caa2686b56b3a205470df6f8..d0533aeb9cc28ee052d971d578495e3801d0322d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-06-09 Borut Razem <borut.razem AT siol.net>
+
+       * src/z80/gen.c: fixed bug #1294691: nested ifs make compiler crash;
+         removed unused swap_sense; removed outBitCLong, replaced with outBitC
+       * support/regression/tests/bug-1294691.c: added
+
 2007-06-09 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * src/SDCCmem.c (allocDefault): removed check sym->level==0 for SPEC_ABSA,
index 54ee2b78e34818c81b3ba1995c7cb2e9fb32036c..0874fbe5ad561a9e914b552854427de49eb71c66 100644 (file)
@@ -2230,29 +2230,22 @@ outAcc (operand * result)
 /** Take the value in carry and put it into a register
  */
 void
-outBitCLong (operand * result, bool swap_sense)
+outBitC (operand * result)
 {
   /* if the result is bit */
   if (AOP_TYPE (result) == AOP_CRY)
     {
-      wassertl (0, "Tried to write carry to a bit");
+      if (!IS_OP_RUONLY (result))
+        aopPut (AOP (result), "c", 0);
     }
   else
     {
       emit2 ("ld a,!zero");
       emit2 ("rla");
-      if (swap_sense)
-        emit2 ("xor a,!immedbyte", 1);
       outAcc (result);
     }
 }
 
-void
-outBitC (operand * result)
-{
-  outBitCLong (result, FALSE);
-}
-
 /*-----------------------------------------------------------------*/
 /* toBoolean - emit code for orl a,operator(sizeop)                */
 /*-----------------------------------------------------------------*/
@@ -4570,7 +4563,6 @@ genCmp (operand * left, operand * right,
 {
   int size, offset = 0;
   unsigned long lit = 0L;
-  bool swap_sense = FALSE;
 
   /* if left & right are bit variables */
   if (AOP_TYPE (left) == AOP_CRY &&
@@ -4637,7 +4629,7 @@ genCmp (operand * left, operand * right,
                         }
                       if (ifx)
                         {
-                          genIfxJump (ifx, swap_sense ? "c" : "nc");
+                          genIfxJump (ifx, "nc");
                           return;
                         }
                     }
@@ -4663,7 +4655,7 @@ release:
           /* Shift the sign bit up into carry */
           emit2 ("rlca");
         }
-      outBitCLong (result, swap_sense);
+      outBitC (result);
     }
   else
     {
@@ -4677,16 +4669,16 @@ release:
               if (IS_GB)
                 {
                   emit2 ("rlca");
-                  genIfxJump (ifx, swap_sense ? "nc" : "c");
+                  genIfxJump (ifx, "c");
                 }
               else
                 {
-                  genIfxJump (ifx, swap_sense ? "p" : "m");
+                  genIfxJump (ifx, "m");
                 }
             }
           else
             {
-              genIfxJump (ifx, swap_sense ? "nc" : "c");
+              genIfxJump (ifx, "c");
             }
         }
       else
@@ -4696,7 +4688,7 @@ release:
               /* Shift the sign bit up into carry */
               emit2 ("rlca");
             }
-          outBitCLong (result, swap_sense);
+          outBitC (result);
         }
       /* leave the result in acc */
     }
diff --git a/support/regression/tests/bug-1294691.c b/support/regression/tests/bug-1294691.c
new file mode 100644 (file)
index 0000000..b352873
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+   bug-1294691.c
+*/
+
+#include <testfwk.h>
+
+unsigned char x = 1;
+unsigned char y = 5;
+int ret;
+
+
+void
+testBug(void)
+{
+  ret = 1;
+
+  if (x)
+  {
+    if (y > 3)
+    {
+      if (y < 8)
+      {
+      }
+    }
+    else
+    {
+    }
+  }
+  else
+  {
+    ret = 0;
+  }
+
+  ASSERT(ret == 1);
+}