diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-01-18 01:25:42 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-01-18 01:25:42 +0000 |
commit | 23e28836edaa6750a48dc318c8e2bbe6dc1529c8 (patch) | |
tree | b6683813e34f19323e8f6858a66b51865152a3d7 /lib/ExecutionEngine/Interpreter/Execution.cpp | |
parent | f89aec655f220fdd70e39fcb8d16943694b85903 (diff) | |
download | external_llvm-23e28836edaa6750a48dc318c8e2bbe6dc1529c8.zip external_llvm-23e28836edaa6750a48dc318c8e2bbe6dc1529c8.tar.gz external_llvm-23e28836edaa6750a48dc318c8e2bbe6dc1529c8.tar.bz2 |
Two changes:
1. Fix logic for executeGEP. Only 32-bit and 64-bit integer types are
acceptable as indices.
2. Ensure that all integer cast operations truncate their result to the
integer size of the operand.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33318 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/Interpreter/Execution.cpp')
-rw-r--r-- | lib/ExecutionEngine/Interpreter/Execution.cpp | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index c93dc62..383e809 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -1073,16 +1073,12 @@ GenericValue Interpreter::executeGEPOperation(Value *Ptr, gep_type_iterator I, int64_t Idx; unsigned BitWidth = cast<IntegerType>(I.getOperand()->getType())->getBitWidth(); - if (BitWidth <= 8) - Idx = (int64_t)(int8_t)IdxGV.Int8Val; - else if (BitWidth <= 16) - Idx = (int64_t)(int16_t)IdxGV.Int16Val; - else if (BitWidth <= 32) + if (BitWidth == 32) Idx = (int64_t)(int32_t)IdxGV.Int32Val; - else if (BitWidth <= 64) + else if (BitWidth == 64) Idx = (int64_t)IdxGV.Int64Val; else - assert(0 && "Integer types >64 bits not supported"); + assert(0 && "Invalid index type for getelementptr"); Total += PointerTy(TD.getTypeSize(ST->getElementType())*Idx); } } @@ -1288,17 +1284,20 @@ void Interpreter::visitAShr(ShiftInst &I) { SetValue(&I, Dest, SF); } -#define INTEGER_ASSIGN(DEST, BITWIDTH, VAL) \ - if (BITWIDTH == 1) { \ - Dest.Int1Val = (bool) VAL; \ - } else if (BITWIDTH <= 8) { \ - Dest.Int8Val = (uint8_t) VAL; \ - } else if (BITWIDTH <= 16) { \ - Dest.Int16Val = (uint16_t) VAL; \ - } else if (BITWIDTH <= 32) { \ - Dest.Int32Val = (uint32_t) VAL; \ - } else \ - Dest.Int64Val = (uint64_t) VAL; +#define INTEGER_ASSIGN(DEST, BITWIDTH, VAL) \ + { \ + uint64_t Mask = (1ull << BITWIDTH) - 1; \ + if (BITWIDTH == 1) { \ + Dest.Int1Val = (bool) (VAL & Mask); \ + } else if (BITWIDTH <= 8) { \ + Dest.Int8Val = (uint8_t) (VAL & Mask); \ + } else if (BITWIDTH <= 16) { \ + Dest.Int16Val = (uint16_t) (VAL & Mask); \ + } else if (BITWIDTH <= 32) { \ + Dest.Int32Val = (uint32_t) (VAL & Mask); \ + } else \ + Dest.Int64Val = (uint64_t) (VAL & Mask); \ + } GenericValue Interpreter::executeTruncInst(Value *SrcVal, const Type *DstTy, ExecutionContext &SF) { |