mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 13:30:45 +00:00
Sema: Fix invalid AIR generation for switch loop with comptime discarded tag
Add an additional check before emitting `.loop_switch_br` instead of `.switch_br` in a tagged switch statement for whether any of the continues referencing its tag are actually runtime reachable. This fixes triggering an assertion in Liveness caused by the invalid assumption that every tagged switch must be a loop if its tag is referenced in any way even if this reference is not runtime reachable.
This commit is contained in:
parent
f43f89a705
commit
29ac68b253
@ -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,
|
||||
|
||||
12
test/cases/discard_labeled_switch_tag.zig
Normal file
12
test/cases/discard_labeled_switch_tag.zig
Normal file
@ -0,0 +1,12 @@
|
||||
// https://github.com/ziglang/zig/issues/24323
|
||||
|
||||
export fn f() void {
|
||||
const x: u32 = 0;
|
||||
sw: switch (x) {
|
||||
else => if (false) continue :sw undefined,
|
||||
}
|
||||
}
|
||||
|
||||
// compile
|
||||
// backend=stage2,llvm
|
||||
// target=native
|
||||
Loading…
x
Reference in New Issue
Block a user