* src/z80/gen.c (genCmpGt, genCmpLt): fixed bug 2094505
authorMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 7 Sep 2008 22:27:12 +0000 (22:27 +0000)
committerMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 7 Sep 2008 22:27:12 +0000 (22:27 +0000)
* support/regression/tests/bug2094505.c: new, added

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

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

index 3b3116508fc92a7ab011404260f1c81f17c97883..b16634f9c9ba29d7d14c28ed1ab4924e74fb4fa6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,14 @@
+2008-09-08 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * src/z80/gen.c (genCmpGt, genCmpLt): fixed bug 2094505
+       * support/regression/tests/bug2094505.c: new, added
+
 2008-09-07 Borut Razem <borut.razem AT siol.net>
 
        * src/SDCCglue.c, src/SDCCast.c:
          fixed throw of "excess elements" warning for char arrays
 
-2008-06-04 Maarten Brock <sourceforge.brock AT dse.nl>
+2008-09-07 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * as/z80/aslist.c (lstsym): changed old K&R to ANSI
        * src/SDCCicode.c (geniCodeCritical): fixed bug for hc08
index 2ef191da5a0f8b66ab8c8db4dd50a3756480d224..226434d2490e25db7265cadf840668edbe339691 100644 (file)
@@ -4787,13 +4787,16 @@ genCmpGt (iCode * ic, iCode * ifx)
   letype = getSpec (operandType (left));
   retype = getSpec (operandType (right));
   sign = !(SPEC_USIGN (letype) | SPEC_USIGN (retype));
-  /* assign the amsops */
+  /* assign the asmops */
   aopOp (left, ic, FALSE, FALSE);
   aopOp (right, ic, FALSE, FALSE);
   aopOp (result, ic, TRUE, FALSE);
 
+  setupToPreserveCarry (ic);
+
   genCmp (right, left, result, ifx, sign);
 
+  _G.preserveCarry = FALSE;
   freeAsmop (left, NULL, ic);
   freeAsmop (right, NULL, ic);
   freeAsmop (result, NULL, ic);
@@ -4817,13 +4820,16 @@ genCmpLt (iCode * ic, iCode * ifx)
   retype = getSpec (operandType (right));
   sign = !(SPEC_USIGN (letype) | SPEC_USIGN (retype));
 
-  /* assign the amsops */
+  /* assign the asmops */
   aopOp (left, ic, FALSE, FALSE);
   aopOp (right, ic, FALSE, FALSE);
   aopOp (result, ic, TRUE, FALSE);
 
+  setupToPreserveCarry (ic);
+
   genCmp (left, right, result, ifx, sign);
 
+  _G.preserveCarry = FALSE;
   freeAsmop (left, NULL, ic);
   freeAsmop (right, NULL, ic);
   freeAsmop (result, NULL, ic);
@@ -7493,8 +7499,7 @@ genCast (iCode * ic)
   else
     {
       /* we need to extend the sign :{ */
-        const char *l = aopGet (AOP (right), AOP_SIZE (right) - 1,
-                        FALSE);
+      const char *l = aopGet (AOP (right), AOP_SIZE (right) - 1, FALSE);
       _moveA (l);
       emit2 ("rla ");
       emit2 ("sbc a,a");
diff --git a/support/regression/tests/bug2094505.c b/support/regression/tests/bug2094505.c
new file mode 100644 (file)
index 0000000..b657a26
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+    bug 2094505
+*/
+
+#include <testfwk.h>
+
+void
+testBug(void)
+{
+#if !defined(SDCC) || !defined(SDCC_mcs51) || defined(SDCC_MODEL_LARGE)
+    // varA has to be declared for the bug to manifest itself
+    volatile char varA[256] = {0};
+    volatile unsigned int varB = 0x1;
+    volatile unsigned short varC = 0x2;
+
+    // The Less Than comparison ASM for this while loop is generated incorrectly.
+    ASSERT (varB < varC);
+#endif
+}