Timm =?utf-8?q?Bäder?= <tbae...@redhat.com> Message-ID: In-Reply-To: <llvm.org/llvm/llvm-project/pull/149...@github.com>
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/149050 >From 361077f6389b7764f1b9ea3084a6caeb51d4cd52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Wed, 16 Jul 2025 11:40:07 +0200 Subject: [PATCH 1/2] [clang][bytecode] Fix contains check using llvm::find We need to compare to the end() interator. --- clang/lib/AST/ByteCode/Interp.cpp | 3 ++- clang/test/AST/ByteCode/placement-new.cpp | 8 ++++++++ clang/test/SemaCXX/cxx2c-constexpr-placement-new.cpp | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 457de2bed37d6..bb9053164930b 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -575,7 +575,8 @@ bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { // The This pointer is writable in constructors and destructors, // even if isConst() returns true. - if (llvm::find(S.InitializingBlocks, Ptr.block())) + if (llvm::find(S.InitializingBlocks, Ptr.block()) != + S.InitializingBlocks.end()) return true; const QualType Ty = Ptr.getType(); diff --git a/clang/test/AST/ByteCode/placement-new.cpp b/clang/test/AST/ByteCode/placement-new.cpp index 670def2d5870e..b587cd6eaf89c 100644 --- a/clang/test/AST/ByteCode/placement-new.cpp +++ b/clang/test/AST/ByteCode/placement-new.cpp @@ -486,3 +486,11 @@ namespace bitcast { } static_assert(foo() == 0); } + +constexpr int modify_const_variable() { + const int a = 10; + new ((int *)&a) int(12); // both-note {{modification of object of const-qualified type 'const int' is not allowed in a constant expression}} + return a; +} +static_assert(modify_const_variable()); // both-error {{not an integral constant expression}} \ + // both-note {{in call to}} diff --git a/clang/test/SemaCXX/cxx2c-constexpr-placement-new.cpp b/clang/test/SemaCXX/cxx2c-constexpr-placement-new.cpp index 6f6f9b04aa392..4cf0e9ffe1d64 100644 --- a/clang/test/SemaCXX/cxx2c-constexpr-placement-new.cpp +++ b/clang/test/SemaCXX/cxx2c-constexpr-placement-new.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -std=c++2c -verify %s +// RUN: %clang_cc1 -std=c++2c -verify %s -fexperimental-new-constant-interpreter namespace std { >From 033b51d7dfd7b76348c9dea8b2dde5a236f5ceda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Wed, 16 Jul 2025 12:20:45 +0200 Subject: [PATCH 2/2] Use is_contained --- clang/lib/AST/ByteCode/Interp.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index bb9053164930b..0bac69e6cc8a2 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -575,8 +575,7 @@ bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { // The This pointer is writable in constructors and destructors, // even if isConst() returns true. - if (llvm::find(S.InitializingBlocks, Ptr.block()) != - S.InitializingBlocks.end()) + if (llvm::is_contained(S.InitializingBlocks, Ptr.block())) return true; const QualType Ty = Ptr.getType(); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits