authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-11-12 10:09:52+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-11-12 14:51:10+00:00
logbbbc95afd0d035224047443d56ed2252d8f47cb9
tree83830e1038aef3f64e89eec815153e47493938b6
parent9fa9c7abd097a8a09e11e049ffcd7d0bbb439683

AstGen: add missing `rvalue` call to `labeledBlockExpr`

...and fix a minor x86_64 backend bug exposed by this fix. Resolves: #21974

3 files changed, 15 insertions(+), 1 deletions(-)

lib/std/zig/AstGen.zig+3-1
......@@ -2435,6 +2435,7 @@ fn blockExpr(
24352435 if (!block_scope.endsWithNoReturn()) {
24362436 // As our last action before the break, "pop" the error trace if needed
24372437 _ = try gz.addRestoreErrRetIndex(.{ .block = block_inst }, .always, block_node);
2438 // No `rvalue` call here, as the block result is always `void`, so we do that below.
24382439 _ = try block_scope.addBreak(.@"break", block_inst, .void_value);
24392440 }
24402441
......@@ -2531,7 +2532,8 @@ fn labeledBlockExpr(
25312532 if (!block_scope.endsWithNoReturn()) {
25322533 // As our last action before the return, "pop" the error trace if needed
25332534 _ = try gz.addRestoreErrRetIndex(.{ .block = block_inst }, .always, block_node);
2534 _ = try block_scope.addBreak(.@"break", block_inst, .void_value);
2535 const result = try rvalue(gz, block_scope.break_result_info, .void_value, block_node);
2536 _ = try block_scope.addBreak(.@"break", block_inst, result);
25352537 }
25362538
25372539 if (!block_scope.label.?.used) {
src/arch/x86_64/Lower.zig+2
......@@ -532,6 +532,8 @@ fn emit(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operand)
532532 },
533533 else => unreachable,
534534 };
535 } else {
536 return lower.fail("TODO: bin format '{s}'", .{@tagName(lower.bin_file.tag)});
535537 }
536538 },
537539 },
test/cases/compile_errors/labeled_block_implicit_value.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo() void {
2 const result: u32 = b: {
3 if (false) break :b 1;
4 };
5 _ = result;
6}
7
8// error
9//
10// :2:28: error: expected type 'u32', found 'void'