[clang] [CIR] Handle non-zero-initializable types in emitNullInitialization (PR #201654)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 9 09:49:55 PDT 2026
================
@@ -1302,10 +1302,19 @@ void CIRGenFunction::emitNullInitialization(mlir::Location loc, Address destPtr,
// If the type contains a pointer to data member we can't memset it to zero.
// Instead, create a null constant and copy it to the destination.
- // TODO: there are other patterns besides zero that we can usefully memset,
- // like -1, which happens to be the pattern used by member-pointers.
+ // Member pointers use -1 as the null value, so a plain zero store would be
+ // incorrect; emitNullConstant produces the right per-field pattern.
if (!cgm.getTypes().isZeroInitializable(ty)) {
- cgm.errorNYI(loc, "type is not zero initializable");
+ // emitNullConstant does not yet handle types with virtual bases.
+ if (const auto *rd = ty->getAsCXXRecordDecl(); rd && rd->getNumVBases()) {
+ cgm.errorNYI(loc,
----------------
adams381 wrote:
Yes. emitNullConstant calls errorNYI for virtual bases and returns {}, which would then crash builder.getConstant. The guard reports the NYI cleanly at this call site instead. Added a comment explaining that.
https://github.com/llvm/llvm-project/pull/201654
More information about the cfe-commits
mailing list