diff mbox series

[3/4] shift-assign: restrict shift count to unsigned int

Message ID 20200806193003.10144-4-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series Fix shifts-assigns and avoid warns on deadcode | expand

Commit Message

Luc Van Oostenryck Aug. 6, 2020, 7:30 p.m. UTC
After the RHS of shift-assigns had been integer-promoted,
both gcc & clang seems to restrict it to an unsigned int.
This only make a difference when the shift count is negative
and would it make it UB.

Better to have the same generated code, so make the same here.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 evaluate.c                        | 5 +++++
 validation/linear/shift-assign2.c | 1 -
 2 files changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/evaluate.c b/evaluate.c
index 6d8ecd7f6c25..a9adc72f6b57 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -1348,6 +1348,11 @@  static int evaluate_assign_op(struct expression *expr)
 			unrestrict(expr->right, sclass, &s);
 			source = integer_promotion(s);
 			expr->right = cast_to(expr->right, source);
+
+			// both gcc & clang seems to do this, so ...
+			if (target->bit_size > source->bit_size)
+				expr->right = cast_to(expr->right, &uint_ctype);
+
 			goto Cast;
 		} else if (!(sclass & TYPE_RESTRICT))
 			goto usual;
diff --git a/validation/linear/shift-assign2.c b/validation/linear/shift-assign2.c
index 30d74376478e..9990ac38e800 100644
--- a/validation/linear/shift-assign2.c
+++ b/validation/linear/shift-assign2.c
@@ -13,7 +13,6 @@  u64 u64s32(u64 a, s32 b) { a >>= b; return a; }
 /*
  * check-name: shift-assign2
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-start
 s64s16: