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

Segfault when compiling undefined function pointer #880

Closed
tiehuis opened this Issue Apr 1, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@tiehuis
Member

tiehuis commented Apr 1, 2018

zig build-exe file.zig

const Cmd = struct {
    exec: fn() void,
};

pub fn main() void {
    const command = Cmd { .exec = undefined };
    command.exec();
}
#0  0x00005555563910f6 in ir_analyze_instruction_call (ira=0x55555d17fcd0, call_instruction=0x55555d17f6a0) at /home/me/src/zig/src/ir.cpp:12409
#1  0x00005555563a5406 in ir_analyze_instruction_nocast (ira=0x55555d17fcd0, instruction=0x55555d17f6a0) at /home/me/src/zig/src/ir.cpp:17953
#2  0x00005555563a5db3 in ir_analyze_instruction (ira=0x55555d17fcd0, instruction=0x55555d17f6a0) at /home/me/src/zig/src/ir.cpp:18163
#3  0x00005555563a60a7 in ir_analyze (codegen=0x55555afbe410, old_exec=0x55555d17b320, new_exec=0x55555d17b408, expected_type=0x55555afd4d50, expected_type_source_node=0x55555b012390) at /home/me/src/zig/src/ir.cpp:18217
#4  0x000055555632e7a2 in analyze_fn_ir (g=0x55555afbe410, fn_table_entry=0x55555d17b2b0, return_type_node=0x55555b012390) at /home/me/src/zig/src/analyze.cpp:3875
#5  0x000055555632ec2e in analyze_fn_body (g=0x55555afbe410, fn_table_entry=0x55555d17b2b0) at /home/me/src/zig/src/analyze.cpp:3962
#6  0x000055555632f84d in semantic_analyze (g=0x55555afbe410) at /home/me/src/zig/src/analyze.cpp:4167
#7  0x000055555635fe25 in gen_root_source (g=0x55555afbe410) at /home/me/src/zig/src/codegen.cpp:6418
#8  0x0000555556361986 in codegen_build (g=0x55555afbe410) at /home/me/src/zig/src/codegen.cpp:6916
#9  0x00005555563be457 in main (argc=3, argv=0x7fffffffdd28) at /home/me/src/zig/src/main.cpp:867

Using an actual function is fine, of course so probably just missing a simple check somewhere down the line.

const Cmd = struct {
    exec: fn() void,
};

fn do() void {}

pub fn main() void {
    const command = Cmd { .exec = do };
    command.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment