mirror of
https://github.com/cc65/cc65.git
synced 2024-12-24 11:31:31 +00:00
The combined assignment operator (-=, +=, ...) did not check that the rhs is
actually an integer. git-svn-id: svn://svn.cc65.org/cc65/trunk@4297 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
ba46bab009
commit
8e35f0d9c8
@ -2843,7 +2843,7 @@ static void hieQuest (ExprDesc* Expr)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void opeq (const GenDesc* Gen, ExprDesc* Expr)
|
static void opeq (const GenDesc* Gen, ExprDesc* Expr, const char* Op)
|
||||||
/* Process "op=" operators. */
|
/* Process "op=" operators. */
|
||||||
{
|
{
|
||||||
ExprDesc Expr2;
|
ExprDesc Expr2;
|
||||||
@ -2890,6 +2890,14 @@ static void opeq (const GenDesc* Gen, ExprDesc* Expr)
|
|||||||
/* Evaluate the rhs */
|
/* Evaluate the rhs */
|
||||||
MarkedExprWithCheck (hie1, &Expr2);
|
MarkedExprWithCheck (hie1, &Expr2);
|
||||||
|
|
||||||
|
/* The rhs must be an integer (or a float, but we don't support that yet */
|
||||||
|
if (!IsClassInt (Expr2.Type)) {
|
||||||
|
Error ("Invalid right operand for binary operator `%s'", Op);
|
||||||
|
/* Continue. Wrong code will be generated, but the compiler won't
|
||||||
|
* break, so this is the best error recovery.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
/* Check for a constant expression */
|
/* Check for a constant expression */
|
||||||
if (ED_IsConstAbs (&Expr2) && ED_CodeRangeIsEmpty (&Expr2)) {
|
if (ED_IsConstAbs (&Expr2) && ED_CodeRangeIsEmpty (&Expr2)) {
|
||||||
/* The resulting value is a constant. If the generator has the NOPUSH
|
/* The resulting value is a constant. If the generator has the NOPUSH
|
||||||
@ -2951,7 +2959,7 @@ static void opeq (const GenDesc* Gen, ExprDesc* Expr)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void addsubeq (const GenDesc* Gen, ExprDesc *Expr)
|
static void addsubeq (const GenDesc* Gen, ExprDesc *Expr, const char* Op)
|
||||||
/* Process the += and -= operators */
|
/* Process the += and -= operators */
|
||||||
{
|
{
|
||||||
ExprDesc Expr2;
|
ExprDesc Expr2;
|
||||||
@ -2963,7 +2971,7 @@ static void addsubeq (const GenDesc* Gen, ExprDesc *Expr)
|
|||||||
/* We're currently only able to handle some adressing modes */
|
/* We're currently only able to handle some adressing modes */
|
||||||
if (ED_GetLoc (Expr) == E_LOC_EXPR || ED_GetLoc (Expr) == E_LOC_PRIMARY) {
|
if (ED_GetLoc (Expr) == E_LOC_EXPR || ED_GetLoc (Expr) == E_LOC_PRIMARY) {
|
||||||
/* Use generic routine */
|
/* Use generic routine */
|
||||||
opeq (Gen, Expr);
|
opeq (Gen, Expr, Op);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2996,8 +3004,16 @@ static void addsubeq (const GenDesc* Gen, ExprDesc *Expr)
|
|||||||
lflags = 0;
|
lflags = 0;
|
||||||
rflags = 0;
|
rflags = 0;
|
||||||
|
|
||||||
/* Evaluate the rhs */
|
/* Evaluate the rhs. We expect an integer here, since float is not
|
||||||
|
* supported
|
||||||
|
*/
|
||||||
hie1 (&Expr2);
|
hie1 (&Expr2);
|
||||||
|
if (!IsClassInt (Expr2.Type)) {
|
||||||
|
Error ("Invalid right operand for binary operator `%s'", Op);
|
||||||
|
/* Continue. Wrong code will be generated, but the compiler won't
|
||||||
|
* break, so this is the best error recovery.
|
||||||
|
*/
|
||||||
|
}
|
||||||
if (ED_IsConstAbs (&Expr2)) {
|
if (ED_IsConstAbs (&Expr2)) {
|
||||||
/* The resulting value is a constant. Scale it. */
|
/* The resulting value is a constant. Scale it. */
|
||||||
if (MustScale) {
|
if (MustScale) {
|
||||||
@ -3091,43 +3107,43 @@ void hie1 (ExprDesc* Expr)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_PLUS_ASSIGN:
|
case TOK_PLUS_ASSIGN:
|
||||||
addsubeq (&GenPASGN, Expr);
|
addsubeq (&GenPASGN, Expr, "+=");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_MINUS_ASSIGN:
|
case TOK_MINUS_ASSIGN:
|
||||||
addsubeq (&GenSASGN, Expr);
|
addsubeq (&GenSASGN, Expr, "-=");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_MUL_ASSIGN:
|
case TOK_MUL_ASSIGN:
|
||||||
opeq (&GenMASGN, Expr);
|
opeq (&GenMASGN, Expr, "*=");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_DIV_ASSIGN:
|
case TOK_DIV_ASSIGN:
|
||||||
opeq (&GenDASGN, Expr);
|
opeq (&GenDASGN, Expr, "/=");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_MOD_ASSIGN:
|
case TOK_MOD_ASSIGN:
|
||||||
opeq (&GenMOASGN, Expr);
|
opeq (&GenMOASGN, Expr, "%=");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_SHL_ASSIGN:
|
case TOK_SHL_ASSIGN:
|
||||||
opeq (&GenSLASGN, Expr);
|
opeq (&GenSLASGN, Expr, "<<=");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_SHR_ASSIGN:
|
case TOK_SHR_ASSIGN:
|
||||||
opeq (&GenSRASGN, Expr);
|
opeq (&GenSRASGN, Expr, ">>=");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_AND_ASSIGN:
|
case TOK_AND_ASSIGN:
|
||||||
opeq (&GenAASGN, Expr);
|
opeq (&GenAASGN, Expr, "&=");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_XOR_ASSIGN:
|
case TOK_XOR_ASSIGN:
|
||||||
opeq (&GenXOASGN, Expr);
|
opeq (&GenXOASGN, Expr, "^=");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_OR_ASSIGN:
|
case TOK_OR_ASSIGN:
|
||||||
opeq (&GenOASGN, Expr);
|
opeq (&GenOASGN, Expr, "|=");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user