From: Martin Liska Date: Thu, 10 Aug 2017 07:43:49 +0000 (+0200) Subject: Fix target attribute handling (PR c++/81355). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2b7d0696e134613819d4c1cdbdd9e055f7a297ea;p=gcc.git Fix target attribute handling (PR c++/81355). 2017-08-10 Martin Liska PR c++/81355 * c-attribs.c (handle_target_attribute): Report warning for an empty string argument of target attribute. 2017-08-10 Martin Liska PR c++/81355 * g++.dg/other/pr81355.C: New test. From-SVN: r251020 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1b029256775..1694c21e497 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-08-10 Martin Liska + + PR c++/81355 + * c-attribs.c (handle_target_attribute): + Report warning for an empty string argument of target attribute. + 2017-08-09 Jakub Jelinek PR c/81687 diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c index 0d9ab2d6ae0..a40b0649ca3 100644 --- a/gcc/c-family/c-attribs.c +++ b/gcc/c-family/c-attribs.c @@ -3139,6 +3139,19 @@ handle_target_attribute (tree *node, tree name, tree args, int flags, flags)) *no_add_attrs = true; + /* Check that there's no empty string in values of the attribute. */ + for (tree t = args; t != NULL_TREE; t = TREE_CHAIN (t)) + { + tree value = TREE_VALUE (t); + if (TREE_CODE (value) == STRING_CST + && TREE_STRING_LENGTH (value) == 1 + && TREE_STRING_POINTER (value)[0] == '\0') + { + warning (OPT_Wattributes, "empty string in attribute %"); + *no_add_attrs = true; + } + } + return NULL_TREE; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6eac250b97d..4d1e3c61444 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-08-10 Martin Liska + + PR c++/81355 + * g++.dg/other/pr81355.C: New test. + 2017-08-09 David Malcolm * jit.dg/all-non-failing-tests.h: Add note about diff --git a/gcc/testsuite/g++.dg/other/pr81355.C b/gcc/testsuite/g++.dg/other/pr81355.C new file mode 100644 index 00000000000..89d1b419581 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/pr81355.C @@ -0,0 +1,14 @@ +/* { dg-do compile { target x86_64-*-* } } */ + +__attribute__((target("default"))) +int foo() {return 1;} + +__attribute__((target("arch=core2", ""))) +int foo2() {return 2;} /* { dg-warning "empty string in attribute .target." } */ + +__attribute__((target("sse4.2", "", ""))) +int foo3() {return 2;} /* { dg-warning "empty string in attribute .target." } */ + +int main() { + return foo() + foo2() + foo3(); +}