astgen.zig: fix false positive in breakExpr's checking for store_to_block_ptr

This commit is contained in:
Matthew Borkowski 2021-10-18 01:12:00 -04:00 committed by Andrew Kelley
parent cde3dd365e
commit 79a3dfcfd8
3 changed files with 11 additions and 2 deletions

View File

@ -1691,9 +1691,9 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn
return Zir.Inst.Ref.unreachable_value;
}
block_gz.break_count += 1;
const prev_rvalue_rl_count = block_gz.rvalue_rl_count;
const operand = try expr(parent_gz, parent_scope, block_gz.break_result_loc, rhs);
const have_store_to_block = block_gz.rvalue_rl_count != prev_rvalue_rl_count;
// if list grew as much as rvalue_rl_count, then a break inside operand already saved the store_to_block_ptr
const have_store_to_block = block_gz.rvalue_rl_count > block_gz.labeled_store_to_block_ptr_list.items.len;
const br = try parent_gz.addBreak(.@"break", block_inst, operand);

View File

@ -112,6 +112,7 @@ test {
_ = @import("behavior/bugs/7047.zig");
_ = @import("behavior/bugs/7250.zig");
_ = @import("behavior/bugs/9584.zig");
_ = @import("behavior/bugs/9967.zig");
_ = @import("behavior/byteswap.zig");
_ = @import("behavior/byval_arg_var.zig");
_ = @import("behavior/call_stage1.zig");

View File

@ -0,0 +1,8 @@
const std = @import("std");
test "nested breaks to same labeled block" {
const a = blk: {
break :blk break :blk @as(u32, 1);
};
try std.testing.expectEqual(a, 1);
}