authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-29 15:19:09-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-09-29 15:19:09-04:00
log56c5b665a1f93fd16a711986e25e4d7c5dfed163
tree287b07063d2097ab77361df849c3444caab4383b
parenta1ae3f92c1cdbae2333d26ad5da224b91e20cb6f
parentcbbcf609688d70ce9e45bde444b2904b39a0ae2c
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #6448 from LemonBoy/some-vec-fixes

Some vector fixes

3 files changed, 31 insertions(+), 11 deletions(-)

src/ir.cpp+14-10
...@@ -16715,16 +16715,12 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -16715,16 +16715,12 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
16715 }16715 }
16716 ZigType *dest_float_type = nullptr;16716 ZigType *dest_float_type = nullptr;
16717 uint32_t op1_bits;16717 uint32_t op1_bits;
16718 if (instr_is_comptime(op1)) {16718 if (instr_is_comptime(op1) && result_type->id != ZigTypeIdVector) {
16719 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefOk);16719 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefOk);
16720 if (op1_val == nullptr)16720 if (op1_val == nullptr)
16721 return ira->codegen->invalid_inst_gen;16721 return ira->codegen->invalid_inst_gen;
16722 if (op1_val->special == ConstValSpecialUndef)16722 if (op1_val->special == ConstValSpecialUndef)
16723 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);16723 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
16724 if (result_type->id == ZigTypeIdVector) {
16725 ir_add_error(ira, &op1->base, buf_sprintf("compiler bug: TODO: support comptime vector here"));
16726 return ira->codegen->invalid_inst_gen;
16727 }
16728 bool is_unsigned;16724 bool is_unsigned;
16729 if (op1_is_float) {16725 if (op1_is_float) {
16730 BigInt bigint = {};16726 BigInt bigint = {};
...@@ -16750,6 +16746,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -16750,6 +16746,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
16750 op1_bits += 1;16746 op1_bits += 1;
16751 }16747 }
16752 } else if (op1_is_float) {16748 } else if (op1_is_float) {
16749 ir_assert(op1_scalar_type->id == ZigTypeIdFloat, source_instr);
16753 dest_float_type = op1_scalar_type;16750 dest_float_type = op1_scalar_type;
16754 } else {16751 } else {
16755 ir_assert(op1_scalar_type->id == ZigTypeIdInt, source_instr);16752 ir_assert(op1_scalar_type->id == ZigTypeIdInt, source_instr);
...@@ -16759,16 +16756,12 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -16759,16 +16756,12 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
16759 }16756 }
16760 }16757 }
16761 uint32_t op2_bits;16758 uint32_t op2_bits;
16762 if (instr_is_comptime(op2)) {16759 if (instr_is_comptime(op2) && result_type->id != ZigTypeIdVector) {
16763 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefOk);16760 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefOk);
16764 if (op2_val == nullptr)16761 if (op2_val == nullptr)
16765 return ira->codegen->invalid_inst_gen;16762 return ira->codegen->invalid_inst_gen;
16766 if (op2_val->special == ConstValSpecialUndef)16763 if (op2_val->special == ConstValSpecialUndef)
16767 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);16764 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
16768 if (result_type->id == ZigTypeIdVector) {
16769 ir_add_error(ira, &op2->base, buf_sprintf("compiler bug: TODO: support comptime vector here"));
16770 return ira->codegen->invalid_inst_gen;
16771 }
16772 bool is_unsigned;16765 bool is_unsigned;
16773 if (op2_is_float) {16766 if (op2_is_float) {
16774 BigInt bigint = {};16767 BigInt bigint = {};
...@@ -16794,6 +16787,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -16794,6 +16787,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
16794 op2_bits += 1;16787 op2_bits += 1;
16795 }16788 }
16796 } else if (op2_is_float) {16789 } else if (op2_is_float) {
16790 ir_assert(op2_scalar_type->id == ZigTypeIdFloat, source_instr);
16797 dest_float_type = op2_scalar_type;16791 dest_float_type = op2_scalar_type;
16798 } else {16792 } else {
16799 ir_assert(op2_scalar_type->id == ZigTypeIdInt, source_instr);16793 ir_assert(op2_scalar_type->id == ZigTypeIdInt, source_instr);
...@@ -21934,7 +21928,17 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -21934,7 +21928,17 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
21934 return ira->codegen->invalid_inst_gen;21928 return ira->codegen->invalid_inst_gen;
21935 }21929 }
21936 safety_check_on = false;21930 safety_check_on = false;
21931 } else if (array_type->id == ZigTypeIdVector) {
21932 uint64_t vector_len = array_type->data.vector.len;
21933 if (index >= vector_len) {
21934 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
21935 buf_sprintf("index %" ZIG_PRI_u64 " outside vector of size %" ZIG_PRI_u64,
21936 index, vector_len));
21937 return ira->codegen->invalid_inst_gen;
21938 }
21939 safety_check_on = false;
21937 }21940 }
21941
21938 if (array_type->id == ZigTypeIdVector) {21942 if (array_type->id == ZigTypeIdVector) {
21939 ZigType *elem_type = array_type->data.vector.elem_type;21943 ZigType *elem_type = array_type->data.vector.elem_type;
21940 uint32_t host_vec_len = array_type->data.vector.len;21944 uint32_t host_vec_len = array_type->data.vector.len;
test/compile_errors.zig+9-1
...@@ -2,6 +2,14 @@ const tests = @import("tests.zig");...@@ -2,6 +2,14 @@ const tests = @import("tests.zig");
2const std = @import("std");2const std = @import("std");
33
4pub fn addCases(cases: *tests.CompileErrorContext) void {4pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add("slice sentinel mismatch",
6 \\export fn entry() void {
7 \\ const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 };
8 \\}
9 , &[_][]const u8{
10 "tmp.zig:2:62: error: index 3 outside vector of size 3",
11 });
12
5 cases.add("slice sentinel mismatch",13 cases.add("slice sentinel mismatch",
6 \\export fn entry() void {14 \\export fn entry() void {
7 \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 };15 \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 };
...@@ -7548,7 +7556,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -7548,7 +7556,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
7548 });7556 });
75497557
7550 cases.add( // fixed bug #20327558 cases.add( // fixed bug #2032
7551 "compile diagnostic string for top level decl type",7559 "compile diagnostic string for top level decl type",
7552 \\export fn entry() void {7560 \\export fn entry() void {
7553 \\ var foo: u32 = @This(){};7561 \\ var foo: u32 = @This(){};
7554 \\}7562 \\}
test/stage1/behavior/vector.zig+8
...@@ -274,6 +274,14 @@ test "vector comparison operators" {...@@ -274,6 +274,14 @@ test "vector comparison operators" {
274 expectEqual(@splat(4, true), v1 != v3);274 expectEqual(@splat(4, true), v1 != v3);
275 expectEqual(@splat(4, false), v1 != v2);275 expectEqual(@splat(4, false), v1 != v2);
276 }276 }
277 {
278 // Comptime-known LHS/RHS
279 var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 };
280 const v2 = @splat(4, @as(u32, 2));
281 const v3: @Vector(4, bool) = [_]bool{ true, false, true, false };
282 expectEqual(v3, v1 == v2);
283 expectEqual(v3, v2 == v1);
284 }
277 }285 }
278 };286 };
279 S.doTheTest();287 S.doTheTest();