From b29facbd2b423f3ad897306d418cade0d5f9e714 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Fri, 15 Sep 2017 14:14:01 +0200 Subject: [PATCH] Backport r251020 2017-09-15 Martin Liska Backport from mainline 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-09-15 Martin Liska Backport from mainline 2017-08-10 Martin Liska PR c++/81355 * g++.dg/other/pr81355.C: New test. From-SVN: r252811 --- gcc/ChangeLog | 9 +++++++++ gcc/c-family/c-common.c | 13 +++++++++++++ gcc/testsuite/ChangeLog | 8 ++++++++ gcc/testsuite/g++.dg/other/pr81355.C | 14 ++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 gcc/testsuite/g++.dg/other/pr81355.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4123cd032c76..c028b6147fc7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2017-09-15 Martin Liska + + Backport from mainline + 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-09-15 Martin Liska Backport from mainline diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index e3e44518a646..35245703202e 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -9308,6 +9308,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 4af92529d7ac..dd465052bc79 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2017-09-15 Martin Liska + + Backport from mainline + 2017-08-10 Martin Liska + + PR c++/81355 + * g++.dg/other/pr81355.C: New test. + 2017-09-15 Martin Liska Backport from mainline diff --git a/gcc/testsuite/g++.dg/other/pr81355.C b/gcc/testsuite/g++.dg/other/pr81355.C new file mode 100644 index 000000000000..89d1b4195814 --- /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(); +} -- 2.47.2