https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/205043

We need a block pointer here for the following operations, and non-block 
pointers aren't valid anyway.

>From c53c0dc71c47fd9125658d407df54e80ac394c0e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Mon, 22 Jun 2026 09:12:56 +0200
Subject: [PATCH] [clang][bytecode] Check for block pointers in Free()

We need a block pointer here for the following operations, and non-block
pointers aren't valid anyway.
---
 clang/lib/AST/ByteCode/Interp.cpp      |  3 +++
 clang/test/AST/ByteCode/new-delete.cpp | 11 +++++++++++
 2 files changed, 14 insertions(+)

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}}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to