Skip to content

stage2: Crash with labeled block expression in nested inline for #13175

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

Open
topolarity opened this issue Oct 15, 2022 · 1 comment
Open

stage2: Crash with labeled block expression in nested inline for #13175

topolarity opened this issue Oct 15, 2022 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@topolarity
Copy link
Contributor

Zig Version

0.10.0-dev.4418+99c3578f6

Steps to Reproduce

test "continue nested inline for loop in named block expr" {
    var a: u8 = 0;
    loop: inline for ([_]u8{ 1, 2 }) |x| {
        a = b: {
            inline for ([_]u8{1}) |y| {
                if (x == y) {
                    continue :loop;
                }
            }
            break :b x;
        };
        try expect(x == 2);
    }
    try expect(a == 2);
}

Basically a more complicated version of #13038

Expected Behavior

Test should pass.

Actual Behavior

Semantic Analysis [2905] foo... thread 169164 panic: reached unreachable code
/home/topolarity/repos/zig/lib/std/debug.zig:281:14: 0x556633ec88d6 in std.debug.assert (zig2)
    if (!ok) unreachable; // assertion failure
             ^
/home/topolarity/repos/zig/src/Sema.zig:5065:11: 0x556634810441 in Sema.analyzeBlockBody (zig2)
    /// use to return from the body.
          ^
/home/topolarity/repos/zig/src/Sema.zig:5031:41: 0x556634a2fc55 in Sema.resolveBlockBody (zig2)
    var child_block: Block = .{
                                        ^
/home/topolarity/repos/zig/src/Sema.zig:5013:33: 0x55663480f4c7 in Sema.zirBlock (zig2)
    // Reserve space for a Block instruction so that generated Break instructions can
                                ^
/home/topolarity/repos/zig/src/Sema.zig:1270:69: 0x5566345cf7eb in Sema.analyzeBodyInner (zig2)
                        orig_captures = 0;
                                                                    ^
/home/topolarity/repos/zig/src/Sema.zig:646:45: 0x5566345bd5bc in Sema.analyzeBodyBreak (zig2)
            });
                                            ^
/home/topolarity/repos/zig/src/Sema.zig:1407:62: 0x5566345d0a8b in Sema.analyzeBodyInner (zig2)
                }
                                                             ^
/home/topolarity/repos/zig/src/Sema.zig:646:45: 0x5566345bd5bc in Sema.analyzeBodyBreak (zig2)
            });
                                            ^
/home/topolarity/repos/zig/src/Sema.zig:1323:65: 0x5566345cfbda in Sema.analyzeBodyInner (zig2)
                    break always_noreturn;
                                                                ^
/home/topolarity/repos/zig/src/Sema.zig:646:45: 0x5566345bd5bc in Sema.analyzeBodyBreak (zig2)
            });
                                            ^
/home/topolarity/repos/zig/src/Sema.zig:1323:65: 0x5566345cfbda in Sema.analyzeBodyInner (zig2)
                    break always_noreturn;
                                                                ^
/home/topolarity/repos/zig/src/Sema.zig:629:30: 0x5566345b643a in Sema.analyzeBody (zig2)
    // we find the corresponding block to this break.
                             ^
/home/topolarity/repos/zig/src/Module.zig:5607:21: 0x5566343b72ed in Module.analyzeFnBody (zig2)

                    ^
/home/topolarity/repos/zig/src/Module.zig:4300:40: 0x556634397aba in Module.ensureFuncBodyAnalyzed (zig2)
            var air = mod.analyzeFnBody(func, sema_arena) catch |err| switch (err) {
                                       ^
/home/topolarity/repos/zig/src/Compilation.zig:3047:42: 0x55663408393c in Compilation.processOneJob (zig2)
            module.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
                                         ^
/home/topolarity/repos/zig/src/Compilation.zig:2985:30: 0x55663407168f in Compilation.performAllTheWork (zig2)
            try processOneJob(comp, work_item);
                             ^
/home/topolarity/repos/zig/src/Compilation.zig:2325:31: 0x556634069d3d in Compilation.update (zig2)
    try comp.performAllTheWork(main_progress_node);
                              ^
/home/topolarity/repos/zig/src/main.zig:3318:20: 0x556633ff52bf in main.updateModule (zig2)
    try comp.update();
                   ^
/home/topolarity/repos/zig/src/main.zig:3003:17: 0x556633f3f105 in main.buildOutputType (zig2)
    updateModule(gpa, comp, hook) catch |err| switch (err) {
                ^
/home/topolarity/repos/zig/src/main.zig:236:31: 0x556633ed800e in main.mainArgs (zig2)
        return buildOutputType(gpa, arena, args, .zig_test);
                              ^
/home/topolarity/repos/zig/src/stage1.zig:56:24: 0x556633ed7755 in main (zig2)
        stage2.mainArgs(gpa, arena, args) catch unreachable;
@topolarity topolarity added bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Oct 15, 2022
topolarity added a commit to topolarity/zig that referenced this issue Oct 15, 2022
This PR (ziglang#12873) in combination with this particular test exposed
a pre-existing bug (ziglang#13175).

This means that the test for ziglang#13038 has regressed.
topolarity added a commit to topolarity/zig that referenced this issue Oct 15, 2022
This PR (ziglang#12873) in combination with this particular test exposed
a pre-existing bug (ziglang#13175).

This means that the test for ziglang#13038 has regressed.
topolarity added a commit to topolarity/zig that referenced this issue Oct 15, 2022
This PR (ziglang#12873) in combination with this particular test exposed
a pre-existing bug (ziglang#13175).

This means that the test for ziglang#13038 has regressed.
topolarity added a commit to topolarity/zig that referenced this issue Oct 16, 2022
This PR (ziglang#12873) in combination with this particular test exposed
a pre-existing bug (ziglang#13175).

This means that the test for ziglang#13038 has regressed
topolarity added a commit to topolarity/zig that referenced this issue Oct 20, 2022
This PR (ziglang#12873) in combination with this particular test exposed
a pre-existing bug (ziglang#13175).

This means that the test for ziglang#13038 has regressed
topolarity added a commit to topolarity/zig that referenced this issue Oct 21, 2022
This PR (ziglang#12873) in combination with this particular test exposed
a pre-existing bug (ziglang#13175).

This means that the test for ziglang#13038 has regressed
@Vexu Vexu added this to the 0.10.1 milestone Oct 22, 2022
@Validark
Copy link
Contributor

Validark commented Nov 3, 2022

Here is another test case:

test "break from named while loop in an inline while loop sandwich" {
    var n: u32 = 0;
    comptime var b = false;

    inline while (true) : (b = true) {
        MID_LOOP: while (true) {
            comptime var a: u2 = 2;
            inline while (true) {
                if (!b and n == 0) break :MID_LOOP;
                a -= 1;
                if (a == 0) break;
                if (n == 0) break;
            }
        }
        if (b) break;
    }
}

@andrewrk andrewrk modified the milestones: 0.10.1, 0.11.0 Jan 10, 2023
@andrewrk andrewrk modified the milestones: 0.11.0, 0.11.1 Jul 20, 2023
@andrewrk andrewrk modified the milestones: 0.11.1, 0.12.0, 0.13.0 Jan 29, 2024
@andrewrk andrewrk modified the milestones: 0.14.0, 0.15.0 Feb 10, 2025
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 frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

4 participants