https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/175176

getType() returns just int for those instead of an array type, so the previous 
condition resulted in the array index missing int the APValue's LValuePath.

>From 6907b0e932c9a006d3a8fcfa20acc089520e8208 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Fri, 9 Jan 2026 15:23:30 +0100
Subject: [PATCH] [clang][bytecode] Fix APValues for arrays in dynamic
 allocations

getType() returns just int for those instead of an array type, so the
previous condition resulted in the array index missing int the APValue's
LValuePath.
---
 clang/lib/AST/ByteCode/Pointer.cpp     | 4 ++--
 clang/test/AST/ByteCode/new-delete.cpp | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

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 9345946a31e99..625f82c973372 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}}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to