diff options
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Constants.cpp | 2 | ||||
-rw-r--r-- | lib/VMCore/Type.cpp | 22 | ||||
-rw-r--r-- | lib/VMCore/Verifier.cpp | 3 |
3 files changed, 25 insertions, 2 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index a4e21e16b3..b96257936d 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -1673,7 +1673,7 @@ Constant *ConstantExpr::getAlignOf(Type* Ty) { // Note that a non-inbounds gep is used, as null isn't within any object. Type *AligningTy = StructType::get(Type::getInt1Ty(Ty->getContext()), Ty, NULL); - Constant *NullPtr = Constant::getNullValue(AligningTy->getPointerTo()); + Constant *NullPtr = Constant::getNullValue(AligningTy->getPointerTo(Ty)); Constant *Zero = ConstantInt::get(Type::getInt64Ty(Ty->getContext()), 0); Constant *One = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1); Constant *Indices[2] = { Zero, One }; diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index 54146e118c..13fae3327b 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -779,6 +779,28 @@ PointerType *Type::getPointerTo(unsigned addrs) { return PointerType::get(this, addrs); } +PointerType *Type::getPointerTo(const Type *Ty) { + unsigned AS = 0; + // For pointers, we return a new pointer based on the address space. + if (Ty->isPointerTy()) AS = Ty->getPointerAddressSpace(); + // For vector of pointers, we return a new pointer based on the + // address space of the element pointer type. + if (Ty->isVectorTy()) + AS = Ty->getVectorElementType()->getPointerAddressSpace(); + // Otherwise return a pointer based on the default address space + // since we want a pointer to the current type without having + // a type that can give us the correct address space. + // An example of this occuring is that you want to get a pointer to + // all of the arguments in a function. However, the PointerType + // for a non-pointer type cannot be determined by the type, so + // the default value is used. + return getPointerTo(AS); +} + +PointerType *Type::getPointerTo() { + return getPointerTo(this); +} + bool PointerType::isValidElementType(Type *ElemTy) { return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() && !ElemTy->isMetadataTy(); diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index eb40b09d29..23f4e54328 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -434,7 +434,8 @@ void Verifier::visitGlobalVariable(GlobalVariable &GV) { if (ArrayType *ATy = dyn_cast<ArrayType>(GV.getType())) { StructType *STy = dyn_cast<StructType>(ATy->getElementType()); PointerType *FuncPtrTy = - FunctionType::get(Type::getVoidTy(*Context), false)->getPointerTo(); + FunctionType::get(Type::getVoidTy(*Context), false) + ->getPointerTo(GV.getType()); Assert1(STy && STy->getNumElements() == 2 && STy->getTypeAtIndex(0u)->isIntegerTy(32) && STy->getTypeAtIndex(1) == FuncPtrTy, |