From 1d4a8fe156fc65124ea03dde46f9aed74b0a3451 Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Fri, 14 Jan 2011 08:07:43 +0000 Subject: Remove casts between Value** and Constant**, which won't work if a static_cast from Constant* to Value* has to adjust the "this" pointer. This is groundwork for PR889. llvm-svn: 123435 --- llvm/lib/VMCore/Constants.cpp | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'llvm/lib/VMCore/Constants.cpp') diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp index 29fc0dbdf8d..46daa61d998 100644 --- a/llvm/lib/VMCore/Constants.cpp +++ b/llvm/lib/VMCore/Constants.cpp @@ -1546,8 +1546,9 @@ Constant *ConstantExpr::getSelectTy(const Type *ReqTy, Constant *C, return pImpl->ExprConstants.getOrCreate(ReqTy, Key); } +template Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C, - Value* const *Idxs, + IndexTy const *Idxs, unsigned NumIdx) { assert(GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx) == @@ -1555,7 +1556,7 @@ Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C, "GEP indices invalid!"); if (Constant *FC = ConstantFoldGetElementPtr(C, /*inBounds=*/false, - (Constant**)Idxs, NumIdx)) + Idxs, NumIdx)) return FC; // Fold a few common cases... assert(C->getType()->isPointerTy() && @@ -1572,9 +1573,10 @@ Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C, return pImpl->ExprConstants.getOrCreate(ReqTy, Key); } +template Constant *ConstantExpr::getInBoundsGetElementPtrTy(const Type *ReqTy, Constant *C, - Value *const *Idxs, + IndexTy const *Idxs, unsigned NumIdx) { assert(GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx) == @@ -1582,7 +1584,7 @@ Constant *ConstantExpr::getInBoundsGetElementPtrTy(const Type *ReqTy, "GEP indices invalid!"); if (Constant *FC = ConstantFoldGetElementPtr(C, /*inBounds=*/true, - (Constant**)Idxs, NumIdx)) + Idxs, NumIdx)) return FC; // Fold a few common cases... assert(C->getType()->isPointerTy() && @@ -1600,8 +1602,9 @@ Constant *ConstantExpr::getInBoundsGetElementPtrTy(const Type *ReqTy, return pImpl->ExprConstants.getOrCreate(ReqTy, Key); } -Constant *ConstantExpr::getGetElementPtr(Constant *C, Value* const *Idxs, - unsigned NumIdx) { +template +Constant *ConstantExpr::getGetElementPtrImpl(Constant *C, IndexTy const *Idxs, + unsigned NumIdx) { // Get the result type of the getelementptr! const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx); @@ -1610,9 +1613,10 @@ Constant *ConstantExpr::getGetElementPtr(Constant *C, Value* const *Idxs, return getGetElementPtrTy(PointerType::get(Ty, As), C, Idxs, NumIdx); } -Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C, - Value* const *Idxs, - unsigned NumIdx) { +template +Constant *ConstantExpr::getInBoundsGetElementPtrImpl(Constant *C, + IndexTy const *Idxs, + unsigned NumIdx) { // Get the result type of the getelementptr! const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx); @@ -1621,15 +1625,26 @@ Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C, return getInBoundsGetElementPtrTy(PointerType::get(Ty, As), C, Idxs, NumIdx); } -Constant *ConstantExpr::getGetElementPtr(Constant *C, Constant* const *Idxs, +Constant *ConstantExpr::getGetElementPtr(Constant *C, Value* const *Idxs, + unsigned NumIdx) { + return getGetElementPtrImpl(C, Idxs, NumIdx); +} + +Constant *ConstantExpr::getGetElementPtr(Constant *C, Constant *const *Idxs, unsigned NumIdx) { - return getGetElementPtr(C, (Value* const *)Idxs, NumIdx); + return getGetElementPtrImpl(C, Idxs, NumIdx); +} + +Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C, + Value* const *Idxs, + unsigned NumIdx) { + return getInBoundsGetElementPtrImpl(C, Idxs, NumIdx); } Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C, - Constant* const *Idxs, + Constant *const *Idxs, unsigned NumIdx) { - return getInBoundsGetElementPtr(C, (Value* const *)Idxs, NumIdx); + return getInBoundsGetElementPtrImpl(C, Idxs, NumIdx); } Constant * -- cgit v1.2.3