@@ -662,21 +662,19 @@ static Address ApplyNonVirtualAndVirtualOffset(
662662 // Compute the offset from the static and dynamic components.
663663 mlir::Value baseOffset;
664664 if (!nonVirtualOffset.isZero ()) {
665- mlir::Type OffsetType =
666- (CGF.CGM .getTarget ().getCXXABI ().isItaniumFamily () &&
667- CGF.CGM .getItaniumVTableContext ().isRelativeLayout ())
668- ? CGF.SInt32Ty
669- : CGF.PtrDiffTy ;
670- baseOffset = CGF.getBuilder ().getConstInt (loc, OffsetType,
671- nonVirtualOffset.getQuantity ());
672665 if (virtualOffset) {
666+ mlir::Type OffsetType =
667+ (CGF.CGM .getTarget ().getCXXABI ().isItaniumFamily () &&
668+ CGF.CGM .getItaniumVTableContext ().isRelativeLayout ())
669+ ? CGF.SInt32Ty
670+ : CGF.PtrDiffTy ;
671+ baseOffset = CGF.getBuilder ().getConstInt (loc, OffsetType,
672+ nonVirtualOffset.getQuantity ());
673673 baseOffset = CGF.getBuilder ().createBinop (
674674 virtualOffset, cir::BinOpKind::Add, baseOffset);
675- } else if (baseValueTy) {
676- // TODO(cir): this should be used as a firt class in this function for the
677- // nonVirtualOffset cases, but all users of this function need to be
678- // updated first.
679- baseOffset.getDefiningOp ()->erase ();
675+ } else {
676+ assert (baseValueTy && " expected base type" );
677+ // If no virtualOffset is present this is the final stop.
680678 return CGF.getBuilder ().createBaseClassAddr (
681679 loc, addr, baseValueTy, nonVirtualOffset.getQuantity (),
682680 assumeNotNull);
@@ -725,6 +723,7 @@ void CIRGenFunction::initializeVTablePointer(mlir::Location loc,
725723 mlir::Value VirtualOffset{};
726724 CharUnits NonVirtualOffset = CharUnits::Zero ();
727725
726+ mlir::Type BaseValueTy;
728727 if (CGM.getCXXABI ().isVirtualOffsetNeededForVTableField (*this , Vptr)) {
729728 // We need to use the virtual base offset offset because the virtual base
730729 // might have a different offset in the most derived class.
@@ -734,14 +733,15 @@ void CIRGenFunction::initializeVTablePointer(mlir::Location loc,
734733 } else {
735734 // We can just use the base offset in the complete class.
736735 NonVirtualOffset = Vptr.Base .getBaseOffset ();
736+ BaseValueTy = convertType (getContext ().getTagDeclType (Vptr.Base .getBase ()));
737737 }
738738
739739 // Apply the offsets.
740740 Address VTableField = LoadCXXThisAddress ();
741741 if (!NonVirtualOffset.isZero () || VirtualOffset) {
742742 VTableField = ApplyNonVirtualAndVirtualOffset (
743743 loc, *this , VTableField, NonVirtualOffset, VirtualOffset,
744- Vptr.VTableClass , Vptr.NearestVBase );
744+ Vptr.VTableClass , Vptr.NearestVBase , BaseValueTy );
745745 }
746746
747747 // Finally, store the address point. Use the same CIR types as the field.
0 commit comments