-
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
Make pointer offset methods/intrinsics const #71500
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Please also move https://github.com/rust-lang/miri/blob/147ea8f400de3ca529abcb5eb7b65f84a4896ae9/src/operator.rs#L98 to the miri engine, so that you don't have to repeat its logic. Miri can then call the engine method in the future. |
@oli-obk after this PR lands I was just going to remove all of the Miri EDIT: I think I understand why I'll move the function over. |
I think this greatly decreased readability. Checked and unchecked arithmetic are very different operations, I am not sure if it is worth sharing the bit of code they have in common. But we'll see again after you moved |
Ping from triage |
Status: Tried getting |
@RalfJung @oli-obk this is ready again for review, sorry for the delay.
I moved miri's BTW: rust-lang/miri#1412 contains the miri cleanup
Looking at this again, you're correct, keeping them separate adds ~3 lines and makes the code much more readable. |
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.
Aside from the nit I raised, Miri implementation and test suite LGTM. For the glue and libcore changes I'll defer to @oli-obk.
@RalfJung Fixed the nits. I had to add EDIT: Note that this is what |
This comment has been minimized.
This comment has been minimized.
In tests I usually add the ignore-line-length thing for tidy rather than breaking the lines...^^ |
This comment has been minimized.
This comment has been minimized.
UB detection shouldn't depend on the target pointer size... so ideally we'd make this consistent. The pointer offset methods in |
In fact the two error messages are almost the same. So probably we should just adjust one of the error sites to use the same message as the other. |
@josephlr you can run the 32bit test suite yourself by passing |
Ya I was able get the tests working (and I can see the error message issues). I think the right approach is to be more strict in the order of the UB checks. Right now we:
On 32-bit, if |
We could do that, but it still seems odd to have almost but not quite identical error messages in both cases. IMO it would make more sense to just say "overflowing in-bounds pointer arithmetic" either way. |
Agreed, while I implemented the checks as described above, the error is always |
42daf7b
to
4b8d424
Compare
We now perform the correct checks even if the pointer size differs between the host and target. Signed-off-by: Joe Richey <joerichey@google.com>
Awesome! |
📌 Commit 7d5415b has been approved by |
Make pointer offset methods/intrinsics const Implements rust-lang#71499 using [the implementations from miri](https://github.com/rust-lang/miri/blob/52f5d202bdcfe8986f0615845f8d1647ab8a2c6a/src/shims/intrinsics.rs#L96-L112). I added some tests what's allowed and what's UB. Let me know if any other cases should be added. CC: @RalfJung @oli-obk
Make pointer offset methods/intrinsics const Implements rust-lang#71499 using [the implementations from miri](https://github.com/rust-lang/miri/blob/52f5d202bdcfe8986f0615845f8d1647ab8a2c6a/src/shims/intrinsics.rs#L96-L112). I added some tests what's allowed and what's UB. Let me know if any other cases should be added. CC: @RalfJung @oli-obk
Make pointer offset methods/intrinsics const Implements rust-lang#71499 using [the implementations from miri](https://github.com/rust-lang/miri/blob/52f5d202bdcfe8986f0615845f8d1647ab8a2c6a/src/shims/intrinsics.rs#L96-L112). I added some tests what's allowed and what's UB. Let me know if any other cases should be added. CC: @RalfJung @oli-obk
Make pointer offset methods/intrinsics const Implements rust-lang#71499 using [the implementations from miri](https://github.com/rust-lang/miri/blob/52f5d202bdcfe8986f0615845f8d1647ab8a2c6a/src/shims/intrinsics.rs#L96-L112). I added some tests what's allowed and what's UB. Let me know if any other cases should be added. CC: @RalfJung @oli-obk
Rollup of 9 pull requests Successful merges: - rust-lang#67460 (Tweak impl signature mismatch errors involving `RegionKind::ReVar` lifetimes) - rust-lang#71095 (impl From<[T; N]> for Box<[T]>) - rust-lang#71500 (Make pointer offset methods/intrinsics const) - rust-lang#71804 (linker: Support `-static-pie` and `-static -shared`) - rust-lang#71862 (Implement RFC 2585: unsafe blocks in unsafe fn) - rust-lang#72103 (borrowck `DefId` -> `LocalDefId`) - rust-lang#72407 (Various minor improvements to Ipv6Addr::Display) - rust-lang#72413 (impl Step for char (make Range*<char> iterable)) - rust-lang#72439 (NVPTX support for new asm!) Failed merges: r? @ghost
Remove pointer arithmetic intrinsics **Do Not Merge** until rust-lang/rust#71500 is in nightly. As rust-lang/rust#71500 implements `offset` and `arith_offset` in rustc's MIR interpreter, these implementations can now be removed from miri. Also, the `pointer_offset_inbounds` method has been moved to the main MIR engine, so that too can be removed. Signed-off-by: Joe Richey <joerichey@google.com>
Implements #71499 using the implementations from miri.
I added some tests what's allowed and what's UB. Let me know if any other cases should be added.
CC: @RalfJung @oli-obk