zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 27d4bf753467894836e960bced73740c95e61db8 (tree)
parent b0dba4680012e47ffc99f87bab4b53a976cb8b8e
Author: amp-59 <114923809+amp-59@users.noreply.github.com>
Date:   Fri, 29 Dec 2023 11:42:44 +0000

Sema: Initialise `want_safety` for switch prong child block


Diffstat:
Msrc/Sema.zig | 1+
Atest/cases/inherit_want_safety.zig | 30++++++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -11806,6 +11806,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r .runtime_cond = block.runtime_cond, .runtime_loop = block.runtime_loop, .runtime_index = block.runtime_index, + .want_safety = block.want_safety, .error_return_trace_index = block.error_return_trace_index, }; const merges = &child_block.label.?.merges; diff --git a/test/cases/inherit_want_safety.zig b/test/cases/inherit_want_safety.zig @@ -0,0 +1,30 @@ +pub const panic = @compileError(""); + +pub export fn entry() usize { + @setRuntimeSafety(false); + var u: usize = 0; + { + u += 1; + } + if (u == 0) { + u += 1; + } + while (u == 0) { + u += 1; + } + for (0..u) |_| { + u += 1; + } + defer { + u += 1; + } + switch (u) { + else => { + u += 1; + }, + } + return u; +} + +// compile +// output_mode=Obj