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

std::mem::zeroed() panics on nightly with ash::Device, but not on stable #77499

Closed
aloucks opened this issue Oct 3, 2020 · 3 comments
Closed

Comments

@aloucks
Copy link
Contributor

aloucks commented Oct 3, 2020

As stated in the title, the behavior of mem::zeroed() seems to have changed on the nightly channel and now panics when called with ash::Device as the type parameter. This is causing vk_mem::AllocatorCreateInfo::default() to panic in the vk_mem crate.

[dependencies]
ash = "0.31"
#[test]
fn zeroed() {
    let _device = unsafe { std::mem::zeroed::<ash::Device>() }; 
}

The last nightly to behave the same as stable

info: latest update on 2020-09-27, rust version 1.48.0-nightly (623fb90b5 2020-09-26)
$ cargo +nightly-2020-09-27 test
...
running 1 test
test zeroed ... ok

And started failing with

info: latest update on 2020-09-28, rust version 1.48.0-nightly (7f7a1cbfd 2020-09-27)
$ cargo +nightly-2020-09-28 test
...
running 1 test
test zeroed ... FAILED

failures:

---- zeroed stdout ----
thread 'zeroed' panicked at 'attempted to zero-initialize type `ash::Device`, which is invalid', /rustc/7f7a1cbfd3b55daee191247770627afab09eece2\library\core\src\mem\mod.rs:622:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@jyn514
Copy link
Member

jyn514 commented Oct 3, 2020

I don't think this is a bug, it's a soundness fix. What's the definition of ash::Device? Not all types are valid as zeroed, for example mem::zeroed<Box<usize>>() is immediate UB.

@aloucks
Copy link
Contributor Author

aloucks commented Oct 3, 2020

@jyn514 It contains function pointers. I suspected the same, but wanted to confirm and report anyway as it will cause a breaking change when it reaches the stable channel.

@jonas-schievink
Copy link
Contributor

Yeah, this was UB and is now being diagnosed, so closing as expected behavior.

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