Skip to content

Conversation

vinay-deshmukh
Copy link
Contributor

@vinay-deshmukh vinay-deshmukh commented Aug 16, 2025

This patch also updates __hash_table to match what we do in __tree now.

Fixes #134330 (comment)

Copy link

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Developer Policy and LLVM Discourse for more information.

Copy link

github-actions bot commented Aug 16, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@vinay-deshmukh vinay-deshmukh changed the title [libc++] Remove UB from std::map __tree_node constructor [libc++] Remove UB from std::map __tree_node construction Aug 16, 2025
@vinay-deshmukh vinay-deshmukh marked this pull request as ready for review August 16, 2025 02:00
@vinay-deshmukh vinay-deshmukh requested a review from a team as a code owner August 16, 2025 02:00
@@ -1808,7 +1842,7 @@ typename __tree<_Tp, _Compare, _Allocator>::__node_holder
__tree<_Tp, _Compare, _Allocator>::__construct_node(_Args&&... __args) {
__node_allocator& __na = __node_alloc();
__node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
__node_traits::construct(__na, std::addressof(__h->__value_), std::forward<_Args>(__args)...);
std::__construct_at(std::addressof(*__h), __na, std::forward<_Args>(__args)...);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N.B. This is the line that prompts this change due to needing workarounds when implementing P3372 for map (Add constexpr)

@vinay-deshmukh
Copy link
Contributor Author

vinay-deshmukh commented Aug 16, 2025

Failed checks seem to have timed out after 2 hours:

image image

@vinay-deshmukh
Copy link
Contributor Author

vinay-deshmukh commented Aug 18, 2025

#153908 (comment)

You mean nothing complained when you made _value private? If that is the case we're definitely missing tests. Please file a bug about it or add some tests yourself. The latter would be appreciated, but not necessary

my bad, false alarm

I do get test failures if I don't update set and multiset...

llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Aug 19, 2025
@vinay-deshmukh
Copy link
Contributor Author

Ping @philnik777 @frederick-vs-ja

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with the last two open comments addressed.

@vinay-deshmukh vinay-deshmukh changed the title [libc++] Remove UB from std::map __tree_node construction [libc++] Remove UB from std::map by updating std::__tree_node construction / Update std::__hash_node construction Sep 1, 2025
@philnik777 philnik777 changed the title [libc++] Remove UB from std::map by updating std::__tree_node construction / Update std::__hash_node construction [libc++] Remove UB from std::map by updating std::__tree_node construction Sep 4, 2025
//
// We don't use the allocator's construct() method to construct the node itself since the
// Cpp17FooInsertable named requirements don't require the allocator's construct() method
// to work on anything other than the value_type.
std::__construct_at(std::addressof(*__h), /* next = */ nullptr, /* hash = */ 0);
std::__construct_at(std::addressof(*__h), /* next = */ nullptr, /* hash = */ 0, __na, std::forward<_Args>(__args)...);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever construct the node with anything but nullptr and 0? If not, I'd just move that into the constructor.

Copy link
Contributor Author

@vinay-deshmukh vinay-deshmukh Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr was used in all instances, but the hash = arg can be 0 or a variable for the second occurrence, so that is still a constructor arg.

one more thing, for the second instance this was 0, but then in the next line, it was being reassigned with a variable, so I changed that to be assigned through the constructor arg.

Update: as it needs to be computed after the __value_ is inititalized, we can't put that as a constructor arg unless we also send in the hash_function as a constructor arg..

: _Base(__next), __hash_(__hash) {
allocator_traits<_Alloc>::construct(__na, std::addressof(__get_value()), std::forward<_Args>(__args)...);
}

_LIBCPP_HIDE_FROM_ABI ~__hash_node() {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be changed to = default; as well? (while I'm changing this code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants