mirror of
https://github.com/cc65/cc65.git
synced 2024-09-29 17:56:21 +00:00
Additional check for out of ranges of bit-fields in bitwise-shifts.
This commit is contained in:
parent
75be73cc8d
commit
73897aface
@ -345,7 +345,12 @@ static void OpAssignBitField (const GenDesc* Gen, ExprDesc* Expr, const char* Op
|
|||||||
|
|
||||||
/* Here we simply "wrap" the shift count around the width */
|
/* Here we simply "wrap" the shift count around the width */
|
||||||
Expr2.IVal &= ExprBits - 1;
|
Expr2.IVal &= ExprBits - 1;
|
||||||
}
|
|
||||||
|
/* Additional check for bit-fields */
|
||||||
|
if (Expr2.IVal >= (long)Expr->Type->A.B.Width) {
|
||||||
|
Warning ("Shift count %ld >= width of bit-field", Expr2.IVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adjust the types of the operands if needed */
|
/* Adjust the types of the operands if needed */
|
||||||
@ -549,6 +554,12 @@ static void OpAssignArithmetic (const GenDesc* Gen, ExprDesc* Expr, const char*
|
|||||||
|
|
||||||
/* Here we simply "wrap" the shift count around the width */
|
/* Here we simply "wrap" the shift count around the width */
|
||||||
Expr2.IVal &= ExprBits - 1;
|
Expr2.IVal &= ExprBits - 1;
|
||||||
|
|
||||||
|
/* Additional check for bit width */
|
||||||
|
if (Expr2.IVal >= (long)BitSizeOf (Expr->Type)) {
|
||||||
|
Warning ("Shift count %ld >= width of %s",
|
||||||
|
Expr2.IVal, GetBasicTypeName (Expr->Type));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Gen->Func (Flags | CF_CONST, Expr2.IVal);
|
Gen->Func (Flags | CF_CONST, Expr2.IVal);
|
||||||
|
@ -160,6 +160,15 @@ void ShiftExpr (struct ExprDesc* Expr)
|
|||||||
/* Here we simply "wrap" the shift count around the width */
|
/* Here we simply "wrap" the shift count around the width */
|
||||||
Expr2.IVal &= ExprBits - 1;
|
Expr2.IVal &= ExprBits - 1;
|
||||||
|
|
||||||
|
/* Additional check for bit-fields */
|
||||||
|
if (IsTypeBitField (Expr->Type) &&
|
||||||
|
Tok == TOK_SHR &&
|
||||||
|
Expr2.IVal >= (long) Expr->Type->A.B.Width) {
|
||||||
|
if (!ED_IsUneval (Expr)) {
|
||||||
|
Warning ("Right-shift count %ld >= width of bit-field", Expr2.IVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* If the shift count is zero, nothing happens. If the left hand
|
/* If the shift count is zero, nothing happens. If the left hand
|
||||||
** side is a constant, the result is constant.
|
** side is a constant, the result is constant.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user