Fixed a bug that pointer subtraction results from two absolute addresses are calculated as unsigned long.

This commit is contained in:
acqn 2021-02-07 11:35:36 +08:00 committed by greg-king5
parent da4cc08b78
commit f1c715c455
2 changed files with 7 additions and 1 deletions

View File

@ -3353,7 +3353,7 @@ static void parsesub (ExprDesc* Expr)
Error ("Incompatible pointer types");
} else {
Expr->IVal = (Expr->IVal - Expr2.IVal) /
CheckedPSizeOf (lhst);
(long)CheckedPSizeOf (lhst);
}
/* Operate on pointers, result type is an integer */
Expr->Type = type_int;

View File

@ -76,6 +76,12 @@ int main (void)
fprintf (stderr, "Expected ~32767U == 32768U, got: %ld\n", (long)~32767U);
failures++;
}
if ((long*)0x1000 - (long*)0x2000 >= 0) {
fprintf (stderr, "Expected (long*)0x1000 - (long*)0x2000 < 0, got: %ld\n", (long*)0x1000 - (long*)0x2000);
failures++;
}
printf ("failures: %u\n", failures);
return failures;
}