Skip to content

Commit bbbc95a

Browse files
committed
AstGen: add missing rvalue call to labeledBlockExpr
...and fix a minor x86_64 backend bug exposed by this fix. Resolves: #21974
1 parent 9fa9c7a commit bbbc95a

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

lib/std/zig/AstGen.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
},
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export 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'

0 commit comments

Comments
 (0)