[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
================
@@ -1006,8 +1010,55 @@ void CIRGenFunction::emitNewArrayInitializer(
// Initializing from a (braced) string literal is a special case; the init
// list element does not initialize a (single) array element.
if ((ile && ile->isStringLiteralInit()) || sl || ocee) {
- cgm.errorNYI(ile->getSourceRange(),
- "emitNewArrayInitializer: string literal init");
+ if (!ile)
+ init = ignoreParen;
+
+ // Initialize the initial portion of length equal to that of the string
+ // literal. The allocation must be for at least this much; we emitted a
+ // check for that earlier. Since we intend to use a cir.copy here, we must
+ // introduce a cast to the string-literal-size here, so that cir.copy does
+ // the right thing.
+
+ const Expr *initExpr = ile ? ile->getInit(0) : init;
+ mlir::Type initExprTy = convertType(initExpr->getType());
+ Address coercedPtrTy{
+ builder.createBitcast(curPtr.getPointer(),
+ builder.getPointerTo(initExprTy)),
+ curPtr.getAlignment()};
----------------
andykaylor wrote:
```suggestion
Address coercedPtr = curPtr.withElementType(builder, initExprTy);
```
This ends up doing the same thing internally, but I think it's cleaner. Why did you have "Ty" in the name?
https://github.com/llvm/llvm-project/pull/192666
More information about the cfe-commits
mailing list