[clang] [clang][bytecode] Accept pointer casts of expr-based opaque pointers (PR #223982)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 16 04:23:50 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/223982
We create opaque pointers for a few types of "opaque" expressions, where we need to just pass the pointer along to the end of the evaluation and such pointer casts are fine on those.
>From c0d0c94ea9dba36b0954937583752be0f5177c1f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Wed, 16 Sep 2026 12:38:15 +0200
Subject: [PATCH] asdf
---
clang/lib/AST/ByteCode/Interp.cpp | 4 ++--
clang/lib/AST/ByteCode/Pointer.h | 1 +
clang/test/CodeGen/cfstring2.c | 1 +
3 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index b02305e9ee753..5b0422d9ae9bd 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1980,9 +1980,9 @@ bool PtrPtrCast(InterpState &S, CodePtr OpPC, bool SrcIsVoidPtr,
// Retain the casted type for opaque pointers.
if (Ptr.isOpaquePointer()) {
Pointer P = S.Stk.pop<Pointer>();
- auto OP = P.asOpaquePointer();
+ const OpaquePointer &OP = P.asOpaquePointer();
- if (!validType(TargetType->getPointeeType()))
+ if (OP.hasDeclBase() && !validType(TargetType->getPointeeType()))
return Invalid(S, OpPC);
S.Stk.push<Pointer>(OP.withFieldType(TargetType), P.getByteOffset());
diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h
index 6e63decec0ebf..d19374acf00c4 100644
--- a/clang/lib/AST/ByteCode/Pointer.h
+++ b/clang/lib/AST/ByteCode/Pointer.h
@@ -437,6 +437,7 @@ struct OpaquePointer {
unsigned PathLength = 0;
ArrayRef<PointerPathEntry> path() const { return ArrayRef(Path, PathLength); }
+ bool hasDeclBase() const { return Base.isDecl(); }
const VarDecl *getBaseDecl() const { return Base.asVarDecl(); }
const Expr *getBaseExpr() const { return Base.asExpr(); }
diff --git a/clang/test/CodeGen/cfstring2.c b/clang/test/CodeGen/cfstring2.c
index 7ff57e14407f7..edc05aed16e15 100644
--- a/clang/test/CodeGen/cfstring2.c
+++ b/clang/test/CodeGen/cfstring2.c
@@ -1,5 +1,6 @@
// UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
// RUN: %clang_cc1 -emit-llvm %s -o %t
+// RUN: %clang_cc1 -emit-llvm %s -o %t -fexperimental-new-constant-interpreter
typedef const struct __CFString * CFStringRef;
More information about the cfe-commits
mailing list