* [PATCH 2/2] c/100547 - reject overly large vector_size attributes
@ 2021-05-12 8:47 Richard Biener
2021-05-12 15:11 ` Martin Sebor
0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2021-05-12 8:47 UTC (permalink / raw)
To: gcc-patches; +Cc: joseph
This rejects a number of vector components that does not fit an 'int'
which is an internal limitation of RTVEC.
This regresses gcc.dg/attr-vector_size.c which checks for much larger
supported vectors. Not sure what to do about this - I'll also note
the RTVEC limitation is a host specific limitation (unless we change
this 'int' to int32_t).
Bootstrapped and tested on x86_64-unknown-linux-gnu with the above
mentioned regression.
Any comments?
Thanks,
Richard.
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.
* gcc.dg/pr100547.c: New testcase.
---
gcc/c-family/c-attribs.c | 10 ++++++++++
gcc/testsuite/gcc.dg/pr100547.c | 35 +++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/pr100547.c
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index c1f652d1dc9..60bcfa22df1 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -4252,6 +4252,16 @@ type_valid_for_vector_size (tree type, tree atname, tree args,
return NULL_TREE;
}
+ if (nunits >= (unsigned HOST_WIDE_INT)INT_MAX)
+ {
+ if (error_p)
+ error ("number of components of the vector exceeds %d", INT_MAX);
+ else
+ warning (OPT_Wattributes,
+ "number of components of the vector exceeds %d", INT_MAX);
+ return NULL_TREE;
+ }
+
if (ptrnunits)
*ptrnunits = nunits;
diff --git a/gcc/testsuite/gcc.dg/pr100547.c b/gcc/testsuite/gcc.dg/pr100547.c
new file mode 100644
index 00000000000..92f34bf974f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr100547.c
@@ -0,0 +1,35 @@
+/* { dg-do compile } */
+/* { 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 components" } */
+void k() { V w = { 0 }; }
--
2.26.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 2/2] c/100547 - reject overly large vector_size attributes
2021-05-12 8:47 [PATCH 2/2] c/100547 - reject overly large vector_size attributes Richard Biener
@ 2021-05-12 15:11 ` Martin Sebor
0 siblings, 0 replies; 2+ messages in thread
From: Martin Sebor @ 2021-05-12 15:11 UTC (permalink / raw)
To: Richard Biener, gcc-patches; +Cc: joseph
On 5/12/21 2:47 AM, Richard Biener wrote:
> This rejects a number of vector components that does not fit an 'int'
> which is an internal limitation of RTVEC.
>
> This regresses gcc.dg/attr-vector_size.c which checks for much larger
> supported vectors. Not sure what to do about this - I'll also note
> the RTVEC limitation is a host specific limitation (unless we change
> this 'int' to int32_t).
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu with the above
> mentioned regression.
>
> Any comments?
Just a few minor ones.
>
> Thanks,
> Richard.
>
> 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.
>
> * gcc.dg/pr100547.c: New testcase.
> ---
> gcc/c-family/c-attribs.c | 10 ++++++++++
> gcc/testsuite/gcc.dg/pr100547.c | 35 +++++++++++++++++++++++++++++++++
> 2 files changed, 45 insertions(+)
> create mode 100644 gcc/testsuite/gcc.dg/pr100547.c
>
> diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
> index c1f652d1dc9..60bcfa22df1 100644
> --- a/gcc/c-family/c-attribs.c
> +++ b/gcc/c-family/c-attribs.c
> @@ -4252,6 +4252,16 @@ type_valid_for_vector_size (tree type, tree atname, tree args,
> return NULL_TREE;
> }
>
> + if (nunits >= (unsigned HOST_WIDE_INT)INT_MAX)
The inequality includes INT_MAX, so the phrasing below doesn't exactly
match the condition. Since nunits must be a power of 2 the condition
might as well be greater than.
> + {
> + if (error_p)
> + error ("number of components of the vector exceeds %d", INT_MAX);
"number of vector components" sounds better (though there are other
messages that use this phrasing already).
Especially since it's computed, I would suggest to mention the value
of nunits in the message (it should also be mentioned in the "power
of two" message).
Martin
> + else
> + warning (OPT_Wattributes,
> + "number of components of the vector exceeds %d", INT_MAX);
> + return NULL_TREE;
> + }
> +
> if (ptrnunits)
> *ptrnunits = nunits;
>
> diff --git a/gcc/testsuite/gcc.dg/pr100547.c b/gcc/testsuite/gcc.dg/pr100547.c
> new file mode 100644
> index 00000000000..92f34bf974f
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr100547.c
> @@ -0,0 +1,35 @@
> +/* { dg-do compile } */
> +/* { 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 components" } */
> +void k() { V w = { 0 }; }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-12 15:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-12 8:47 [PATCH 2/2] c/100547 - reject overly large vector_size attributes Richard Biener
2021-05-12 15:11 ` Martin Sebor
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).