[clang] [clang][bytecode] Check for block pointers in Free() (PR #205043)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 22 00:15:09 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
We need a block pointer here for the following operations, and non-block pointers aren't valid anyway.
---
Full diff: https://github.com/llvm/llvm-project/pull/205043.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Interp.cpp (+3)
- (modified) clang/test/AST/ByteCode/new-delete.cpp (+11)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 60914a2da111a..c444d0aa8e6d4 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1380,6 +1380,9 @@ bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm,
if (Ptr.isZero())
return true;
+ if (!Ptr.isBlockPointer())
+ return false;
+
// Remove base casts.
QualType InitialType = Ptr.getType();
Ptr = Ptr.expand().stripBaseCasts();
diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp
index dd61accc898cd..a3ae4d0c8764c 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -1254,6 +1254,17 @@ namespace AllocInBase {
// both-note {{pointer to heap-allocated object is not a constant expression}}
}
+namespace FreeNonBlockPointer {
+#define fold(x) (__builtin_constant_p(x) ? (x) : (x))
+ constexpr int foo() {
+ int *p;
+ p = fold((int*)(void*)f);
+ delete p;
+ return 10;
+ }
+ static_assert(foo() == 10); // both-error {{not an integral constant expression}}
+}
+
#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/205043
More information about the cfe-commits
mailing list