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`).
This commit is contained in:
John Schmidt 2022-03-17 22:29:39 +01:00 committed by Andrew Kelley
parent adfcc8851b
commit d7d2ccb7af
2 changed files with 6 additions and 11 deletions

View File

@ -3205,14 +3205,11 @@ fn zirValidateArrayInit(
// instruction after it within the same block. // instruction after it within the same block.
// Possible performance enhancement: save the `block_index` between iterations // Possible performance enhancement: save the `block_index` between iterations
// of the for loop. // of the for loop.
const next_air_inst = inst: { var block_index = block.instructions.items.len - 1;
var block_index = block.instructions.items.len - 1; while (block.instructions.items[block_index] != elem_ptr_air_inst) {
while (block.instructions.items[block_index] != elem_ptr_air_inst) { block_index -= 1;
block_index -= 1; }
} first_block_index = @minimum(first_block_index, block_index);
first_block_index = @minimum(first_block_index, block_index);
break :inst block.instructions.items[block_index + 1];
};
// Array has one possible value, so value is always comptime-known // Array has one possible value, so value is always comptime-known
if (opt_opv) |opv| { if (opt_opv) |opv| {
@ -3222,6 +3219,7 @@ fn zirValidateArrayInit(
// If the next instructon is a store with a comptime operand, this element // If the next instructon is a store with a comptime operand, this element
// is comptime. // is comptime.
const next_air_inst = block.instructions.items[block_index + 1];
switch (air_tags[next_air_inst]) { switch (air_tags[next_air_inst]) {
.store => { .store => {
const bin_op = air_datas[next_air_inst].bin_op; const bin_op = air_datas[next_air_inst].bin_op;

View File

@ -114,9 +114,6 @@ fn vector0() !void {
} }
test "@byteSwap vectors u0" { test "@byteSwap vectors u0" {
// TODO: vector initialization for @Vector(x, u0) currently fails.
if (builtin.zig_backend == .stage2_llvm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;