@@ -467,6 +467,10 @@ class MicrosoftCXXABI : public CGCXXABI {
467
467
return GetVBaseOffsetFromVBPtr (CGF, Base, VBPOffset, VBTOffset, VBPtr);
468
468
}
469
469
470
+ std::pair<llvm::Value *, llvm::Value *>
471
+ performBaseAdjustment (CodeGenFunction &CGF, llvm::Value *Value,
472
+ QualType SrcRecordTy);
473
+
470
474
// / \brief Performs a full virtual base adjustment. Used to dereference
471
475
// / pointers to members of virtual bases.
472
476
llvm::Value *AdjustVirtualBase (CodeGenFunction &CGF, const Expr *E,
@@ -691,31 +695,25 @@ void MicrosoftCXXABI::emitRethrow(CodeGenFunction &CGF, bool isNoReturn) {
691
695
CGF.EmitRuntimeCallOrInvoke (Fn, Args);
692
696
}
693
697
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) {
711
701
Value = CGF.Builder .CreateBitCast (Value, CGF.Int8PtrTy );
712
702
const CXXRecordDecl *SrcDecl = SrcRecordTy->getAsCXXRecordDecl ();
703
+ const ASTContext &Context = CGF.getContext ();
713
704
714
- if (CGF. getContext () .getASTRecordLayout (SrcDecl).hasExtendableVFPtr ())
705
+ if (Context .getASTRecordLayout (SrcDecl).hasExtendableVFPtr ())
715
706
return std::make_pair (Value, llvm::ConstantInt::get (CGF.Int32Ty , 0 ));
716
707
717
708
// 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 ());
719
717
Value = CGF.Builder .CreateInBoundsGEP (Value, Offset);
720
718
Offset = CGF.Builder .CreateTrunc (Offset, CGF.Int32Ty );
721
719
return std::make_pair (Value, Offset);
0 commit comments