Merge pull request #24433 from Justus2308/switch-label-halt

Sema: Fix invalid AIR generation for switch loop with comptime discarded tag
This commit is contained in:
Andrew Kelley
2025-07-14 19:04:19 +02:00
committed by GitHub
2 changed files with 13 additions and 1 deletions

View File

@@ -13041,8 +13041,10 @@ fn analyzeSwitchRuntimeBlock(
sema.air_extra.appendSliceAssumeCapacity(@ptrCast(cases_extra.items));
sema.air_extra.appendSliceAssumeCapacity(@ptrCast(else_body));
const has_any_continues = spa.operand == .loop and child_block.label.?.merges.extra_insts.items.len > 0;
return try child_block.addInst(.{
.tag = if (spa.operand == .loop) .loop_switch_br else .switch_br,
.tag = if (has_any_continues) .loop_switch_br else .switch_br,
.data = .{ .pl_op = .{
.operand = operand,
.payload = payload_index,

View File

@@ -216,3 +216,13 @@ test "switch loop with pointer capture" {
try S.doTheTest();
try comptime S.doTheTest();
}
test "unanalyzed continue with operand" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
@setRuntimeSafety(false);
label: switch (false) {
false => if (false) continue :label true,
true => {},
}
}