Skip to content

Commit 6f986bf

Browse files
committed
[clang] Remove CGBuilderTy::CreateElementBitCast
`CGBuilderTy::CreateElementBitCast()` no longer does what its name suggests. Remove remaining in-tree uses by one of the following methods. * drop the call entirely * fold it to an `Address` construction * replace it with `Address::withElementType()` This is a NFC cleanup effort. Reviewed By: barannikov88, nikic, jrtc27 Differential Revision: https://reviews.llvm.org/D154285
1 parent f55d96b commit 6f986bf

File tree

9 files changed

+63
-91
lines changed

9 files changed

+63
-91
lines changed

clang/lib/CodeGen/CGBuilder.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,6 @@ class CGBuilderTy : public CGBuilderBaseTy {
155155
Addr.isKnownNonNull());
156156
}
157157

158-
/// This method is to be deprecated. Use `Address::withElementType` instead.
159-
Address CreateElementBitCast(Address Addr, llvm::Type *Ty) {
160-
return Address(Addr.getPointer(), Ty, Addr.getAlignment(),
161-
Addr.isKnownNonNull());
162-
}
163-
164158
using CGBuilderBaseTy::CreatePointerBitCastOrAddrSpaceCast;
165159
Address CreatePointerBitCastOrAddrSpaceCast(Address Addr, llvm::Type *Ty,
166160
llvm::Type *ElementTy,

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3951,7 +3951,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
39513951

39523952
// Call LLVM's EH setjmp, which is lightweight.
39533953
Function *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_setjmp);
3954-
Buf = Builder.CreateElementBitCast(Buf, Int8Ty);
39553954
return RValue::get(Builder.CreateCall(F, Buf.getPointer()));
39563955
}
39573956
case Builtin::BI__builtin_longjmp: {
@@ -4259,7 +4258,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
42594258
PtrTy->castAs<PointerType>()->getPointeeType().isVolatileQualified();
42604259

42614260
Address Ptr = EmitPointerWithAlignment(E->getArg(0));
4262-
Ptr = Builder.CreateElementBitCast(Ptr, Int8Ty);
4261+
Ptr = Ptr.withElementType(Int8Ty);
42634262
Value *NewVal = Builder.getInt8(0);
42644263
Value *Order = EmitScalarExpr(E->getArg(1));
42654264
if (isa<llvm::ConstantInt>(Order)) {
@@ -7287,7 +7286,7 @@ Value *CodeGenFunction::EmitCommonNeonBuiltinExpr(
72877286
case NEON::BI__builtin_neon_vld1_dup_v:
72887287
case NEON::BI__builtin_neon_vld1q_dup_v: {
72897288
Value *V = PoisonValue::get(Ty);
7290-
PtrOp0 = Builder.CreateElementBitCast(PtrOp0, VTy->getElementType());
7289+
PtrOp0 = PtrOp0.withElementType(VTy->getElementType());
72917290
LoadInst *Ld = Builder.CreateLoad(PtrOp0);
72927291
llvm::Constant *CI = ConstantInt::get(SizeTy, 0);
72937292
Ops[0] = Builder.CreateInsertElement(V, Ld, CI);
@@ -8099,7 +8098,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
80998098
Value *Val = EmitScalarExpr(E->getArg(0));
81008099
Builder.CreateStore(Val, Tmp);
81018100

8102-
Address LdPtr = Builder.CreateElementBitCast(Tmp, STy);
8101+
Address LdPtr = Tmp.withElementType(STy);
81038102
Val = Builder.CreateLoad(LdPtr);
81048103

81058104
Value *Arg0 = Builder.CreateExtractValue(Val, 0);
@@ -8473,7 +8472,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
84738472
[[fallthrough]];
84748473
case NEON::BI__builtin_neon_vld1_lane_v: {
84758474
Ops[1] = Builder.CreateBitCast(Ops[1], Ty);
8476-
PtrOp0 = Builder.CreateElementBitCast(PtrOp0, VTy->getElementType());
8475+
PtrOp0 = PtrOp0.withElementType(VTy->getElementType());
84778476
Value *Ld = Builder.CreateLoad(PtrOp0);
84788477
return Builder.CreateInsertElement(Ops[1], Ld, Ops[2], "vld1_lane");
84798478
}
@@ -8537,9 +8536,8 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
85378536
case NEON::BI__builtin_neon_vst1_lane_v: {
85388537
Ops[1] = Builder.CreateBitCast(Ops[1], Ty);
85398538
Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2]);
8540-
auto St = Builder.CreateStore(
8541-
Ops[1], Builder.CreateElementBitCast(PtrOp0, Ops[1]->getType()));
8542-
return St;
8539+
return Builder.CreateStore(Ops[1],
8540+
PtrOp0.withElementType(Ops[1]->getType()));
85438541
}
85448542
case NEON::BI__builtin_neon_vtbl1_v:
85458543
return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl1),
@@ -10203,7 +10201,7 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
1020310201
Address Tmp = CreateMemTemp(E->getArg(0)->getType());
1020410202
EmitAnyExprToMem(E->getArg(0), Tmp, Qualifiers(), /*init*/ true);
1020510203

10206-
Tmp = Builder.CreateElementBitCast(Tmp, STy);
10204+
Tmp = Tmp.withElementType(STy);
1020710205
llvm::Value *Val = Builder.CreateLoad(Tmp);
1020810206

1020910207
Value *Arg0 = Builder.CreateExtractValue(Val, 0);
@@ -20001,8 +19999,8 @@ Value *CodeGenFunction::EmitHexagonBuiltinExpr(unsigned BuiltinID,
2000119999
case Hexagon::BI__builtin_HEXAGON_V6_vsubcarry_128B: {
2000220000
// Get the type from the 0-th argument.
2000320001
llvm::Type *VecType = ConvertType(E->getArg(0)->getType());
20004-
Address PredAddr = Builder.CreateElementBitCast(
20005-
EmitPointerWithAlignment(E->getArg(2)), VecType);
20002+
Address PredAddr =
20003+
EmitPointerWithAlignment(E->getArg(2)).withElementType(VecType);
2000620004
llvm::Value *PredIn = V2Q(Builder.CreateLoad(PredAddr));
2000720005
llvm::Value *Result = Builder.CreateCall(CGM.getIntrinsic(ID),
2000820006
{EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1)), PredIn});
@@ -20021,8 +20019,8 @@ Value *CodeGenFunction::EmitHexagonBuiltinExpr(unsigned BuiltinID,
2002120019
case Hexagon::BI__builtin_HEXAGON_V6_vsubcarryo_128B: {
2002220020
// Get the type from the 0-th argument.
2002320021
llvm::Type *VecType = ConvertType(E->getArg(0)->getType());
20024-
Address PredAddr = Builder.CreateElementBitCast(
20025-
EmitPointerWithAlignment(E->getArg(2)), VecType);
20022+
Address PredAddr =
20023+
EmitPointerWithAlignment(E->getArg(2)).withElementType(VecType);
2002620024
llvm::Value *Result = Builder.CreateCall(CGM.getIntrinsic(ID),
2002720025
{EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1))});
2002820026

clang/lib/CodeGen/CGCall.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ static llvm::Value *CreateCoercedLoad(Address Src, llvm::Type *Ty,
12861286
//
12871287
// FIXME: Assert that we aren't truncating non-padding bits when have access
12881288
// to that information.
1289-
Src = CGF.Builder.CreateElementBitCast(Src, Ty);
1289+
Src = Src.withElementType(Ty);
12901290
return CGF.Builder.CreateLoad(Src);
12911291
}
12921292

@@ -1396,7 +1396,7 @@ static void CreateCoercedStore(llvm::Value *Src,
13961396
if (isa<llvm::ScalableVectorType>(SrcTy) ||
13971397
isa<llvm::ScalableVectorType>(DstTy) ||
13981398
SrcSize.getFixedValue() <= DstSize.getFixedValue()) {
1399-
Dst = CGF.Builder.CreateElementBitCast(Dst, SrcTy);
1399+
Dst = Dst.withElementType(SrcTy);
14001400
CGF.EmitAggregateStore(Src, Dst, DstIsVolatile);
14011401
} else {
14021402
// Otherwise do coercion through memory. This is stupid, but
@@ -1420,10 +1420,10 @@ static void CreateCoercedStore(llvm::Value *Src,
14201420
static Address emitAddressAtOffset(CodeGenFunction &CGF, Address addr,
14211421
const ABIArgInfo &info) {
14221422
if (unsigned offset = info.getDirectOffset()) {
1423-
addr = CGF.Builder.CreateElementBitCast(addr, CGF.Int8Ty);
1423+
addr = addr.withElementType(CGF.Int8Ty);
14241424
addr = CGF.Builder.CreateConstInBoundsByteGEP(addr,
14251425
CharUnits::fromQuantity(offset));
1426-
addr = CGF.Builder.CreateElementBitCast(addr, info.getCoerceToType());
1426+
addr = addr.withElementType(info.getCoerceToType());
14271427
}
14281428
return addr;
14291429
}
@@ -3190,7 +3190,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
31903190

31913191
Address AddrToStoreInto = Address::invalid();
31923192
if (SrcSize <= DstSize) {
3193-
AddrToStoreInto = Builder.CreateElementBitCast(Ptr, STy);
3193+
AddrToStoreInto = Ptr.withElementType(STy);
31943194
} else {
31953195
AddrToStoreInto =
31963196
CreateTempAlloca(STy, Alloca.getAlignment(), "coerce");
@@ -3235,7 +3235,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
32353235
ArgVals.push_back(ParamValue::forIndirect(alloca));
32363236

32373237
auto coercionType = ArgI.getCoerceAndExpandType();
3238-
alloca = Builder.CreateElementBitCast(alloca, coercionType);
3238+
alloca = alloca.withElementType(coercionType);
32393239

32403240
unsigned argIndex = FirstIRArg;
32413241
for (unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
@@ -3837,7 +3837,7 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
38373837

38383838
// Load all of the coerced elements out into results.
38393839
llvm::SmallVector<llvm::Value*, 4> results;
3840-
Address addr = Builder.CreateElementBitCast(ReturnValue, coercionType);
3840+
Address addr = ReturnValue.withElementType(coercionType);
38413841
for (unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
38423842
auto coercedEltType = coercionType->getElementType(i);
38433843
if (ABIArgInfo::isPaddingForCoerceAndExpand(coercedEltType))
@@ -5063,10 +5063,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
50635063
// Store the RValue into the argument struct.
50645064
Address Addr =
50655065
Builder.CreateStructGEP(ArgMemory, ArgInfo.getInAllocaFieldIndex());
5066-
// There are some cases where a trivial bitcast is not avoidable. The
5067-
// definition of a type later in a translation unit may change it's type
5068-
// from {}* to (%struct.foo*)*.
5069-
Addr = Builder.CreateElementBitCast(Addr, ConvertTypeForMem(I->Ty));
5066+
Addr = Addr.withElementType(ConvertTypeForMem(I->Ty));
50705067
I->copyInto(*this, Addr);
50715068
}
50725069
break;
@@ -5261,7 +5258,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
52615258
Builder.CreateMemCpy(TempAlloca, Src, SrcSize);
52625259
Src = TempAlloca;
52635260
} else {
5264-
Src = Builder.CreateElementBitCast(Src, STy);
5261+
Src = Src.withElementType(STy);
52655262
}
52665263

52675264
assert(NumIRArgs == STy->getNumElements());
@@ -5325,7 +5322,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
53255322
Builder.CreateStore(RV.getScalarVal(), addr);
53265323
}
53275324

5328-
addr = Builder.CreateElementBitCast(addr, coercionType);
5325+
addr = addr.withElementType(coercionType);
53295326

53305327
unsigned IRArgPos = FirstIRArg;
53315328
for (unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
@@ -5680,8 +5677,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
56805677
case ABIArgInfo::CoerceAndExpand: {
56815678
auto coercionType = RetAI.getCoerceAndExpandType();
56825679

5683-
Address addr = SRetPtr;
5684-
addr = Builder.CreateElementBitCast(addr, coercionType);
5680+
Address addr = SRetPtr.withElementType(coercionType);
56855681

56865682
assert(CI->getType() == RetAI.getUnpaddedCoerceAndExpandType());
56875683
bool requiresExtract = isa<llvm::StructType>(CI->getType());

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ static Address EmitPointerWithAlignment(const Expr *E, LValueBaseInfo *BaseInfo,
10891089

10901090
llvm::Type *ElemTy =
10911091
CGF.ConvertTypeForMem(E->getType()->getPointeeType());
1092-
Addr = CGF.Builder.CreateElementBitCast(Addr, ElemTy);
1092+
Addr = Addr.withElementType(ElemTy);
10931093
if (CE->getCastKind() == CK_AddressSpaceConversion)
10941094
Addr = CGF.Builder.CreateAddrSpaceCast(Addr,
10951095
CGF.ConvertType(E->getType()));
@@ -1829,15 +1829,15 @@ static Address MaybeConvertMatrixAddress(Address Addr, CodeGenFunction &CGF,
18291829
auto *VectorTy = llvm::FixedVectorType::get(ArrayTy->getElementType(),
18301830
ArrayTy->getNumElements());
18311831

1832-
return Address(CGF.Builder.CreateElementBitCast(Addr, VectorTy));
1832+
return Addr.withElementType(VectorTy);
18331833
}
18341834
auto *VectorTy = dyn_cast<llvm::VectorType>(Addr.getElementType());
18351835
if (VectorTy && !IsVector) {
18361836
auto *ArrayTy = llvm::ArrayType::get(
18371837
VectorTy->getElementType(),
18381838
cast<llvm::FixedVectorType>(VectorTy)->getNumElements());
18391839

1840-
return Address(CGF.Builder.CreateElementBitCast(Addr, ArrayTy));
1840+
return Addr.withElementType(ArrayTy);
18411841
}
18421842

18431843
return Addr;
@@ -2510,7 +2510,7 @@ static LValue EmitThreadPrivateVarDeclLValue(
25102510
Addr =
25112511
CGF.CGM.getOpenMPRuntime().getAddrOfThreadPrivate(CGF, VD, Addr, Loc);
25122512

2513-
Addr = CGF.Builder.CreateElementBitCast(Addr, RealVarTy);
2513+
Addr = Addr.withElementType(RealVarTy);
25142514
return CGF.MakeAddrLValue(Addr, T, AlignmentSource::Decl);
25152515
}
25162516

@@ -3628,7 +3628,7 @@ Address CodeGenFunction::EmitArrayToPointerDecay(const Expr *E,
36283628
// If the array type was an incomplete type, we need to make sure
36293629
// the decay ends up being the right type.
36303630
llvm::Type *NewTy = ConvertType(E->getType());
3631-
Addr = Builder.CreateElementBitCast(Addr, NewTy);
3631+
Addr = Addr.withElementType(NewTy);
36323632

36333633
// Note that VLA pointers are always decayed, so we don't need to do
36343634
// anything here.
@@ -3647,7 +3647,7 @@ Address CodeGenFunction::EmitArrayToPointerDecay(const Expr *E,
36473647
if (BaseInfo) *BaseInfo = LV.getBaseInfo();
36483648
if (TBAAInfo) *TBAAInfo = CGM.getTBAAAccessInfo(EltType);
36493649

3650-
return Builder.CreateElementBitCast(Addr, ConvertTypeForMem(EltType));
3650+
return Addr.withElementType(ConvertTypeForMem(EltType));
36513651
}
36523652

36533653
/// isSimpleArrayDecayOperand - If the specified expr is a simple decay from an
@@ -3893,18 +3893,14 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E,
38933893
// correctly, so we need to cast to i8*. FIXME: is this actually
38943894
// true? A lot of other things in the fragile ABI would break...
38953895
llvm::Type *OrigBaseElemTy = Addr.getElementType();
3896-
Addr = Builder.CreateElementBitCast(Addr, Int8Ty);
38973896

38983897
// Do the GEP.
38993898
CharUnits EltAlign =
39003899
getArrayElementAlign(Addr.getAlignment(), Idx, InterfaceSize);
39013900
llvm::Value *EltPtr =
3902-
emitArraySubscriptGEP(*this, Addr.getElementType(), Addr.getPointer(),
3903-
ScaledIdx, false, SignedIndices, E->getExprLoc());
3904-
Addr = Address(EltPtr, Addr.getElementType(), EltAlign);
3905-
3906-
// Cast back.
3907-
Addr = Builder.CreateElementBitCast(Addr, OrigBaseElemTy);
3901+
emitArraySubscriptGEP(*this, Int8Ty, Addr.getPointer(), ScaledIdx,
3902+
false, SignedIndices, E->getExprLoc());
3903+
Addr = Address(EltPtr, OrigBaseElemTy, EltAlign);
39083904
} else if (const Expr *Array = isSimpleArrayDecayOperand(E->getBase())) {
39093905
// If this is A[i] where A is an array, the frontend will have decayed the
39103906
// base to be a ArrayToPointerDecay implicit cast. While correct, it is
@@ -3982,7 +3978,7 @@ static Address emitOMPArraySectionBase(CodeGenFunction &CGF, const Expr *Base,
39823978
// If the array type was an incomplete type, we need to make sure
39833979
// the decay ends up being the right type.
39843980
llvm::Type *NewTy = CGF.ConvertType(BaseTy);
3985-
Addr = CGF.Builder.CreateElementBitCast(Addr, NewTy);
3981+
Addr = Addr.withElementType(NewTy);
39863982

39873983
// Note that VLA pointers are always decayed, so we don't need to do
39883984
// anything here.
@@ -3992,8 +3988,7 @@ static Address emitOMPArraySectionBase(CodeGenFunction &CGF, const Expr *Base,
39923988
Addr = CGF.Builder.CreateConstArrayGEP(Addr, 0, "arraydecay");
39933989
}
39943990

3995-
return CGF.Builder.CreateElementBitCast(Addr,
3996-
CGF.ConvertTypeForMem(ElTy));
3991+
return Addr.withElementType(CGF.ConvertTypeForMem(ElTy));
39973992
}
39983993
LValueBaseInfo TypeBaseInfo;
39993994
TBAAAccessInfo TypeTBAAInfo;
@@ -4310,7 +4305,7 @@ static Address emitAddrOfZeroSizeField(CodeGenFunction &CGF, Address Base,
43104305
CGF.getContext().getFieldOffset(Field));
43114306
if (Offset.isZero())
43124307
return Base;
4313-
Base = CGF.Builder.CreateElementBitCast(Base, CGF.Int8Ty);
4308+
Base = Base.withElementType(CGF.Int8Ty);
43144309
return CGF.Builder.CreateConstInBoundsByteGEP(Base, Offset);
43154310
}
43164311

@@ -4398,8 +4393,7 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
43984393
UseVolatile ? Info.VolatileStorageSize : Info.StorageSize;
43994394
// Get the access type.
44004395
llvm::Type *FieldIntTy = llvm::Type::getIntNTy(getLLVMContext(), SS);
4401-
if (Addr.getElementType() != FieldIntTy)
4402-
Addr = Builder.CreateElementBitCast(Addr, FieldIntTy);
4396+
Addr = Addr.withElementType(FieldIntTy);
44034397
if (UseVolatile) {
44044398
const unsigned VolatileOffset = Info.VolatileStorageOffset.getQuantity();
44054399
if (VolatileOffset)
@@ -4830,7 +4824,7 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
48304824
if (V.isValid()) {
48314825
llvm::Type *T = ConvertTypeForMem(E->getType());
48324826
if (V.getElementType() != T)
4833-
LV.setAddress(Builder.CreateElementBitCast(V, T));
4827+
LV.setAddress(V.withElementType(T));
48344828
}
48354829
}
48364830
return LV;
@@ -4889,8 +4883,7 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
48894883

48904884
CGM.EmitExplicitCastExprType(CE, this);
48914885
LValue LV = EmitLValue(E->getSubExpr());
4892-
Address V = Builder.CreateElementBitCast(
4893-
LV.getAddress(*this),
4886+
Address V = LV.getAddress(*this).withElementType(
48944887
ConvertTypeForMem(CE->getTypeAsWritten()->getPointeeType()));
48954888

48964889
if (SanOpts.has(SanitizerKind::CFIUnrelatedCast))
@@ -4914,8 +4907,7 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
49144907
}
49154908
case CK_ObjCObjectLValueCast: {
49164909
LValue LV = EmitLValue(E->getSubExpr());
4917-
Address V = Builder.CreateElementBitCast(LV.getAddress(*this),
4918-
ConvertType(E->getType()));
4910+
Address V = LV.getAddress(*this).withElementType(ConvertType(E->getType()));
49194911
return MakeAddrLValue(V, E->getType(), LV.getBaseInfo(),
49204912
CGM.getTBAAInfoForSubobject(LV, E->getType()));
49214913
}
@@ -5225,8 +5217,8 @@ CodeGenFunction::EmitCXXTypeidLValue(const CXXTypeidExpr *E) {
52255217
}
52265218

52275219
Address CodeGenFunction::EmitCXXUuidofExpr(const CXXUuidofExpr *E) {
5228-
return Builder.CreateElementBitCast(CGM.GetAddrOfMSGuidDecl(E->getGuidDecl()),
5229-
ConvertType(E->getType()));
5220+
return CGM.GetAddrOfMSGuidDecl(E->getGuidDecl())
5221+
.withElementType(ConvertType(E->getType()));
52305222
}
52315223

52325224
LValue CodeGenFunction::EmitCXXUuidofLValue(const CXXUuidofExpr *E) {

clang/lib/CodeGen/CGExprCXX.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ static void EmitNullBaseClassInitialization(CodeGenFunction &CGF,
502502
if (Base->isEmpty())
503503
return;
504504

505-
DestPtr = CGF.Builder.CreateElementBitCast(DestPtr, CGF.Int8Ty);
505+
DestPtr = DestPtr.withElementType(CGF.Int8Ty);
506506

507507
const ASTRecordLayout &Layout = CGF.getContext().getASTRecordLayout(Base);
508508
CharUnits NVSize = Layout.getNonVirtualSize();
@@ -1076,7 +1076,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
10761076
if (const ConstantArrayType *CAT = dyn_cast_or_null<ConstantArrayType>(
10771077
AllocType->getAsArrayTypeUnsafe())) {
10781078
ElementTy = ConvertTypeForMem(AllocType);
1079-
CurPtr = Builder.CreateElementBitCast(CurPtr, ElementTy);
1079+
CurPtr = CurPtr.withElementType(ElementTy);
10801080
InitListElements *= getContext().getConstantArrayElementCount(CAT);
10811081
}
10821082

@@ -1133,7 +1133,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
11331133
}
11341134

11351135
// Switch back to initializing one base element at a time.
1136-
CurPtr = Builder.CreateElementBitCast(CurPtr, BeginPtr.getElementType());
1136+
CurPtr = CurPtr.withElementType(BeginPtr.getElementType());
11371137
}
11381138

11391139
// If all elements have already been initialized, skip any further
@@ -1715,7 +1715,7 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
17151715
}
17161716

17171717
llvm::Type *elementTy = ConvertTypeForMem(allocType);
1718-
Address result = Builder.CreateElementBitCast(allocation, elementTy);
1718+
Address result = allocation.withElementType(elementTy);
17191719

17201720
// Passing pointer through launder.invariant.group to avoid propagation of
17211721
// vptrs information which may be included in previous type.

0 commit comments

Comments
 (0)