public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][ARM] pr50193: ICE on a | (b << negative-constant)
@ 2011-09-01 11:24 Andrew Stubbs
  2011-09-01 13:21 ` Joseph S. Myers
  0 siblings, 1 reply; 9+ messages in thread
From: Andrew Stubbs @ 2011-09-01 11:24 UTC (permalink / raw)
  To: gcc-patches; +Cc: patches

[-- Attachment #1: Type: text/plain, Size: 469 bytes --]

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.

OK?

Andrew

[-- Attachment #2: pr50193.patch --]
[-- Type: text/x-patch, Size: 946 bytes --]

2011-09-01  Andrew Stubbs  <ams@codesourcery.com>

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

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

--- a/gcc/config/arm/predicates.md
+++ b/gcc/config/arm/predicates.md
@@ -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" } */
+
+int
+foo(int a, int b)
+{
+  return a | (b << -3); /* { dg-warning "left shift count is negative" } */
+}

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-09-07 15:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-01 11:24 [PATCH][ARM] pr50193: ICE on a | (b << negative-constant) Andrew Stubbs
2011-09-01 13:21 ` Joseph S. Myers
2011-09-01 15:26   ` Andrew Stubbs
2011-09-01 15:29     ` Andrew Stubbs
2011-09-01 15:52       ` Jakub Jelinek
2011-09-01 16:21         ` Andrew Stubbs
2011-09-05 17:07           ` Andrew Stubbs
2011-09-07 15:05             ` Ramana Radhakrishnan
2011-09-07 15:37         ` Richard Earnshaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).