Skip to content

Commit 9b835be

Browse files
committed
stage2: fix crash with comptime vector reduce
1 parent beb7a1e commit 9b835be

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/value.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,16 @@ pub const Value = extern union {
11941194
return switch (self.tag()) {
11951195
.bool_true, .one => true,
11961196
.bool_false, .zero => false,
1197+
.int_u64 => switch (self.castTag(.int_u64).?.data) {
1198+
0 => false,
1199+
1 => true,
1200+
else => unreachable,
1201+
},
1202+
.int_i64 => switch (self.castTag(.int_i64).?.data) {
1203+
0 => false,
1204+
1 => true,
1205+
else => unreachable,
1206+
},
11971207
else => unreachable,
11981208
};
11991209
}

test/behavior/vector.zig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,23 @@ test "vector reduce operation" {
807807
comptime try S.doTheTest();
808808
}
809809

810+
test "vector @reduce comptime" {
811+
if (builtin.zig_backend == .stage1) return error.SkipZigTest;
812+
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
813+
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
814+
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
815+
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
816+
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
817+
818+
const value = @Vector(4, i32){ 1, -1, 1, -1 };
819+
const result = value > @splat(4, @as(i32, 0));
820+
// result is { true, false, true, false };
821+
comptime try expect(@TypeOf(result) == @Vector(4, bool));
822+
const is_all_true = @reduce(.And, result);
823+
comptime try expect(@TypeOf(is_all_true) == bool);
824+
try expect(is_all_true == false);
825+
}
826+
810827
test "mask parameter of @shuffle is comptime scope" {
811828
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
812829
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO

0 commit comments

Comments
 (0)