summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-08-11 18:28:09 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-08-11 18:28:09 +0000
commit919fe2bd2fbb066c2674bb74256840c70605cecc (patch)
treea1fd865429ffe42d4089324b9c6087a1c4e6d53f
parent270968279b3e1e7d15c857b54d4defb685d02b88 (diff)
downloadbcm5719-llvm-919fe2bd2fbb066c2674bb74256840c70605cecc.tar.gz
bcm5719-llvm-919fe2bd2fbb066c2674bb74256840c70605cecc.zip
Simplify ConstantExpr::getInBoundsGetElementPtr and fix a possible crash, if
constant folding eliminated the GEP instruction. - clang was hitting this on its test suite (for x86_64, at least). llvm-svn: 78698
-rw-r--r--llvm/lib/VMCore/Constants.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index 89578fb8972..70d43576a73 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -1442,14 +1442,11 @@ Constant *ConstantExpr::getGetElementPtr(Constant *C, Value* const *Idxs,
Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C,
Value* const *Idxs,
unsigned NumIdx) {
- // Get the result type of the getelementptr!
- const Type *Ty =
- GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx);
- assert(Ty && "GEP indices invalid!");
- unsigned As = cast<PointerType>(C->getType())->getAddressSpace();
- Constant *Result = getGetElementPtrTy(PointerType::get(Ty, As), C,
- Idxs, NumIdx);
- cast<GEPOperator>(Result)->setIsInBounds(true);
+ Constant *Result = getGetElementPtr(C, Idxs, NumIdx);
+ // Set in bounds attribute, assuming constant folding didn't eliminate the
+ // GEP.
+ if (GEPOperator *GEP = dyn_cast<GEPOperator>(Result))
+ GEP->setIsInBounds(true);
return Result;
}
OpenPOWER on IntegriCloud