-
Notifications
You must be signed in to change notification settings - Fork 82
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
Should not use transmute to cast between pointers and integers #288
Comments
There's nothing wrong with actually casting (or transmuting) pointers, just using them. My understanding is that |
there is though |
Is there? |
As far as I can tell, only |
|
Interesting. That must be the distinction I missed. Does LLVM even support this? The tracking issue for strict provenance implies this isn't valid at all, but I suppose this is saying that violating strict provenance isn't necessarily UB. |
yes. casting int <-> ptr has been part of C for years...iirc it is part of the original C spec.
yes, strict provenance is intended to codify a simple-to-understand useful subset of what's considered valid -- int <-> pointer casting currently has ill-defined semantics -- C is currently trying to decide which formal model they use to describe it. |
Opened rust-lang/rust#98441 |
FWIW, Miri actually does support this, but you lose precision -- as in, Miri might miss some UB when you do that.
LLVM does not say what its ptr2int and int2ptr cast and transmute semantics are. And the implied semantics (by observing what optimizations do) are inconsistent -- they turn well-defined programs into UB. See my recent blog post for a lot more details on all that. |
Fixed in #287 |
Pointer to integer transmutes are almost certainly UB if you want to convert the resulting integer to a valid pointer again...you need a explicit pointer cast operation instead.
rust-lang/unsafe-code-guidelines#286
imho integer to pointer transmutes should be avoided too (even though they aren't necessarily UB), to go along with avoiding pointer to integer transmutes.
See also: #287
The text was updated successfully, but these errors were encountered: