Skip to content

Assertion `incoming_count != 0' failed. #712

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

Closed
bnoordhuis opened this issue Jan 21, 2018 · 1 comment
Closed

Assertion `incoming_count != 0' failed. #712

bnoordhuis opened this issue Jan 21, 2018 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@bnoordhuis
Copy link
Contributor

With commit 517e8ea:

fn S(comptime _: type) -> type {
    return union(enum) { M };
}

pub fn main() {
    switch (@typeOf(S(i8).M)) {}
}

Produces:

$ zig version
0.1.1.517e8ea4

$ zig build-exe x.zig
zig: /home/bnoordhuis/src/zig/src/ir.cpp:955: IrInstruction* ir_build_phi(IrBuilder*, Scope*, AstNode*, size_t, IrBasicBlock**, IrInstruction**): Assertion `incoming_count != 0' failed.

Backtrace:

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007ffff3913f5d in __GI_abort () at abort.c:90
#2  0x00007ffff3909f17 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x555556e2a355 "incoming_count != 0", file=file@entry=0x555556e2a268 "/home/bnoordhuis/src/zig/src/ir.cpp", line=line@entry=955, function=function@entry=0x555556e2f5c0 <ir_build_phi(IrBuilder*, Scope*, AstNode*, unsigned long, IrBasicBlock**, IrInstruction**)::__PRETTY_FUNCTION__> "IrInstruction* ir_build_phi(IrBuilder*, Scope*, AstNode*, size_t, IrBasicBlock**, IrInstruction**)") at assert.c:92
#3  0x00007ffff3909fc2 in __GI___assert_fail (assertion=0x555556e2a355 "incoming_count != 0", file=0x555556e2a268 "/home/bnoordhuis/src/zig/src/ir.cpp", line=955, function=0x555556e2f5c0 <ir_build_phi(IrBuilder*, Scope*, AstNode*, unsigned long, IrBasicBlock**, IrInstruction**)::__PRETTY_FUNCTION__> "IrInstruction* ir_build_phi(IrBuilder*, Scope*, AstNode*, size_t, IrBasicBlock**, IrInstruction**)") at assert.c:101
#4  0x0000555555da36f1 in ir_build_phi (irb=0x7fffffffd4f0, scope=0x5555595dba30, source_node=0x555557667c70, incoming_count=0, incoming_blocks=0x0, incoming_values=0x0) at /home/bnoordhuis/src/zig/src/ir.cpp:955
#5  0x0000555555db2df9 in ir_gen_switch_expr (irb=0x7fffffffd4f0, scope=0x5555595dba30, node=0x555557667c70) at /home/bnoordhuis/src/zig/src/ir.cpp:4995
#6  0x0000555555db4a4b in ir_gen_node_raw (irb=0x7fffffffd4f0, node=0x555557667c70, scope=0x5555595dba30, lval=...) at /home/bnoordhuis/src/zig/src/ir.cpp:5441
#7  0x0000555555db4c7d in ir_gen_node_extra (irb=0x7fffffffd4f0, node=0x555557667c70, scope=0x5555595dba30, lval=...) at /home/bnoordhuis/src/zig/src/ir.cpp:5467
#8  0x0000555555db4d0d in ir_gen_node (irb=0x7fffffffd4f0, node=0x555557667c70, scope=0x5555595dba30) at /home/bnoordhuis/src/zig/src/ir.cpp:5473
#9  0x0000555555da81f2 in ir_gen_block (irb=0x7fffffffd4f0, parent_scope=0x5555595d8920, block_node=0x555557667bd0) at /home/bnoordhuis/src/zig/src/ir.cpp:2584
#10 0x0000555555db4537 in ir_gen_node_raw (irb=0x7fffffffd4f0, node=0x555557667bd0, scope=0x5555595d8920, lval=...) at /home/bnoordhuis/src/zig/src/ir.cpp:5385
#11 0x0000555555db4c7d in ir_gen_node_extra (irb=0x7fffffffd4f0, node=0x555557667bd0, scope=0x5555595d8920, lval=...) at /home/bnoordhuis/src/zig/src/ir.cpp:5467
#12 0x0000555555db4e93 in ir_gen (codegen=0x55555762edc0, node=0x555557667bd0, scope=0x5555595d8920, ir_executable=0x5555595d8730) at /home/bnoordhuis/src/zig/src/ir.cpp:5504
#13 0x0000555555db4fbc in ir_gen_fn (codegen=0x55555762edc0, fn_entry=0x5555595d86c0) at /home/bnoordhuis/src/zig/src/ir.cpp:5524
#14 0x0000555555d7042b in analyze_fn_body (g=0x55555762edc0, fn_table_entry=0x5555595d86c0) at /home/bnoordhuis/src/zig/src/analyze.cpp:3683
#15 0x0000555555d7111d in semantic_analyze (g=0x55555762edc0) at /home/bnoordhuis/src/zig/src/analyze.cpp:3900
#16 0x0000555555d9d43d in gen_root_source (g=0x55555762edc0) at /home/bnoordhuis/src/zig/src/codegen.cpp:5744
#17 0x0000555555d9e66c in codegen_build (g=0x55555762edc0) at /home/bnoordhuis/src/zig/src/codegen.cpp:6064
#18 0x0000555555dec8d1 in main (argc=3, argv=0x7fffffffdb18) at /home/bnoordhuis/src/zig/src/main.cpp:852
@andrewrk andrewrk added this to the 0.2.0 milestone Jan 21, 2018
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Jan 21, 2018
@andrewrk
Copy link
Member

Thanks for the report. I think this has to do with the union having only 1 field.

Zig has runtime safety for unions, and there is an optimization where the secret enum field does not need to exist if there is only 1 field. Looks like a bug with that situation.

I'll look into this over the next couple days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants