zig
zig copied to clipboard
stage2: Teach Liveness that some safety checks do not observably modify memory
Spun off from #13074
This is a crude pattern match for try-like .cond_br
blocks emitted by Sema's safety checks. It looks for:
%x = block(void, {
cond_br(..., {
br(%x, @Zir.Inst.Ref.void_value)
}, {
call(...)
})
})
This matches the signature of many of our safety checks which look like this:
%14 = ... ; generate check condition
%23!= block(void, {
%24!= cond_br(%14!, {
%13! %21!
%25!= br(%23, @Zir.Inst.Ref.void_value)
}, {
%22!= call(%21!, [%12, %13!])
})
})
The reasoning here is that control flow either diverges (the call must be noreturn
to be at the end of the block) or continues directly to the following instructions in the block without modifying memory. This was inspired by https://github.com/ziglang/zig/issues/11772#issuecomment-1144203077
Resolves https://github.com/ziglang/zig/issues/12215