-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Implement some more checks in ptr_guaranteed_cmp
.
#144885
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
base: master
Are you sure you want to change the base?
Conversation
Pointers with different residues modulo their least common allocation alignment are never equal. Pointers to the same static allocation are equal if and only if they have the same offset. Pointers to different non-zero-sized static allocations are unequal if both point within their allocation, and not on opposite ends.
r? @davidtwco rustbot has assigned @davidtwco. Use |
Are two different immutable statics required to have distinct addresses? In other words, is the compiler allowed to optimize two immutable statics with identical contents to be stored at the same place? |
I don't think it is, but this also restricts people doing their own custom linking shenanigans, so we should have some stable docs to point to before having logic of this sort in const-eval. That sounds like something t-lang should sign off on. |
If you just want to fix #144584, please reduce the PR to only affect the case where both pointers are based on the same static. |
Yes, they are required to have distinct addresses (if non-zero-sized). No, the compiler is not allowed to coalesce two immutable statics with the same contents.
This is guaranteed for non-zero-sized statics, in the Reference:
This (non-zero-sized statics not overlapping) has been FCP'd by T-lang here (though not anything about consteval specifically) |
Tracking issue for
const_raw_ptr_comparison
: #53020This should not affect
is_null
, the only usage of this intrinsic on stable.Closes #144584