[clang] [clang][bytecode] Fix ImplicitValueInitExpr array initializer (PR #205754)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 25 02:13:27 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
... if the allocation is dynamic and the array is multidimensional.
---
Full diff: https://github.com/llvm/llvm-project/pull/205754.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+10-5)
- (modified) clang/test/AST/ByteCode/new-delete.cpp (+11)
``````````diff
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}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/205754
More information about the cfe-commits
mailing list