From fd4147f619200e8ce0e9fcdfefb35266bf6d8274 Mon Sep 17 00:00:00 2001 From: MaartenBrock Date: Sun, 7 Sep 2008 22:27:12 +0000 Subject: [PATCH] * src/z80/gen.c (genCmpGt, genCmpLt): fixed bug 2094505 * 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 | 7 ++++++- src/z80/gen.c | 13 +++++++++---- support/regression/tests/bug2094505.c | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 support/regression/tests/bug2094505.c diff --git a/ChangeLog b/ChangeLog index 3b311650..b16634f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,14 @@ +2008-09-08 Maarten Brock + + * src/z80/gen.c (genCmpGt, genCmpLt): fixed bug 2094505 + * support/regression/tests/bug2094505.c: new, added + 2008-09-07 Borut Razem * src/SDCCglue.c, src/SDCCast.c: fixed throw of "excess elements" warning for char arrays -2008-06-04 Maarten Brock +2008-09-07 Maarten Brock * as/z80/aslist.c (lstsym): changed old K&R to ANSI * src/SDCCicode.c (geniCodeCritical): fixed bug for hc08 diff --git a/src/z80/gen.c b/src/z80/gen.c index 2ef191da..226434d2 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -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 index 00000000..b657a26a --- /dev/null +++ b/support/regression/tests/bug2094505.c @@ -0,0 +1,19 @@ +/* + bug 2094505 +*/ + +#include + +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 +} -- 2.30.2