This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C PATCH] Reject shifts of float vectors by int count (PR c/84853)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: "Joseph S. Myers" <joseph at codesourcery dot com>, Marek Polacek <polacek at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 14 Mar 2018 23:14:13 +0100
- Subject: [C PATCH] Reject shifts of float vectors by int count (PR c/84853)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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.
--- 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 >>" } */
+}
Jakub