[clang] [clang][bytecode] Accept pointer casts of expr-based opaque pointers (PR #223982)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 16 04:24:30 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/223982.diff
3 Files Affected:
- (modified) clang/lib/AST/ByteCode/Interp.cpp (+2-2)
- (modified) clang/lib/AST/ByteCode/Pointer.h (+1)
- (modified) clang/test/CodeGen/cfstring2.c (+1)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/223982
More information about the cfe-commits
mailing list