llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> If the size isn't a number, we can't convert it to a numeric value. --- Full diff: https://github.com/llvm/llvm-project/pull/237852.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/InterpHelpers.h (+3) - (modified) clang/test/AST/ByteCode/new-delete.cpp (+11) ``````````diff diff --git a/clang/lib/AST/ByteCode/InterpHelpers.h b/clang/lib/AST/ByteCode/InterpHelpers.h index 8a99406eb1b67..e6e9d73ee1540 100644 --- a/clang/lib/AST/ByteCode/InterpHelpers.h +++ b/clang/lib/AST/ByteCode/InterpHelpers.h @@ -157,6 +157,9 @@ bool CheckArraySize(InterpState &S, CodePtr OpPC, SizeT NumElements, if (ElemSize == 0) return true; + if (!NumElements.isNumber()) + return Invalid(S, OpPC); + // 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 a9a297a10e76c..40454a8d1969a 100644 --- a/clang/test/AST/ByteCode/new-delete.cpp +++ b/clang/test/AST/ByteCode/new-delete.cpp @@ -1322,6 +1322,17 @@ namespace ZeroSizeElems { static_assert(foo()); } +namespace NonNumber { + constexpr int m() { // both-error {{never produces a constant expression}} + int baz; + int *p = new int [(long)&baz]; // both-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}} \ + // both-note {{subexpression not valid in a constant expression}} + return 0; + } + static_assert(m() == 0); // both-error {{not an integral constant expression}} \ + // both-note {{in call to}} +} + #else /// Make sure we reject this prior to C++20 constexpr int a() { // both-error {{never produces a constant expression}} `````````` </details> https://github.com/llvm/llvm-project/pull/237852 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
