public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-859] c/100547 - reject overly large vector_size attributes
Date: Tue, 18 May 2021 07:03:46 +0000 (GMT)	[thread overview]
Message-ID: <20210518070346.DAADE3850404@sourceware.org> (raw)

https://gcc.gnu.org/g:4054472b3fa15e11ccd48190f5e3ecfc89d65af9

commit r12-859-g4054472b3fa15e11ccd48190f5e3ecfc89d65af9
Author: Richard Biener <rguenther@suse.de>
Date:   Wed May 12 09:20:17 2021 +0200

    c/100547 - reject overly large vector_size attributes
    
    This rejects a number of vector components that does not fit an 'int'
    which is an internal limitation of RTVEC.  This requires adjusting
    gcc.dg/attr-vector_size.c which checks for much larger
    supported vectors.  Note that the RTVEC limitation is a host specific
    limitation (unless we change this 'int' to int32_t), but should be
    32bits in practice everywhere.
    
    2021-05-12  Richard Biener  <rguenther@suse.de>
    
            PR c/100547
    gcc/c-family/
            * c-attribs.c (type_valid_for_vector_size): Reject too large nunits.
            Reword existing nunit diagnostic.
    
    gcc/testsuite/
            * gcc.dg/pr100547.c: New testcase.
            * gcc.dg/attr-vector_size.c: Adjust.

Diff:
---
 gcc/c-family/c-attribs.c                | 16 +++++++++++++--
 gcc/testsuite/gcc.dg/attr-vector_size.c | 16 ---------------
 gcc/testsuite/gcc.dg/pr100547.c         | 35 +++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 18 deletions(-)

diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index f54388e9939..ecb32c70172 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -4245,10 +4245,22 @@ type_valid_for_vector_size (tree type, tree atname, tree args,
   if (nunits & (nunits - 1))
     {
       if (error_p)
-	error ("number of components of the vector not a power of two");
+	error ("number of vector components %wu not a power of two", nunits);
       else
 	warning (OPT_Wattributes,
-		 "number of components of the vector not a power of two");
+		 "number of vector components %wu not a power of two", nunits);
+      return NULL_TREE;
+    }
+
+  if (nunits >= (unsigned HOST_WIDE_INT)INT_MAX)
+    {
+      if (error_p)
+	error ("number of vector components %wu exceeds %d",
+	       nunits, INT_MAX - 1);
+      else
+	warning (OPT_Wattributes,
+		 "number of vector components %wu exceeds %d",
+		 nunits, INT_MAX - 1);
       return NULL_TREE;
     }
 
diff --git a/gcc/testsuite/gcc.dg/attr-vector_size.c b/gcc/testsuite/gcc.dg/attr-vector_size.c
index 00be26accd5..3f2ce889121 100644
--- a/gcc/testsuite/gcc.dg/attr-vector_size.c
+++ b/gcc/testsuite/gcc.dg/attr-vector_size.c
@@ -22,14 +22,6 @@ DEFVEC (extern, 30);
 
 #if __SIZEOF_SIZE_T__ > 4
 
-DEFVEC (extern, 31);
-DEFVEC (extern, 32);
-DEFVEC (extern, 33);
-DEFVEC (extern, 34);
-DEFVEC (extern, 60);
-DEFVEC (extern, 61);
-DEFVEC (extern, 62);
-
 VEC (POW2 (63)) char v63;     /* { dg-error  "'vector_size' attribute argument value '9223372036854775808' exceeds 9223372036854775807" "LP64" { target lp64 } } */
 
 #else
@@ -49,14 +41,6 @@ void test_local_scope (void)
 
 #if __SIZEOF_SIZE_T__ > 4
 
-  DEFVEC (auto, 31);
-  DEFVEC (auto, 32);
-  DEFVEC (auto, 33);
-  DEFVEC (auto, 34);
-  DEFVEC (auto, 60);
-  DEFVEC (auto, 61);
-  DEFVEC (auto, 62);
-
   VEC (POW2 (63)) char v63;   /* { dg-error  "'vector_size' attribute argument value '9223372036854775808' exceeds 9223372036854775807" "LP64" { target lp64 } } */
 
 #else
diff --git a/gcc/testsuite/gcc.dg/pr100547.c b/gcc/testsuite/gcc.dg/pr100547.c
new file mode 100644
index 00000000000..2d3da4eb50e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr100547.c
@@ -0,0 +1,35 @@
+/* { dg-do compile { target lp64 } } */
+/* { dg-options "-O -g" } */
+
+typedef int __attribute__((vector_size(
+    ((((((((((((((((((((((((((((((8 * sizeof(short)) * sizeof(short)) *
+                                sizeof(short)) *
+                               sizeof(short)) *
+                              sizeof(short)) *
+                             sizeof(short)) *
+                            sizeof(short)) *
+                           sizeof(short)) *
+                          sizeof(short)) *
+                         sizeof(short)) *
+                        sizeof(short)) *
+                       sizeof(short)) *
+                      sizeof(short)) *
+                     sizeof(short)) *
+                    sizeof(short)) *
+                   sizeof(short)) *
+                  sizeof(short)) *
+                 sizeof(short)) *
+                sizeof(short)) *
+               sizeof(short)) *
+              sizeof(short)) *
+             sizeof(short)) *
+            sizeof(short)) *
+           sizeof(short)) *
+          sizeof(short)) *
+         sizeof(short)) *
+        sizeof(short)) *
+       sizeof(short)) *
+      sizeof(short)) *
+     sizeof(short)) *
+    sizeof(short)))) V; /* { dg-error "number of vector components" } */
+void k() { V w = { 0 }; }


                 reply	other threads:[~2021-05-18  7:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210518070346.DAADE3850404@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).