From 547b5a3c8e72fc6ee5163144880184b414cbce3a Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Wed, 26 Nov 2025 18:33:36 +0100 Subject: [PATCH] [vecops] Alignment-related fix for getting first element of small vector In the RVec code, we assumed that the location of the SmallVectorBase subobject inside the RVec is identical to the RVec itself. This assumption is not always correct. For example, on AArch64 GCC 14, some extra padding seems to be inserted before the base class. This commit generalized the implementation of getting the first element by first casting to the SmallVectorBase class, which is what is required to calculate the correct offset to the SmallVectorBase data members. --- math/vecops/inc/ROOT/RVec.hxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/math/vecops/inc/ROOT/RVec.hxx b/math/vecops/inc/ROOT/RVec.hxx index 30524acf8e008..c6750a8d36490 100644 --- a/math/vecops/inc/ROOT/RVec.hxx +++ b/math/vecops/inc/ROOT/RVec.hxx @@ -213,7 +213,9 @@ class R__CLING_PTRCHECK(off) SmallVectorTemplateCommon : public SmallVectorBase /// SmallVectorStorage is properly-aligned even for small-size of 0. void *getFirstEl() const { - return const_cast(reinterpret_cast(reinterpret_cast(this) + + // get the SmallVectorBase subobject inside RVec + auto *base = static_cast(this); + return const_cast(reinterpret_cast(reinterpret_cast(base) + offsetof(SmallVectorAlignmentAndSize, FirstEl))); } // Space after 'FirstEl' is clobbered, do not add any instance vars after it.