Skip to content

Commit 2c8551a

Browse files
committed
stage2: fix crash with comptime vector reduce
1 parent e285675 commit 2c8551a

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,16 @@ test "vector reduce operation" {
807807
comptime try S.doTheTest();
808808
}
809809

810+
test "vector @reduce comptime" {
811+
const value = @Vector(4, i32){ 1, -1, 1, -1 };
812+
const result = value > @splat(4, @as(i32, 0));
813+
// result is { true, false, true, false };
814+
comptime try expect(@TypeOf(result) == @Vector(4, bool));
815+
const is_all_true = @reduce(.And, result);
816+
comptime try expect(@TypeOf(is_all_true) == bool);
817+
try expect(is_all_true == false);
818+
}
819+
810820
test "mask parameter of @shuffle is comptime scope" {
811821
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
812822
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO

0 commit comments

Comments
 (0)