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

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 6 12:36:05 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");
----------------
erichkeane wrote:

What should we do if `num_elements` ends up being a constant?  I wonder if we should either auto-const-fold here (to convert this to the other form if we can figure out the type?), or have a transform for it? 

Consider:

```
void foo() {
int N = 5;
int arr[N]; // Technically non-constant/a VLA, but we could 'promote' this in CIR since we know the size.
}
```

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


More information about the cfe-commits mailing list