Skip to content

Commit 211bf60

Browse files
JOE1994Chenyang-L
authored andcommitted
[clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)
Partial progress towards replacing `CreateElementBitCast`, as it no longer does what its name suggests. Either replace its uses with `Address::withElementType()`, or remove them if no longer needed. Reviewed By: barannikov88, nikic Differential Revision: https://reviews.llvm.org/D153314
1 parent a8dedbc commit 211bf60

File tree

10 files changed

+86
-118
lines changed

10 files changed

+86
-118
lines changed

clang/lib/CodeGen/CGAtomic.cpp

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ namespace {
166166
}
167167

168168
Address getAtomicAddressAsAtomicIntPointer() const {
169-
return emitCastToAtomicIntPointer(getAtomicAddress());
169+
return castToAtomicIntPointer(getAtomicAddress());
170170
}
171171

172172
/// Is the atomic size larger than the underlying value type?
@@ -188,7 +188,7 @@ namespace {
188188

189189
/// Cast the given pointer to an integer pointer suitable for atomic
190190
/// operations if the source.
191-
Address emitCastToAtomicIntPointer(Address Addr) const;
191+
Address castToAtomicIntPointer(Address Addr) const;
192192

193193
/// If Addr is compatible with the iN that will be used for an atomic
194194
/// operation, bitcast it. Otherwise, create a temporary that is suitable
@@ -988,21 +988,21 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
988988
AtomicInfo Atomics(*this, AtomicVal);
989989

990990
if (ShouldCastToIntPtrTy) {
991-
Ptr = Atomics.emitCastToAtomicIntPointer(Ptr);
991+
Ptr = Atomics.castToAtomicIntPointer(Ptr);
992992
if (Val1.isValid())
993993
Val1 = Atomics.convertToAtomicIntPointer(Val1);
994994
if (Val2.isValid())
995995
Val2 = Atomics.convertToAtomicIntPointer(Val2);
996996
}
997997
if (Dest.isValid()) {
998998
if (ShouldCastToIntPtrTy)
999-
Dest = Atomics.emitCastToAtomicIntPointer(Dest);
999+
Dest = Atomics.castToAtomicIntPointer(Dest);
10001000
} else if (E->isCmpXChg())
10011001
Dest = CreateMemTemp(RValTy, "cmpxchg.bool");
10021002
else if (!RValTy->isVoidType()) {
10031003
Dest = Atomics.CreateTempAlloca();
10041004
if (ShouldCastToIntPtrTy)
1005-
Dest = Atomics.emitCastToAtomicIntPointer(Dest);
1005+
Dest = Atomics.castToAtomicIntPointer(Dest);
10061006
}
10071007

10081008
// Use a library call. See: http://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary .
@@ -1352,16 +1352,14 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
13521352
if (E->getOp() == AtomicExpr::AO__atomic_nand_fetch)
13531353
ResVal = Builder.CreateNot(ResVal);
13541354

1355-
Builder.CreateStore(
1356-
ResVal, Builder.CreateElementBitCast(Dest, ResVal->getType()));
1355+
Builder.CreateStore(ResVal, Dest.withElementType(ResVal->getType()));
13571356
}
13581357

13591358
if (RValTy->isVoidType())
13601359
return RValue::get(nullptr);
13611360

1362-
return convertTempToRValue(
1363-
Builder.CreateElementBitCast(Dest, ConvertTypeForMem(RValTy)),
1364-
RValTy, E->getExprLoc());
1361+
return convertTempToRValue(Dest.withElementType(ConvertTypeForMem(RValTy)),
1362+
RValTy, E->getExprLoc());
13651363
}
13661364

13671365
bool IsStore = E->getOp() == AtomicExpr::AO__c11_atomic_store ||
@@ -1412,9 +1410,8 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
14121410
if (RValTy->isVoidType())
14131411
return RValue::get(nullptr);
14141412

1415-
return convertTempToRValue(
1416-
Builder.CreateElementBitCast(Dest, ConvertTypeForMem(RValTy)),
1417-
RValTy, E->getExprLoc());
1413+
return convertTempToRValue(Dest.withElementType(ConvertTypeForMem(RValTy)),
1414+
RValTy, E->getExprLoc());
14181415
}
14191416

14201417
// Long case, when Order isn't obviously constant.
@@ -1484,15 +1481,14 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
14841481
return RValue::get(nullptr);
14851482

14861483
assert(Atomics.getValueSizeInBits() <= Atomics.getAtomicSizeInBits());
1487-
return convertTempToRValue(
1488-
Builder.CreateElementBitCast(Dest, ConvertTypeForMem(RValTy)),
1489-
RValTy, E->getExprLoc());
1484+
return convertTempToRValue(Dest.withElementType(ConvertTypeForMem(RValTy)),
1485+
RValTy, E->getExprLoc());
14901486
}
14911487

1492-
Address AtomicInfo::emitCastToAtomicIntPointer(Address addr) const {
1488+
Address AtomicInfo::castToAtomicIntPointer(Address addr) const {
14931489
llvm::IntegerType *ty =
14941490
llvm::IntegerType::get(CGF.getLLVMContext(), AtomicSizeInBits);
1495-
return CGF.Builder.CreateElementBitCast(addr, ty);
1491+
return addr.withElementType(ty);
14961492
}
14971493

14981494
Address AtomicInfo::convertToAtomicIntPointer(Address Addr) const {
@@ -1505,7 +1501,7 @@ Address AtomicInfo::convertToAtomicIntPointer(Address Addr) const {
15051501
Addr = Tmp;
15061502
}
15071503

1508-
return emitCastToAtomicIntPointer(Addr);
1504+
return castToAtomicIntPointer(Addr);
15091505
}
15101506

15111507
RValue AtomicInfo::convertAtomicTempToRValue(Address addr,
@@ -1577,7 +1573,7 @@ RValue AtomicInfo::ConvertIntToValueOrAtomic(llvm::Value *IntVal,
15771573
}
15781574

15791575
// Slam the integer into the temporary.
1580-
Address CastTemp = emitCastToAtomicIntPointer(Temp);
1576+
Address CastTemp = castToAtomicIntPointer(Temp);
15811577
CGF.Builder.CreateStore(IntVal, CastTemp)
15821578
->setVolatile(TempIsVolatile);
15831579

@@ -1755,7 +1751,7 @@ llvm::Value *AtomicInfo::convertRValueToInt(RValue RVal) const {
17551751
Address Addr = materializeRValue(RVal);
17561752

17571753
// Cast the temporary to the atomic int type and pull a value out.
1758-
Addr = emitCastToAtomicIntPointer(Addr);
1754+
Addr = castToAtomicIntPointer(Addr);
17591755
return CGF.Builder.CreateLoad(Addr);
17601756
}
17611757

@@ -1933,7 +1929,7 @@ void AtomicInfo::EmitAtomicUpdateOp(
19331929
/*NumReservedValues=*/2);
19341930
PHI->addIncoming(OldVal, CurBB);
19351931
Address NewAtomicAddr = CreateTempAlloca();
1936-
Address NewAtomicIntAddr = emitCastToAtomicIntPointer(NewAtomicAddr);
1932+
Address NewAtomicIntAddr = castToAtomicIntPointer(NewAtomicAddr);
19371933
if ((LVal.isBitField() && BFI.Size != ValueSizeInBits) ||
19381934
requiresMemSetZero(getAtomicAddress().getElementType())) {
19391935
CGF.Builder.CreateStore(PHI, NewAtomicIntAddr);
@@ -2015,7 +2011,7 @@ void AtomicInfo::EmitAtomicUpdateOp(llvm::AtomicOrdering AO, RValue UpdateRVal,
20152011
/*NumReservedValues=*/2);
20162012
PHI->addIncoming(OldVal, CurBB);
20172013
Address NewAtomicAddr = CreateTempAlloca();
2018-
Address NewAtomicIntAddr = emitCastToAtomicIntPointer(NewAtomicAddr);
2014+
Address NewAtomicIntAddr = castToAtomicIntPointer(NewAtomicAddr);
20192015
if ((LVal.isBitField() && BFI.Size != ValueSizeInBits) ||
20202016
requiresMemSetZero(getAtomicAddress().getElementType())) {
20212017
CGF.Builder.CreateStore(PHI, NewAtomicIntAddr);
@@ -2109,8 +2105,7 @@ void CodeGenFunction::EmitAtomicStore(RValue rvalue, LValue dest,
21092105
llvm::Value *intValue = atomics.convertRValueToInt(rvalue);
21102106

21112107
// Do the atomic store.
2112-
Address addr =
2113-
atomics.emitCastToAtomicIntPointer(atomics.getAtomicAddress());
2108+
Address addr = atomics.castToAtomicIntPointer(atomics.getAtomicAddress());
21142109
intValue = Builder.CreateIntCast(
21152110
intValue, addr.getElementType(), /*isSigned=*/false);
21162111
llvm::StoreInst *store = Builder.CreateStore(intValue, addr);

clang/lib/CodeGen/CGCXXABI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ void CGCXXABI::ReadArrayCookie(CodeGenFunction &CGF, Address ptr,
260260
llvm::Value *&numElements,
261261
llvm::Value *&allocPtr, CharUnits &cookieSize) {
262262
// Derive a char* in the same address space as the pointer.
263-
ptr = CGF.Builder.CreateElementBitCast(ptr, CGF.Int8Ty);
263+
ptr = ptr.withElementType(CGF.Int8Ty);
264264

265265
// If we don't need an array cookie, bail out early.
266266
if (!requiresArrayCookie(expr, eltTy)) {

clang/lib/CodeGen/CGNonTrivialStruct.cpp

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,8 @@ template <class Derived> struct GenFuncBase {
365365
llvm::ConstantInt::get(NumElts->getType(), BaseEltSize);
366366
llvm::Value *SizeInBytes =
367367
CGF.Builder.CreateNUWMul(BaseEltSizeVal, NumElts);
368-
Address BC = CGF.Builder.CreateElementBitCast(DstAddr, CGF.CGM.Int8Ty);
369-
llvm::Value *DstArrayEnd =
370-
CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, BC.getPointer(), SizeInBytes);
368+
llvm::Value *DstArrayEnd = CGF.Builder.CreateInBoundsGEP(
369+
CGF.Int8Ty, DstAddr.getPointer(), SizeInBytes);
371370
DstArrayEnd = CGF.Builder.CreateBitCast(
372371
DstArrayEnd, CGF.CGM.Int8PtrPtrTy, "dstarray.end");
373372
llvm::BasicBlock *PreheaderBB = CGF.Builder.GetInsertBlock();
@@ -426,9 +425,9 @@ template <class Derived> struct GenFuncBase {
426425
assert(Addr.isValid() && "invalid address");
427426
if (Offset.getQuantity() == 0)
428427
return Addr;
429-
Addr = CGF->Builder.CreateElementBitCast(Addr, CGF->CGM.Int8Ty);
428+
Addr = Addr.withElementType(CGF->CGM.Int8Ty);
430429
Addr = CGF->Builder.CreateConstInBoundsGEP(Addr, Offset.getQuantity());
431-
return CGF->Builder.CreateElementBitCast(Addr, CGF->CGM.Int8PtrTy);
430+
return Addr.withElementType(CGF->CGM.Int8PtrTy);
432431
}
433432

434433
Address getAddrWithOffset(Address Addr, CharUnits StructFieldOffset,
@@ -491,8 +490,7 @@ template <class Derived> struct GenFuncBase {
491490

492491
for (unsigned I = 0; I < N; ++I) {
493492
Alignments[I] = Addrs[I].getAlignment();
494-
Ptrs[I] = CallerCGF.Builder.CreateElementBitCast(
495-
Addrs[I], CallerCGF.CGM.Int8PtrTy).getPointer();
493+
Ptrs[I] = Addrs[I].getPointer();
496494
}
497495

498496
if (llvm::Function *F =
@@ -526,17 +524,15 @@ struct GenBinaryFunc : CopyStructVisitor<Derived, IsMove>,
526524
!llvm::has_single_bit<uint32_t>(Size.getQuantity())) {
527525
llvm::Value *SizeVal =
528526
llvm::ConstantInt::get(this->CGF->SizeTy, Size.getQuantity());
529-
DstAddr =
530-
this->CGF->Builder.CreateElementBitCast(DstAddr, this->CGF->Int8Ty);
531-
SrcAddr =
532-
this->CGF->Builder.CreateElementBitCast(SrcAddr, this->CGF->Int8Ty);
527+
DstAddr = DstAddr.withElementType(this->CGF->Int8Ty);
528+
SrcAddr = SrcAddr.withElementType(this->CGF->Int8Ty);
533529
this->CGF->Builder.CreateMemCpy(DstAddr, SrcAddr, SizeVal, false);
534530
} else {
535531
llvm::Type *Ty = llvm::Type::getIntNTy(
536532
this->CGF->getLLVMContext(),
537533
Size.getQuantity() * this->CGF->getContext().getCharWidth());
538-
DstAddr = this->CGF->Builder.CreateElementBitCast(DstAddr, Ty);
539-
SrcAddr = this->CGF->Builder.CreateElementBitCast(SrcAddr, Ty);
534+
DstAddr = DstAddr.withElementType(Ty);
535+
SrcAddr = SrcAddr.withElementType(Ty);
540536
llvm::Value *SrcVal = this->CGF->Builder.CreateLoad(SrcAddr, false);
541537
this->CGF->Builder.CreateStore(SrcVal, DstAddr, false);
542538
}
@@ -556,19 +552,17 @@ struct GenBinaryFunc : CopyStructVisitor<Derived, IsMove>,
556552
QualType RT = QualType(FD->getParent()->getTypeForDecl(), 0);
557553
llvm::Type *Ty = this->CGF->ConvertType(RT);
558554
Address DstAddr = this->getAddrWithOffset(Addrs[DstIdx], Offset);
559-
LValue DstBase = this->CGF->MakeAddrLValue(
560-
this->CGF->Builder.CreateElementBitCast(DstAddr, Ty), FT);
555+
LValue DstBase =
556+
this->CGF->MakeAddrLValue(DstAddr.withElementType(Ty), FT);
561557
DstLV = this->CGF->EmitLValueForField(DstBase, FD);
562558
Address SrcAddr = this->getAddrWithOffset(Addrs[SrcIdx], Offset);
563-
LValue SrcBase = this->CGF->MakeAddrLValue(
564-
this->CGF->Builder.CreateElementBitCast(SrcAddr, Ty), FT);
559+
LValue SrcBase =
560+
this->CGF->MakeAddrLValue(SrcAddr.withElementType(Ty), FT);
565561
SrcLV = this->CGF->EmitLValueForField(SrcBase, FD);
566562
} else {
567563
llvm::Type *Ty = this->CGF->ConvertTypeForMem(FT);
568-
Address DstAddr =
569-
this->CGF->Builder.CreateElementBitCast(Addrs[DstIdx], Ty);
570-
Address SrcAddr =
571-
this->CGF->Builder.CreateElementBitCast(Addrs[SrcIdx], Ty);
564+
Address DstAddr = Addrs[DstIdx].withElementType(Ty);
565+
Address SrcAddr = Addrs[SrcIdx].withElementType(Ty);
572566
DstLV = this->CGF->MakeAddrLValue(DstAddr, FT);
573567
SrcLV = this->CGF->MakeAddrLValue(SrcAddr, FT);
574568
}
@@ -666,7 +660,7 @@ struct GenDefaultInitialize
666660

667661
llvm::Constant *SizeVal = CGF->Builder.getInt64(Size.getQuantity());
668662
Address DstAddr = getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD);
669-
Address Loc = CGF->Builder.CreateElementBitCast(DstAddr, CGF->Int8Ty);
663+
Address Loc = DstAddr.withElementType(CGF->Int8Ty);
670664
CGF->Builder.CreateMemSet(Loc, CGF->Builder.getInt8(0), SizeVal,
671665
IsVolatile);
672666
}
@@ -818,8 +812,7 @@ void CodeGenFunction::destroyNonTrivialCStruct(CodeGenFunction &CGF,
818812
// such structure.
819813
void CodeGenFunction::defaultInitNonTrivialCStructVar(LValue Dst) {
820814
GenDefaultInitialize Gen(getContext());
821-
Address DstPtr =
822-
Builder.CreateElementBitCast(Dst.getAddress(*this), CGM.Int8PtrTy);
815+
Address DstPtr = Dst.getAddress(*this).withElementType(CGM.Int8PtrTy);
823816
Gen.setCGF(this);
824817
QualType QT = Dst.getType();
825818
QT = Dst.isVolatile() ? QT.withVolatile() : QT;
@@ -832,7 +825,7 @@ static void callSpecialFunction(G &&Gen, StringRef FuncName, QualType QT,
832825
std::array<Address, N> Addrs) {
833826
auto SetArtificialLoc = ApplyDebugLocation::CreateArtificial(CGF);
834827
for (unsigned I = 0; I < N; ++I)
835-
Addrs[I] = CGF.Builder.CreateElementBitCast(Addrs[I], CGF.CGM.Int8PtrTy);
828+
Addrs[I] = Addrs[I].withElementType(CGF.CGM.Int8PtrTy);
836829
QT = IsVolatile ? QT.withVolatile() : QT;
837830
Gen.callFunc(FuncName, QT, Addrs, CGF);
838831
}

clang/lib/CodeGen/MicrosoftCXXABI.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ void MicrosoftCXXABI::emitBeginCatch(CodeGenFunction &CGF,
937937
std::tuple<Address, llvm::Value *, const CXXRecordDecl *>
938938
MicrosoftCXXABI::performBaseAdjustment(CodeGenFunction &CGF, Address Value,
939939
QualType SrcRecordTy) {
940-
Value = CGF.Builder.CreateElementBitCast(Value, CGF.Int8Ty);
940+
Value = Value.withElementType(CGF.Int8Ty);
941941
const CXXRecordDecl *SrcDecl = SrcRecordTy->getAsCXXRecordDecl();
942942
const ASTContext &Context = getContext();
943943

@@ -1461,7 +1461,7 @@ Address MicrosoftCXXABI::adjustThisArgumentForVirtualFunctionCall(
14611461
if (Adjustment.isZero())
14621462
return This;
14631463

1464-
This = CGF.Builder.CreateElementBitCast(This, CGF.Int8Ty);
1464+
This = This.withElementType(CGF.Int8Ty);
14651465
assert(Adjustment.isPositive());
14661466
return CGF.Builder.CreateConstByteGEP(This, Adjustment);
14671467
}
@@ -1492,7 +1492,7 @@ Address MicrosoftCXXABI::adjustThisArgumentForVirtualFunctionCall(
14921492

14931493
Address Result = This;
14941494
if (ML.VBase) {
1495-
Result = CGF.Builder.CreateElementBitCast(Result, CGF.Int8Ty);
1495+
Result = Result.withElementType(CGF.Int8Ty);
14961496

14971497
const CXXRecordDecl *Derived = MD->getParent();
14981498
const CXXRecordDecl *VBase = ML.VBase;
@@ -1506,7 +1506,7 @@ Address MicrosoftCXXABI::adjustThisArgumentForVirtualFunctionCall(
15061506
}
15071507
if (!StaticOffset.isZero()) {
15081508
assert(StaticOffset.isPositive());
1509-
Result = CGF.Builder.CreateElementBitCast(Result, CGF.Int8Ty);
1509+
Result = Result.withElementType(CGF.Int8Ty);
15101510
if (ML.VBase) {
15111511
// Non-virtual adjustment might result in a pointer outside the allocated
15121512
// object, e.g. if the final overrider class is laid out after the virtual
@@ -2226,7 +2226,7 @@ llvm::Value *MicrosoftCXXABI::performThisAdjustment(CodeGenFunction &CGF,
22262226
if (TA.isEmpty())
22272227
return This.getPointer();
22282228

2229-
This = CGF.Builder.CreateElementBitCast(This, CGF.Int8Ty);
2229+
This = This.withElementType(CGF.Int8Ty);
22302230

22312231
llvm::Value *V;
22322232
if (TA.Virtual.isEmpty()) {
@@ -2237,7 +2237,7 @@ llvm::Value *MicrosoftCXXABI::performThisAdjustment(CodeGenFunction &CGF,
22372237
Address VtorDispPtr =
22382238
CGF.Builder.CreateConstInBoundsByteGEP(This,
22392239
CharUnits::fromQuantity(TA.Virtual.Microsoft.VtordispOffset));
2240-
VtorDispPtr = CGF.Builder.CreateElementBitCast(VtorDispPtr, CGF.Int32Ty);
2240+
VtorDispPtr = VtorDispPtr.withElementType(CGF.Int32Ty);
22412241
llvm::Value *VtorDisp = CGF.Builder.CreateLoad(VtorDispPtr, "vtordisp");
22422242
V = CGF.Builder.CreateGEP(This.getElementType(), This.getPointer(),
22432243
CGF.Builder.CreateNeg(VtorDisp));
@@ -2279,7 +2279,7 @@ MicrosoftCXXABI::performReturnAdjustment(CodeGenFunction &CGF, Address Ret,
22792279
return Ret.getPointer();
22802280

22812281
auto OrigTy = Ret.getType();
2282-
Ret = CGF.Builder.CreateElementBitCast(Ret, CGF.Int8Ty);
2282+
Ret = Ret.withElementType(CGF.Int8Ty);
22832283

22842284
llvm::Value *V = Ret.getPointer();
22852285
if (RA.Virtual.Microsoft.VBIndex) {
@@ -2323,8 +2323,7 @@ CharUnits MicrosoftCXXABI::getArrayCookieSizeImpl(QualType type) {
23232323
llvm::Value *MicrosoftCXXABI::readArrayCookieImpl(CodeGenFunction &CGF,
23242324
Address allocPtr,
23252325
CharUnits cookieSize) {
2326-
Address numElementsPtr =
2327-
CGF.Builder.CreateElementBitCast(allocPtr, CGF.SizeTy);
2326+
Address numElementsPtr = allocPtr.withElementType(CGF.SizeTy);
23282327
return CGF.Builder.CreateLoad(numElementsPtr);
23292328
}
23302329

@@ -2342,8 +2341,7 @@ Address MicrosoftCXXABI::InitializeArrayCookie(CodeGenFunction &CGF,
23422341
Address cookiePtr = newPtr;
23432342

23442343
// Write the number of elements into the appropriate slot.
2345-
Address numElementsPtr
2346-
= CGF.Builder.CreateElementBitCast(cookiePtr, CGF.SizeTy);
2344+
Address numElementsPtr = cookiePtr.withElementType(CGF.SizeTy);
23472345
CGF.Builder.CreateStore(numElements, numElementsPtr);
23482346

23492347
// Finally, compute a pointer to the actual data buffer by skipping
@@ -3143,12 +3141,10 @@ MicrosoftCXXABI::GetVBaseOffsetFromVBPtr(CodeGenFunction &CGF,
31433141
llvm::Value **VBPtrOut) {
31443142
CGBuilderTy &Builder = CGF.Builder;
31453143
// Load the vbtable pointer from the vbptr in the instance.
3146-
This = Builder.CreateElementBitCast(This, CGM.Int8Ty);
3147-
llvm::Value *VBPtr = Builder.CreateInBoundsGEP(
3148-
This.getElementType(), This.getPointer(), VBPtrOffset, "vbptr");
3149-
if (VBPtrOut) *VBPtrOut = VBPtr;
3150-
VBPtr = Builder.CreateBitCast(VBPtr,
3151-
CGM.Int32Ty->getPointerTo(0)->getPointerTo(This.getAddressSpace()));
3144+
llvm::Value *VBPtr = Builder.CreateInBoundsGEP(CGM.Int8Ty, This.getPointer(),
3145+
VBPtrOffset, "vbptr");
3146+
if (VBPtrOut)
3147+
*VBPtrOut = VBPtr;
31523148

31533149
CharUnits VBPtrAlign;
31543150
if (auto CI = dyn_cast<llvm::ConstantInt>(VBPtrOffset)) {
@@ -3169,7 +3165,6 @@ MicrosoftCXXABI::GetVBaseOffsetFromVBPtr(CodeGenFunction &CGF,
31693165
// Load an i32 offset from the vb-table.
31703166
llvm::Value *VBaseOffs =
31713167
Builder.CreateInBoundsGEP(CGM.Int32Ty, VBTable, VBTableIndex);
3172-
VBaseOffs = Builder.CreateBitCast(VBaseOffs, CGM.Int32Ty->getPointerTo(0));
31733168
return Builder.CreateAlignedLoad(CGM.Int32Ty, VBaseOffs,
31743169
CharUnits::fromQuantity(4), "vbase_offs");
31753170
}
@@ -3180,7 +3175,7 @@ llvm::Value *MicrosoftCXXABI::AdjustVirtualBase(
31803175
CodeGenFunction &CGF, const Expr *E, const CXXRecordDecl *RD,
31813176
Address Base, llvm::Value *VBTableOffset, llvm::Value *VBPtrOffset) {
31823177
CGBuilderTy &Builder = CGF.Builder;
3183-
Base = Builder.CreateElementBitCast(Base, CGM.Int8Ty);
3178+
Base = Base.withElementType(CGM.Int8Ty);
31843179
llvm::BasicBlock *OriginalBB = nullptr;
31853180
llvm::BasicBlock *SkipAdjustBB = nullptr;
31863181
llvm::BasicBlock *VBaseAdjustBB = nullptr;

0 commit comments

Comments
 (0)