diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 89578fb8972..70d43576a73 100644 --- a/lib/VMCore/Constants.cpp +++ b/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(C->getType())->getAddressSpace(); - Constant *Result = getGetElementPtrTy(PointerType::get(Ty, As), C, - Idxs, NumIdx); - cast(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(Result)) + GEP->setIsInBounds(true); return Result; }