[clang] 319feac - [clang][bytecode] Fix AccessKinds in placement new CheckStore() call (#141123)
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 23 04:00:59 PDT 2025
Author: Timm Baeder
Date: 2025-05-23T13:00:57+02:00
New Revision: 319feac43d8d1362307076ade85dc6d5bc4b4007
URL: https://github.com/llvm/llvm-project/commit/319feac43d8d1362307076ade85dc6d5bc4b4007
DIFF: https://github.com/llvm/llvm-project/commit/319feac43d8d1362307076ade85dc6d5bc4b4007.diff
LOG: [clang][bytecode] Fix AccessKinds in placement new CheckStore() call (#141123)
CheckStore is for assignments, but we're constructing something here, so
pass AK_Construct instead. We already diagnosed the test case, but as an
assignment.
Added:
Modified:
clang/lib/AST/ByteCode/Interp.cpp
clang/test/AST/ByteCode/placement-new.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 17660570d24cd..6d6beef73a726 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1703,9 +1703,25 @@ bool CheckNewTypeMismatch(InterpState &S, CodePtr OpPC, const Expr *E,
std::optional<uint64_t> ArraySize) {
const Pointer &Ptr = S.Stk.peek<Pointer>();
+ // Similar to CheckStore(), but with the additional CheckTemporary() call and
+ // the AccessKinds are
diff erent.
if (!CheckTemporary(S, OpPC, Ptr, AK_Construct))
return false;
- if (!CheckStore(S, OpPC, Ptr))
+ if (!CheckLive(S, OpPC, Ptr, AK_Construct))
+ return false;
+ if (!CheckDummy(S, OpPC, Ptr, AK_Construct))
+ return false;
+ if (!CheckLifetime(S, OpPC, Ptr, AK_Construct))
+ return false;
+ if (!CheckExtern(S, OpPC, Ptr))
+ return false;
+ if (!CheckRange(S, OpPC, Ptr, AK_Construct))
+ return false;
+ if (!CheckGlobal(S, OpPC, Ptr))
+ return false;
+ if (!CheckConst(S, OpPC, Ptr))
+ return false;
+ if (!S.inConstantContext() && isConstexprUnknown(Ptr))
return false;
if (!InvalidNewDeleteExpr(S, OpPC, E))
diff --git a/clang/test/AST/ByteCode/placement-new.cpp b/clang/test/AST/ByteCode/placement-new.cpp
index 9015690256458..81f7782c6f252 100644
--- a/clang/test/AST/ByteCode/placement-new.cpp
+++ b/clang/test/AST/ByteCode/placement-new.cpp
@@ -16,8 +16,8 @@ namespace std {
new (p) T((Args&&)args...); // both-note {{in call to}} \
// both-note {{placement new would change type of storage from 'int' to 'float'}} \
// both-note {{construction of subobject of member 'x' of union with active member 'a' is not allowed in a constant expression}} \
- // both-note {{construction of temporary is not allowed}}
-
+ // both-note {{construction of temporary is not allowed}} \
+ // both-note {{construction of heap allocated object that has been deleted}}
}
}
@@ -398,3 +398,14 @@ namespace Temp {
static_assert((std::construct_at<int>(&temporary, 1), true)); // both-error{{not an integral constant expression}} \
// both-note {{in call}}
}
+
+namespace PlacementNewAfterDelete {
+ constexpr bool construct_after_lifetime() {
+ int *p = new int;
+ delete p;
+ std::construct_at<int>(p); // both-note {{in call}}
+ return true;
+ }
+ static_assert(construct_after_lifetime()); // both-error {{}} \
+ // both-note {{in call}}
+}
More information about the cfe-commits
mailing list