[llvm] [ADT] Simplify getFirstEl (NFC) (PR #153127)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 11 19:58:49 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/153127
getFirstEl computes the address of FirstEl. This patch computes the
address by first casting this to SmallVectorAlignmentAndSize<T> and
letting the C++ language compute the field address instead of adding
the offset to this on our own.
>From f7feffe174f595962d6a18ef4319eaca7e7ccdbb Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 9 Aug 2025 21:08:41 -0700
Subject: [PATCH] [ADT] Simplify getFirstEl (NFC)
getFirstEl computes the address of FirstEl. This patch computes the
address by first casting this to SmallVectorAlignmentAndSize<T> and
letting the C++ language compute the field address instead of adding
the offset to this on our own.
---
llvm/include/llvm/ADT/SmallVector.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index 80f7734b86907..6da519adcee6f 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -128,8 +128,8 @@ class SmallVectorTemplateCommon
/// SmallVectorStorage is properly-aligned even for small-size of 0.
void *getFirstEl() const {
return const_cast<void *>(reinterpret_cast<const void *>(
- reinterpret_cast<const char *>(this) +
- offsetof(SmallVectorAlignmentAndSize<T>, FirstEl)));
+ reinterpret_cast<const SmallVectorAlignmentAndSize<T> *>(this)
+ ->FirstEl));
}
// Space after 'FirstEl' is clobbered, do not add any instance vars after it.
More information about the llvm-commits
mailing list