-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix make_key_iterator/make_value_iterator for prvalue iterators #3348
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
Conversation
If the iterator dereference operator returns a value rather than a reference (and that pair also does not *contain* references), make_key_iterator and make_value_iterator will return a reference to a temporary, causing a segfault.
If an iterator returns a pair<T1, T2> rather than a reference to a pair or a pair of references, make_key_iterator and make_value_iterator would return a reference to a temporary, typically leading to a segfault. This is because the value category of member access to a prvalue is an xvalue, not a prvalue, so decltype produces an rvalue reference type. Fix the type calculation to handle this case. I also removed some decltype parentheses that weren't needed, either because the expression isn't one of the special cases for decltype or because decltype was only used for SFINAE. Hopefully that makes the code a bit more readable. Closes pybind#3347
|
cc @henryiii @rwgk @rainwoodman since you reviewed #3271. |
|
Argh, why is there always a compiler bug?! Looks like I'm going to have to come up with a workaround for MSVC, but I probably won't have time for that today. An alternative idea I had, but couldn't quite make work, is to have the access helper classes return a |
|
@bmerry It's not a MSVC issue, it's a CUDA compiler issue on Ubuntu 20. It seems like it's emitting an error for the same UB that this PR is suppose to be guarding against. |
|
Sorry, MSVC was a typo - I had seen it was an CUDA issue. Apparently implementing decltype correctly is hard: I've now seen (different) implementation bugs in MSVC, ICC and nvcc. |
|
Ok, I've found a workaround for the nvcc issue, and also filed bug 3399127 with Nvidia. There are still a few CI jobs running but I'm optimistic. |
|
I applied this PR on top of the smart_holder branch, along with updates from master, and manually ran all tests/ with asan, msan, ubsan, tsan (for completeness: this does not include the embedding tests). There were no new issues (only 2 known ubsan failures, 1 known tsan failure). I also initiated google global testing. Results are expected by tomorrow morning (pacific time). |
rwgk
left a comment
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.
Google global testing was successful.
(I didn't review in detail.)
Description
If an iterator returns a pair<T1, T2> rather than a reference to a pair or a pair of references, make_key_iterator and make_value_iterator would return a reference to a temporary, typically leading to a segfault. This is because the value category of member access to a prvalue is an xvalue, not a prvalue, so decltype produces an rvalue reference type. Fix the type calculation to handle this case.
I also removed some decltype parentheses that weren't needed, either because the expression isn't one of the special cases for decltype or because decltype was only used for SFINAE. Hopefully that makes the code a bit more readable.
Closes #3347
Suggested changelog entry: