aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2020-11-01 22:14:08 +0100
committerAndrew Kelley <andrew@ziglang.org>2020-11-02 13:40:00 -0500
commitbe26c3bf4e4c6a7654ea68e6606c1167ef969a09 (patch)
tree7aa5e1e1f9795f7aa1d01ff970ea22e9dd901d00
parentad9655db3a0e831f8e88bc902db7363547f9a12b (diff)
downloadzig-be26c3bf4e4c6a7654ea68e6606c1167ef969a09.tar.gz
zig-be26c3bf4e4c6a7654ea68e6606c1167ef969a09.zip
stage1: Fix *WithOverflow intrinsics with u0 values
Closes #5369
-rw-r--r--src/stage1/ir.cpp4
-rw-r--r--test/stage1/behavior/math.zig8
2 files changed, 12 insertions, 0 deletions
diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp
index 3fea4ed7f0..91fb81c24a 100644
--- a/src/stage1/ir.cpp
+++ b/src/stage1/ir.cpp
@@ -28880,6 +28880,10 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv
if (type_is_invalid(casted_result_ptr->value->type))
return ira->codegen->invalid_inst_gen;
+ // Don't write anything to the result pointer.
+ if (dest_type->data.integral.bit_count == 0)
+ return ir_const_bool(ira, &instruction->base.base, false);
+
if (instr_is_comptime(casted_op1) &&
instr_is_comptime(casted_op2) &&
instr_is_comptime(casted_result_ptr))
diff --git a/test/stage1/behavior/math.zig b/test/stage1/behavior/math.zig
index b13b1ce1e0..68690c9af8 100644
--- a/test/stage1/behavior/math.zig
+++ b/test/stage1/behavior/math.zig
@@ -109,6 +109,14 @@ test "@shlWithOverflow" {
expect(result == 0b1011111111111100);
}
+test "@*WithOverflow with u0 values" {
+ var result: u0 = undefined;
+ expect(!@addWithOverflow(u0, 0, 0, &result));
+ expect(!@subWithOverflow(u0, 0, 0, &result));
+ expect(!@mulWithOverflow(u0, 0, 0, &result));
+ expect(!@shlWithOverflow(u0, 0, 0, &result));
+}
+
test "@clz" {
testClz();
comptime testClz();