Zig Version
0.16.0-dev.3142+5ccfeb926
Steps to Reproduce and Observed Behavior
First reduction of issue
The self-hosted x86_64 backend crashes on @bitCast of a packed struct containing a void (zero-bit) field. Removing the void field, using a release build, or targeting aarch64 all work fine.
repro.zig:
const S = packed struct { _: void = {}, a: u8 = 0 };
export fn f(x: u8) u8 { return @bitCast(S{ .a = x }); }
Debug on x86_64 fails:
% zig build-obj -ODebug -target x86_64-linux-gnu repro.zig
zsh: segmentation fault zig build-obj -ODebug -target x86_64-linux-gnu repro.zig
ReleaseSafe is fine:
zig build-obj -OReleaseSafe -target x86_64-linux-gnu repro.zig
Second reduction of issue
Another interesting minimal repro, with no @bitCast:
const S = packed struct { _: void = {}, a: u5 = 0 };
fn inner(x: u8) u5 {
const s = S{ .a = @truncate(x) };
return s.a;
}
export fn f(x: u8) u8 { return inner(x); }
Expected Behavior
No compiler segfault
### Zig Version
0.16.0-dev.3142+5ccfeb926
### Steps to Reproduce and Observed Behavior
## First reduction of issue
The self-hosted x86_64 backend crashes on `@bitCast` of a `packed struct` containing a void (zero-bit) field. Removing the void field, using a release build, or targeting aarch64 all work fine.
`repro.zig`:
```
const S = packed struct { _: void = {}, a: u8 = 0 };
export fn f(x: u8) u8 { return @bitCast(S{ .a = x }); }
```
Debug on x86_64 fails:
```
% zig build-obj -ODebug -target x86_64-linux-gnu repro.zig
zsh: segmentation fault zig build-obj -ODebug -target x86_64-linux-gnu repro.zig
```
ReleaseSafe is fine:
```
zig build-obj -OReleaseSafe -target x86_64-linux-gnu repro.zig
```
## Second reduction of issue
Another interesting minimal repro, with no `@bitCast`:
```
const S = packed struct { _: void = {}, a: u5 = 0 };
fn inner(x: u8) u5 {
const s = S{ .a = @truncate(x) };
return s.a;
}
export fn f(x: u8) u8 { return inner(x); }
```
### Expected Behavior
No compiler segfault