diff options
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Function.cpp | 24 | ||||
-rw-r--r-- | lib/VMCore/Value.cpp | 28 | ||||
-rw-r--r-- | lib/VMCore/Verifier.cpp | 5 |
3 files changed, 30 insertions, 27 deletions
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index f14c455bce..546cadb0f3 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -357,28 +357,4 @@ Function *Intrinsic::getDeclaration(Module *M, ID id, const Type **Tys, getType(id, Tys, numTys))); } -Value *IntrinsicInst::StripPointerCasts(Value *Ptr) { - if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ptr)) { - if (CE->getOpcode() == Instruction::BitCast) { - if (isa<PointerType>(CE->getOperand(0)->getType())) - return StripPointerCasts(CE->getOperand(0)); - } else if (CE->getOpcode() == Instruction::GetElementPtr) { - for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i) - if (!CE->getOperand(i)->isNullValue()) - return Ptr; - return StripPointerCasts(CE->getOperand(0)); - } - return Ptr; - } - - if (BitCastInst *CI = dyn_cast<BitCastInst>(Ptr)) { - if (isa<PointerType>(CI->getOperand(0)->getType())) - return StripPointerCasts(CI->getOperand(0)); - } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr)) { - if (GEP->hasAllZeroIndices()) - return StripPointerCasts(GEP->getOperand(0)); - } - return Ptr; -} - // vim: sw=2 ai diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index e55e558e0f..93a71518eb 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Constant.h" +#include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/InstrTypes.h" #include "llvm/Instructions.h" @@ -331,3 +332,30 @@ void User::replaceUsesOfWith(Value *From, Value *To) { } } +//===----------------------------------------------------------------------===// +// Utility functions +//===----------------------------------------------------------------------===// + +Value *llvm::StripPointerCasts(Value *Ptr) { + if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ptr)) { + if (CE->getOpcode() == Instruction::BitCast) { + if (isa<PointerType>(CE->getOperand(0)->getType())) + return StripPointerCasts(CE->getOperand(0)); + } else if (CE->getOpcode() == Instruction::GetElementPtr) { + for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i) + if (!CE->getOperand(i)->isNullValue()) + return Ptr; + return StripPointerCasts(CE->getOperand(0)); + } + return Ptr; + } + + if (BitCastInst *CI = dyn_cast<BitCastInst>(Ptr)) { + if (isa<PointerType>(CI->getOperand(0)->getType())) + return StripPointerCasts(CI->getOperand(0)); + } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr)) { + if (GEP->hasAllZeroIndices()) + return StripPointerCasts(GEP->getOperand(0)); + } + return Ptr; +} diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 7449fe7ed6..be54673869 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -1271,8 +1271,7 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) { "Intrinsic parameter #1 is not i8**.", &CI); Assert1(CI.getOperand(2)->getType() == PtrTy, "Intrinsic parameter #2 is not i8*.", &CI); - Assert1(isa<AllocaInst>( - IntrinsicInst::StripPointerCasts(CI.getOperand(1))), + Assert1(isa<AllocaInst>(StripPointerCasts(CI.getOperand(1))), "llvm.gcroot parameter #1 must be an alloca.", &CI); Assert1(isa<Constant>(CI.getOperand(2)), "llvm.gcroot parameter #2 must be a constant.", &CI); @@ -1298,7 +1297,7 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) { &CI); } break; case Intrinsic::init_trampoline: - Assert1(isa<Function>(IntrinsicInst::StripPointerCasts(CI.getOperand(2))), + Assert1(isa<Function>(StripPointerCasts(CI.getOperand(2))), "llvm.init_trampoline parameter #2 must resolve to a function.", &CI); break; |