Skip to content
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

crash when capturing errdefer in test block #22174

Open
Rexicon226 opened this issue Dec 6, 2024 · 0 comments · May be fixed by #22217
Open

crash when capturing errdefer in test block #22174

Rexicon226 opened this issue Dec 6, 2024 · 0 comments · May be fixed by #22217
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@Rexicon226
Copy link
Contributor

Rexicon226 commented Dec 6, 2024

Zig Version

0.14.0-dev.2385+ca069244b

Steps to Reproduce and Observed Behavior

test {
    errdefer |err| {
        _ = err;
        unreachable;
    }

    var x: bool = false;
    _ = &x;
    if (x) return error.Something;
}

zig test foo.zig

Stack Trace
thread 41208291 panic: integer overflow
Analyzing empty.zig
      %21 = dbg_stmt(9, 12)
      %22 = ret_err_value_code("Something")
    > %23 = defer_err_code(%2 = %22, {
        %3 = dbg_var_val(%2, "err")
        %4 = dbg_stmt(2, 20)
        %5 = block({
          %6 = dbg_stmt(3, 9)
          %7 = ensure_result_non_error(%2)
          %8 = dbg_stmt(4, 9)
          %9 = unreachable()
        })
        %10 = break_inline(%0, @void_value)
      })
      %24 = dbg_stmt(9, 12)
      %25 = ret_node(%22)
    For full context, use the command
      zig ast-check -t empty.zig

  in empty.zig
    > %19 = condbr(%18, {%21..%25}, {%26})
  in empty.zig
    > %20 = block({%18, %19})

/Users/david/Code/zig/src/Sema.zig:268:37: 0x105d373b7 in putAssumeCapacity (zig)
        map.items[@intFromEnum(key) - @intFromEnum(map.start)] = ref;
                                    ^
/Users/david/Code/zig/src/Sema.zig:1819:38: 0x10587de87 in analyzeBodyInner (zig)
                map.putAssumeCapacity(extra.remapped_err_code, err_code);
                                     ^
/Users/david/Code/zig/src/Sema.zig:917:26: 0x1060fcdbf in analyzeBodyRuntimeBreak (zig)
    sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                         ^
/Users/david/Code/zig/src/Sema.zig:19879:55: 0x105d321cb in zirCondbr (zig)
    const true_hint = try sema.analyzeBodyRuntimeBreak(&sub_block, then_body);

Expected Behavior

No crash!

@Rexicon226 Rexicon226 added the bug Observed behavior contradicts documented or intended behavior label Dec 6, 2024
@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Dec 7, 2024
@Vexu Vexu added this to the 0.14.0 milestone Dec 7, 2024
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

Successfully merging a pull request may close this issue.

2 participants