diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 93e16575042c4..b0d1fcd26a5f4 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1376,7 +1376,7 @@ static void CreateCoercedStore(llvm::Value *Src, llvm::PointerType *DstPtrTy = llvm::dyn_cast(DstTy); if (SrcPtrTy && DstPtrTy && SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace()) { - Src = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Src, DstTy); + Src = CGF.Builder.CreateAddrSpaceCast(Src, DstTy); CGF.Builder.CreateStore(Src, Dst, DstIsVolatile); return; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 9b21f428b0af7..08db8384bef41 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1121,11 +1121,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, Address(&*AI, ConvertType(RetTy), CurFnInfo->getReturnInfo().getIndirectAlign(), KnownNonNull); if (!CurFnInfo->getReturnInfo().getIndirectByVal()) { - ReturnValuePointer = - CreateDefaultAlignTempAlloca(Int8PtrTy, "result.ptr"); - Builder.CreateStore(Builder.CreatePointerBitCastOrAddrSpaceCast( - ReturnValue.getPointer(), Int8PtrTy), - ReturnValuePointer); + ReturnValuePointer = CreateDefaultAlignTempAlloca( + ReturnValue.getPointer()->getType(), "result.ptr"); + Builder.CreateStore(ReturnValue.getPointer(), ReturnValuePointer); } } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::InAlloca && !hasScalarEvaluationKind(CurFnInfo->getReturnType())) { diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index 0c89871420bdd..f7ef9503aa610 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -3088,9 +3088,6 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs( CharUnits Align = CGM.getContext().getDeclAlign(VD); Val = Builder.CreateAlignedLoad(Var->getValueType(), Val, Align); } - if (Val->getType() != Wrapper->getReturnType()) - Val = Builder.CreatePointerBitCastOrAddrSpaceCast( - Val, Wrapper->getReturnType(), ""); Builder.CreateRet(Val); } diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 3d79f92137abc..60224d458f6a2 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -137,7 +137,7 @@ llvm::Value *TargetCodeGenInfo::performAddrSpaceCast( if (auto *C = dyn_cast(Src)) return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestAddr, DestTy); // Try to preserve the source's name to make IR more readable. - return CGF.Builder.CreatePointerBitCastOrAddrSpaceCast( + return CGF.Builder.CreateAddrSpaceCast( Src, DestTy, Src->hasName() ? Src->getName() + ".ascast" : ""); } diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h index c9f243fdb12e4..7f842a733cf71 100644 --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -2138,6 +2138,9 @@ class IRBuilderBase { return Insert(CastInst::CreatePointerCast(V, DestTy), Name); } + // With opaque pointers enabled, this can be substituted with + // CreateAddrSpaceCast. + // TODO: Replace uses of this method and remove the method itself. Value *CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name = "") { if (V->getType() == DestTy)