diff options
| author | John Schmidt <john.schmidt.h@gmail.com> | 2022-03-17 22:29:39 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-03-17 18:00:48 -0700 |
| commit | d7d2ccb7af7349617fa76eef3bdead7c259654a5 (patch) | |
| tree | d5585a7215f338a5c22cbbbbe4199a0b1ea58543 /src | |
| parent | adfcc8851b6bb47b085cfe2526f0797b1f414996 (diff) | |
| download | zig-d7d2ccb7af7349617fa76eef3bdead7c259654a5.tar.gz zig-d7d2ccb7af7349617fa76eef3bdead7c259654a5.zip | |
Avoid index out of bounds for one-valued types in zirValidateArrayInit
Previously, the code assumed that `ptr_elem_ptr` was always followed by
a `store`, but this is not true for types with one value (such as `u0`).
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sema.zig | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 4e30953fd6..7c7eef4818 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -3205,14 +3205,11 @@ fn zirValidateArrayInit( // instruction after it within the same block. // Possible performance enhancement: save the `block_index` between iterations // of the for loop. - const next_air_inst = inst: { - var block_index = block.instructions.items.len - 1; - while (block.instructions.items[block_index] != elem_ptr_air_inst) { - block_index -= 1; - } - first_block_index = @minimum(first_block_index, block_index); - break :inst block.instructions.items[block_index + 1]; - }; + var block_index = block.instructions.items.len - 1; + while (block.instructions.items[block_index] != elem_ptr_air_inst) { + block_index -= 1; + } + first_block_index = @minimum(first_block_index, block_index); // Array has one possible value, so value is always comptime-known if (opt_opv) |opv| { @@ -3222,6 +3219,7 @@ fn zirValidateArrayInit( // If the next instructon is a store with a comptime operand, this element // is comptime. + const next_air_inst = block.instructions.items[block_index + 1]; switch (air_tags[next_air_inst]) { .store => { const bin_op = air_datas[next_air_inst].bin_op; |
