Zig Version
0.16.0-dev.1503+738d2be9d
Steps to Reproduce and Observed Behavior
Attempt to compile the following repro.zig
pubfnmain()void{constblah=comptimeblk:{varbuf:u8=0;break:blk.{.a=&buf};};@import("std").debug.print("{any}\n",.{blah});}
With a debug build of the compiler:
$ zig build-exe repro.zig
Compiler crash context:
(no context)
thread 6370 panic: reached unreachable code
[...]/zig/src/codegen.zig:742:56: 0x28f6a46 in lowerPtr (main.zig)
.arr_elem, .comptime_field, .comptime_alloc => unreachable,
^
[...]/zig/src/codegen.zig:444:29: 0x23dbe8f in generateSymbol (main.zig)
.ptr => try lowerPtr(bin_file, pt, src_loc, val.toIntern(), w, reloc_parent, 0),
^
[...]/zig/src/link/Dwarf.zig:2130:35: 0x4219deb in blockValue (main.zig)
try codegen.generateSymbol(
^
[...]/zig/src/link/Dwarf.zig:4579:59: 0x45e6496 in updateContainerTypeWriterError (main.zig)
try wip_nav.blockValue(ty_src_loc, .fromInterned(field_init));
^
[...]/zig/src/link/Dwarf.zig:4383:48: 0x3d5c046 in updateContainerType (main.zig)
return dwarf.updateContainerTypeWriterError(pt, type_index) catch |err| switch (err) {
^
[...]/zig/src/link/Elf/ZigObject.zig:1718:59: 0x33303fd in updateContainerType (main.zig)
if (self.dwarf) |*dwarf| try dwarf.updateContainerType(pt, ty);
^
[...]/zig/src/link/Elf.zig:1710:53: 0x3330c23 in updateContainerType (main.zig)
return self.zigObjectPtr().?.updateContainerType(pt, ty) catch |err| switch (err) {
^
[...]/zig/src/link.zig:787:91: 0x2cde4f3 in updateContainerType (main.zig)
return @as(*tag.Type(), @fieldParentPtr("base", base)).updateContainerType(pt, ty);
^
[...]/zig/src/link.zig:1549:43: 0x2843282 in doZcuTask (main.zig)
lf.updateContainerType(pt, ty) catch |err| switch (err) {
^
[...]/zig/src/link/Queue.zig:318:23: 0x28209a7 in flushTaskQueue (main.zig)
link.doZcuTask(comp, tid, task);
^
[...]/lib/std/Thread/Pool.zig:180:50: 0x2821153 in runFn (std.zig)
@call(.auto, func, .{id.?} ++ closure.arguments);
^
[...]/lib/std/Thread/Pool.zig:293:27: 0x22b6d20 in worker (std.zig)
runnable.runFn(runnable, id);
^
[...]/lib/std/Thread.zig:559:13: 0x20dac90 in callFn__anon_198523 (std.zig)
@call(.auto, f, args);
^
[...]/lib/std/Thread.zig:1535:30: 0x1f6a500 in entryFn (std.zig)
return callFn(f, self.fn_args);
^
[...]/lib/std/os/linux/x86_64.zig:105:5: 0x1cdc725 in clone (std.zig)
asm volatile (
^
Error: nu::shell::core_dumped
×ばつ External command core dumped
╭─[entry #11:1:1]
1 │ zig build-exe repro.zig
· ─┬─
· ╰── core dumped with SIGABRT (6)
╰────
Something about breaking with a struct allows this to slip through the cracks, since applying either
< break :blk .{ .a = &buf };
---
> break :blk .{ &buf };
< break :blk .{ .a = &buf };
---
> break :blk &buf;
produces the correct error.
In the inciting code this ended up happening due to a slice that wasn't dereferenced to an array that erroneously worked in 0.14.
Expected Behavior
The compiler not to crash and report the usual runtime reference to comptime memory.
### Zig Version
0.16.0-dev.1503+738d2be9d
### Steps to Reproduce and Observed Behavior
Attempt to compile the following `repro.zig`
```zig
pub fn main() void {
const blah = comptime blk: {
var buf: u8 = 0;
break :blk .{ .a = &buf };
};
@import("std").debug.print("{any}\n", .{blah});
}
```
With a debug build of the compiler:
```
$ zig build-exe repro.zig
Compiler crash context:
(no context)
thread 6370 panic: reached unreachable code
[...]/zig/src/codegen.zig:742:56: 0x28f6a46 in lowerPtr (main.zig)
.arr_elem, .comptime_field, .comptime_alloc => unreachable,
^
[...]/zig/src/codegen.zig:444:29: 0x23dbe8f in generateSymbol (main.zig)
.ptr => try lowerPtr(bin_file, pt, src_loc, val.toIntern(), w, reloc_parent, 0),
^
[...]/zig/src/link/Dwarf.zig:2130:35: 0x4219deb in blockValue (main.zig)
try codegen.generateSymbol(
^
[...]/zig/src/link/Dwarf.zig:4579:59: 0x45e6496 in updateContainerTypeWriterError (main.zig)
try wip_nav.blockValue(ty_src_loc, .fromInterned(field_init));
^
[...]/zig/src/link/Dwarf.zig:4383:48: 0x3d5c046 in updateContainerType (main.zig)
return dwarf.updateContainerTypeWriterError(pt, type_index) catch |err| switch (err) {
^
[...]/zig/src/link/Elf/ZigObject.zig:1718:59: 0x33303fd in updateContainerType (main.zig)
if (self.dwarf) |*dwarf| try dwarf.updateContainerType(pt, ty);
^
[...]/zig/src/link/Elf.zig:1710:53: 0x3330c23 in updateContainerType (main.zig)
return self.zigObjectPtr().?.updateContainerType(pt, ty) catch |err| switch (err) {
^
[...]/zig/src/link.zig:787:91: 0x2cde4f3 in updateContainerType (main.zig)
return @as(*tag.Type(), @fieldParentPtr("base", base)).updateContainerType(pt, ty);
^
[...]/zig/src/link.zig:1549:43: 0x2843282 in doZcuTask (main.zig)
lf.updateContainerType(pt, ty) catch |err| switch (err) {
^
[...]/zig/src/link/Queue.zig:318:23: 0x28209a7 in flushTaskQueue (main.zig)
link.doZcuTask(comp, tid, task);
^
[...]/lib/std/Thread/Pool.zig:180:50: 0x2821153 in runFn (std.zig)
@call(.auto, func, .{id.?} ++ closure.arguments);
^
[...]/lib/std/Thread/Pool.zig:293:27: 0x22b6d20 in worker (std.zig)
runnable.runFn(runnable, id);
^
[...]/lib/std/Thread.zig:559:13: 0x20dac90 in callFn__anon_198523 (std.zig)
@call(.auto, f, args);
^
[...]/lib/std/Thread.zig:1535:30: 0x1f6a500 in entryFn (std.zig)
return callFn(f, self.fn_args);
^
[...]/lib/std/os/linux/x86_64.zig:105:5: 0x1cdc725 in clone (std.zig)
asm volatile (
^
Error: nu::shell::core_dumped
×ばつ External command core dumped
╭─[entry #11:1:1]
1 │ zig build-exe repro.zig
· ─┬─
· ╰── core dumped with SIGABRT (6)
╰────
```
Something about breaking with a struct allows this to slip through the cracks, since applying either
```diff
< break :blk .{ .a = &buf };
---
> break :blk .{ &buf };
```
```diff
< break :blk .{ .a = &buf };
---
> break :blk &buf;
```
produces the correct error.
In the inciting code this ended up happening due to a slice that wasn't dereferenced to an array that erroneously worked in 0.14.
### Expected Behavior
The compiler not to crash and report the usual runtime reference to comptime memory.