zig icon indicating copy to clipboard operation
zig copied to clipboard

-fstage1 crashes on wasm32-freestanding with async

Open AmandaCameron opened this issue 3 years ago • 0 comments

Zig Version

0.11.0-dev.3+0bbb00035

Steps to Reproduce and Observed Behavior

The following program causes the compiler to SIGABRT when compiled with stage1.

Build commandline: zig build-lib issue-repro.zig --name issue-repro -dynamic -target wasm32-freestanding -mcpu generic --enable-cache

The output of the compiler is:

when analyzing .../issue-repro.zig:6:22 in compiler source at /workspace/src/stage1/codegen.cpp:2068: thread 2553910 panic: assertion failed. This is a bug in the Zig compiler.
Unable to dump stack trace: debug info stripped
fish: Job 1, 'zig build-lib  issue-repro.zig…' terminated by signal SIGABRT (Abort)
var main_frame: ?@Frame(main) = undefined;

// Run is called by the wasm runtime multiple times, after events happen.
export fn run() void {
    if(main_frame == null) {
        main_frame = async main();
        return;
    }

    resume main_frame.?;
    return;
}

// The idea is main would utilise an event loop from run which occasonally checks if an event has been returned in run, then resume the relevent frame.
fn main() void {
    while(true) {
        suspend{}
    }
}

Expected Behavior

The program to compile. This same code works fine with 0.9.1, at least the code I distilled the crash down from does.

AmandaCameron avatar Nov 01 '22 15:11 AmandaCameron