authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-10-30 15:13:13-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-10-30 15:38:46-04:00
log01d76d419e0d03ba6ccc5a79dab02eed75e989a6
tree313073a04e6c9a7349ef7bf67a20e26a71e80f06
parent5c3a486639443e2fa62433b95108d956088e73bd

Sema: avoid comptime null unwrap

This avoids a crash analyzing check_comptime_control_flow.

1 files changed, 5 insertions(+), 6 deletions(-)

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