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 does not report UB for reference to uninitialized value #2795

Closed
gftea opened this issue Feb 22, 2023 · 5 comments
Closed

miri does not report UB for reference to uninitialized value #2795

gftea opened this issue Feb 22, 2023 · 5 comments

Comments

@gftea
Copy link

gftea commented Feb 22, 2023

run MIRI on below rust playground, it does not report undefined behavior for the codes reference to unitialized value

// example from rust-std docs
let m = MaybeUninit::<UnsafeCell<i32>>::uninit();
unsafe { UnsafeCell::raw_get(m.as_ptr()).write(5); }
let uc = unsafe { m.assume_init() };

assert_eq!(uc.into_inner(), 5);

// reference to unitiailized value due to `&*m.as_ptr()`
let m = MaybeUninit::<UnsafeCell<i32>>::uninit();
unsafe { UnsafeCell::get(&*m.as_ptr()).write(5); }
let uc = unsafe { m.assume_init() };

assert_eq!(uc.into_inner(), 5);
@bjorn3
Copy link
Member

bjorn3 commented Feb 22, 2023

@saethlin
Copy link
Member

See #2518 (comment)

@RalfJung
Copy link
Member

Also see #2518 -- this is a deliberate decision, for now. Though maybe we should keep one issue open to make it easier to find? Not sure.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 22, 2023

I pinned #2518, turns out you can pin closed issues

@RalfJung
Copy link
Member

Sounds good, let's close this one then.

Thanks for reporting a potential problem, @gftea.

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

5 participants