https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/227976

>From f93cd644df6f51f1d167a0b992f2636129a51693 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Thu, 1 Oct 2026 08:27:40 +0200
Subject: [PATCH] [clang][bytecode][NFC] Don't take a pointer in CheckArraySize

We used to assign a new value to NumElements, but we don't anymore.
---
 clang/lib/AST/ByteCode/Interp.h        |  4 ++--
 clang/lib/AST/ByteCode/InterpHelpers.h | 20 +++++++++-----------
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index aed1e17a97479..7592d9e3c68ea 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -3979,7 +3979,7 @@ inline bool AllocN(InterpState &S, CodePtr OpPC, PrimType 
T, const Expr *Source,
     return false;
 
   SizeT NumElements = S.Stk.pop<SizeT>();
-  if (!CheckArraySize(S, OpPC, &NumElements, primSize(T), IsNoThrow)) {
+  if (!CheckArraySize(S, OpPC, NumElements, primSize(T), IsNoThrow)) {
     if (!IsNoThrow)
       return false;
 
@@ -4021,7 +4021,7 @@ inline bool AllocCN(InterpState &S, CodePtr OpPC, const 
Descriptor *ElementDesc,
     return false;
 
   SizeT NumElements = S.Stk.pop<SizeT>();
-  if (!CheckArraySize(S, OpPC, &NumElements, ElementDesc->getSize(),
+  if (!CheckArraySize(S, OpPC, NumElements, ElementDesc->getSize(),
                       IsNoThrow)) {
     if (!IsNoThrow)
       return false;
diff --git a/clang/lib/AST/ByteCode/InterpHelpers.h 
b/clang/lib/AST/ByteCode/InterpHelpers.h
index 25881bbfe1a3b..738094361e8d1 100644
--- a/clang/lib/AST/ByteCode/InterpHelpers.h
+++ b/clang/lib/AST/ByteCode/InterpHelpers.h
@@ -134,7 +134,7 @@ inline bool Invalid(InterpState &S, CodePtr OpPC) {
 }
 
 template <typename SizeT>
-bool CheckArraySize(InterpState &S, CodePtr OpPC, SizeT *NumElements,
+bool CheckArraySize(InterpState &S, CodePtr OpPC, SizeT NumElements,
                     unsigned ElemSize, bool IsNoThrow) {
 
   if (ElemSize == 0)
@@ -145,7 +145,7 @@ bool CheckArraySize(InterpState &S, CodePtr OpPC, SizeT 
*NumElements,
 
   // Can't be too many elements if the bitwidth of NumElements is lower than
   // that of Descriptor::MaxArrayElemBytes.
-  if ((NumElements->bitWidth() - NumElements->isSigned()) <
+  if ((NumElements.bitWidth() - NumElements.isSigned()) <
       (sizeof(Descriptor::MaxArrayElemBytes) * 8))
     return true;
 
@@ -155,18 +155,16 @@ bool CheckArraySize(InterpState &S, CodePtr OpPC, SizeT 
*NumElements,
   // constructing the array, we catch this here.
   SizeT MaxElements = SizeT::from(Descriptor::MaxArrayElemBytes / ElemSize);
   assert(MaxElements.isPositive());
-  if (NumElements->toAPSInt().getActiveBits() >
+  if (NumElements.toAPSInt().getActiveBits() >
           ConstantArrayType::getMaxSizeBits(S.getASTContext()) ||
-      *NumElements > MaxElements) {
+      NumElements > MaxElements) {
     if (!IsNoThrow) {
-      const SourceInfo &Loc = S.Current->getSource(OpPC);
-
-      if (NumElements->isSigned() && NumElements->isNegative()) {
-        S.FFDiag(Loc, diag::note_constexpr_new_negative)
-            << NumElements->toDiagnosticString(S.getASTContext());
+      if (NumElements.isSigned() && NumElements.isNegative()) {
+        S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_new_negative)
+            << NumElements.toDiagnosticString(S.getASTContext());
       } else {
-        S.FFDiag(Loc, diag::note_constexpr_new_too_large)
-            << NumElements->toDiagnosticString(S.getASTContext());
+        S.FFDiag(S.Current->getSource(OpPC), 
diag::note_constexpr_new_too_large)
+            << NumElements.toDiagnosticString(S.getASTContext());
       }
     }
     return false;

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

Reply via email to