This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Reject bogus vector sizes
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 28 Dec 2005 07:39:14 -0500
- Subject: [PATCH] Reject bogus vector sizes
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
It is pretty strange that we reject say
int __attribute__((vector_size (12)))
but not even more bogus sizes like
int __attribute__((vector_size (5)))
or even
int __attribute__((vector_size (0))).
While vector_size (5) on int would have the same effect as
vector_size (4), vector_size (n) where n < sizeof (int)
upset various parts of the middle end.
Is it ok to reject all this, in 4.0/4.1/on the trunk?
2005-12-28 Jakub Jelinek <jakub@redhat.com>
PR c/25559
* c-common.c (handle_vector_size_attribute): Reject zero vector size
as well as sizes not multiple of component size.
* gcc.dg/pr25559.c: New test.
--- gcc/c-common.c.jj 2005-12-23 10:32:49.000000000 +0100
+++ gcc/c-common.c 2005-12-28 13:22:14.000000000 +0100
@@ -5184,6 +5184,18 @@ handle_vector_size_attribute (tree *node
return NULL_TREE;
}
+ if (vecsize % tree_low_cst (TYPE_SIZE_UNIT (type), 1))
+ {
+ error ("vector size not an integral multiple of component size");
+ return NULL;
+ }
+
+ if (vecsize == 0)
+ {
+ error ("zero vector size");
+ return NULL;
+ }
+
/* Calculate how many units fit in the vector. */
nunits = vecsize / tree_low_cst (TYPE_SIZE_UNIT (type), 1);
if (nunits & (nunits - 1))
--- gcc/testsuite/gcc.dg/pr25559.c.jj 2005-12-28 13:29:24.000000000 +0100
+++ gcc/testsuite/gcc.dg/pr25559.c 2005-12-28 13:33:50.000000000 +0100
@@ -0,0 +1,10 @@
+/* PR c/25559 */
+/* { dg-do compile } */
+
+#define vs(n) __attribute__((vector_size (n)))
+int vs (-1) a; /* { dg-warning "attribute ignored" } */
+int vs (0) b; /* { dg-error "zero vector size" } */
+int vs (1) c; /* { dg-error "multiple of component size" } */
+int vs (sizeof (int) / 2) d; /* { dg-error "multiple of component size" } */
+int vs (sizeof (int)) e;
+int vs (sizeof (int) * 2) f;
Jakub