summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>2017-08-10 07:43:49 +0000
committermarxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>2017-08-10 07:43:49 +0000
commit98afa00e3de78c71c6e85d11a1ffa3c76a47f647 (patch)
treeaeb62d896db715cdd80544148c07b70a8a07e2ed
parented5078db5b63d5c66070fb7cd6a24c003d61301e (diff)
downloadgcc-98afa00e3de78c71c6e85d11a1ffa3c76a47f647.tar.gz
Fix target attribute handling (PR c++/81355).
2017-08-10 Martin Liska <mliska@suse.cz> PR c++/81355 * c-attribs.c (handle_target_attribute): Report warning for an empty string argument of target attribute. 2017-08-10 Martin Liska <mliska@suse.cz> PR c++/81355 * g++.dg/other/pr81355.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@251020 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/c-family/c-attribs.c13
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/other/pr81355.C14
4 files changed, 38 insertions, 0 deletions
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 <mliska@suse.cz>
+
+ PR c++/81355
+ * c-attribs.c (handle_target_attribute):
+ Report warning for an empty string argument of target attribute.
+
2017-08-09 Jakub Jelinek <jakub@redhat.com>
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 %<target%>");
+ *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 <mliska@suse.cz>
+
+ PR c++/81355
+ * g++.dg/other/pr81355.C: New test.
+
2017-08-09 David Malcolm <dmalcolm@redhat.com>
* 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();
+}