[llvm] [ADT] Simplify getFirstEl (NFC) (PR #153127)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 11 19:59:22 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/153127.diff
1 Files Affected:
- (modified) llvm/include/llvm/ADT/SmallVector.h (+2-2)
``````````diff
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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/153127
More information about the llvm-commits
mailing list