authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-09 18:32:15+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-11 18:00:05+02:00
log40a2dfc12a611082ba6810c566a6a46acdb864fc
tree566aaa3511c394dbd47fb15cd24bab720dbefea4
parent9b832e7f530833de93857444a86e34c8d99e4755

Sema: coerce array operands to shuffle

Closes #13494

2 files changed, 17 insertions(+), 2 deletions(-)

src/Sema.zig+2-2
......@@ -20179,8 +20179,8 @@ fn analyzeShuffle(
2017920179 .elem_type = elem_ty,
2018020180 });
2018120181
20182 if (maybe_a_len == null) a = try sema.addConstUndef(a_ty);
20183 if (maybe_b_len == null) b = try sema.addConstUndef(b_ty);
20182 if (maybe_a_len == null) a = try sema.addConstUndef(a_ty) else a = try sema.coerce(block, a_ty, a, a_src);
20183 if (maybe_b_len == null) b = try sema.addConstUndef(b_ty) else b = try sema.coerce(block, b_ty, b, b_src);
2018420184
2018520185 const operand_info = [2]std.meta.Tuple(&.{ u64, LazySrcLoc, Type }){
2018620186 .{ a_len, a_src, a_ty },
test/behavior/vector.zig+15
......@@ -3,6 +3,7 @@ const builtin = @import("builtin");
33const mem = std.mem;
44const math = std.math;
55const expect = std.testing.expect;
6const expectEqual = std.testing.expectEqual;
67
78test "implicit cast vector to array - bool" {
89 if (builtin.zig_backend == .stage1) {
......@@ -1231,3 +1232,17 @@ test "modRem with zero divisor" {
12311232 _ = zeros[0];
12321233 }
12331234}
1235
1236test "array operands to shuffle are coerced to vectors" {
1237 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1238 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
1239 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
1240 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1241 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1242
1243 const mask = [5]i32{ -1, 0, 1, 2, 3 };
1244
1245 var a = [5]u32{ 3, 5, 7, 9, 0 };
1246 var b = @shuffle(u32, a, @splat(5, @as(u24, 0)), mask);
1247 try expectEqual([_]u32{ 0, 3, 5, 7, 9 }, b);
1248}