-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Miri: Check that a ptr is aligned and inbounds already when evaluating *
#63075
Conversation
*
*
See rust-lang/miri#863 for what this does with the Miri test suite. |
This comment has been minimized.
This comment has been minimized.
@mjbshaw I just realized that this PR as-is would break your CTFE version of I am not sure what to do about this. On the one hand this makes this PR a breaking change, on the other hand the unsafe CTFE code that it breaks is UB and has been called out as such in the reference since forever, and on yet another hand I don't know of anything else you can currently do in CTFE to do |
Thanks for the heads up, @RalfJung.
I don't really see it as a breaking change (at least not the kind that break's Rust's promises). I'm relying on UB, and I know that. UB can change (including break) at any time, which I'm okay with. I've got mixed feelings here. On the one hand, I always knew this day would come and I can't blame you/anyone for making improvements like this. On the other hand, it sucks not being able to implement |
Could you use a Union to create an undef value of your type, take a reference to the field you want, make it a pointer, subtract that from the base pointer? Undef values are pretty well defined in miri |
That only works for |
@oli-obk No. It's not possible to use a real object at all because Miri won't let you. Doing this requires:
But even with all of that, Miri won't let you use the offset value. |
Why doesn't the error say what the actual problem is...?
My guess is that
Nit: Miri-the-tool has no issue with any of this. The problem here is the variant of the Miri engine used by CTFE. |
Let's make Also yea, what's up with that horrible diagnostic |
Uh, implementing this in general requires ptr-to-int casts... CTFE can only do this for pointers to the same object. |
Sure, but that's fine imo. Casting raw pointers to usize will error for non-integer values, so calling
|
But then I don't see how this helps... |
Why integer-only?. |
So you want to have a This is an "unconst" function. We should likely not allow calling it outside |
Oops, sorry, I meant |
That I guess we could do. It would have to become an intrinsic or so I suppose. |
Miri: Check that a ptr is aligned and inbounds already when evaluating `*` This syncs Miri with what the Nomicon and the Reference say, and resolves rust-lang/miri#447. Also this would not have worked without rust-lang#62982 due to new cycles. ;) r? @oli-obk
Miri: Check that a ptr is aligned and inbounds already when evaluating `*` This syncs Miri with what the Nomicon and the Reference say, and resolves rust-lang/miri#447. Also this would not have worked without rust-lang#62982 due to new cycles. ;) r? @oli-obk
Rollup of 10 pull requests Successful merges: - #62984 (Add lint for excess trailing semicolons) - #63075 (Miri: Check that a ptr is aligned and inbounds already when evaluating `*`) - #63490 (libsyntax: cleanup and refactor `pat.rs`) - #63495 ( Remove redundant `ty` fields from `mir::Constant` and `hair::pattern::PatternRange`.) - #63509 (Point at the right enclosing scope when using `await` in non-async fn) - #63528 (syntax: Remove `DummyResult::expr_only`) - #63534 (Bump to 1.39) - #63537 (expand: Unimplement `MutVisitor` on `MacroExpander`) - #63542 (Add NodeId for Arm, Field and FieldPat) - #63560 (move test that shouldn't be in test/run-pass/) Failed merges: r? @ghost
Miri: Check that a ptr is aligned and inbounds already when evaluating `*` This syncs Miri with what the Nomicon and the Reference say, and resolves rust-lang/miri#447. Also this would not have worked without rust-lang#62982 due to new cycles. ;) r? @oli-obk
Miri: Check that a ptr is aligned and inbounds already when evaluating `*` This syncs Miri with what the Nomicon and the Reference say, and resolves rust-lang/miri#447. Also this would not have worked without rust-lang#62982 due to new cycles. ;) r? @oli-obk
Rollup of 11 pull requests Successful merges: - #62984 (Add lint for excess trailing semicolons) - #63075 (Miri: Check that a ptr is aligned and inbounds already when evaluating `*`) - #63490 (libsyntax: cleanup and refactor `pat.rs`) - #63507 (When needing type annotations in local bindings, account for impl Trait and closures) - #63509 (Point at the right enclosing scope when using `await` in non-async fn) - #63528 (syntax: Remove `DummyResult::expr_only`) - #63537 (expand: Unimplement `MutVisitor` on `MacroExpander`) - #63542 (Add NodeId for Arm, Field and FieldPat) - #63543 (Merge Variant and Variant_) - #63560 (move test that shouldn't be in test/run-pass/) - #63570 (Adjust tracking issues for `MaybeUninit<T>` gates) Failed merges: r? @ghost
adjust tests for eager pointer checks on deref The Miri side of rust-lang/rust#63075. Fixes #447.
…ng,nikic Make <*const/mut T>::offset_from `const fn` This reenables offset_of cc @mjbshaw after rust-lang#63075 broke it
…ng,nikic Make <*const/mut T>::offset_from `const fn` This reenables offset_of cc @mjbshaw after rust-lang#63075 broke it
…ng,nikic Make <*const/mut T>::offset_from `const fn` This reenables offset_of cc @mjbshaw after rust-lang#63075 broke it
…ng,nikic Make <*const/mut T>::offset_from `const fn` This reenables offset_of cc @mjbshaw after rust-lang#63075 broke it
…ng,nikic Make <*const/mut T>::offset_from `const fn` This reenables offset_of cc @mjbshaw after rust-lang#63075 broke it
This syncs Miri with what the Nomicon and the Reference say, and resolves rust-lang/miri#447.
Also this would not have worked without #62982 due to new cycles. ;)
r? @oli-obk