zig
zig copied to clipboard
compiler segfault with empty union
Zig Version
0.11.0-dev.5
Steps to Reproduce and Observed Behavior
const U = union(enum) {};
fn f2(u: U) void {
_ = u;
}
pub fn main() void {
_ = f2;
}
Expected Behavior
stage1 gives an error:
./main.zig:1:11: error: unions must have 1 or more fields
const U = union(enum) {};
stack trace on 0.11.0-dev.6+2943df016
thread 662502 panic: index out of bounds
/home/meghan/src/zig/src/codegen/llvm.zig:7900:34: 0xc913a7 in codegen.llvm.FuncGen.airArg (zig2)
const arg_val = self.args[self.arg_index];
^
/home/meghan/src/zig/src/codegen/llvm.zig:4531:51: 0xc7844d in codegen.llvm.FuncGen.genBody (zig2)
.arg => try self.airArg(inst),
^
/home/meghan/src/zig/src/codegen/llvm.zig:1225:19: 0xc73227 in codegen.llvm.Object.updateFunc (zig2)
fg.genBody(air.getMainBody()) catch |err| switch (err) {
^
/home/meghan/src/zig/src/link/Elf.zig:2411:74: 0x9bf0a7 in link.Elf.updateFunc (zig2)
if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(module, func, air, liveness);
^
/home/meghan/src/zig/src/link.zig:558:77: 0x7d3ca9 in link.File.updateFunc (zig2)
.elf => return @fieldParentPtr(Elf, "base", base).updateFunc(module, func, air, liveness),
^
/home/meghan/src/zig/src/Module.zig:4385:37: 0x7b1221 in Module.ensureFuncBodyAnalyzed (zig2)
comp.bin_file.updateFunc(mod, func, air, liveness) catch |err| switch (err) {
^
/home/meghan/src/zig/src/Compilation.zig:3065:42: 0x65fde3 in Compilation.processOneJob (zig2)
module.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
^
/home/meghan/src/zig/src/Compilation.zig:3003:30: 0x64d66f in Compilation.performAllTheWork (zig2)
try processOneJob(comp, work_item);
^
/home/meghan/src/zig/src/Compilation.zig:2331:31: 0x645d1e in Compilation.update (zig2)
try comp.performAllTheWork(main_progress_node);
^
/home/meghan/src/zig/src/main.zig:3337:20: 0x5d12bf in main.updateModule (zig2)
try comp.update();
^
/home/meghan/src/zig/src/main.zig:3008:17: 0x518618 in main.buildOutputType (zig2)
updateModule(gpa, comp, hook) catch |err| switch (err) {
^
/home/meghan/src/zig/src/main.zig:238:31: 0x4b10af in main.mainArgs (zig2)
return buildOutputType(gpa, arena, args, .run);
^
/home/meghan/src/zig/src/stage1.zig:56:24: 0x4b0725 in main (zig2)
stage2.mainArgs(gpa, arena, args) catch unreachable;
^
Related #12376