-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
PtrExt::offset taking an isize argument is not ideal #22104
Comments
/cc @aturon |
With high probability we will add It's not like anyone ever does a check for "the uint is too large" when they cast, so this would just be an ergonomic improvement. I suppose we could add some friendly debug asserts in there. That said, this API taking a signed int is a soundness issue for us due to being able to allocate more than int::MAX contiguous bytes in some situations. There are a few options to address this, but all of them have drawbacks. |
Not sure we need those methods. I'll be the conservative side and say that hiding the problem doesn't help. Users of .offset need to be aware, and a cast to isize might help them with that. |
Why is the intrinsic different than casting the ptr to usize, modifying it, and casting back to a ptr? |
That's this question in the GEP FAQ. thestinger was the guy to make sure Rust used GEP so that llvm could optimize much better. |
The maximum object size in Rust is equal to |
@Thiez that specification was of course added in response to this problem, so it's a bit of a circular argument. |
You couldn't do this in C either, because the difference between two pointers has type |
Nominating for 1.0-beta P-backcompat-libs. We need to resolve this issue. |
assigning to self (to get answers to some questions I have) |
Not 1.0 blocker based on current understanding of situation. P-high. |
The libs team discussed this in triage yesterday and the conclusion was that this cannot be changed due to it being stable, and the situation is also intended due to the limitations imposed by LLVM. Pointer offsets need to be able to go backwards (e.g. move around in an array), but it's undefined behavior to overflow, so the only defined way to do this is to have a signed offset. |
I also just reread the docs and I think that they adequately reflect this. |
PtrExt::offset
taking an isize argument prevents being able to advance forward / back the full possible range of a pointer. A better option might be to have separate functions for forwards / backwards that take usize arguments.The text was updated successfully, but these errors were encountered: