aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2009-02-09 20:54:38 +0000
committerEvan Cheng <evan.cheng@apple.com>2009-02-09 20:54:38 +0000
commitb1032a8a2f322e031f7c0947c3fb60fe9e8a10e6 (patch)
treeb149ba2e249bee73ad4b3e82327bc1e6a2329f80 /lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
parent484f01b386d3489717cb0f30bcbc4b5a7ac34de5 (diff)
Make sure constant subscript is truncated to ptr size if it may not fit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@64163 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp')
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
index 3c90cd767c..7b613d7f24 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
@@ -2699,8 +2699,15 @@ void SelectionDAGLowering::visitGetElementPtr(User &I) {
if (CI->getZExtValue() == 0) continue;
uint64_t Offs =
TD->getTypePaddedSize(Ty)*cast<ConstantInt>(CI)->getSExtValue();
+ SDValue OffsVal = DAG.getConstant(Offs, MVT::i64);
+ unsigned PtrBits = TLI.getPointerTy().getSizeInBits();
+ if (PtrBits < 64)
+ OffsVal = DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(),
+ TLI.getPointerTy(), OffsVal);
+ else
+ OffsVal = DAG.getIntPtrConstant(Offs);
N = DAG.getNode(ISD::ADD, getCurDebugLoc(), N.getValueType(), N,
- DAG.getIntPtrConstant(Offs));
+ OffsVal);
continue;
}