mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
Fix bitwise not for signed integers
This commit is contained in:
+1
-1
@@ -1465,7 +1465,7 @@ void check_unary_expr(CheckerContext *c, Operand *o, Token op, AstNode *node) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
o->value = exact_unary_operator_value(op.kind, o->value, precision);
|
o->value = exact_unary_operator_value(op.kind, o->value, precision, is_type_unsigned(type));
|
||||||
|
|
||||||
if (is_type_typed(type)) {
|
if (is_type_typed(type)) {
|
||||||
if (node != nullptr) {
|
if (node != nullptr) {
|
||||||
|
|||||||
+4
-2
@@ -353,7 +353,7 @@ ExactValue exact_value_make_imag(ExactValue v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ExactValue exact_unary_operator_value(TokenKind op, ExactValue v, i32 precision) {
|
ExactValue exact_unary_operator_value(TokenKind op, ExactValue v, i32 precision, bool is_unsigned) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case Token_Add: {
|
case Token_Add: {
|
||||||
switch (v.kind) {
|
switch (v.kind) {
|
||||||
@@ -404,7 +404,9 @@ ExactValue exact_unary_operator_value(TokenKind op, ExactValue v, i32 precision)
|
|||||||
// NOTE(bill): unsigned integers will be negative and will need to be
|
// NOTE(bill): unsigned integers will be negative and will need to be
|
||||||
// limited to the types precision
|
// limited to the types precision
|
||||||
// IMPORTANT NOTE(bill): Max precision is 64 bits as that's how integers are stored
|
// IMPORTANT NOTE(bill): Max precision is 64 bits as that's how integers are stored
|
||||||
i = i & unsigned_integer_maxs[precision/8];
|
if (is_unsigned) {
|
||||||
|
i = i & unsigned_integer_maxs[precision/8];
|
||||||
|
}
|
||||||
// if (0 < precision && precision < 64) {
|
// if (0 < precision && precision < 64) {
|
||||||
// i = i & ~(-1ll << precision);
|
// i = i & ~(-1ll << precision);
|
||||||
// }
|
// }
|
||||||
|
|||||||
Reference in New Issue
Block a user