llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> --- Full diff: https://github.com/llvm/llvm-project/pull/179618.diff 3 Files Affected: - (modified) clang/lib/AST/ByteCode/Interp.h (+2-4) - (modified) clang/lib/AST/ByteCode/Pointer.cpp (+1-2) - (modified) clang/lib/AST/ByteCode/Pointer.h (+9) ``````````diff 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"); `````````` </details> https://github.com/llvm/llvm-project/pull/179618 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
