[clang] [CIR] Handle non-zero-initializable types in emitNullInitialization (PR #201654)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 22 10:46:20 PDT 2026


================
@@ -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);
----------------
erichkeane wrote:

You've misunderstood here I think.  I was saying we can do away wtih the assert (skip it) and let the NYI  in emitNullConstant catch it.

As far as the assert I WAS requesting: Any case where `ty` is not pointer-to-member, since you don't have any tests for anything else.

https://github.com/llvm/llvm-project/pull/201654


More information about the cfe-commits mailing list