[clang] [clang][bytecode] Simplify Pointer::getByteOffset() (PR #223382)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 14 05:24:52 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/223382
Return `Offset` directly, except for block pointers. This also allows us to remove `getRawOffset()`.
>From 2951438486c380df334340ef7d38a42afdac14cf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 14 Sep 2026 14:22:15 +0200
Subject: [PATCH] [clang][bytecode] Simplify Pointer::getByteOffset()
---
clang/lib/AST/ByteCode/Interp.h | 4 ++--
clang/lib/AST/ByteCode/Pointer.h | 12 ++----------
2 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 7c71635561708..3d8c7c813f719 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2614,9 +2614,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)) {
S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_array_index)
diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h
index 5b43df9db49c4..9f46dc615f461 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())
More information about the cfe-commits
mailing list