attributes: target_clone expects a string argument

Message ID 306a7985-b324-6adf-7194-995f36975a81@suse.cz
State New
Headers show
Series
  • attributes: target_clone expects a string argument
Related show

Commit Message

Martin Liška May 13, 2021, 12:05 p.m.
Hello.

The change is about error handling.

Ready to be installed?
Thanks,
Martin

	PR middle-end/100504

gcc/c-family/ChangeLog:

	* c-attribs.c (handle_target_clones_attribute): Expect a string
	argument to target_clone argument.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr100504.c: New test.
---
  gcc/c-family/c-attribs.c                 | 6 ++++++
  gcc/testsuite/gcc.target/i386/pr100504.c | 7 +++++++
  2 files changed, 13 insertions(+)
  create mode 100644 gcc/testsuite/gcc.target/i386/pr100504.c

-- 
2.31.1

Comments

Feng Xue OS via Gcc-patches May 13, 2021, 3:12 p.m. | #1
On 5/13/21 6:05 AM, Martin Liška wrote:
> Hello.

> 

> The change is about error handling.

> 

> Ready to be installed?

> Thanks,

> Martin

> 

>      PR middle-end/100504

> 

> gcc/c-family/ChangeLog:

> 

>      * c-attribs.c (handle_target_clones_attribute): Expect a string

>      argument to target_clone argument.

> 

> gcc/testsuite/ChangeLog:

> 

>      * gcc.target/i386/pr100504.c: New test.

> ---

>   gcc/c-family/c-attribs.c                 | 6 ++++++

>   gcc/testsuite/gcc.target/i386/pr100504.c | 7 +++++++

>   2 files changed, 13 insertions(+)

>   create mode 100644 gcc/testsuite/gcc.target/i386/pr100504.c

> 

> diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c

> index c1f652d1dc9..9905ee56947 100644

> --- a/gcc/c-family/c-attribs.c

> +++ b/gcc/c-family/c-attribs.c

> @@ -5300,6 +5300,12 @@ handle_target_clones_attribute (tree *node, tree 

> name, tree ARG_UNUSED (args),

>              "with %qs attribute", name, "target");

>         *no_add_attrs = true;

>       }

> +      else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)

> +    {

> +      error ("%qE attribute argument not a string constant", name);

> +      *no_add_attrs = true;

> +    }


Since errors are higher priority than warnings I'd suggest making
this the first check, before the warnings above, (and adding a test
to verify that that's how it works).

Martin

> +

>         else

>         /* Do not inline functions with multiple clone targets.  */

>       DECL_UNINLINABLE (*node) = 1;

> diff --git a/gcc/testsuite/gcc.target/i386/pr100504.c 

> b/gcc/testsuite/gcc.target/i386/pr100504.c

> new file mode 100644

> index 00000000000..2910dfb948b

> --- /dev/null

> +++ b/gcc/testsuite/gcc.target/i386/pr100504.c

> @@ -0,0 +1,7 @@

> +/* PR middle-end/100504 */

> +/* { dg-do compile } */

> +

> +__attribute__((target_clones(0)))

> +foo()

> +{ /* { dg-error ".target_clones. attribute argument not a string 

> constant" } */

> +}
Feng Xue OS via Gcc-patches May 13, 2021, 3:18 p.m. | #2
On 5/13/2021 6:05 AM, Martin Liška wrote:
> Hello.

>

> The change is about error handling.

>

> Ready to be installed?

> Thanks,

> Martin

>

>     PR middle-end/100504

>

> gcc/c-family/ChangeLog:

>

>     * c-attribs.c (handle_target_clones_attribute): Expect a string

>     argument to target_clone argument.

>

> gcc/testsuite/ChangeLog:

>

>     * gcc.target/i386/pr100504.c: New test.


OK

jeff
Martin Liška May 13, 2021, 5:30 p.m. | #3
On 5/13/21 5:12 PM, Martin Sebor wrote:
> Since errors are higher priority than warnings I'd suggest making

> this the first check, before the warnings above, (and adding a test

> to verify that that's how it works).


Good idea. I've just pushed such change.

Martin

Patch

diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index c1f652d1dc9..9905ee56947 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -5300,6 +5300,12 @@  handle_target_clones_attribute (tree *node, tree name, tree ARG_UNUSED (args),
  		   "with %qs attribute", name, "target");
  	  *no_add_attrs = true;
  	}
+      else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
+	{
+	  error ("%qE attribute argument not a string constant", name);
+	  *no_add_attrs = true;
+	}
+
        else
        /* Do not inline functions with multiple clone targets.  */
  	DECL_UNINLINABLE (*node) = 1;
diff --git a/gcc/testsuite/gcc.target/i386/pr100504.c b/gcc/testsuite/gcc.target/i386/pr100504.c
new file mode 100644
index 00000000000..2910dfb948b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr100504.c
@@ -0,0 +1,7 @@ 
+/* PR middle-end/100504 */
+/* { dg-do compile } */
+
+__attribute__((target_clones(0)))
+foo()
+{ /* { dg-error ".target_clones. attribute argument not a string constant" } */
+}