@@ -289,7 +289,7 @@ void CIRGenFunction::initializeVTablePointer(mlir::Location loc,
289289 }
290290
291291 // Apply the offsets.
292- Address vtableField = loadCXXThisAddress ();
292+ Address classAddr = loadCXXThisAddress ();
293293 if (!nonVirtualOffset.isZero () || virtualOffset) {
294294 cgm.errorNYI (loc,
295295 " initializeVTablePointer: non-virtual and virtual offset" );
@@ -300,9 +300,9 @@ void CIRGenFunction::initializeVTablePointer(mlir::Location loc,
300300 // vtable field is derived from `this` pointer, therefore they should be in
301301 // the same addr space.
302302 assert (!cir::MissingFeatures::addressSpace ());
303- // TODO(cir): This should be cir.vtable.get_vptr.
304- vtableField = builder. createElementBitCast ( loc, vtableField,
305- vtableAddressPoint. getType ());
303+ auto vtablePtr = cir::VTableGetVPtrOp::create (
304+ builder, loc, builder. getPtrToVPtrType (), classAddr. getPointer ());
305+ Address vtableField = Address (vtablePtr, classAddr. getAlignment ());
306306 builder.createStore (loc, vtableAddressPoint, vtableField);
307307 assert (!cir::MissingFeatures::opTBAA ());
308308 assert (!cir::MissingFeatures::createInvariantGroup ());
@@ -657,6 +657,23 @@ Address CIRGenFunction::getAddressOfBaseClass(
657657 return value;
658658}
659659
660+ mlir::Value CIRGenFunction::getVTablePtr (mlir::Location loc, Address thisAddr,
661+ const CXXRecordDecl *rd) {
662+ auto vtablePtr = cir::VTableGetVPtrOp::create (
663+ builder, loc, builder.getPtrToVPtrType (), thisAddr.getPointer ());
664+ Address vtablePtrAddr = Address (vtablePtr, thisAddr.getAlignment ());
665+
666+ auto vtable = builder.createLoad (loc, vtablePtrAddr);
667+ assert (!cir::MissingFeatures::opTBAA ());
668+
669+ if (cgm.getCodeGenOpts ().OptimizationLevel > 0 &&
670+ cgm.getCodeGenOpts ().StrictVTablePointers ) {
671+ assert (!cir::MissingFeatures::createInvariantGroup ());
672+ }
673+
674+ return vtable;
675+ }
676+
660677void CIRGenFunction::emitCXXConstructorCall (const clang::CXXConstructorDecl *d,
661678 clang::CXXCtorType type,
662679 bool forVirtualBase,
0 commit comments