diff options
| author | gingerBill <bill@gingerbill.org> | 2018-07-28 00:41:31 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-07-28 00:41:31 +0100 |
| commit | c3c783424604b14cdd86950bf4b0aaded1f97316 (patch) | |
| tree | cf8eb6d5f40545bdd63c2b8f81ffa645119e8473 /src/check_stmt.cpp | |
| parent | d0e04bf569465196e0679bf068126988dcab5122 (diff) | |
BigInt support in the constant system
Diffstat (limited to 'src/check_stmt.cpp')
| -rw-r--r-- | src/check_stmt.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 3ce7373b6..453127f0c 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -260,18 +260,17 @@ Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs) if (rhs->mode == Addressing_Constant) { ExactValue v = exact_value_to_integer(rhs->value); if (v.kind == ExactValue_Integer) { - i64 i = v.value_integer; - u64 u = bit_cast<u64>(i); - u64 umax = ~cast(u64)0ull; - if (lhs_bits < 64) { - umax = (1ull << cast(u64)lhs_bits) - 1ull; - } - i64 imax = 1ll << (cast(i64)lhs_bits-1ll); - - bool ok = !(u < 0 || u > umax); + BigInt i = v.value_integer; + if (!i.neg) { + u64 imax_ = ~cast(u64)0ull; + if (lhs_bits < 64) { + imax_ = (1ull << cast(u64)lhs_bits) - 1ull; + } - if (ok) { - return rhs->type; + BigInt imax = big_int_make_u64(imax_); + if (big_int_cmp(&i, &imax) > 0) { + return rhs->type; + } } } } else if (is_type_integer(rhs->type)) { |