[clang] [CIR] Implement emitNewArrayInit for constant and strings (PR #192666)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 17 15:02:44 PDT 2026


================
@@ -1154,14 +1204,54 @@ void CIRGenFunction::emitNewArrayInitializer(
   }
 
   // If this is value-initialization, we can usually use memset.
+  ImplicitValueInitExpr ivie(elementType);
   if (isa<ImplicitValueInitExpr>(init)) {
     if (tryMemsetInitialization())
       return;
-    cgm.errorNYI(init->getSourceRange(),
-                 "emitNewArrayInitializer: implicit value init");
-    return;
+    // Switch to an ImplicitValueInitExpr for the element type. This handles
+    // only one case: multidimensional array new of pointers to members. In
+    // all other cases, we already have an initializer for the array element.
+    init = &ivie;
+  }
+
+  // At this point we should have found an initializer for the individual
+  // elements of the array.
+  assert(getContext().hasSameUnqualifiedType(elementType, init->getType()) &&
+         "got wrong type of element to initialize");
+
+  // If we have a struct whose every field is value-initialized, we can
+  // usually use memset.
+  if (auto *ile = dyn_cast<InitListExpr>(init)) {
+
+    // If we have an empty initializer list, we can usually use memset.
+    if (ile->getNumInits() == 0 && tryMemsetInitialization())
+      return;
+
+    if (const RecordType *rtype =
----------------
andykaylor wrote:

auto?

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


More information about the cfe-commits mailing list