From 04b03cced9b3363f5678ea2234a1e36d71386739 Mon Sep 17 00:00:00 2001 From: bernhardheld Date: Thu, 26 Feb 2004 20:51:08 +0000 Subject: [PATCH] * src/SDCCicode.c (operandOperation): fixed EQ_OP bug, now same as in valCompare(); regression tested in muldiv.c * support/regression/tests/muldiv.c: mod sign follows dividend only git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3235 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 4 +++ src/SDCCicode.c | 42 +++++++++++++++++++------------ support/regression/tests/muldiv.c | 2 -- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 35fa24b1..aafd0fa0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,10 @@ modified to finally use computeType() all over SDCC, see Feature Request #877103 * src/SDCCval.h: cosmetic + * src/SDCCicode.c (operandOperation): fixed EQ_OP bug, now same as in + valCompare(); regression tested in muldiv.c + * support/regression/tests/muldiv.c (testMod): mod sign follows + dividend only 2004-02-23 Bernhard Held diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 50e86608..5c875c1a 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -1219,22 +1219,32 @@ operandOperation (operand * left, operand * right, (TYPE_UDWORD) operandLitValue (right)); break; case EQ_OP: - /* this op doesn't care about signedness */ - { - TYPE_UDWORD l, r; - - l = (TYPE_UDWORD) operandLitValue (left); - if (IS_CHAR(OP_VALUE(left)->type)) - l &= 0xff; - else if (!IS_LONG (OP_VALUE(left)->type)) - l &= 0xffff; - r = (TYPE_UDWORD) operandLitValue (right); - if (IS_CHAR(OP_VALUE(right)->type)) - r &= 0xff; - else if (!IS_LONG (OP_VALUE(right)->type)) - r &= 0xffff; - retval = operandFromLit (l == r); - } + if (IS_FLOAT (let) || + IS_FLOAT (ret)) + { + retval = operandFromLit (operandLitValue (left) == + operandLitValue (right)); + } + else + { + /* this op doesn't care about signedness */ + TYPE_UDWORD l, r; + + l = (TYPE_UDWORD) operandLitValue (left); + r = (TYPE_UDWORD) operandLitValue (right); + /* In order to correctly compare 'signed int' and 'unsigned int' it's + neccessary to strip them to 16 bit. + Literals are reduced to their cheapest type, therefore left and + right might have different types. It's neccessary to find a + common type: int (used for char too) or long */ + if (!IS_LONG (let) && + !IS_LONG (ret)) + { + r = (TYPE_UWORD) r; + l = (TYPE_UWORD) l; + } + retval = operandFromLit (l == r); + } break; case '<': retval = operandFromLit (operandLitValue (left) < diff --git a/support/regression/tests/muldiv.c b/support/regression/tests/muldiv.c index 63a3b72d..b354d352 100644 --- a/support/regression/tests/muldiv.c +++ b/support/regression/tests/muldiv.c @@ -98,7 +98,6 @@ testMod(void) // LOG(("i%%17 == 15 = %u\n", (int)(i%9))); ASSERT(i%17 == 15); -#if MOD_SIGN_FOLLOWS_DIVIDEND // LOG(("i%%-7 == 2 = %u\n", (int)i%-7)); ASSERT(i%-7 == 2); @@ -107,5 +106,4 @@ testMod(void) ASSERT(i%3 == -1); // LOG(("i%%-5 == -4 = %u\n", (int)i%-5)); ASSERT(i%-5 == -4); -#endif } -- 2.39.5