@@ -662,21 +662,19 @@ static Address ApplyNonVirtualAndVirtualOffset(
662
662
// Compute the offset from the static and dynamic components.
663
663
mlir::Value baseOffset;
664
664
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 ());
672
665
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 ());
673
673
baseOffset = CGF.getBuilder ().createBinop (
674
674
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.
680
678
return CGF.getBuilder ().createBaseClassAddr (
681
679
loc, addr, baseValueTy, nonVirtualOffset.getQuantity (),
682
680
assumeNotNull);
@@ -725,6 +723,7 @@ void CIRGenFunction::initializeVTablePointer(mlir::Location loc,
725
723
mlir::Value VirtualOffset{};
726
724
CharUnits NonVirtualOffset = CharUnits::Zero ();
727
725
726
+ mlir::Type BaseValueTy;
728
727
if (CGM.getCXXABI ().isVirtualOffsetNeededForVTableField (*this , Vptr)) {
729
728
// We need to use the virtual base offset offset because the virtual base
730
729
// might have a different offset in the most derived class.
@@ -734,14 +733,15 @@ void CIRGenFunction::initializeVTablePointer(mlir::Location loc,
734
733
} else {
735
734
// We can just use the base offset in the complete class.
736
735
NonVirtualOffset = Vptr.Base .getBaseOffset ();
736
+ BaseValueTy = convertType (getContext ().getTagDeclType (Vptr.Base .getBase ()));
737
737
}
738
738
739
739
// Apply the offsets.
740
740
Address VTableField = LoadCXXThisAddress ();
741
741
if (!NonVirtualOffset.isZero () || VirtualOffset) {
742
742
VTableField = ApplyNonVirtualAndVirtualOffset (
743
743
loc, *this , VTableField, NonVirtualOffset, VirtualOffset,
744
- Vptr.VTableClass , Vptr.NearestVBase );
744
+ Vptr.VTableClass , Vptr.NearestVBase , BaseValueTy );
745
745
}
746
746
747
747
// Finally, store the address point. Use the same CIR types as the field.
0 commit comments