https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/205754
... if the allocation is dynamic and the array is multidimensional. >From dc97c1eda18c75cbb1b55e9bf1bd8ecd9fb4a57e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Thu, 25 Jun 2026 11:11:01 +0200 Subject: [PATCH] [clang][bytecode] Fix ImplicitValueInitExpr array initializer ... if the allocation is dynamic and the array is multidimensional. --- clang/lib/AST/ByteCode/Compiler.cpp | 15 ++++++++++----- clang/test/AST/ByteCode/new-delete.cpp | 11 +++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index d2e28e516eaab..cadb040048384 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -4102,11 +4102,16 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) { DynamicInit->getType()->isArrayType()) { QualType ElemType = DynamicInit->getType()->getAsArrayTypeUnsafe()->getElementType(); - PrimType InitT = classifyPrim(ElemType); - if (!this->visitZeroInitializer(InitT, ElemType, E)) - return false; - if (!this->emitStorePop(InitT, E)) - return false; + if (OptPrimType InitT = classify(ElemType)) { + if (!this->visitZeroInitializer(*InitT, ElemType, E)) + return false; + if (!this->emitStorePop(*InitT, E)) + return false; + } else { + assert(ElemType->isArrayType()); + if (!this->visitZeroArrayInitializer(ElemType, E)) + return false; + } } else if (DynamicInit) { if (OptPrimType InitT = classify(DynamicInit)) { if (!this->visit(DynamicInit)) diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp index 43d770d5c9e61..0e2db787ca48c 100644 --- a/clang/test/AST/ByteCode/new-delete.cpp +++ b/clang/test/AST/ByteCode/new-delete.cpp @@ -1267,6 +1267,17 @@ namespace FreeNonBlockPointer { static_assert(foo() == 10); // both-error {{not an integral constant expression}} } +namespace NonPrimitiveImplicitValueInitExpr { + constexpr int m() { + int r; + auto foo = new int[2][4][1]{}; + r = foo[0][2][0]; + delete[] foo; + return r; + } + static_assert(m() == 0); +} + #else /// Make sure we reject this prior to C++20 constexpr int a() { // both-error {{never produces a constant expression}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
