diff mbox series

[C] Reject shifts of float vectors by int count (PR c/84853)

Message ID 20180314221413.GK8577@tucnak
State New
Headers show
Series [C] Reject shifts of float vectors by int count (PR c/84853) | expand

Commit Message

Jakub Jelinek March 14, 2018, 10:14 p.m. UTC
Hi!

The change for better warnings on vector shifts unfortunately started
accepting even shifts of floating point vectors by int shift count, which is
something that shouldn't be supported and ICEs later on.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2018-03-14  Jakub Jelinek  <jakub@redhat.com>

	PR c/84853
	* c-typeck.c (build_binary_op) <case RSHIFT_EXPR, case LSHIFT_EXPR>:
	If code1 is INTEGER_TYPE, only allow code0 VECTOR_TYPE if it has
	INTEGER_TYPE element type.

	* gcc.dg/pr84853.c: New test.


	Jakub

Comments

Joseph Myers March 15, 2018, 12:38 a.m. UTC | #1
On Wed, 14 Mar 2018, Jakub Jelinek wrote:

> Hi!
> 
> The change for better warnings on vector shifts unfortunately started
> accepting even shifts of floating point vectors by int shift count, which is
> something that shouldn't be supported and ICEs later on.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

OK.
diff mbox series

Patch

--- gcc/c/c-typeck.c.jj	2018-03-13 21:32:00.441647458 +0100
+++ gcc/c/c-typeck.c	2018-03-13 23:03:27.659789112 +0100
@@ -11350,7 +11350,8 @@  build_binary_op (location_t location, en
 	  converted = 1;
 	}
       else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
-		|| code0 == VECTOR_TYPE)
+		|| (code0 == VECTOR_TYPE
+		    && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
 	       && code1 == INTEGER_TYPE)
 	{
 	  doing_shift = true;
@@ -11408,7 +11409,8 @@  build_binary_op (location_t location, en
 	  converted = 1;
 	}
       else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
-		|| code0 == VECTOR_TYPE)
+		|| (code0 == VECTOR_TYPE
+		    && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
 	       && code1 == INTEGER_TYPE)
 	{
 	  doing_shift = true;
--- gcc/testsuite/gcc.dg/pr84853.c.jj	2018-03-13 23:07:05.910890067 +0100
+++ gcc/testsuite/gcc.dg/pr84853.c	2018-03-13 23:06:38.546877404 +0100
@@ -0,0 +1,19 @@ 
+/* PR c/84853 */
+/* { dg-do compile } */
+
+typedef float V __attribute__((__vector_size__ (16)));
+typedef int W __attribute__((__vector_size__ (16)));
+
+void
+foo (int x, V *y, V *z, W *w)
+{
+  *y = *y << x;		/* { dg-error "invalid operands to binary <<" } */
+  *z = *z << *w;	/* { dg-error "invalid operands to binary <<" } */
+}
+
+void
+bar (int x, V *y, V *z, W *w)
+{
+  *y = *y >> x;		/* { dg-error "invalid operands to binary >>" } */
+  *z = *z >> *w;	/* { dg-error "invalid operands to binary >>" } */
+}