Skip to content

Commit 5bc883f

Browse files
committed
MS ABI: Simplify the code which performs base adjustments
llvm-svn: 230722
1 parent 0b0cafc commit 5bc883f

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

clang/lib/CodeGen/MicrosoftCXXABI.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,10 @@ class MicrosoftCXXABI : public CGCXXABI {
467467
return GetVBaseOffsetFromVBPtr(CGF, Base, VBPOffset, VBTOffset, VBPtr);
468468
}
469469

470+
std::pair<llvm::Value *, llvm::Value *>
471+
performBaseAdjustment(CodeGenFunction &CGF, llvm::Value *Value,
472+
QualType SrcRecordTy);
473+
470474
/// \brief Performs a full virtual base adjustment. Used to dereference
471475
/// pointers to members of virtual bases.
472476
llvm::Value *AdjustVirtualBase(CodeGenFunction &CGF, const Expr *E,
@@ -691,31 +695,25 @@ void MicrosoftCXXABI::emitRethrow(CodeGenFunction &CGF, bool isNoReturn) {
691695
CGF.EmitRuntimeCallOrInvoke(Fn, Args);
692696
}
693697

694-
/// \brief Gets the offset to the virtual base that contains the vfptr for
695-
/// MS-ABI polymorphic types.
696-
static llvm::Value *getPolymorphicOffset(CodeGenFunction &CGF,
697-
const CXXRecordDecl *RD,
698-
llvm::Value *Value) {
699-
const ASTContext &Context = RD->getASTContext();
700-
for (const CXXBaseSpecifier &Base : RD->vbases())
701-
if (Context.getASTRecordLayout(Base.getType()->getAsCXXRecordDecl())
702-
.hasExtendableVFPtr())
703-
return CGF.CGM.getCXXABI().GetVirtualBaseClassOffset(
704-
CGF, Value, RD, Base.getType()->getAsCXXRecordDecl());
705-
llvm_unreachable("One of our vbases should be polymorphic.");
706-
}
707-
708-
static std::pair<llvm::Value *, llvm::Value *>
709-
performBaseAdjustment(CodeGenFunction &CGF, llvm::Value *Value,
710-
QualType SrcRecordTy) {
698+
std::pair<llvm::Value *, llvm::Value *>
699+
MicrosoftCXXABI::performBaseAdjustment(CodeGenFunction &CGF, llvm::Value *Value,
700+
QualType SrcRecordTy) {
711701
Value = CGF.Builder.CreateBitCast(Value, CGF.Int8PtrTy);
712702
const CXXRecordDecl *SrcDecl = SrcRecordTy->getAsCXXRecordDecl();
703+
const ASTContext &Context = CGF.getContext();
713704

714-
if (CGF.getContext().getASTRecordLayout(SrcDecl).hasExtendableVFPtr())
705+
if (Context.getASTRecordLayout(SrcDecl).hasExtendableVFPtr())
715706
return std::make_pair(Value, llvm::ConstantInt::get(CGF.Int32Ty, 0));
716707

717708
// Perform a base adjustment.
718-
llvm::Value *Offset = getPolymorphicOffset(CGF, SrcDecl, Value);
709+
const CXXBaseSpecifier *PolymorphicBase = std::find_if(
710+
SrcDecl->vbases_begin(), SrcDecl->vbases_end(),
711+
[&](const CXXBaseSpecifier &Base) {
712+
const CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl();
713+
return Context.getASTRecordLayout(BaseDecl).hasExtendableVFPtr();
714+
});
715+
llvm::Value *Offset = GetVirtualBaseClassOffset(
716+
CGF, Value, SrcDecl, PolymorphicBase->getType()->getAsCXXRecordDecl());
719717
Value = CGF.Builder.CreateInBoundsGEP(Value, Offset);
720718
Offset = CGF.Builder.CreateTrunc(Offset, CGF.Int32Ty);
721719
return std::make_pair(Value, Offset);

0 commit comments

Comments
 (0)