1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-23 04:30:10 +00:00

Fixed a bug

git-svn-id: svn://svn.cc65.org/cc65/trunk@2511 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2003-10-10 19:33:22 +00:00
parent 3741e48e97
commit 7ed0eb2228

View File

@ -144,7 +144,16 @@ static int DoConversion (ExprDesc* Expr, int k, type* NewType)
/* If the new type is signed, sign extend the value */
if (!IsSignUnsigned (NewType)) {
if (Expr->ConstVal & (0x01UL << (NewBits-1))) {
Expr->ConstVal |= ((~0L) << NewBits);
/* Beware: NewBits may be 32, in which case a shift
* creates undefined behaviour if a long does also
* have 32 bits. So apply a somewhat complex special
* handling.
*/
unsigned long SignBits = ~0UL;
SignBits <<= (NewBits / 2);
NewBits -= (NewBits / 2);
SignBits <<= NewBits;
Expr->ConstVal |= SignBits;
}
}
}