Index: llvm/include/llvm/IR/Type.h =================================================================== --- llvm/include/llvm/IR/Type.h +++ llvm/include/llvm/IR/Type.h @@ -366,7 +366,16 @@ return ContainedTys[0]; } + /// This method is deprecated without replacement. Pointer element types are + /// not available with opaque pointers. Type *getPointerElementType() const { + return getNonOpaquePointerElementType(); + } + + /// Only use this method in code that is not reachable with opaque pointers, + /// or part of deprecated methods that will be removed as part of the opaque + /// pointers transition. + Type *getNonOpaquePointerElementType() const { assert(getTypeID() == PointerTyID); assert(NumContainedTys && "Attempting to get element type of opaque pointer"); Index: llvm/lib/AsmParser/LLParser.cpp =================================================================== --- llvm/lib/AsmParser/LLParser.cpp +++ llvm/lib/AsmParser/LLParser.cpp @@ -1410,11 +1410,12 @@ nullptr, GlobalVariable::NotThreadLocal, PTy->getAddressSpace()); - if (auto *FT = dyn_cast(PTy->getPointerElementType())) + Type *ElemTy = PTy->getNonOpaquePointerElementType(); + if (auto *FT = dyn_cast(ElemTy)) return Function::Create(FT, GlobalValue::ExternalWeakLinkage, PTy->getAddressSpace(), "", M); else - return new GlobalVariable(*M, PTy->getPointerElementType(), false, + return new GlobalVariable(*M, ElemTy, false, GlobalValue::ExternalWeakLinkage, nullptr, "", nullptr, GlobalVariable::NotThreadLocal, PTy->getAddressSpace()); @@ -5602,7 +5603,7 @@ if (FRVI != ForwardRefVals.end()) { FwdFn = FRVI->second.first; if (!FwdFn->getType()->isOpaque()) { - if (!FwdFn->getType()->getPointerElementType()->isFunctionTy()) + if (!FwdFn->getType()->getNonOpaquePointerElementType()->isFunctionTy()) return error(FRVI->second.second, "invalid forward reference to " "function as global value!"); if (FwdFn->getType() != PFT) Index: llvm/lib/IR/Core.cpp =================================================================== --- llvm/lib/IR/Core.cpp +++ llvm/lib/IR/Core.cpp @@ -1691,8 +1691,7 @@ ArrayRef IdxList(unwrap(ConstantIndices, NumIndices), NumIndices); Constant *Val = unwrap(ConstantVal); - Type *Ty = - cast(Val->getType()->getScalarType())->getElementType(); + Type *Ty = Val->getType()->getScalarType()->getNonOpaquePointerElementType(); return wrap(ConstantExpr::getGetElementPtr(Ty, Val, IdxList)); } @@ -1710,8 +1709,7 @@ ArrayRef IdxList(unwrap(ConstantIndices, NumIndices), NumIndices); Constant *Val = unwrap(ConstantVal); - Type *Ty = - cast(Val->getType()->getScalarType())->getElementType(); + Type *Ty = Val->getType()->getScalarType()->getNonOpaquePointerElementType(); return wrap(ConstantExpr::getInBoundsGetElementPtr(Ty, Val, IdxList)); } @@ -2278,7 +2276,8 @@ LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, const char *Name) { auto *PTy = cast(unwrap(Ty)); - return wrap(GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(), + return wrap(GlobalAlias::create(PTy->getNonOpaquePointerElementType(), + PTy->getAddressSpace(), GlobalValue::ExternalLinkage, Name, unwrap(Aliasee), unwrap(M))); } @@ -3218,7 +3217,7 @@ const char *Name) { Value *V = unwrap(Fn); FunctionType *FnT = - cast(cast(V->getType())->getElementType()); + cast(V->getType()->getNonOpaquePointerElementType()); return wrap( unwrap(B)->CreateInvoke(FnT, unwrap(Fn), unwrap(Then), unwrap(Catch), @@ -3590,7 +3589,8 @@ Value *V = unwrap(PointerVal); PointerType *Ty = cast(V->getType()); - return wrap(unwrap(B)->CreateLoad(Ty->getElementType(), V, Name)); + return wrap(unwrap(B)->CreateLoad(Ty->getNonOpaquePointerElementType(), V, + Name)); } LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef B, LLVMTypeRef Ty, @@ -3692,8 +3692,7 @@ const char *Name) { ArrayRef IdxList(unwrap(Indices), NumIndices); Value *Val = unwrap(Pointer); - Type *Ty = - cast(Val->getType()->getScalarType())->getElementType(); + Type *Ty = Val->getType()->getScalarType()->getNonOpaquePointerElementType(); return wrap(unwrap(B)->CreateGEP(Ty, Val, IdxList, Name)); } @@ -3709,8 +3708,7 @@ const char *Name) { ArrayRef IdxList(unwrap(Indices), NumIndices); Value *Val = unwrap(Pointer); - Type *Ty = - cast(Val->getType()->getScalarType())->getElementType(); + Type *Ty = Val->getType()->getScalarType()->getNonOpaquePointerElementType(); return wrap(unwrap(B)->CreateInBoundsGEP(Ty, Val, IdxList, Name)); } @@ -3725,8 +3723,7 @@ LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer, unsigned Idx, const char *Name) { Value *Val = unwrap(Pointer); - Type *Ty = - cast(Val->getType()->getScalarType())->getElementType(); + Type *Ty = Val->getType()->getScalarType()->getNonOpaquePointerElementType(); return wrap(unwrap(B)->CreateStructGEP(Ty, Val, Idx, Name)); } @@ -3947,7 +3944,7 @@ const char *Name) { Value *V = unwrap(Fn); FunctionType *FnT = - cast(cast(V->getType())->getElementType()); + cast(V->getType()->getNonOpaquePointerElementType()); return wrap(unwrap(B)->CreateCall(FnT, unwrap(Fn), makeArrayRef(unwrap(Args), NumArgs), Name)); Index: llvm/lib/Transforms/Coroutines/Coroutines.cpp =================================================================== --- llvm/lib/Transforms/Coroutines/Coroutines.cpp +++ llvm/lib/Transforms/Coroutines/Coroutines.cpp @@ -679,8 +679,8 @@ if (AsyncFuncPtrAddr->getType()->isOpaquePointerTy()) return; - auto *StructTy = - cast(AsyncFuncPtrAddr->getType()->getPointerElementType()); + auto *StructTy = cast( + AsyncFuncPtrAddr->getType()->getNonOpaquePointerElementType()); if (StructTy->isOpaque() || !StructTy->isPacked() || StructTy->getNumElements() != 2 || !StructTy->getElementType(0)->isIntegerTy(32) || Index: llvm/lib/Transforms/Scalar/SROA.cpp =================================================================== --- llvm/lib/Transforms/Scalar/SROA.cpp +++ llvm/lib/Transforms/Scalar/SROA.cpp @@ -1437,8 +1437,9 @@ if (Indices.size() == 1 && cast(Indices.back())->isZero()) return BasePtr; - return IRB.CreateInBoundsGEP(BasePtr->getType()->getPointerElementType(), - BasePtr, Indices, NamePrefix + "sroa_idx"); + return IRB.CreateInBoundsGEP( + BasePtr->getType()->getNonOpaquePointerElementType(), BasePtr, Indices, + NamePrefix + "sroa_idx"); } /// Get a natural GEP off of the BasePtr walking through Ty toward