mirror of
https://github.com/cc65/cc65.git
synced 2025-02-06 12:31:12 +00:00
Fixed signed char type comparison with unsigned numeric constants.
This commit is contained in:
parent
f1c715c455
commit
d628772cd1
@ -2845,7 +2845,7 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Determine the type of the operation. */
|
/* Determine the type of the operation. */
|
||||||
if (IsTypeChar (Expr->Type) && rconst) {
|
if (IsTypeChar (Expr->Type) && rconst && RightSigned) {
|
||||||
|
|
||||||
/* Left side is unsigned char, right side is constant.
|
/* Left side is unsigned char, right side is constant.
|
||||||
** Determine the minimum and maximum values
|
** Determine the minimum and maximum values
|
||||||
@ -2858,20 +2858,6 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||||||
LeftMin = 0;
|
LeftMin = 0;
|
||||||
LeftMax = 255;
|
LeftMax = 255;
|
||||||
}
|
}
|
||||||
/* An integer value is always represented as a signed in the
|
|
||||||
** ExprDesc structure. This may lead to false results below,
|
|
||||||
** if it is actually unsigned, but interpreted as signed
|
|
||||||
** because of the representation. Fortunately, in this case,
|
|
||||||
** the actual value doesn't matter, since it's always greater
|
|
||||||
** than what can be represented in a char. So correct the
|
|
||||||
** value accordingly.
|
|
||||||
*/
|
|
||||||
if (!RightSigned && Expr2.IVal < 0) {
|
|
||||||
/* Correct the value so it is an unsigned. It will then
|
|
||||||
** anyway match one of the cases below.
|
|
||||||
*/
|
|
||||||
Expr2.IVal = LeftMax + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Comparing a char against a constant may have a constant
|
/* Comparing a char against a constant may have a constant
|
||||||
** result. Please note: It is not possible to remove the code
|
** result. Please note: It is not possible to remove the code
|
||||||
@ -2951,7 +2937,7 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||||||
if (rconst) {
|
if (rconst) {
|
||||||
flags |= CF_FORCECHAR;
|
flags |= CF_FORCECHAR;
|
||||||
}
|
}
|
||||||
if (!LeftSigned) {
|
if (!LeftSigned || !RightSigned) {
|
||||||
flags |= CF_UNSIGNED;
|
flags |= CF_UNSIGNED;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -2959,11 +2945,11 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||||||
flags |= g_typeadjust (ltype, rtype);
|
flags |= g_typeadjust (ltype, rtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the left side is an unsigned and the right is a constant,
|
/* If the comparison is made as unsigned types and the right is a
|
||||||
** we may be able to change the compares to something more
|
** constant, we may be able to change the compares to something more
|
||||||
** effective.
|
** effective.
|
||||||
*/
|
*/
|
||||||
if (!LeftSigned && rconst) {
|
if ((!LeftSigned || !RightSigned) && rconst) {
|
||||||
|
|
||||||
switch (Tok) {
|
switch (Tok) {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user