Index: llvm/include/llvm/FuzzMutate/OpDescriptor.h =================================================================== --- llvm/include/llvm/FuzzMutate/OpDescriptor.h +++ llvm/include/llvm/FuzzMutate/OpDescriptor.h @@ -146,7 +146,7 @@ return false; if (const auto *PtrT = dyn_cast(V->getType())) - return PtrT->getElementType()->isSized(); + return PtrT->getPointerElementType()->isSized(); return false; }; auto Make = [](ArrayRef, ArrayRef Ts) { Index: llvm/include/llvm/IR/DerivedTypes.h =================================================================== --- llvm/include/llvm/IR/DerivedTypes.h +++ llvm/include/llvm/IR/DerivedTypes.h @@ -667,9 +667,11 @@ unsigned AddressSpace) { if (PT->isOpaque()) return get(PT->getContext(), AddressSpace); - return get(PT->getElementType(), AddressSpace); + return get(PT->PointeeTy, AddressSpace); } + [[deprecated("Pointer element types are deprecated. You can *temporarily* " + "use Type::getPointerElementType() instead")]] Type *getElementType() const { assert(!isOpaque() && "Attempting to get element type of opaque pointer"); return PointeeTy; Index: llvm/include/llvm/IR/Statepoint.h =================================================================== --- llvm/include/llvm/IR/Statepoint.h +++ llvm/include/llvm/IR/Statepoint.h @@ -123,7 +123,7 @@ /// statepoint. Type *getActualReturnType() const { auto *CalleeTy = - cast(getActualCalledOperand()->getType())->getElementType(); + getActualCalledOperand()->getType()->getPointerElementType(); return cast(CalleeTy)->getReturnType(); } Index: llvm/lib/Analysis/ScalarEvolution.cpp =================================================================== --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -7599,7 +7599,7 @@ // Also make sure step was increased the same with sizeof allocated // element type. const PointerType *GEPT = dyn_cast(GEP->getType()); - if (Ty->getElementType() != GEPT->getElementType()) + if (Ty->getElementType() != GEPT->getPointerElementType()) continue; // FIXME: Since gep indices are silently zext to the indexing type, Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2702,7 +2702,7 @@ PointerType *OrigPtrTy = cast(Elt0FullTy->getScalarType()); if (!PointeeType) - PointeeType = OrigPtrTy->getElementType(); + PointeeType = OrigPtrTy->getPointerElementType(); else if (!OrigPtrTy->isOpaqueOrPointeeTypeMatches(PointeeType)) return error("Explicit gep operator type does not match pointee type " "of pointer operand"); @@ -2826,7 +2826,7 @@ UpgradeInlineAsmString(&AsmStr); // FIXME: support upgrading in opaque pointers mode. V = InlineAsm::get( - cast(cast(CurTy)->getElementType()), + cast(CurTy->getPointerElementType()), AsmStr, ConstrStr, HasSideEffects, IsAlignStack); break; } @@ -2853,7 +2853,7 @@ UpgradeInlineAsmString(&AsmStr); // FIXME: support upgrading in opaque pointers mode. V = InlineAsm::get( - cast(cast(CurTy)->getElementType()), + cast(CurTy->getPointerElementType()), AsmStr, ConstrStr, HasSideEffects, IsAlignStack, InlineAsm::AsmDialect(AsmDialect)); break; @@ -2885,7 +2885,7 @@ UpgradeInlineAsmString(&AsmStr); // FIXME: support upgrading in opaque pointers mode. V = InlineAsm::get( - cast(cast(CurTy)->getElementType()), + cast(CurTy->getPointerElementType()), AsmStr, ConstrStr, HasSideEffects, IsAlignStack, InlineAsm::AsmDialect(AsmDialect), CanThrow); break; @@ -3282,7 +3282,7 @@ if (!Ty->isPointerTy()) return error("Invalid type for value"); AddressSpace = cast(Ty)->getAddressSpace(); - Ty = cast(Ty)->getElementType(); + Ty = Ty->getPointerElementType(); } uint64_t RawLinkage = Record[3]; @@ -3375,7 +3375,7 @@ if (!FTy) return error("Invalid record"); if (auto *PTy = dyn_cast(FTy)) - FTy = PTy->getElementType(); + FTy = PTy->getPointerElementType(); if (!isa(FTy)) return error("Invalid type for value"); @@ -3416,7 +3416,7 @@ Func->removeParamAttr(i, Kind); Type *PTy = cast(FTy)->getParamType(i); - Type *PtrEltTy = cast(PTy)->getElementType(); + Type *PtrEltTy = PTy->getPointerElementType(); Attribute NewAttr; switch (Kind) { case Attribute::ByVal: @@ -3539,7 +3539,7 @@ auto *PTy = dyn_cast(Ty); if (!PTy) return error("Invalid type for value"); - Ty = PTy->getElementType(); + Ty = PTy->getPointerElementType(); AddrSpace = PTy->getAddressSpace(); } else { AddrSpace = Record[OpNum++]; @@ -3908,7 +3908,7 @@ CB->removeParamAttr(i, Kind); - Type *PtrEltTy = cast(ArgsTys[i])->getElementType(); + Type *PtrEltTy = ArgsTys[i]->getPointerElementType(); Attribute NewAttr; switch (Kind) { case Attribute::ByVal: @@ -3949,7 +3949,7 @@ case Intrinsic::preserve_array_access_index: case Intrinsic::preserve_struct_access_index: if (!CB->getAttributes().getParamElementType(0)) { - Type *ElTy = cast(ArgsTys[0])->getElementType(); + Type *ElTy = ArgsTys[0]->getPointerElementType(); Attribute NewAttr = Attribute::get(Context, Attribute::ElementType, ElTy); CB->addParamAttr(0, NewAttr); } @@ -4239,8 +4239,7 @@ return error("Invalid record"); if (!Ty) { - Ty = cast(BasePtr->getType()->getScalarType()) - ->getElementType(); + Ty = BasePtr->getType()->getScalarType()->getPointerElementType(); } else if (!cast(BasePtr->getType()->getScalarType()) ->isOpaqueOrPointeeTypeMatches(Ty)) { return error( @@ -4757,7 +4756,7 @@ return error("Callee is not a pointer"); if (!FTy) { FTy = dyn_cast( - cast(Callee->getType())->getElementType()); + Callee->getType()->getPointerElementType()); if (!FTy) return error("Callee is not of pointer to function type"); } else if (!CalleeTy->isOpaqueOrPointeeTypeMatches(FTy)) @@ -4838,7 +4837,7 @@ return error("Callee is not a pointer type"); if (!FTy) { FTy = dyn_cast( - cast(Callee->getType())->getElementType()); + Callee->getType()->getPointerElementType()); if (!FTy) return error("Callee is not of pointer to function type"); } else if (!OpTy->isOpaqueOrPointeeTypeMatches(FTy)) @@ -5000,7 +4999,7 @@ auto *PTy = dyn_cast_or_null(Ty); if (!PTy) return error("Old-style alloca with a non-pointer type"); - Ty = PTy->getElementType(); + Ty = PTy->getPointerElementType(); } Type *OpTy = getTypeByID(Record[1]); Value *Size = getFnValueByID(Record[2], OpTy); @@ -5045,7 +5044,7 @@ if (OpNum + 3 == Record.size()) { Ty = getTypeByID(Record[OpNum++]); } else { - Ty = cast(Op->getType())->getElementType(); + Ty = Op->getType()->getPointerElementType(); } if (Error Err = typeCheckLoadStoreInst(Ty, Op->getType())) @@ -5078,7 +5077,7 @@ if (OpNum + 5 == Record.size()) { Ty = getTypeByID(Record[OpNum++]); } else { - Ty = cast(Op->getType())->getElementType(); + Ty = Op->getType()->getPointerElementType(); } if (Error Err = typeCheckLoadStoreInst(Ty, Op->getType())) @@ -5110,8 +5109,7 @@ (BitCode == bitc::FUNC_CODE_INST_STORE ? getValueTypePair(Record, OpNum, NextValueNo, Val) : popValue(Record, OpNum, NextValueNo, - cast(Ptr->getType())->getElementType(), - Val)) || + Ptr->getType()->getPointerElementType(), Val)) || OpNum + 2 != Record.size()) return error("Invalid record"); @@ -5139,8 +5137,7 @@ (BitCode == bitc::FUNC_CODE_INST_STOREATOMIC ? getValueTypePair(Record, OpNum, NextValueNo, Val) : popValue(Record, OpNum, NextValueNo, - cast(Ptr->getType())->getElementType(), - Val)) || + Ptr->getType()->getPointerElementType(), Val)) || OpNum + 4 != Record.size()) return error("Invalid record"); @@ -5392,7 +5389,7 @@ return error("Callee is not a pointer type"); if (!FTy) { FTy = dyn_cast( - cast(Callee->getType())->getElementType()); + Callee->getType()->getPointerElementType()); if (!FTy) return error("Callee is not of pointer to function type"); } else if (!OpTy->isOpaqueOrPointeeTypeMatches(FTy)) Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -948,7 +948,7 @@ } else { // POINTER: [pointee type, address space] Code = bitc::TYPE_CODE_POINTER; - TypeVals.push_back(VE.getTypeID(PTy->getElementType())); + TypeVals.push_back(VE.getTypeID(PTy->getNonOpaquePointerElementType())); TypeVals.push_back(AddressSpace); if (AddressSpace == 0) AbbrevToUse = PtrAbbrev; Index: llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp =================================================================== --- llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp +++ llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp @@ -313,7 +313,7 @@ PointerType *PtrTy = dyn_cast(OpTy); if (!PtrTy) report_fatal_error("Indirect operand for inline asm not a pointer!"); - OpTy = PtrTy->getElementType(); + OpTy = PtrTy->getPointerElementType(); } // FIXME: Support aggregate input operands Index: llvm/lib/FuzzMutate/RandomIRBuilder.cpp =================================================================== --- llvm/lib/FuzzMutate/RandomIRBuilder.cpp +++ llvm/lib/FuzzMutate/RandomIRBuilder.cpp @@ -54,7 +54,7 @@ assert(IP != BB.end() && "guaranteed by the findPointer"); } auto *NewLoad = new LoadInst( - cast(Ptr->getType())->getElementType(), Ptr, "L", &*IP); + Ptr->getType()->getPointerElementType(), Ptr, "L", &*IP); // Only sample this load if it really matches the descriptor if (Pred.matches(Srcs, NewLoad)) @@ -141,12 +141,12 @@ if (auto PtrTy = dyn_cast(Inst->getType())) { // We can never generate loads from non first class or non sized types - if (!PtrTy->getElementType()->isSized() || - !PtrTy->getElementType()->isFirstClassType()) + Type *ElemTy = PtrTy->getPointerElementType(); + if (!ElemTy->isSized() || !ElemTy->isFirstClassType()) return false; // TODO: Check if this is horribly expensive. - return Pred.matches(Srcs, UndefValue::get(PtrTy->getElementType())); + return Pred.matches(Srcs, UndefValue::get(ElemTy)); } return false; }; Index: llvm/lib/IR/AsmWriter.cpp =================================================================== --- llvm/lib/IR/AsmWriter.cpp +++ llvm/lib/IR/AsmWriter.cpp @@ -587,7 +587,7 @@ OS << " addrspace(" << AddressSpace << ')'; return; } - print(PTy->getElementType(), OS); + print(PTy->getNonOpaquePointerElementType(), OS); if (unsigned AddressSpace = PTy->getAddressSpace()) OS << " addrspace(" << AddressSpace << ')'; OS << '*'; Index: llvm/lib/IR/AutoUpgrade.cpp =================================================================== --- llvm/lib/IR/AutoUpgrade.cpp +++ llvm/lib/IR/AutoUpgrade.cpp @@ -4495,7 +4495,7 @@ if (F.getCallingConv() == CallingConv::X86_INTR && !F.arg_empty() && !F.hasParamAttribute(0, Attribute::ByVal)) { - Type *ByValTy = cast(F.getArg(0)->getType())->getElementType(); + Type *ByValTy = F.getArg(0)->getType()->getPointerElementType(); Attribute NewAttr = Attribute::getWithByValType(F.getContext(), ByValTy); F.addParamAttr(0, NewAttr); } Index: llvm/lib/IR/Core.cpp =================================================================== --- llvm/lib/IR/Core.cpp +++ llvm/lib/IR/Core.cpp @@ -796,7 +796,7 @@ LLVMTypeRef LLVMGetElementType(LLVMTypeRef WrappedTy) { auto *Ty = unwrap(WrappedTy); if (auto *PTy = dyn_cast(Ty)) - return wrap(PTy->getElementType()); + return wrap(PTy->getPointerElementType()); if (auto *ATy = dyn_cast(Ty)) return wrap(ATy->getElementType()); return wrap(cast(Ty)->getElementType()); Index: llvm/lib/IR/Function.cpp =================================================================== --- llvm/lib/IR/Function.cpp +++ llvm/lib/IR/Function.cpp @@ -817,7 +817,8 @@ // Opaque pointer doesn't have pointee type information, so we just mangle // address space for opaque pointer. if (!PTyp->isOpaque()) - Result += getMangledTypeStr(PTyp->getElementType(), HasUnnamedType); + Result += getMangledTypeStr( + PTyp->getNonOpaquePointerElementType(), HasUnnamedType); } else if (ArrayType *ATyp = dyn_cast(Ty)) { Result += "a" + utostr(ATyp->getNumElements()) + getMangledTypeStr(ATyp->getElementType(), HasUnnamedType); @@ -1465,8 +1466,8 @@ if (!PT || PT->getAddressSpace() != D.Pointer_AddressSpace) return true; if (!PT->isOpaque()) - return matchIntrinsicType(PT->getElementType(), Infos, ArgTys, - DeferredChecks, IsDeferredCheck); + return matchIntrinsicType(PT->getNonOpaquePointerElementType(), Infos, + ArgTys, DeferredChecks, IsDeferredCheck); // Consume IIT descriptors relating to the pointer element type. while (Infos.front().Kind == IITDescriptor::Pointer) Infos = Infos.slice(1); @@ -1573,7 +1574,8 @@ return IsDeferredCheck || DeferCheck(Ty); Type * ReferenceType = ArgTys[D.getArgumentNumber()]; PointerType *ThisArgType = dyn_cast(Ty); - return (!ThisArgType || ThisArgType->getElementType() != ReferenceType); + return (!ThisArgType || + ThisArgType->getPointerElementType() != ReferenceType); } case IITDescriptor::PtrToElt: { if (D.getArgumentNumber() >= ArgTys.size()) Index: llvm/lib/IR/IRBuilder.cpp =================================================================== --- llvm/lib/IR/IRBuilder.cpp +++ llvm/lib/IR/IRBuilder.cpp @@ -679,7 +679,7 @@ const Twine &Name) { // Extract out the type of the callee. auto *FuncPtrType = cast(ActualCallee->getType()); - assert(isa(FuncPtrType->getElementType()) && + assert(isa(FuncPtrType->getPointerElementType()) && "actual callee must be a callable value"); Module *M = Builder->GetInsertBlock()->getParent()->getParent(); @@ -736,7 +736,7 @@ ArrayRef GCArgs, const Twine &Name) { // Extract out the type of the callee. auto *FuncPtrType = cast(ActualInvokee->getType()); - assert(isa(FuncPtrType->getElementType()) && + assert(isa(FuncPtrType->getPointerElementType()) && "actual callee must be a callable value"); Module *M = Builder->GetInsertBlock()->getParent()->getParent(); Index: llvm/lib/IR/Verifier.cpp =================================================================== --- llvm/lib/IR/Verifier.cpp +++ llvm/lib/IR/Verifier.cpp @@ -1826,33 +1826,34 @@ "Attribute 'preallocated' does not support unsized types!", V); } if (!PTy->isOpaque()) { - if (!isa(PTy->getElementType())) + if (!isa(PTy->getNonOpaquePointerElementType())) Assert(!Attrs.hasAttribute(Attribute::SwiftError), "Attribute 'swifterror' only applies to parameters " "with pointer to pointer type!", V); if (Attrs.hasAttribute(Attribute::ByRef)) { - Assert(Attrs.getByRefType() == PTy->getElementType(), + Assert(Attrs.getByRefType() == PTy->getNonOpaquePointerElementType(), "Attribute 'byref' type does not match parameter!", V); } if (Attrs.hasAttribute(Attribute::ByVal) && Attrs.getByValType()) { - Assert(Attrs.getByValType() == PTy->getElementType(), + Assert(Attrs.getByValType() == PTy->getNonOpaquePointerElementType(), "Attribute 'byval' type does not match parameter!", V); } if (Attrs.hasAttribute(Attribute::Preallocated)) { - Assert(Attrs.getPreallocatedType() == PTy->getElementType(), + Assert(Attrs.getPreallocatedType() == + PTy->getNonOpaquePointerElementType(), "Attribute 'preallocated' type does not match parameter!", V); } if (Attrs.hasAttribute(Attribute::InAlloca)) { - Assert(Attrs.getInAllocaType() == PTy->getElementType(), + Assert(Attrs.getInAllocaType() == PTy->getNonOpaquePointerElementType(), "Attribute 'inalloca' type does not match parameter!", V); } if (Attrs.hasAttribute(Attribute::ElementType)) { - Assert(Attrs.getElementType() == PTy->getElementType(), + Assert(Attrs.getElementType() == PTy->getNonOpaquePointerElementType(), "Attribute 'elementtype' type does not match parameter!", V); } } @@ -2195,9 +2196,10 @@ const Value *Target = Call.getArgOperand(2); auto *PT = dyn_cast(Target->getType()); - Assert(PT && PT->getElementType()->isFunctionTy(), + Assert(PT && PT->getPointerElementType()->isFunctionTy(), "gc.statepoint callee must be of function pointer type", Call, Target); - FunctionType *TargetFuncType = cast(PT->getElementType()); + FunctionType *TargetFuncType = + cast(PT->getPointerElementType()); const int NumCallArgs = cast(Call.getArgOperand(3))->getZExtValue(); Assert(NumCallArgs >= 0, @@ -5005,7 +5007,7 @@ // Assert that result type matches wrapped callee. const Value *Target = StatepointCall->getArgOperand(2); auto *PT = cast(Target->getType()); - auto *TargetFuncType = cast(PT->getElementType()); + auto *TargetFuncType = cast(PT->getPointerElementType()); Assert(Call.getType() == TargetFuncType->getReturnType(), "gc.result result type does not match wrapped callee", Call); break; @@ -5312,7 +5314,7 @@ PointerType *Op0PtrTy = cast(Call.getArgOperand(0)->getType()); if (!Op0PtrTy->isOpaque()) - Op0ElemTy = Op0PtrTy->getElementType(); + Op0ElemTy = Op0PtrTy->getNonOpaquePointerElementType(); break; } case Intrinsic::matrix_column_major_store: { @@ -5326,7 +5328,7 @@ PointerType *Op1PtrTy = cast(Call.getArgOperand(1)->getType()); if (!Op1PtrTy->isOpaque()) - Op1ElemTy = Op1PtrTy->getElementType(); + Op1ElemTy = Op1PtrTy->getNonOpaquePointerElementType(); break; } default: Index: llvm/lib/Transforms/Coroutines/CoroFrame.cpp =================================================================== --- llvm/lib/Transforms/Coroutines/CoroFrame.cpp +++ llvm/lib/Transforms/Coroutines/CoroFrame.cpp @@ -808,7 +808,7 @@ if (Ty->isPointerTy()) { auto *PtrTy = cast(Ty); - Type *PointeeTy = PtrTy->getElementType(); + Type *PointeeTy = PtrTy->getPointerElementType(); auto Name = solveTypeName(PointeeTy); if (Name == "UnknownType") return "PointerType"; @@ -2278,7 +2278,7 @@ IRBuilder<> Builder(F.getEntryBlock().getFirstNonPHIOrDbg()); auto ArgTy = cast(Arg.getType()); - auto ValueTy = ArgTy->getElementType(); + auto ValueTy = ArgTy->getPointerElementType(); // Reduce to the alloca case: Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2502,7 +2502,7 @@ if (!Call.isByValArgument(ix)) return false; - Type *SrcElemTy = SrcTy->getElementType(); + Type *SrcElemTy = SrcTy->getNonOpaquePointerElementType(); Type *DstElemTy = Call.getParamByValType(ix); if (!SrcElemTy->isSized() || !DstElemTy->isSized()) return false; @@ -2767,7 +2767,7 @@ Call.removeParamAttr(ix, Attribute::ByVal); Call.addParamAttr( ix, Attribute::getWithByValType( - Call.getContext(), NewTy->getElementType())); + Call.getContext(), NewTy->getPointerElementType())); } Changed = true; } @@ -3016,12 +3016,12 @@ // sized type and the sized type has to have the same size as the old type. if (ParamTy != ActTy && CallerPAL.hasParamAttr(i, Attribute::ByVal)) { PointerType *ParamPTy = dyn_cast(ParamTy); - if (!ParamPTy || !ParamPTy->getElementType()->isSized()) + if (!ParamPTy || !ParamPTy->getPointerElementType()->isSized()) return false; Type *CurElTy = Call.getParamByValType(i); if (DL.getTypeAllocSize(CurElTy) != - DL.getTypeAllocSize(ParamPTy->getElementType())) + DL.getTypeAllocSize(ParamPTy->getPointerElementType())) return false; } } @@ -3035,16 +3035,16 @@ // call. We don't want to introduce a varargs call where one doesn't // already exist. PointerType *APTy = cast(Call.getCalledOperand()->getType()); - if (FT->isVarArg()!=cast(APTy->getElementType())->isVarArg()) + if (FT->isVarArg()!=cast(APTy->getPointerElementType())->isVarArg()) return false; // If both the callee and the cast type are varargs, we still have to make // sure the number of fixed parameters are the same or we have the same // ABI issues as if we introduce a varargs call. if (FT->isVarArg() && - cast(APTy->getElementType())->isVarArg() && + cast(APTy->getPointerElementType())->isVarArg() && FT->getNumParams() != - cast(APTy->getElementType())->getNumParams()) + cast(APTy->getPointerElementType())->getNumParams()) return false; } Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -91,7 +91,7 @@ // Get the type really allocated and the type casted to. Type *AllocElTy = AI.getAllocatedType(); - Type *CastElTy = PTy->getElementType(); + Type *CastElTy = PTy->getPointerElementType(); if (!AllocElTy->isSized() || !CastElTy->isSized()) return nullptr; // This optimisation does not work for cases where the cast type @@ -2649,8 +2649,8 @@ if (SrcPTy->isOpaque() || DstPTy->isOpaque()) return nullptr; - Type *DstElTy = DstPTy->getElementType(); - Type *SrcElTy = SrcPTy->getElementType(); + Type *DstElTy = DstPTy->getNonOpaquePointerElementType(); + Type *SrcElTy = SrcPTy->getNonOpaquePointerElementType(); // When the type pointed to is not sized the cast cannot be // turned into a gep. Index: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -345,7 +345,8 @@ #ifndef NDEBUG auto *PT = cast(I.getType()); auto *NT = cast(V->getType()); - assert(PT != NT && PT->getElementType() == NT->getElementType() && + assert(PT != NT && + PT->getPointerElementType() == NT->getPointerElementType() && "Invalid usage"); #endif WorkMap[&I] = V; Index: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1308,7 +1308,7 @@ Type * InstCombinerImpl::FindElementAtOffset(PointerType *PtrTy, int64_t IntOffset, SmallVectorImpl &NewIndices) { - Type *Ty = PtrTy->getElementType(); + Type *Ty = PtrTy->getPointerElementType(); if (!Ty->isSized()) return nullptr; @@ -2247,7 +2247,7 @@ // type. For now, skip these. if (StrippedPtr != PtrOp && !StrippedPtrTy->isOpaque()) { bool HasZeroPointerIndex = false; - Type *StrippedPtrEltTy = StrippedPtrTy->getElementType(); + Type *StrippedPtrEltTy = StrippedPtrTy->getNonOpaquePointerElementType(); if (auto *C = dyn_cast(GEP.getOperand(1))) HasZeroPointerIndex = C->isZero(); @@ -2434,7 +2434,7 @@ if (auto *BCI = dyn_cast(ASCStrippedPtrOp)) { Value *SrcOp = BCI->getOperand(0); PointerType *SrcType = cast(BCI->getSrcTy()); - Type *SrcEltType = SrcType->getElementType(); + Type *SrcEltType = SrcType->getPointerElementType(); // GEP directly using the source operand if this GEP is accessing an element // of a bitcasted pointer to vector or array of the same dimensions: Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1559,7 +1559,7 @@ auto BasePtr = CI->getOperand(OpOffset); if (ignoreAccess(LI, BasePtr)) return; - auto Ty = cast(BasePtr->getType())->getElementType(); + auto Ty = BasePtr->getType()->getPointerElementType(); MaybeAlign Alignment = Align(1); // Otherwise no alignment guarantees. We probably got Undef. if (auto *Op = dyn_cast(CI->getOperand(1 + OpOffset))) @@ -1656,8 +1656,7 @@ unsigned Granularity, uint32_t TypeSize, bool IsWrite, Value *SizeArgument, bool UseCalls, uint32_t Exp) { - auto *VTy = cast( - cast(Addr->getType())->getElementType()); + auto *VTy = cast(Addr->getType()->getPointerElementType()); uint64_t ElemTypeSize = DL.getTypeStoreSizeInBits(VTy->getScalarType()); unsigned Num = VTy->getNumElements(); auto Zero = ConstantInt::get(IntptrTy, 0); Index: llvm/lib/Transforms/Scalar/SROA.cpp =================================================================== --- llvm/lib/Transforms/Scalar/SROA.cpp +++ llvm/lib/Transforms/Scalar/SROA.cpp @@ -1512,7 +1512,7 @@ if (Ty == IRB.getInt8PtrTy(Ty->getAddressSpace()) && TargetTy->isIntegerTy(8)) return nullptr; - Type *ElementTy = Ty->getElementType(); + Type *ElementTy = Ty->getPointerElementType(); if (!ElementTy->isSized()) return nullptr; // We can't GEP through an unsized element. @@ -1571,7 +1571,7 @@ APInt Int8PtrOffset(Offset.getBitWidth(), 0); PointerType *TargetPtrTy = cast(PointerTy); - Type *TargetTy = TargetPtrTy->getElementType(); + Type *TargetTy = TargetPtrTy->getPointerElementType(); // As `addrspacecast` is , `Ptr` (the storage pointer) may have different // address space from the expected `PointerTy` (the pointer to be used). Index: llvm/lib/Transforms/Scalar/Scalarizer.cpp =================================================================== --- llvm/lib/Transforms/Scalar/Scalarizer.cpp +++ llvm/lib/Transforms/Scalar/Scalarizer.cpp @@ -270,7 +270,7 @@ Type *Ty = V->getType(); PtrTy = dyn_cast(Ty); if (PtrTy) - Ty = PtrTy->getElementType(); + Ty = PtrTy->getPointerElementType(); Size = cast(Ty)->getNumElements(); if (!CachePtr) Tmp.resize(Size, nullptr); @@ -288,7 +288,8 @@ return CV[I]; IRBuilder<> Builder(BB, BBI); if (PtrTy) { - Type *ElTy = cast(PtrTy->getElementType())->getElementType(); + Type *ElTy = + cast(PtrTy->getPointerElementType())->getElementType(); if (!CV[0]) { Type *NewPtrTy = PointerType::get(ElTy, PtrTy->getAddressSpace()); CV[0] = Builder.CreateBitCast(V, NewPtrTy, V->getName() + ".i0"); Index: llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp =================================================================== --- llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -173,7 +173,7 @@ auto *PtrTy = cast(Ty); if (DL.isNonIntegralPointerType(PtrTy)) { auto *Int8PtrTy = Builder.getInt8PtrTy(PtrTy->getAddressSpace()); - assert(DL.getTypeAllocSize(Int8PtrTy->getElementType()) == 1 && + assert(DL.getTypeAllocSize(Int8PtrTy->getPointerElementType()) == 1 && "alloc size of i8 must by 1 byte for the GEP to be correct"); auto *GEP = Builder.CreateGEP( Builder.getInt8Ty(), Constant::getNullValue(Int8PtrTy), V, "uglygep"); @@ -471,7 +471,7 @@ // indexes into the array implied by the pointer operand; the rest of // the indices index into the element or field type selected by the // preceding index. - Type *ElTy = PTy->getElementType(); + Type *ElTy = PTy->getNonOpaquePointerElementType(); for (;;) { // If the scale size is not 0, attempt to factor out a scale for // array indexing. @@ -640,8 +640,8 @@ Value *Casted = V; if (V->getType() != PTy) Casted = InsertNoopCastOfTo(Casted, PTy); - Value *GEP = Builder.CreateGEP(PTy->getElementType(), Casted, GepIndices, - "scevgep"); + Value *GEP = Builder.CreateGEP( + PTy->getNonOpaquePointerElementType(), Casted, GepIndices, "scevgep"); Ops.push_back(SE.getUnknown(GEP)); }