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

We can only use block pointers here.

>From 1c77bfe245acdfc22cbc607a11407f5c9ef370e7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Mon, 9 Feb 2026 15:06:21 +0100
Subject: [PATCH] [clang][bytecode] Check evaluate{String,Strlen} for pointer
 type

We can only use block pointers here.
---
 clang/lib/AST/ByteCode/Context.cpp | 6 ++++++
 clang/test/AST/ByteCode/c.c        | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Context.cpp 
b/clang/lib/AST/ByteCode/Context.cpp
index b4b8939f3fe00..879d51e6a2c3e 100644
--- a/clang/lib/AST/ByteCode/Context.cpp
+++ b/clang/lib/AST/ByteCode/Context.cpp
@@ -245,6 +245,9 @@ bool Context::evaluateString(State &Parent, const Expr *E,
   Compiler<EvalEmitter> C(*this, *P, Parent, Stk);
 
   auto PtrRes = C.interpretAsPointer(E, [&](const Pointer &Ptr) {
+    if (!Ptr.isBlockPointer())
+      return false;
+
     const Descriptor *FieldDesc = Ptr.getFieldDesc();
     if (!FieldDesc->isPrimitiveArray())
       return false;
@@ -291,6 +294,9 @@ std::optional<uint64_t> Context::evaluateStrlen(State 
&Parent, const Expr *E) {
 
   std::optional<uint64_t> Result;
   auto PtrRes = C.interpretAsPointer(E, [&](const Pointer &Ptr) {
+    if (!Ptr.isBlockPointer())
+      return false;
+
     const Descriptor *FieldDesc = Ptr.getFieldDesc();
     if (!FieldDesc->isPrimitiveArray())
       return false;
diff --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c
index 9496f8060884a..48a1b36259165 100644
--- a/clang/test/AST/ByteCode/c.c
+++ b/clang/test/AST/ByteCode/c.c
@@ -433,3 +433,9 @@ void intPtrCmp1(void) { &i + 1 == 2; } // all-warning 
{{comparison between point
                                        // all-warning {{equality comparison 
result unused}}
 void intPtrCmp2(void) { 2 == &i + 1; } // all-warning {{comparison between 
pointer and integer}} \
                                        // all-warning {{equality comparison 
result unused}}
+
+/// evaluateStrlen on a non-block pointer.
+char *strcpy(char *restrict s1, const char *restrict s2);
+void strcpy_fn(char *x) {
+  strcpy(x, (char*)&strcpy_fn);
+}

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

Reply via email to