diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-01-08 22:35:31 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-01-08 22:35:31 -0500 |
| commit | 8d27a027051e93e6f63aa9b969fed1dbfcf2aa73 (patch) | |
| tree | 8bcf4f88dd85a8907a42c3b49a51f5e5520cb571 /src/ir.cpp | |
| parent | 6caf32195af7aab084f3f2fee37239de0eb67adb (diff) | |
| download | zig-8d27a027051e93e6f63aa9b969fed1dbfcf2aa73.tar.gz zig-8d27a027051e93e6f63aa9b969fed1dbfcf2aa73.zip | |
pass division by zero test
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 4923591c21..b4475499d3 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -6915,6 +6915,25 @@ static int ir_eval_bignum(ConstExprValue *op1_val, ConstExprValue *op2_val, ConstExprValue *out_val, bool (*bignum_fn)(BigNum *, BigNum *, BigNum *), TypeTableEntry *type, bool wrapping_op) { + bool is_int = false; + bool is_float = false; + if (bignum_fn == bignum_div || bignum_fn == bignum_mod) { + if (type->id == TypeTableEntryIdInt || + type->id == TypeTableEntryIdNumLitInt) + { + is_int = true; + } else if (type->id == TypeTableEntryIdFloat || + type->id == TypeTableEntryIdNumLitFloat) + { + is_float = true; + } + if ((is_int && op2_val->data.x_bignum.data.x_uint == 0) || + (is_float && op2_val->data.x_bignum.data.x_float == 0.0)) + { + return ErrorDivByZero; + } + } + bool overflow = bignum_fn(&out_val->data.x_bignum, &op1_val->data.x_bignum, &op2_val->data.x_bignum); if (overflow) { return ErrorOverflow; |
