mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Improve error handling with assignments to bit_field using constants
This commit is contained in:
+27
-5
@@ -1886,15 +1886,36 @@ gb_internal bool check_representable_as_constant(CheckerContext *c, ExactValue i
|
|||||||
|
|
||||||
BigInt i = v.value_integer;
|
BigInt i = v.value_integer;
|
||||||
|
|
||||||
i64 bit_size = type_size_of(type);
|
i64 byte_size = type_size_of(type);
|
||||||
BigInt umax = {};
|
BigInt umax = {};
|
||||||
BigInt imin = {};
|
BigInt imin = {};
|
||||||
BigInt imax = {};
|
BigInt imax = {};
|
||||||
|
|
||||||
if (bit_size < 16) {
|
if (c->bit_field_bit_size > 0) {
|
||||||
big_int_from_u64(&umax, unsigned_integer_maxs[bit_size]);
|
i64 bit_size = gb_min(cast(i64)(8*byte_size), cast(i64)c->bit_field_bit_size);
|
||||||
big_int_from_i64(&imin, signed_integer_mins[bit_size]);
|
|
||||||
big_int_from_i64(&imax, signed_integer_maxs[bit_size]);
|
big_int_from_u64(&umax, 1);
|
||||||
|
big_int_from_i64(&imin, 1);
|
||||||
|
big_int_from_i64(&imax, 1);
|
||||||
|
|
||||||
|
BigInt bu = {};
|
||||||
|
BigInt bi = {};
|
||||||
|
big_int_from_i64(&bu, bit_size);
|
||||||
|
big_int_from_i64(&bi, bit_size-1);
|
||||||
|
|
||||||
|
big_int_shl_eq(&umax, &bu);
|
||||||
|
mp_decr(&umax);
|
||||||
|
|
||||||
|
big_int_shl_eq(&imin, &bi);
|
||||||
|
big_int_neg(&imin, &imin);
|
||||||
|
|
||||||
|
big_int_shl_eq(&imax, &bi);
|
||||||
|
mp_decr(&imax);
|
||||||
|
} else {
|
||||||
|
if (byte_size < 16) {
|
||||||
|
big_int_from_u64(&umax, unsigned_integer_maxs[byte_size]);
|
||||||
|
big_int_from_i64(&imin, signed_integer_mins[byte_size]);
|
||||||
|
big_int_from_i64(&imax, signed_integer_maxs[byte_size]);
|
||||||
} else {
|
} else {
|
||||||
big_int_from_u64(&umax, 1);
|
big_int_from_u64(&umax, 1);
|
||||||
big_int_from_i64(&imin, 1);
|
big_int_from_i64(&imin, 1);
|
||||||
@@ -1914,6 +1935,7 @@ gb_internal bool check_representable_as_constant(CheckerContext *c, ExactValue i
|
|||||||
big_int_shl_eq(&imax, &bi127);
|
big_int_shl_eq(&imax, &bi127);
|
||||||
mp_decr(&imax);
|
mp_decr(&imax);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (type->Basic.kind) {
|
switch (type->Basic.kind) {
|
||||||
case Basic_rune:
|
case Basic_rune:
|
||||||
|
|||||||
Reference in New Issue
Block a user