From ef5a4db12e547d4758151f58606d4eb5f5b59297 Mon Sep 17 00:00:00 2001 From: acqn Date: Mon, 3 Aug 2020 01:15:57 +0800 Subject: [PATCH] Improved warning messages on UB shifts. --- src/cc65/shiftexpr.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cc65/shiftexpr.c b/src/cc65/shiftexpr.c index c7aea5255..9fe9d1188 100644 --- a/src/cc65/shiftexpr.c +++ b/src/cc65/shiftexpr.c @@ -139,9 +139,14 @@ void ShiftExpr (struct ExprDesc* Expr) ** the operand, the behaviour is undefined according to the ** standard. */ - if (Expr2.IVal < 0 || Expr2.IVal >= (long) ExprBits) { + if (Expr2.IVal < 0) { - Warning ("Shift count too large for operand type"); + Warning ("Shift count '%ld' is negative", Expr2.IVal); + Expr2.IVal &= ExprBits - 1; + + } else if (Expr2.IVal >= (long) ExprBits) { + + Warning ("Shift count '%ld' >= width of type", Expr2.IVal); Expr2.IVal &= ExprBits - 1; }