authorgravatar for matthew.h.borkowski@gmail.comMatthew Borkowski <matthew.h.borkowski@gmail.com> 2021-10-18 01:12:00-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-10-18 13:18:47-04:00
log79a3dfcfd8c822096ed40fbe6f930d614a8dcb40
treed4885241b4f2c9987ce710ad38ea4cb3b01ff259
parentcde3dd365e1fed806294eddc91700558d2135a64

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


3 files changed, 11 insertions(+), 2 deletions(-)

src/AstGen.zig+2-2
......@@ -1691,9 +1691,9 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn
16911691 return Zir.Inst.Ref.unreachable_value;
16921692 }
16931693 block_gz.break_count += 1;
1694 const prev_rvalue_rl_count = block_gz.rvalue_rl_count;
16951694 const operand = try expr(parent_gz, parent_scope, block_gz.break_result_loc, rhs);
1696 const have_store_to_block = block_gz.rvalue_rl_count != prev_rvalue_rl_count;
1695 // if list grew as much as rvalue_rl_count, then a break inside operand already saved the store_to_block_ptr
1696 const have_store_to_block = block_gz.rvalue_rl_count > block_gz.labeled_store_to_block_ptr_list.items.len;
16971697
16981698 const br = try parent_gz.addBreak(.@"break", block_inst, operand);
16991699
test/behavior.zig+1
......@@ -112,6 +112,7 @@ test {
112112 _ = @import("behavior/bugs/7047.zig");
113113 _ = @import("behavior/bugs/7250.zig");
114114 _ = @import("behavior/bugs/9584.zig");
115 _ = @import("behavior/bugs/9967.zig");
115116 _ = @import("behavior/byteswap.zig");
116117 _ = @import("behavior/byval_arg_var.zig");
117118 _ = @import("behavior/call_stage1.zig");
test/behavior/bugs/9967.zig created+8
......@@ -0,0 +1,8 @@
1const std = @import("std");
2
3test "nested breaks to same labeled block" {
4 const a = blk: {
5 break :blk break :blk @as(u32, 1);
6 };
7 try std.testing.expectEqual(a, 1);
8}