-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[libc++] Add assumption for align of begin and end pointers of vector. #108961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
94c2ede
3daa6c5
ddb387b
a2cd12c
a9fb6aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
#include <__type_traits/is_constructible.h> | ||
#include <__type_traits/is_nothrow_assignable.h> | ||
#include <__type_traits/is_nothrow_constructible.h> | ||
#include <__type_traits/is_pointer.h> | ||
#include <__type_traits/is_same.h> | ||
#include <__type_traits/is_trivially_relocatable.h> | ||
#include <__type_traits/type_identity.h> | ||
|
@@ -341,13 +342,17 @@ class _LIBCPP_TEMPLATE_VIS vector { | |
// | ||
// Iterators | ||
// | ||
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __make_iter(this->__begin_); } | ||
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { | ||
return __make_iter(__add_alignment_assumption(this->__begin_)); | ||
} | ||
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { | ||
return __make_iter(this->__begin_); | ||
return __make_iter(__add_alignment_assumption(this->__begin_)); | ||
} | ||
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { | ||
return __make_iter(__add_alignment_assumption(this->__end_)); | ||
} | ||
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __make_iter(this->__end_); } | ||
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { | ||
return __make_iter(this->__end_); | ||
return __make_iter(__add_alignment_assumption(this->__end_)); | ||
} | ||
|
||
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { | ||
|
@@ -775,6 +780,17 @@ class _LIBCPP_TEMPLATE_VIS vector { | |
} | ||
|
||
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector&, false_type) _NOEXCEPT {} | ||
|
||
static _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer __add_alignment_assumption(pointer __p) _NOEXCEPT { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly to #118837 (review) I think this one needs (Apologies for the late notice, we're a bit behind on libc++.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ack. I'd be curious to see how this failure can be reproduced. Is it just a matter of adding a CF #124837 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also #124839 for adding NO_CFI There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't tried to reproduce it on the libc++ tests directly, but it should be possible. I think we're currently only using a subset of the cfi checks: |
||
#ifndef _LIBCPP_CXX03_LANG | ||
if constexpr (is_pointer<pointer>::value) { | ||
Comment on lines
+785
to
+786
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ldionne Are we using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's fine to use compiler extensions in the library as long as our supported compilers implement them. |
||
if (!__libcpp_is_constant_evaluated()) { | ||
return static_cast<pointer>(__builtin_assume_aligned(__p, alignof(decltype(*__p)))); | ||
} | ||
} | ||
#endif | ||
return __p; | ||
} | ||
}; | ||
|
||
#if _LIBCPP_STD_VER >= 17 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@huixie90 Do these changes look correct to you? Is there a reason why you used
ranges::iterator_t
in the first place?