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

AstGen: avoid generating unreachable defer expressions #8822

Closed
andrewrk opened this issue May 18, 2021 · 0 comments
Closed

AstGen: avoid generating unreachable defer expressions #8822

andrewrk opened this issue May 18, 2021 · 0 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@andrewrk
Copy link
Member

test {
    blk: {
        defer a();
        break :blk;
    }
}
%15 = extended(struct_decl(parent, Auto, {
  test line(0) hash(aa57e7731b05b3a86ade2d43f978df23): %0 = block_inline({
    %13 = extended(func(test, [], @Ref.void_type, inferror, {
      %1 = dbg_stmt(1, 4)
      %2 = block({
        %3 = dbg_stmt(3, 8)
        %4 = dbg_stmt(2, 14)
        %5 = decl_val("a") token_offset:3:15
        %6 = call_chkused(%5, []) node_offset:3:16
        %7 = break(%2, @Ref.void_value)
        %8 = dbg_stmt(2, 14)
        %9 = decl_val("a") token_offset:3:15
        %10 = call_chkused(%9, []) node_offset:3:16
      }) node_offset:2:10
      %11 = ensure_result_used(%2) node_offset:2:10
      %12 = ret_coerce(@Ref.void_value) token_offset:6:1
    }) (lbrace=0:5,rbrace=5:0) node_offset:1:1
    %14 = break_inline(%0, %13)
  }) node_offset:1:1
}, {}, {})

Here you can see there is an unreachable call to a(). The defer expression should not be generated at the block exit, since the block result was unreachable.

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels May 18, 2021
@andrewrk andrewrk added this to the 0.8.0 milestone May 18, 2021
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Jun 4, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 22, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Aug 23, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Jun 19, 2023
mlugg added a commit to mlugg/zig that referenced this issue Feb 28, 2024
@mlugg mlugg closed this as completed in 07d8740 Mar 2, 2024
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Mar 3, 2024
RossComputerGuy pushed a commit to ExpidusOS-archive/zig that referenced this issue Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

1 participant