Skip to content

Compiler crash hits data.live_set.count() == 0 assert in Liveness.zig #21516

@eshom

Description

@eshom

Zig Version

0.15.0-dev.1253+fc4b7c968

Steps to Reproduce and Observed Behavior

src/main.zig

const std = @import("std");

pub fn main() !void {
    const c = @cImport({
        @cInclude("pty.h");
    });

    var master_fd: c_int = 0;
    var pid: c.pid_t = 0;

    pid = c.forkpty(&master_fd, null, null, null);
    if (pid == -1) {
        std.debug.print("forkpty failed\n", .{});
        return;
    }

    if (pid == 0) {
        var args = [_:null]?[*:0]const u8{ "/bin/sh", "-il" };
        const err = std.posix.execvpeZ(args[0].?, &args, std.c.environ);
        std.log.err("exec failed: {}", .{err});
    } else {
        std.debug.print("Parent process: forkpty succeeded\n", .{});

        const master_file = std.fs.File{ .handle = master_fd };
        var buf: [1024:0]u8 = undefined;

        // compiler crash
        if (master_file.read(buf[0..])) |read_results| {
            std.debug.print("read result: {}\n", .{read_results});
        } else |err| {
            std.debug.print("Read error: {}\n", .{err});
        }

        // Below doesn't crash

        // const read_result = master_file.read(buf[0..]) catch |err| {
        //     std.debug.print("Read error: {}\n", .{err});
        //     std.process.exit(0);
        // };

        // const read_result = try master_file.read(buf[0..]);
        // std.debug.print("read result: {}\n", .{read_result});
    }
}

Output:

❯ ~/.local/share/zig/zig-dev-debug/bin/zig run -lc test10.zig
thread 37941 panic: reached unreachable code
/home/erez/src/zig/build/stage3/lib/zig/std/debug.zig:559:14: 0x624b349 in assert (std.zig)
    if (!ok) unreachable; // assertion failure
             ^
/home/erez/src/zig/src/Air/Liveness.zig:178:15: 0x7a0e924 in analyze (main.zig)
        assert(data.live_set.count() == 0);
              ^
/home/erez/src/zig/src/Zcu/PerThread.zig:4361:21: 0x72fd170 in runCodegenInner (main.zig)
        try .analyze(zcu, air.*, ip)
                    ^
/home/erez/src/zig/src/Zcu/PerThread.zig:4310:46: 0x6dd04f7 in runCodegen (main.zig)
    const success: bool = if (runCodegenInner(pt, func_index, air)) |mir| success: {
                                             ^
/home/erez/src/zig/src/Compilation.zig:5425:18: 0x72bd3a1 in workerZcuCodegen (main.zig)
    pt.runCodegen(func_index, &air, out);
                 ^
/home/erez/src/zig/build/stage3/lib/zig/std/Thread/Pool.zig:180:50: 0x72bd7dc in runFn (std.zig)
            @call(.auto, func, .{id.?} ++ closure.arguments);
                                                 ^
/home/erez/src/zig/build/stage3/lib/zig/std/Thread/Pool.zig:293:27: 0x720245d in worker (std.zig)
            runnable.runFn(runnable, id);
                          ^
/home/erez/src/zig/build/stage3/lib/zig/std/Thread.zig:510:13: 0x6ceee70 in callFn__anon_195317 (std.zig)
            @call(.auto, f, args);
            ^
/home/erez/src/zig/build/stage3/lib/zig/std/Thread.zig:782:30: 0x6796989 in entryFn (std.zig)
                return callFn(f, args_ptr.*);
                             ^
???:?:?: 0x7febab69a7bd in ??? (libc.so.6)
Unwind information for `libc.so.6:0x7febab69a7bd` was not available, trace may be incomplete

Expected Behavior

No compiler crash

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions