[libcxx-commits] [libcxx] [libc++] Add assumption for align of begin and end pointers of vector. (PR #108961)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Sep 19 07:05:50 PDT 2024
================
@@ -1027,6 +1027,10 @@ private:
}
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector&, false_type) _NOEXCEPT {}
+
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer __add_alignment_assumption(pointer __p) const _NOEXCEPT {
+ return static_cast<pointer>(__builtin_assume_aligned(__p, alignof(decltype(*__p))));
+ }
----------------
ldionne wrote:
Reintroducing @philnik777 's comment:
> Does this work with fancy pointers? Also, shouldn't the compiler be able to infer this?
No, that wouldn't work AFAIU and I don't think this can work for fancy pointers (which could be implemented in very unusual ways). We may need to guard this with `if constexpr (is_pointer<pointer>::value)`.
https://github.com/llvm/llvm-project/pull/108961
More information about the libcxx-commits
mailing list