Author: Timm Baeder Date: 2026-09-14T16:05:05+02:00 New Revision: 68a20cedb4548b5d8c89f4676bd80cb480ae3591
URL: https://github.com/llvm/llvm-project/commit/68a20cedb4548b5d8c89f4676bd80cb480ae3591 DIFF: https://github.com/llvm/llvm-project/commit/68a20cedb4548b5d8c89f4676bd80cb480ae3591.diff LOG: [clang][bytecode] Simplify Pointer::getByteOffset() (#223382) Return `Offset` directly, except for block pointers. This also allows us to remove `getRawOffset()`. Added: Modified: clang/lib/AST/ByteCode/Interp.h clang/lib/AST/ByteCode/Pointer.h Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 747311f42d757..1322136f23fdb 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -2617,9 +2617,9 @@ std::optional<Pointer> OffsetHelper(InterpState &S, CodePtr OpPC, } else if (Ptr.isStringPointer()) { int64_t NewOffset; if constexpr (Op == ArithOp::Add) - NewOffset = Ptr.getRawOffset() + static_cast<int64_t>(Offset); + NewOffset = Ptr.getByteOffset() + static_cast<int64_t>(Offset); else - NewOffset = Ptr.getRawOffset() - static_cast<int64_t>(Offset); + NewOffset = Ptr.getByteOffset() - static_cast<int64_t>(Offset); if (NewOffset < 0 || NewOffset > (Ptr.asStringPointer().getLiteral()->getLength() + 1)) { diagnoseArrayIndex(S, OpPC, APSInt::get(NewOffset), diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h index 0953c897b2564..fe9001ceeb846 100644 --- a/clang/lib/AST/ByteCode/Pointer.h +++ b/clang/lib/AST/ByteCode/Pointer.h @@ -968,19 +968,11 @@ class Pointer { /// Returns the byte offset from the start. uint64_t getByteOffset() const { - if (isIntegralPointer()) - return Int.Value + Offset; - if (isTypeidPointer()) - return reinterpret_cast<uintptr_t>(Typeid.TypePtr) + Offset; - if (isOpaquePointer()) - return Offset; - if (isOnePastEnd()) - return PtrView::PastEndMark; + if (isBlockPointer()) + return isOnePastEnd() ? PtrView::PastEndMark : Offset; return Offset; } - uint64_t getRawOffset() const { return Offset; } - /// Returns the number of elements. unsigned getNumElems() const { if (isStringPointer()) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
