Skip to content
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 does not support slice::align_to method #55886

Closed
earthengine opened this issue Nov 12, 2018 · 2 comments
Closed

Miri check does not support slice::align_to method #55886

earthengine opened this issue Nov 12, 2018 · 2 comments

Comments

@earthengine
Copy link

earthengine commented Nov 12, 2018

The following

fn main() {
    let data:[u8;200] = [0;200];
    let (_,m,_) = unsafe { data[1..].align_to::<i32>() };
    println!("m.len()={}", m.len());
}

Playground

prints m.len()=49 in normal run, but m.len()=0 in Miri check.

@RalfJung
Copy link
Member

This is not a bug, this is expected behavior. align_to is explicitly documented to give a best-effort answer:

The method does a best effort to make the middle slice the greatest length possible for a given type and input slice, but only your algorithm's performance should depend on that, not its correctness.

The reason is that miri cannot know "how aligned" the allocation is. The 49 in a normal run can change from execution to execution, it depends on which base address got picked. miri does not pick a base address.

@oli-obk
Copy link
Contributor

oli-obk commented Nov 12, 2018

Closing since it is working as intended as per the RFC rust-lang/rfcs#2043

If anything is unclear about the motivation or documentation, don't hesitate to open an issue about that or ask here

@oli-obk oli-obk closed this as completed Nov 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants