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

mem::transmute to nevertype causes Illigal instruction #51005

Closed
DutchGhost opened this issue May 23, 2018 · 3 comments
Closed

mem::transmute to nevertype causes Illigal instruction #51005

DutchGhost opened this issue May 23, 2018 · 3 comments

Comments

@DutchGhost
Copy link
Contributor

DutchGhost commented May 23, 2018

transmuting to the never type causes an Illigal instruction: https://play.rust-lang.org/?gist=390b8739cfe0e25504f0602dcf546e7b&version=nightly&mode=release

#![feature(never_type)]

use std::mem;

fn main() {
    let _: ! = unsafe { mem::transmute( {} ) };
}

Now, it's true that this requires unsafe, and might not even considered an issue or bug, and probably never happens in real productions code. However, many transmutes give a segfault when done wrong, this instead gives an illigal instruction.

@jonas-schievink
Copy link
Contributor

This is just UB, the code can do whatever. It's only an illegal instruction (ud2) because the compiler is nice. I think LLVM's trap-unreachable flag is doing this - otherwise main would just contain no instructions (since ! cannot be created main can never be reached) and fall through to whatever code happens to follow it.

@cuviper
Copy link
Member

cuviper commented May 23, 2018

This is very similar to #50976.

@sfackler
Copy link
Member

Closing as a duplicate of #50976.

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

4 participants