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

>From d4b850c6f7252fda50ff6ad5e74832daba3d9f19 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Thu, 25 Jun 2026 14:22:32 +0200
Subject: [PATCH] [clang][bytecode] Fix divisin by zero in CXXNewExpr handling

---
 clang/lib/AST/ByteCode/InterpHelpers.h |  4 ++++
 clang/test/AST/ByteCode/new-delete.cpp | 11 +++++++++++
 2 files changed, 15 insertions(+)

diff --git a/clang/lib/AST/ByteCode/InterpHelpers.h 
b/clang/lib/AST/ByteCode/InterpHelpers.h
index da305dcb565d5..4d908d1e44546 100644
--- a/clang/lib/AST/ByteCode/InterpHelpers.h
+++ b/clang/lib/AST/ByteCode/InterpHelpers.h
@@ -118,6 +118,10 @@ inline bool Invalid(InterpState &S, CodePtr OpPC) {
 template <typename SizeT>
 bool CheckArraySize(InterpState &S, CodePtr OpPC, SizeT *NumElements,
                     unsigned ElemSize, bool IsNoThrow) {
+
+  if (ElemSize == 0)
+    return true;
+
   // FIXME: Both the SizeT::from() as well as the
   // NumElements.toAPSInt() in this function are rather expensive.
 
diff --git a/clang/test/AST/ByteCode/new-delete.cpp 
b/clang/test/AST/ByteCode/new-delete.cpp
index 0e2db787ca48c..b9c1e089e6536 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -1278,6 +1278,17 @@ namespace NonPrimitiveImplicitValueInitExpr {
   static_assert(m() == 0);
 }
 
+namespace ZeroSizeElems {
+  typedef int U[0];
+
+  constexpr bool foo() {
+    auto p = new U[3.14]; // both-warning {{implicit conversion}}
+    delete[] p;
+    return true;
+  }
+  static_assert(foo());
+}
+
 #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

Reply via email to