[clang] [CIR] Add support for variable sized array new. (PR #190656)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 7 11:36:29 PDT 2026


================
@@ -4592,9 +4608,20 @@ def CIR_ArrayCtor : CIR_Op<"array.ctor"> {
         $_state.addOperands(ValueRange{addr});
         $_builder.createBlock(r);
         regionBuilder($_builder, $_state.location);
+    }]>,
+    // Dynamic form: addr is ptr<T>, num_elements is the runtime count.
+    OpBuilder<(ins "mlir::Value":$addr, "mlir::Value":$num_elements,
+      "llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)>":$regionBuilder), [{
+        assert(regionBuilder && "builder callback expected");
----------------
andykaylor wrote:

I don't think we should attempt that level of constant folding in the front end. We get the array length as an l-value. To constant fold it, we'd have to look back at where it was written and infer the constant from that. That's kind of trivial, but I don't see much value in it at this stage.

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


More information about the cfe-commits mailing list