stage2: fix crash with comptime vector reduce

This commit is contained in:
Andrew Kelley
2022-08-07 22:48:34 -07:00
parent 3c4e9b5983
commit 4d7f5a1917
2 changed files with 27 additions and 0 deletions

View File

@@ -1194,6 +1194,16 @@ pub const Value = extern union {
return switch (self.tag()) {
.bool_true, .one => true,
.bool_false, .zero => false,
.int_u64 => switch (self.castTag(.int_u64).?.data) {
0 => false,
1 => true,
else => unreachable,
},
.int_i64 => switch (self.castTag(.int_i64).?.data) {
0 => false,
1 => true,
else => unreachable,
},
else => unreachable,
};
}

View File

@@ -807,6 +807,23 @@ test "vector reduce operation" {
comptime try S.doTheTest();
}
test "vector @reduce comptime" {
if (builtin.zig_backend == .stage1) return error.SkipZigTest;
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 value = @Vector(4, i32){ 1, -1, 1, -1 };
const result = value > @splat(4, @as(i32, 0));
// result is { true, false, true, false };
comptime try expect(@TypeOf(result) == @Vector(4, bool));
const is_all_true = @reduce(.And, result);
comptime try expect(@TypeOf(is_all_true) == bool);
try expect(is_all_true == false);
}
test "mask parameter of @shuffle is comptime scope" {
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO