public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c: check if target_clone attrs are all string
@ 2022-12-28  8:16 Martin Liška
  2023-01-09  7:45 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Liška @ 2022-12-28  8:16 UTC (permalink / raw)
  To: gcc-patches

Hi.

The patch checks all attribute arguments if they are string. If not,
an error message is emitted.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

	PR c/107993

gcc/c-family/ChangeLog:

	* c-attribs.cc (handle_target_clones_attribute): Check for
	string constant for all target_clone attribute values.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr107993.c: New test.
---
 gcc/c-family/c-attribs.cc                | 14 ++++++++++----
 gcc/testsuite/gcc.target/i386/pr107993.c |  9 +++++++++
 2 files changed, 19 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr107993.c

diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index b36dd97802b..33d84cb6e07 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -5574,12 +5574,18 @@ handle_target_clones_attribute (tree *node, tree name, tree ARG_UNUSED (args),
   /* Ensure we have a function type.  */
   if (TREE_CODE (*node) == FUNCTION_DECL)
     {
-      if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
+      for (tree t = args; t != NULL_TREE; t = TREE_CHAIN (t))
 	{
-	  error ("%qE attribute argument not a string constant", name);
-	  *no_add_attrs = true;
+	  tree value = TREE_VALUE (t);
+	  if (TREE_CODE (value) != STRING_CST)
+	    {
+	      error ("%qE attribute argument not a string constant", name);
+	      *no_add_attrs = true;
+	      return NULL_TREE;
+	    }
 	}
-      else if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node)))
+
+      if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node)))
 	{
 	  warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
 		   "with %qs attribute", name, "always_inline");
diff --git a/gcc/testsuite/gcc.target/i386/pr107993.c b/gcc/testsuite/gcc.target/i386/pr107993.c
new file mode 100644
index 00000000000..b0b84a677d8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr107993.c
@@ -0,0 +1,9 @@
+/* PR c/107993 */
+/* { dg-do compile } */
+
+typedef union { int x; } u;
+__attribute__((target_clones("arch=alderlake",!"default")))
+int f (u *x)
+{ /* { dg-error ".target_clones. attribute argument not a string constant" } */
+  return 0;
+}
-- 
2.39.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c: check if target_clone attrs are all string
  2022-12-28  8:16 [PATCH] c: check if target_clone attrs are all string Martin Liška
@ 2023-01-09  7:45 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-01-09  7:45 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches

On Wed, Dec 28, 2022 at 9:17 AM Martin Liška <mliska@suse.cz> wrote:
>
> Hi.
>
> The patch checks all attribute arguments if they are string. If not,
> an error message is emitted.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?

OK.

Richard.

> Thanks,
> Martin
>
>         PR c/107993
>
> gcc/c-family/ChangeLog:
>
>         * c-attribs.cc (handle_target_clones_attribute): Check for
>         string constant for all target_clone attribute values.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/i386/pr107993.c: New test.
> ---
>  gcc/c-family/c-attribs.cc                | 14 ++++++++++----
>  gcc/testsuite/gcc.target/i386/pr107993.c |  9 +++++++++
>  2 files changed, 19 insertions(+), 4 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr107993.c
>
> diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
> index b36dd97802b..33d84cb6e07 100644
> --- a/gcc/c-family/c-attribs.cc
> +++ b/gcc/c-family/c-attribs.cc
> @@ -5574,12 +5574,18 @@ handle_target_clones_attribute (tree *node, tree name, tree ARG_UNUSED (args),
>    /* Ensure we have a function type.  */
>    if (TREE_CODE (*node) == FUNCTION_DECL)
>      {
> -      if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
> +      for (tree t = args; t != NULL_TREE; t = TREE_CHAIN (t))
>         {
> -         error ("%qE attribute argument not a string constant", name);
> -         *no_add_attrs = true;
> +         tree value = TREE_VALUE (t);
> +         if (TREE_CODE (value) != STRING_CST)
> +           {
> +             error ("%qE attribute argument not a string constant", name);
> +             *no_add_attrs = true;
> +             return NULL_TREE;
> +           }
>         }
> -      else if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node)))
> +
> +      if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node)))
>         {
>           warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
>                    "with %qs attribute", name, "always_inline");
> diff --git a/gcc/testsuite/gcc.target/i386/pr107993.c b/gcc/testsuite/gcc.target/i386/pr107993.c
> new file mode 100644
> index 00000000000..b0b84a677d8
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr107993.c
> @@ -0,0 +1,9 @@
> +/* PR c/107993 */
> +/* { dg-do compile } */
> +
> +typedef union { int x; } u;
> +__attribute__((target_clones("arch=alderlake",!"default")))
> +int f (u *x)
> +{ /* { dg-error ".target_clones. attribute argument not a string constant" } */
> +  return 0;
> +}
> --
> 2.39.0
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-09  7:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-28  8:16 [PATCH] c: check if target_clone attrs are all string Martin Liška
2023-01-09  7:45 ` Richard Biener

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).