]> git.sur5r.net Git - cc65/commitdiff
Last fix was wrong
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 4 Mar 2003 11:02:11 +0000 (11:02 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 4 Mar 2003 11:02:11 +0000 (11:02 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1999 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/typecast.c

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