authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-11-01 22:14:08+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-02 13:40:00-05:00
logbe26c3bf4e4c6a7654ea68e6606c1167ef969a09
tree7aa5e1e1f9795f7aa1d01ff970ea22e9dd901d00
parentad9655db3a0e831f8e88bc902db7363547f9a12b

stage1: Fix *WithOverflow intrinsics with u0 values

Closes #5369

2 files changed, 12 insertions(+), 0 deletions(-)

src/stage1/ir.cpp+4
......@@ -28880,6 +28880,10 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv
2888028880 if (type_is_invalid(casted_result_ptr->value->type))
2888128881 return ira->codegen->invalid_inst_gen;
2888228882
28883 // Don't write anything to the result pointer.
28884 if (dest_type->data.integral.bit_count == 0)
28885 return ir_const_bool(ira, &instruction->base.base, false);
28886
2888328887 if (instr_is_comptime(casted_op1) &&
2888428888 instr_is_comptime(casted_op2) &&
2888528889 instr_is_comptime(casted_result_ptr))
test/stage1/behavior/math.zig+8
......@@ -109,6 +109,14 @@ test "@shlWithOverflow" {
109109 expect(result == 0b1011111111111100);
110110}
111111
112test "@*WithOverflow with u0 values" {
113 var result: u0 = undefined;
114 expect(!@addWithOverflow(u0, 0, 0, &result));
115 expect(!@subWithOverflow(u0, 0, 0, &result));
116 expect(!@mulWithOverflow(u0, 0, 0, &result));
117 expect(!@shlWithOverflow(u0, 0, 0, &result));
118}
119
112120test "@clz" {
113121 testClz();
114122 comptime testClz();