Last fix was wrong

git-svn-id: svn://svn.cc65.org/cc65/trunk@1999 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2003-03-04 11:02:11 +00:00
parent c008e555b2
commit 0ae6ab57ae

View File

@@ -144,27 +144,20 @@ int TypeCast (ExprDesc* lval)
unsigned OldBits = OldSize * 8; unsigned OldBits = OldSize * 8;
unsigned NewBits = NewSize * 8; unsigned NewBits = NewSize * 8;
/* Remember if the old value was negative */ /* Check if the new datatype will have a smaller range. If it
int Negative = (lval->ConstVal & (0x01UL << (OldBits-1))) != 0UL; * has a larger range, things are ok, since the value is
* internally already represented by a long.
/* Check if the new datatype will have a smaller range */ */
if (NewBits <= OldBits) { if (NewBits <= OldBits) {
/* Cut the value to the new size */ /* Cut the value to the new size */
lval->ConstVal &= (0xFFFFFFFFUL >> (32 - NewBits)); lval->ConstVal &= (0xFFFFFFFFUL >> (32 - NewBits));
/* If the new type is signed and negative, sign extend the /* If the new type is signed, sign extend the value */
* value if (!IsSignUnsigned (NewType)) {
*/ if (lval->ConstVal & (0x01UL << (NewBits-1))) {
if (Negative && !IsSignUnsigned (NewType)) { lval->ConstVal |= ((~0L) << NewBits);
lval->ConstVal |= ((~0L) << NewBits); }
}
} else {
/* Sign extend the value if needed */
if (Negative && !IsSignUnsigned (OldType) && !IsSignUnsigned (NewType)) {
lval->ConstVal |= ((~0L) << OldBits);
} }
} }