Author: Timm Baeder Date: 2026-06-26T09:16:18+02:00 New Revision: 9d6e0dd15a5f9aa975ffaa45da183c6c05cb8a03
URL: https://github.com/llvm/llvm-project/commit/9d6e0dd15a5f9aa975ffaa45da183c6c05cb8a03 DIFF: https://github.com/llvm/llvm-project/commit/9d6e0dd15a5f9aa975ffaa45da183c6c05cb8a03.diff LOG: [clang][bytecode] Fix division by zero in CXXNewExpr handling (#205800) Added: Modified: clang/lib/AST/ByteCode/InterpHelpers.h clang/test/AST/ByteCode/new-delete.cpp Removed: ################################################################################ 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
