[llvm] 478aa02 - [ADT] Simplify getFirstEl (NFC) (#153127)

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 11 22:51:44 PDT 2025


Author: Kazu Hirata
Date: 2025-08-11T22:51:41-07:00
New Revision: 478aa0270915d9866bd3fe6fa2a4d156c6b473a8

URL: https://github.com/llvm/llvm-project/commit/478aa0270915d9866bd3fe6fa2a4d156c6b473a8
DIFF: https://github.com/llvm/llvm-project/commit/478aa0270915d9866bd3fe6fa2a4d156c6b473a8.diff

LOG: [ADT] Simplify getFirstEl (NFC) (#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.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/SmallVector.h

Removed: 
    


################################################################################
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