authorgravatar for john.schmidt.h@gmail.comJohn Schmidt <john.schmidt.h@gmail.com> 2022-03-17 22:29:39+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-17 18:00:48-07:00
logd7d2ccb7af7349617fa76eef3bdead7c259654a5
treed5585a7215f338a5c22cbbbbe4199a0b1ea58543
parentadfcc8851b6bb47b085cfe2526f0797b1f414996

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`).

2 files changed, 6 insertions(+), 11 deletions(-)

src/Sema.zig+6-8
......@@ -3205,14 +3205,11 @@ fn zirValidateArrayInit(
32053205 // instruction after it within the same block.
32063206 // Possible performance enhancement: save the `block_index` between iterations
32073207 // of the for loop.
3208 const next_air_inst = inst: {
3209 var block_index = block.instructions.items.len - 1;
3210 while (block.instructions.items[block_index] != elem_ptr_air_inst) {
3211 block_index -= 1;
3212 }
3213 first_block_index = @minimum(first_block_index, block_index);
3214 break :inst block.instructions.items[block_index + 1];
3215 };
3208 var block_index = block.instructions.items.len - 1;
3209 while (block.instructions.items[block_index] != elem_ptr_air_inst) {
3210 block_index -= 1;
3211 }
3212 first_block_index = @minimum(first_block_index, block_index);
32163213
32173214 // Array has one possible value, so value is always comptime-known
32183215 if (opt_opv) |opv| {
......@@ -3222,6 +3219,7 @@ fn zirValidateArrayInit(
32223219
32233220 // If the next instructon is a store with a comptime operand, this element
32243221 // is comptime.
3222 const next_air_inst = block.instructions.items[block_index + 1];
32253223 switch (air_tags[next_air_inst]) {
32263224 .store => {
32273225 const bin_op = air_datas[next_air_inst].bin_op;
test/behavior/byteswap.zig-3
......@@ -114,9 +114,6 @@ fn vector0() !void {
114114}
115115
116116test "@byteSwap vectors u0" {
117 // TODO: vector initialization for @Vector(x, u0) currently fails.
118 if (builtin.zig_backend == .stage2_llvm) return error.SkipZigTest;
119
120117 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
121118 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
122119 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;