zig icon indicating copy to clipboard operation
zig copied to clipboard

stage2 segfaults when constructing an enum type with an integer given by `@Type`

Open tauoverpi opened this issue 3 years ago • 1 comments

Zig Version

0.10.0-dev.3361+c650ccfca

Steps to Reproduce

Run the following with zig test -fno-stage1

test {
    const Int = @Type(.{ .Int = .{
        .signedness = .unsigned,
        .bits = 12,
    } });
    _ = enum(Int) { empty };
}

Expected Behavior

Compiles without errors.

Actual Behavior

Crashes the compiler.

$ zig test -fno-stage1 bug.zig
fish: Job 1, 'zig test -fno-stage1 bug.zig' terminated by signal SIGSEGV (Address boundary error)

tauoverpi avatar Jul 28 '22 16:07 tauoverpi

This happens because zirEnumDecl tries to eagerly analyze the enum type before the closure_capture instructions after it have been analyzed.

Vexu avatar Jul 28 '22 17:07 Vexu

Stack trace:

thread 27665 panic: attempt to use null value
/home/david/dev/official-zig/src/Sema.zig:14019:29: 0x562265d504cb in Sema.zirClosureGet (zig2)
        scope = scope.parent.?;
                            ^
/home/david/dev/official-zig/src/Sema.zig:728:68: 0x562265bab07d in Sema.analyzeBodyInner (zig2)
            .closure_get                  => try sema.zirClosureGet(block, inst),
                                                                   ^
/home/david/dev/official-zig/src/Sema.zig:611:30: 0x562265b9ea9a in Sema.analyzeBody (zig2)
    _ = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                             ^
/home/david/dev/official-zig/src/Sema.zig:2633:33: 0x562265dc1e1d in Sema.zirEnumDecl (zig2)
            try sema.analyzeBody(&enum_block, body);
                                ^
/home/david/dev/official-zig/src/Sema.zig:926:67: 0x562265bb3838 in Sema.analyzeBodyInner (zig2)
                    .enum_decl             => try sema.zirEnumDecl(          block, extended, inst),
                                                                  ^
/home/david/dev/official-zig/src/Sema.zig:611:30: 0x562265b9ea9a in Sema.analyzeBody (zig2)
    _ = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                             ^
/home/david/dev/official-zig/src/Module.zig:5591:21: 0x5622659a2043 in Module.analyzeFnBody (zig2)
    sema.analyzeBody(&inner_block, fn_info.body) catch |err| switch (err) {
                    ^
/home/david/dev/official-zig/src/Module.zig:4291:40: 0x56226598296a in Module.ensureFuncBodyAnalyzed (zig2)
            var air = mod.analyzeFnBody(func, sema_arena) catch |err| switch (err) {
                                       ^
/home/david/dev/official-zig/src/Compilation.zig:3047:42: 0x56226567271c in Compilation.processOneJob (zig2)
            module.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
                                         ^
/home/david/dev/official-zig/src/Compilation.zig:2985:30: 0x56226566046f in Compilation.performAllTheWork (zig2)
            try processOneJob(comp, work_item);
                             ^
/home/david/dev/official-zig/src/Compilation.zig:2325:31: 0x562265658b1d in Compilation.update (zig2)
    try comp.performAllTheWork(main_progress_node);
                              ^
/home/david/dev/official-zig/src/main.zig:3304:20: 0x5622655e40ff in main.updateModule (zig2)
    try comp.update();
                   ^
/home/david/dev/official-zig/src/main.zig:2989:17: 0x5622655311e4 in main.buildOutputType (zig2)
    updateModule(gpa, comp, hook) catch |err| switch (err) {
                ^
/home/david/dev/official-zig/src/main.zig:236:31: 0x5622654d470e in main.mainArgs (zig2)
        return buildOutputType(gpa, arena, args, .zig_test);
                              ^
/home/david/dev/official-zig/src/stage1.zig:48:24: 0x5622654d3e59 in main (zig2)
        stage2.mainArgs(gpa, arena, args) catch unreachable;
                       ^

davidgmbb avatar Sep 30 '22 05:09 davidgmbb