motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 01d76d419e0d03ba6ccc5a79dab02eed75e989a6 (tree)
parent 5c3a486639443e2fa62433b95108d956088e73bd
Author: Jacob Young <jacobly0@users.noreply.github.com>
Date:   Sun, 30 Oct 2022 15:13:13 -0400

Sema: avoid comptime null unwrap

This avoids a crash analyzing check_comptime_control_flow.

Diffstat:
Msrc/Sema.zig | 11+++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -71,8 +71,8 @@ preallocated_new_func: ?*Module.Fn = null, /// TODO: after upgrading to use InternPool change the key here to be an /// InternPool value index. types_to_resolve: std.ArrayListUnmanaged(Air.Inst.Ref) = .{}, -/// These are lazily created runtime blocks from inline_block instructions. -/// They are created when an inline_break passes through a runtime condition, because +/// These are lazily created runtime blocks from block_inline instructions. +/// They are created when an break_inline passes through a runtime condition, because /// Sema must convert comptime control flow to runtime control flow, which means /// breaking from a block. post_hoc_blocks: std.AutoHashMapUnmanaged(Air.Inst.Index, *LabeledBlock) = .{}, @@ -147,7 +147,7 @@ pub const Block = struct { /// for the one that will be the same for all Block instances. src_decl: Decl.Index, /// Non zero if a non-inline loop or a runtime conditional have been encountered. - /// Stores to to comptime variables are only allowed when var.runtime_index <= runtime_index. + /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index. runtime_index: Value.RuntimeIndex = .zero, inline_block: Zir.Inst.Index = 0, @@ -1391,9 +1391,8 @@ fn analyzeBodyInner( // If this block contains a function prototype, we need to reset the // current list of parameters and restore it later. // Note: this probably needs to be resolved in a more general manner. - if (tags[inline_body[inline_body.len - 1]] == .repeat_inline) { - child_block.inline_block = inline_body[0]; - } else child_block.inline_block = block.inline_block; + child_block.inline_block = + if (tags[inline_body[inline_body.len - 1]] == .repeat_inline) inline_body[0] else inst; var label: Block.Label = .{ .zir_block = inst,