[out.ptr.t][inout.ptr.t] Get rid of TBAA-violating implication#8740
Open
frederick-vs-ja wants to merge 1 commit intocplusplus:mainfrom
Open
[out.ptr.t][inout.ptr.t] Get rid of TBAA-violating implication#8740frederick-vs-ja wants to merge 1 commit intocplusplus:mainfrom
frederick-vs-ja wants to merge 1 commit intocplusplus:mainfrom
Conversation
On many platforms, we can just reuse the object/value representation of the raw pointer stored within `(in)out_ptr_t` for `operator void**`. However, directly use of `reinterpret_cast` violates the strict aliasing rule ([basic.lval]/11). At the time when `out_ptr_t` and `inout_ptr_t` were added to C++23, there was not yet any standard utility bypassing the strict aliasing rule, and thus the notes had to indicate core UB and were only applicable for implementations that didn't aggressively perform type-based aliasing analysis (TBAA). Luckily, `start_lifetime_as` was added later, making it possible to reuse value representation without UB. This PR uses `start_lifetime_as` in the notes, and thus makes them probably applicable for implementations that have compatible representations for `T*` and `void*`. Note that `start_lifetime_as` can cause conflicts on object creation, but conflicts are already allowed in [out.ptr.t]/5 and [inout.ptr.t]/5.
783e243 to
44c228d
Compare
Member
|
On what grounds do you believe the value representation is the same for a |
Contributor
Author
I don't think this is necessarily true for all implementations, and the notes are already saying "for some implementations" (see #5158 and #4773). I think the intent of the original notes was noting that reusing value representation is possible for some implementations. However, the original strategy still caused core UB, and I believe |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On many platforms, we can just reuse the object/value representation of the raw pointer stored within
(in)out_ptr_tforoperator void**. However, directly use ofreinterpret_castviolates the strict aliasing rule ([basic.lval]/11). At the time whenout_ptr_tandinout_ptr_twere added to C++23, there was not yet any standard utility bypassing the strict aliasing rule, and thus the notes had to indicate core UB and were only applicable for implementations that didn't aggressively perform type-based aliasing analysis (TBAA).Luckily,
start_lifetime_aswas added later, making it possible to reuse value representation without UB. This PR usesstart_lifetime_asin the notes, and thus makes them probably applicable for implementations that have compatible representations forT*andvoid*.Note that
start_lifetime_ascan cause conflicts on object creation, but conflicts are already allowed in [out.ptr.t]/5 and [inout.ptr.t]/5.