Author: Timm Baeder Date: 2026-06-25T11:57:44+02:00 New Revision: be8255a294a8fe9f404fcde0bd92b507cf152670
URL: https://github.com/llvm/llvm-project/commit/be8255a294a8fe9f404fcde0bd92b507cf152670 DIFF: https://github.com/llvm/llvm-project/commit/be8255a294a8fe9f404fcde0bd92b507cf152670.diff LOG: [clang][bytecode] Fix ImplicitValueInitExpr array initializer (#205754) ... if the allocation is dynamic and the array is multidimensional. Added: Modified: clang/lib/AST/ByteCode/Compiler.cpp clang/test/AST/ByteCode/new-delete.cpp Removed: ################################################################################ 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
