]> git.sur5r.net Git - cc65/commitdiff
Use safe shift routines
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 11 Nov 2003 09:44:19 +0000 (09:44 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 11 Nov 2003 09:44:19 +0000 (09:44 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@2637 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/typeconv.c

index 5af7e513c435db669a241d8660540eeac273251c..4db76fb24dbaa057c1a7341cdb939cbb9e08a3fa 100644 (file)
@@ -33,6 +33,9 @@
 
 
 
+/* common */
+#include "shift.h"
+
 /* cc65 */
 #include "codegen.h"
 #include "datatype.h"
@@ -144,16 +147,8 @@ 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))) {
-                        /* 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;
+                        /* Beware: Use the safe shift routine here. */
+                        Expr->ConstVal |= shl_l (~0UL, NewBits);
                     }
                 }
             }
@@ -304,3 +299,4 @@ int TypeCast (ExprDesc* Expr)
 
 
 
+