1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-25 02:29:52 +00:00

Added basic shift count check for <<= and >>= operations.

This commit is contained in:
acqn 2022-11-12 12:34:16 +08:00
parent 2c3ca15d90
commit d0c9b2de99

View File

@ -322,6 +322,12 @@ static void OpAssignBitField (const GenDesc* Gen, ExprDesc* Expr, const char* Op
} else if (Gen->Func == g_mod) {
Error ("Modulo operation with zero");
}
} else if (Gen->Func == g_asl || Gen->Func == g_asr) {
if (Expr2.IVal < 0) {
Warning ("Shift count '%ld' is negative", Expr2.IVal);
} else if (Expr2.IVal >= (long)(SizeOf (Expr->Type) * 8)) {
Warning ("Shift count '%ld' >= width of type", Expr2.IVal);
}
}
/* Adjust the types of the operands if needed */
@ -502,6 +508,12 @@ static void OpAssignArithmetic (const GenDesc* Gen, ExprDesc* Expr, const char*
} else if (Gen->Func == g_mod) {
Error ("Modulo operation with zero");
}
} else if (Gen->Func == g_asl || Gen->Func == g_asr) {
if (Expr2.IVal < 0) {
Warning ("Shift count '%ld' is negative", Expr2.IVal);
} else if (Expr2.IVal >= (long)(SizeOf (Expr->Type) * 8)) {
Warning ("Shift count '%ld' >= width of type", Expr2.IVal);
}
}
Gen->Func (Flags | CF_CONST, Expr2.IVal);
}