[clang] ff94a19 - [clang][bytecode] Fix APValues for arrays in dynamic allocations (#175176)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 9 07:37:53 PST 2026
Author: Timm Baeder
Date: 2026-01-09T16:37:48+01:00
New Revision: ff94a19f5ca8fa928517036a287cb3040bec4261
URL: https://github.com/llvm/llvm-project/commit/ff94a19f5ca8fa928517036a287cb3040bec4261
DIFF: https://github.com/llvm/llvm-project/commit/ff94a19f5ca8fa928517036a287cb3040bec4261.diff
LOG: [clang][bytecode] Fix APValues for arrays in dynamic allocations (#175176)
getType() returns just int for those instead of an array type, so the
previous condition resulted in the array index missing in the APValue's
LValuePath.
Added:
Modified:
clang/lib/AST/ByteCode/Pointer.cpp
clang/test/AST/ByteCode/new-delete.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp
index 5d11321d09079..c5e0fd83021d7 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -248,7 +248,7 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
unsigned Index = Ptr.getIndex();
QualType ElemType = Desc->getElemQualType();
Offset += (Index * ASTCtx.getTypeSizeInChars(ElemType));
- if (Ptr.getArray().getType()->isArrayType())
+ if (Ptr.getArray().getFieldDesc()->IsArray)
Path.push_back(APValue::LValuePathEntry::ArrayIndex(Index));
Ptr = Ptr.getArray();
} else {
@@ -278,7 +278,7 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
} else {
Offset += (Index * ASTCtx.getTypeSizeInChars(ElemType));
}
- if (Ptr.getArray().getType()->isArrayType())
+ if (Ptr.getArray().getFieldDesc()->IsArray)
Path.push_back(APValue::LValuePathEntry::ArrayIndex(Index));
Ptr = Ptr.getArray();
} else {
diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp
index e88e970c63ba4..d77107856c30f 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -14,6 +14,9 @@ constexpr int *Global = new int(12); // both-error {{must be initialized by a co
static_assert(*(new int(12)) == 12); // both-error {{not an integral constant expression}} \
// both-note {{allocation performed here was not deallocated}}
+static_assert((delete[] (new int[3] + 1), true)); // both-error {{not an integral constant expression}} \
+ // both-note {{delete of pointer to subobject '&{*new int[3]#0}[1]'}}
+
constexpr int a() {
new int(12); // both-note {{allocation performed here was not deallocated}}
More information about the cfe-commits
mailing list