aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2022-10-30 15:13:13 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2022-10-30 15:38:46 -0400
commit01d76d419e0d03ba6ccc5a79dab02eed75e989a6 (patch)
tree313073a04e6c9a7349ef7bf67a20e26a71e80f06 /src
parent5c3a486639443e2fa62433b95108d956088e73bd (diff)
downloadzig-01d76d419e0d03ba6ccc5a79dab02eed75e989a6.tar.gz
zig-01d76d419e0d03ba6ccc5a79dab02eed75e989a6.zip
Sema: avoid comptime null unwrap
This avoids a crash analyzing check_comptime_control_flow.
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index a73c1eedcb..39f57ad1f2 100644
--- 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,