@@ -654,7 +654,8 @@ void CIRGenFunction::emitCtorPrologue(const CXXConstructorDecl *CD,
654654static Address ApplyNonVirtualAndVirtualOffset (
655655 mlir::Location loc, CIRGenFunction &CGF, Address addr,
656656 CharUnits nonVirtualOffset, mlir::Value virtualOffset,
657- const CXXRecordDecl *derivedClass, const CXXRecordDecl *nearestVBase) {
657+ const CXXRecordDecl *derivedClass, const CXXRecordDecl *nearestVBase,
658+ mlir::Type baseValueTy = {}, bool assumeNotNull = true ) {
658659 // Assert that we have something to do.
659660 assert (!nonVirtualOffset.isZero () || virtualOffset != nullptr );
660661
@@ -671,6 +672,14 @@ static Address ApplyNonVirtualAndVirtualOffset(
671672 if (virtualOffset) {
672673 baseOffset = CGF.getBuilder ().createBinop (
673674 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 ();
680+ return CGF.getBuilder ().createBaseClassAddr (
681+ loc, addr, baseValueTy, nonVirtualOffset.getQuantity (),
682+ assumeNotNull);
674683 }
675684 } else {
676685 baseOffset = virtualOffset;
@@ -1589,22 +1598,17 @@ CIRGenFunction::getAddressOfBaseClass(Address Value,
15891598 if (VBase) {
15901599 VirtualOffset = CGM.getCXXABI ().getVirtualBaseClassOffset (
15911600 getLoc (Loc), *this , Value, Derived, VBase);
1592- } else {
1593- Value = builder.createBaseClassAddr (getLoc (Loc), Value, BaseValueTy,
1594- NonVirtualOffset.getQuantity (),
1595- /* assumeNotNull=*/ not NullCheckValue);
15961601 }
15971602
15981603 // Apply both offsets.
1599- // FIXME: remove condition.
1600- if (VBase)
1601- Value = ApplyNonVirtualAndVirtualOffset (getLoc (Loc), *this , Value,
1602- NonVirtualOffset, VirtualOffset,
1603- Derived, VBase);
1604+ Value = ApplyNonVirtualAndVirtualOffset (
1605+ getLoc (Loc), *this , Value, NonVirtualOffset, VirtualOffset, Derived,
1606+ VBase, BaseValueTy, not NullCheckValue);
16041607
16051608 // Cast to the destination type.
16061609 if (VBase)
16071610 Value = Value.withElementType (BaseValueTy);
1611+
16081612 return Value;
16091613}
16101614
0 commit comments