================
@@ -1305,7 +1305,21 @@ void
CIRGenFunction::emitNullInitialization(mlir::Location loc, Address destPtr,
// TODO: there are other patterns besides zero that we can usefully memset,
// like -1, which happens to be the pattern used by member-pointers.
if (!cgm.getTypes().isZeroInitializable(ty)) {
- cgm.errorNYI(loc, "type is not zero initializable");
+ // Classic codegen handles non-zero-init VLAs here via emitNonZeroVLAInit.
+ // In CIR, getTypeSizeInChars returns 0 for VLAs, so they are caught by
+ // the errorNYI above.
+ //
+ // Guard: emitNullConstant calls errorNYI for virtual bases and returns {},
+ // which would crash builder.getConstant; report the NYI here instead.
+ if (const auto *rd = ty->getAsCXXRecordDecl(); rd && rd->getNumVBases()) {
+ cgm.errorNYI(loc,
+ "emitNullInitialization: non-zero-init type with virtual "
+ "bases");
+ return;
+ }
+ mlir::Value nullVal = cgm.emitNullConstant(ty, loc);
----------------
adams381 wrote:
Added the assert: `ty->isMemberDataPointerType() || ty->isRecordType()`. Record
stays because the tests null-init a struct, not a bare member pointer, and we
only reach here when `ty` isn't zero-initializable -- so the record has a
member pointer in it. Arrays/anything else assert now.
https://github.com/llvm/llvm-project/pull/201654
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits