From: johanknol Date: Sat, 2 Mar 2002 11:31:56 +0000 (+0000) Subject: fixed the literal shift bug exposed by bug #524685, the bug still stands X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=d507403e3cbc47b43e2a5e5e8b2f717cf921aa52;p=fw%2Fsdcc fixed the literal shift bug exposed by bug #524685, the bug still stands git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1972 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 4b44dd25..31666eaf 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -1078,14 +1078,27 @@ operandOperation (operand * left, operand * right, (unsigned long) operandLitValue (right) : (long) operandLitValue (right))); break; - case RIGHT_OP: - retval = operandFromLit ((SPEC_USIGN(let) ? - (unsigned long) operandLitValue (left) : - (long) operandLitValue (left)) >> - (SPEC_USIGN(ret) ? - (unsigned long) operandLitValue (right) : - (long) operandLitValue (right))); + case RIGHT_OP: { + double lval = operandLitValue(left), rval = operandLitValue(right); + double res; + switch ((SPEC_USIGN(let) ? 2 : 0) + (SPEC_USIGN(ret) ? 1 : 0)) + { + case 0: // left=unsigned right=unsigned + res=(unsigned long)lval >> (unsigned long)rval; + break; + case 1: // left=unsigned right=signed + res=(unsigned long)lval >> (signed long)rval; + break; + case 2: // left=signed right=unsigned + res=(signed long)lval >> (unsigned long)rval; + break; + case 3: // left=signed right=signed + res=(signed long)lval >> (signed long)rval; + break; + } + retval = operandFromLit (res); break; + } case EQ_OP: retval = operandFromLit (operandLitValue (left) == operandLitValue (right));