[clang] 87e38d3 - [clang][bytecode][NFC] Add Pointer::canDeref (#179618)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 4 00:18:28 PST 2026
Author: Timm Baeder
Date: 2026-02-04T09:18:23+01:00
New Revision: 87e38d3b9767df0e3a289bf46af11115de14eb7d
URL: https://github.com/llvm/llvm-project/commit/87e38d3b9767df0e3a289bf46af11115de14eb7d
DIFF: https://github.com/llvm/llvm-project/commit/87e38d3b9767df0e3a289bf46af11115de14eb7d.diff
LOG: [clang][bytecode][NFC] Add Pointer::canDeref (#179618)
Added:
Modified:
clang/lib/AST/ByteCode/Interp.h
clang/lib/AST/ByteCode/Pointer.cpp
clang/lib/AST/ByteCode/Pointer.h
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index d856cd7c0a2d9..3313e819e694b 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1973,8 +1973,7 @@ bool Load(InterpState &S, CodePtr OpPC) {
return false;
if (!Ptr.isBlockPointer())
return false;
- if (const Descriptor *D = Ptr.getFieldDesc();
- !(D->isPrimitive() || D->isPrimitiveArray()) || D->getPrimType() != Name)
+ if (!Ptr.canDeref(Name))
return false;
S.Stk.push<T>(Ptr.deref<T>());
return true;
@@ -1987,8 +1986,7 @@ bool LoadPop(InterpState &S, CodePtr OpPC) {
return false;
if (!Ptr.isBlockPointer())
return false;
- if (const Descriptor *D = Ptr.getFieldDesc();
- !(D->isPrimitive() || D->isPrimitiveArray()) || D->getPrimType() != Name)
+ if (!Ptr.canDeref(Name))
return false;
S.Stk.push<T>(Ptr.deref<T>());
return true;
diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp
index b625128514f83..fb9202c6d66c8 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -947,8 +947,7 @@ std::optional<APValue> Pointer::toRValue(const Context &Ctx,
// Just load primitive types.
if (OptPrimType T = Ctx.classify(ResultType)) {
- if (const Descriptor *D = getFieldDesc();
- (D->isPrimitive() || D->isPrimitiveArray()) && D->getPrimType() != *T)
+ if (!canDeref(*T))
return std::nullopt;
TYPE_SWITCH(*T, return this->deref<T>().toAPValue(ASTCtx));
}
diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h
index 7ff1559cd0000..2515b2fe56ab9 100644
--- a/clang/lib/AST/ByteCode/Pointer.h
+++ b/clang/lib/AST/ByteCode/Pointer.h
@@ -666,6 +666,15 @@ class Pointer {
return false;
}
+ /// Checks whether the pointer can be dereferenced to the given PrimType.
+ bool canDeref(PrimType T) const {
+ if (const Descriptor *FieldDesc = getFieldDesc()) {
+ return (FieldDesc->isPrimitive() || FieldDesc->isPrimitiveArray()) &&
+ FieldDesc->getPrimType() == T;
+ }
+ return false;
+ }
+
/// Dereferences the pointer, if it's live.
template <typename T> T &deref() const {
assert(isLive() && "Invalid pointer");
More information about the cfe-commits
mailing list