Open toffaletti opened 3 years ago
I suspect this might be related to https://github.com/ziglang/zig/issues/4680
I suspect I'm encountering the same or a closely related issue, without even using @embedFile
(which might suggest it's not closely tied to #4680):
pub fn main() anyerror!void {
_ = length_codes[0];
}
const length_codes = blk: {
var codes: [2]SomeStruct = undefined;
for (codes[0..1]) |_| {
}
break :blk codes;
};
const SomeStruct = struct {
val: u64,
};
$ zig version
0.9.0-dev.1679+6cf8a49bb
$ zig build-exe src/main.zig
Unreachable at /home/tau/foreign/zig/src/stage1/ir.cpp:22940 in buf_write_value_bytes. This is a bug in the Zig compiler.
This occurs whether I set the array to undefined
or initialize it explicitly, but only if its length is greater than 1. Does anyone have a workaround for the issue?
[EDIT 2021-11-19: still broken on current master.]
~For what its worth, I no longer encounter this in 0.8.1 on an M1 Mac.~ I spoke too soon. I found a case where removing my work around triggers it still.
This looks like the same bug as #10024
Given this code in a file named
ptr_cast_crasher.zig
:This code can be modified to crash in other ways as well, for example, if we change
&data[0..8]
todata[0..8]
: