OSDN Git Service

For PR1188:
authorReid Spencer <rspencer@reidspencer.com>
Thu, 8 Feb 2007 00:29:31 +0000 (00:29 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Thu, 8 Feb 2007 00:29:31 +0000 (00:29 +0000)
Compute BitMask correctly.

Patch by Leo (wenwenti@hotmail.com).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34026 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ExecutionEngine/Interpreter/Execution.cpp
lib/ExecutionEngine/Interpreter/Interpreter.h

index 565915b..fe80dfd 100644 (file)
@@ -1307,7 +1307,7 @@ void Interpreter::visitAShr(BinaryOperator &I) {
 
 #define INTEGER_ASSIGN(DEST, BITWIDTH, VAL)     \
   {                                             \
-    uint64_t Mask = (1ull << BITWIDTH) - 1;     \
+    uint64_t Mask = ~(uint64_t)(0ull) >> (64-BITWIDTH);     \
     if (BITWIDTH == 1) {                        \
       Dest.Int1Val = (bool) (VAL & Mask);       \
     } else if (BITWIDTH <= 8) {                 \
index a8deb01..aef4cb2 100644 (file)
@@ -236,7 +236,7 @@ private:  // Helper functions
 };
 
 inline void maskToBitWidth(GenericValue& GV, unsigned BitWidth) {
-  uint64_t BitMask = (1ull << BitWidth) - 1;
+  uint64_t BitMask = ~(uint64_t)(0ull) >> (64-BitWidth);
   if (BitWidth <= 8)
     GV.Int8Val &= BitMask;
   else if (BitWidth <= 16)