-
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
Compiler segfaults when boxing a ZST from an external crate #28766
Comments
Looks like this is tripping an LLVM assertion:
I think if you use nightly it's got LLVM assertions enabled, which is why it looks like a segfault on stable! |
backtrace? |
cc @dotdash |
Backtrace for me looks like:
|
Problematic IR:
Why is there a
and compiles on vanilla and rustc |
cc @dotdash |
It looks like a real LLVM bug, but one that rustc could easily dodge by generating |
Quoting the LLVM reference:
|
The only way to get a value for a zero-sized type is `undef`, so there's really no point in actually having a return type other than void for such types. Also, while the comment in return_type_is_void mentioned something about aiding C ABI support, @eddyb correctly pointed out on IRC that there is no such thing as a zero-sized type in C. And even with clang, which allows empty structs, those get translated as void return types as well. Fixes rust-lang#28766
The only way to get a value for a zero-sized type is `undef`, so there's really no point in actually having a return type other than void for such types. Also, while the comment in return_type_is_void mentioned something about aiding C ABI support, @eddyb correctly pointed out on IRC that there is no such thing as a zero-sized type in C. And even with clang, which allows empty structs, those get translated as void return types as well. Fixes rust-lang#28766
Demonstration
I uploaded a repo with the simplest possible case I could come up with that demonstrates this issue here. Here's how it works:
Explanation
So I have a crate in my project, brilliantly named
my_crate
.my_crate
is pretty simple, it contains a struct, calledFoo
, made up of zero-sized types.Foo
also has a constructor function calledFoo::new()
:Now, in my library,
segfault
, I have a single function, calledbox_foo()
, that just returns aBox<Foo>
. It constructs aFoo
, then boxes it:Well, that's about it. Building
segfault
andmy_crate
withcargo build
works perfectly fine. However,cargo build --release
crashes with a signal 11, a segfault.Some observations
Foo
must be a zero-sized type, but cannot be a unit structFoo
must be constructed with a function (e.gBox::new(Foo(())
would not segfault)Foo
must be from another cratebox_foo()
is public (otherwise it's dead code, and I guessrustc
doesn't even attempt to compile it?)impl Foo
, but it does have to come frommy_crate
let boxed: Box<Foo> = Foo::new_box();
would not segfault)Foo
has the same issueBox<Foo>
, but by constructing one withBox::new
. That is, the following also causes a segfault:The text was updated successfully, but these errors were encountered: