This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][ARM] pr50193: ICE on a | (b << negative-constant)

This patch should fix the bug in pr50193.

The problem is that the arith_shiftsi pattern accepted any arbitrary constant as the shift amount (via the shift_amount_operand predicate) where in fact the constant must be in the range 0..32.

This patch fixes the problem by merely checking that the constant is positive. I've confirmed that values larger than the mode-size are not a problem because the compiler optimizes those away earlier, even at -O0.


2011-09-01  Andrew Stubbs  <>

	* config/arm/ (shift_amount_operand): Ensure shift
	amount is positive.

	* gcc.dg/pr50193-1.c: New file.

--- a/gcc/config/arm/
+++ b/gcc/config/arm/
@@ -132,7 +132,8 @@
 (define_predicate "shift_amount_operand"
   (ior (and (match_test "TARGET_ARM")
 	    (match_operand 0 "s_register_operand"))
-       (match_operand 0 "const_int_operand")))
+       (and (match_operand 0 "const_int_operand")
+	    (match_test "INTVAL (op) > 0"))))
 (define_predicate "arm_add_operand"
   (ior (match_operand 0 "arm_rhs_operand")
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr50193-1.c
@@ -0,0 +1,10 @@
+/* PR 50193: ARM: ICE on a | (b << negative-constant) */
+/* Ensure that the compiler doesn't ICE.  */
+/* { dg-options "-O2" } */
+foo(int a, int b)
+  return a | (b << -3); /* { dg-warning "left shift count is negative" } */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]