From 40a2dfc12a611082ba6810c566a6a46acdb864fc Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Wed, 9 Nov 2022 18:32:15 +0200 Subject: [PATCH] Sema: coerce array operands to shuffle Closes #13494 --- src/Sema.zig | 4 ++-- test/behavior/vector.zig | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index b93a892dcc..51b1592c26 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -20179,8 +20179,8 @@ fn analyzeShuffle( .elem_type = elem_ty, }); - if (maybe_a_len == null) a = try sema.addConstUndef(a_ty); - if (maybe_b_len == null) b = try sema.addConstUndef(b_ty); + if (maybe_a_len == null) a = try sema.addConstUndef(a_ty) else a = try sema.coerce(block, a_ty, a, a_src); + if (maybe_b_len == null) b = try sema.addConstUndef(b_ty) else b = try sema.coerce(block, b_ty, b, b_src); const operand_info = [2]std.meta.Tuple(&.{ u64, LazySrcLoc, Type }){ .{ a_len, a_src, a_ty }, diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig index 1f4faae636..36a51d8275 100644 --- a/test/behavior/vector.zig +++ b/test/behavior/vector.zig @@ -3,6 +3,7 @@ const builtin = @import("builtin"); const mem = std.mem; const math = std.math; const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "implicit cast vector to array - bool" { if (builtin.zig_backend == .stage1) { @@ -1231,3 +1232,17 @@ test "modRem with zero divisor" { _ = zeros[0]; } } + +test "array operands to shuffle are coerced to vectors" { + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + + const mask = [5]i32{ -1, 0, 1, 2, 3 }; + + var a = [5]u32{ 3, 5, 7, 9, 0 }; + var b = @shuffle(u32, a, @splat(5, @as(u24, 0)), mask); + try expectEqual([_]u32{ 0, 3, 5, 7, 9 }, b); +}