-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Union comptime var compiler crash #19720
Labels
Milestone
Comments
I got the first one trying to reduce this one, I suppose they are related. // bug.zig
pub fn main() void {
comptime var defs: [5]union(enum) { bar: []const u8, foo } = undefined;
inline for (&defs) |*def| {
def.* = .{ .bar = "foo" };
}
} debug zig build-exe bug.zig output$ ../zig/stage3/bin/zig build-exe bug.zig
thread 24618 panic: reached unreachable code
/home/jean/src/zig/src/codegen/llvm.zig:4281:60: 0xa1fb5b7 in lowerPtr (zig)
.arr_elem, .comptime_field, .comptime_alloc => unreachable,
^
/home/jean/src/zig/src/codegen/llvm.zig:3798:35: 0x9f40730 in lowerValue (zig)
.ptr => try o.lowerPtr(arg_val, 0),
^
/home/jean/src/zig/src/codegen/llvm.zig:4736:42: 0xa734b37 in resolveValue (zig)
const llvm_val = try o.lowerValue(val.toIntern());
^
/home/jean/src/zig/src/codegen/llvm.zig:4727:47: 0xa7348d1 in resolveInst (zig)
const llvm_val = try self.resolveValue((try self.air.value(inst, mod)).?);
^
/home/jean/src/zig/src/codegen/llvm.zig:9353:47: 0xa790205 in airSetUnionTag (zig)
const union_ptr = try self.resolveInst(bin_op.lhs);
^
/home/jean/src/zig/src/codegen/llvm.zig:4933:59: 0xa3e3a4d in genBody (zig)
.set_union_tag => try self.airSetUnionTag(inst),
^
/home/jean/src/zig/src/codegen/llvm.zig:1709:19: 0xa3dc9c6 in updateFunc (zig)
fg.genBody(air.getMainBody()) catch |err| switch (err) {
^
/home/jean/src/zig/src/link/Elf.zig:3029:70: 0xa720819 in updateFunc (zig)
if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
^
/home/jean/src/zig/src/link.zig:420:82: 0xa3eb158 in updateFunc (zig)
return @as(*tag.Type(), @fieldParentPtr("base", base)).updateFunc(module, func_index, air, liveness);
^
/home/jean/src/zig/src/Module.zig:3219:22: 0xa15dd37 in ensureFuncBodyAnalyzed (zig)
lf.updateFunc(zcu, func_index, air, liveness) catch |err| switch (err) {
^
/home/jean/src/zig/src/Compilation.zig:3419:42: 0xa15ae62 in processOneJob (zig)
module.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
^
/home/jean/src/zig/src/Compilation.zig:3359:30: 0x9f89f9a in performAllTheWork (zig)
try processOneJob(comp, work_item, main_progress_node);
^
/home/jean/src/zig/src/Compilation.zig:2132:31: 0x9f854d2 in update (zig)
try comp.performAllTheWork(main_progress_node);
^
/home/jean/src/zig/src/main.zig:4483:24: 0x9fb6c2f in updateModule (zig)
try comp.update(main_progress_node);
^
/home/jean/src/zig/src/main.zig:3405:17: 0xa01f554 in buildOutputType (zig)
updateModule(comp, color) catch |err| switch (err) {
^
/home/jean/src/zig/src/main.zig:260:31: 0x9e67a31 in mainArgs (zig)
return buildOutputType(gpa, arena, args, .{ .build = .Exe });
^
/home/jean/src/zig/src/main.zig:206:20: 0x9e649c5 in main (zig)
return mainArgs(gpa, arena, args);
^
/home/jean/src/zig/lib/std/start.zig:511:37: 0x9e6445e in main (zig)
const result = root.main() catch |err| {
^
../sysdeps/nptl/libc_start_call_main.h:58:16: 0x7f998a35bc4b in __libc_start_call_main (../sysdeps/x86/libc-start.c)
../csu/libc-start.c:360:3: 0x7f998a35bd04 in __libc_start_main_impl (../sysdeps/x86/libc-start.c)
../sysdeps/x86_64/start.S:115:0: 0x4f6eb60 in _start (../sysdeps/x86_64/start.S)
???:?:?: 0x0 in ??? (???)
Aborted AIR logs are similar, it crashes when trying to print the value. |
Note: works fine if value assigned is explicitly marked pub fn main() void {
comptime var def: union(enum) { bar: []const u8, foo } = undefined;
def = comptime .{ .bar = "bar" };
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Zig Version
0.12.0
Steps to Reproduce and Observed Behavior
With the
zig
binary from the release tarball:$ zig build-exe bug.zig Trace/breakpoint trap
With a debug 0.12.0 `zig`:
AIR logs (crashes in `print_value.zig`)
Expected Behavior
Program compiles, or an error is printed.
The text was updated successfully, but these errors were encountered: