mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Fix Duplicate integer switch case values incorrectly consider its absolute value #502
(Hashing proc was wrong for big ints)
This commit is contained in:
+5
-2
@@ -550,6 +550,7 @@ struct TypeAndToken {
|
|||||||
Token token;
|
Token token;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void add_constant_switch_case(CheckerContext *ctx, Map<TypeAndToken> *seen, Operand operand, bool use_expr = true) {
|
void add_constant_switch_case(CheckerContext *ctx, Map<TypeAndToken> *seen, Operand operand, bool use_expr = true) {
|
||||||
if (operand.mode != Addressing_Constant) {
|
if (operand.mode != Addressing_Constant) {
|
||||||
return;
|
return;
|
||||||
@@ -567,7 +568,10 @@ void add_constant_switch_case(CheckerContext *ctx, Map<TypeAndToken> *seen, Oper
|
|||||||
multi_map_get_all(seen, key, taps);
|
multi_map_get_all(seen, key, taps);
|
||||||
for (isize i = 0; i < count; i++) {
|
for (isize i = 0; i < count; i++) {
|
||||||
TypeAndToken tap = taps[i];
|
TypeAndToken tap = taps[i];
|
||||||
if (are_types_identical(operand.type, tap.type)) {
|
if (!are_types_identical(operand.type, tap.type)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
TokenPos pos = tap.token.pos;
|
TokenPos pos = tap.token.pos;
|
||||||
if (use_expr) {
|
if (use_expr) {
|
||||||
gbString expr_str = expr_to_string(operand.expr);
|
gbString expr_str = expr_to_string(operand.expr);
|
||||||
@@ -585,7 +589,6 @@ void add_constant_switch_case(CheckerContext *ctx, Map<TypeAndToken> *seen, Oper
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
TypeAndToken tap = {operand.type, ast_token(operand.expr)};
|
TypeAndToken tap = {operand.type, ast_token(operand.expr)};
|
||||||
multi_map_insert(seen, key, tap);
|
multi_map_insert(seen, key, tap);
|
||||||
|
|||||||
+6
-1
@@ -71,7 +71,12 @@ HashKey hash_exact_value(ExactValue v) {
|
|||||||
case ExactValue_String:
|
case ExactValue_String:
|
||||||
return hash_string(v.value_string);
|
return hash_string(v.value_string);
|
||||||
case ExactValue_Integer:
|
case ExactValue_Integer:
|
||||||
return hashing_proc(big_int_ptr(&v.value_integer), v.value_integer.len * gb_size_of(u64));
|
{
|
||||||
|
HashKey key = hashing_proc(big_int_ptr(&v.value_integer), v.value_integer.len * gb_size_of(u64));
|
||||||
|
u8 last = (u8)v.value_integer.neg;
|
||||||
|
key.key = (key.key ^ last) * 0x100000001b3ll;
|
||||||
|
return key;
|
||||||
|
}
|
||||||
case ExactValue_Float:
|
case ExactValue_Float:
|
||||||
return hash_f64(v.value_float);
|
return hash_f64(v.value_float);
|
||||||
case ExactValue_Pointer:
|
case ExactValue_Pointer:
|
||||||
|
|||||||
Reference in New Issue
Block a user