From: sandeep Date: Mon, 14 May 2001 04:12:11 +0000 (+0000) Subject: Fixed a bug in operandOperation, should not uncoditionally cast to X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=c3560462d55e84f10d737d03a1bce575bab3b8b3;p=fw%2Fsdcc Fixed a bug in operandOperation, should not uncoditionally cast to unsigned long git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@815 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 3731ecb7..7a6f0505 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -838,11 +838,15 @@ operand * operandOperation (operand * left, operand * right, int op, sym_link * type) { + sym_link *let , *ret; operand *retval = (operand *) 0; - + assert (isOperandLiteral (left)); - if (right) + let = getSpec(operandType(left)); + if (right) { assert (isOperandLiteral (right)); + ret = getSpec(operandType(left)); + } switch (op) { @@ -874,22 +878,34 @@ operandOperation (operand * left, operand * right, operandLitValue (right))); break; case '%': - if ((unsigned long) operandLitValue (right) == 0) - { + if ((unsigned long) operandLitValue (right) == 0) { werror (E_DIVIDE_BY_ZERO); retval = right; - } - else - retval = operandFromLit ((unsigned long) operandLitValue (left) % - (unsigned long) operandLitValue (right)); + } + else + retval = operandFromLit ((SPEC_USIGN(let) ? + (unsigned long) operandLitValue (left) : + (long) operandLitValue (left)) % + (SPEC_USIGN(ret) ? + (unsigned long) operandLitValue (right) : + (long) operandLitValue (right))); + break; case LEFT_OP: - retval = operandFromLit ((unsigned long) operandLitValue (left) << - (unsigned long) operandLitValue (right)); + retval = operandFromLit (((SPEC_USIGN(let) ? + (unsigned long) operandLitValue (left) : + (long) operandLitValue (left)) << + (SPEC_USIGN(ret) ? + (unsigned long) operandLitValue (right) : + (long) operandLitValue (right)))); break; case RIGHT_OP: - retval = operandFromLit ((unsigned long) operandLitValue (left) >> - (unsigned long) operandLitValue (right)); + retval = operandFromLit (((SPEC_USIGN(let) ? + (unsigned long) operandLitValue (left) : + (long) operandLitValue (left)) >> + (SPEC_USIGN(ret) ? + (unsigned long) operandLitValue (right) : + (long) operandLitValue (right)))); break; case EQ_OP: retval = operandFromLit (operandLitValue (left) ==