diff mbox

Fix target attribute handling (PR c++/81355).

Message ID b1cece8b-4522-f539-1b31-7f9da596f862@suse.cz
State New
Headers show

Commit Message

Martin Liška July 28, 2017, 11:13 a.m. UTC
Hello.

Following patch skips empty strings in 'target' attribute.
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin

gcc/ChangeLog:

2017-07-13  Martin Liska  <mliska@suse.cz>

	PR c++/81355
	* attribs.c (sorted_attr_string): Skip empty strings.

gcc/testsuite/ChangeLog:

2017-07-13  Martin Liska  <mliska@suse.cz>

	PR c++/81355
	* g++.dg/other/pr81355.C: New test.
---
 gcc/attribs.c                        |  6 ++++++
 gcc/testsuite/g++.dg/other/pr81355.C | 14 ++++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/other/pr81355.C

Comments

Jeff Law Aug. 2, 2017, 7:04 p.m. UTC | #1
On 07/28/2017 05:13 AM, Martin Liška wrote:
> Hello.
> 
> Following patch skips empty strings in 'target' attribute.
> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
> 
> Ready to be installed?
> Martin
> 
> gcc/ChangeLog:
> 
> 2017-07-13  Martin Liska  <mliska@suse.cz>
> 
> 	PR c++/81355
> 	* attribs.c (sorted_attr_string): Skip empty strings.
> 
> gcc/testsuite/ChangeLog:
> 
> 2017-07-13  Martin Liska  <mliska@suse.cz>
> 
> 	PR c++/81355
> 	* g++.dg/other/pr81355.C: New test.
OK.  THough one could legitimately ask if this ought to be a parsing error.

jeff
Martin Sebor Aug. 2, 2017, 7:56 p.m. UTC | #2
On 08/02/2017 01:04 PM, Jeff Law wrote:
> On 07/28/2017 05:13 AM, Martin Liška wrote:
>> Hello.
>>
>> Following patch skips empty strings in 'target' attribute.
>> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
>>
>> Ready to be installed?
>> Martin
>>
>> gcc/ChangeLog:
>>
>> 2017-07-13  Martin Liska  <mliska@suse.cz>
>>
>> 	PR c++/81355
>> 	* attribs.c (sorted_attr_string): Skip empty strings.
>>
>> gcc/testsuite/ChangeLog:
>>
>> 2017-07-13  Martin Liska  <mliska@suse.cz>
>>
>> 	PR c++/81355
>> 	* g++.dg/other/pr81355.C: New test.
> OK.  THough one could legitimately ask if this ought to be a parsing error.

I would suggest to at least issue a warning.  It seems that
the empty string must almost certainly be a bug here, say due
to unintended macro expansion.

Otherwise, if it should remain silently (and intentionally)
accepted, I recommend to document it.  As it is, the manual
says that the "string" argument is equivalent to compiling
with -mstring which for "" would be rejected by the driver.

Martin
diff mbox

Patch

diff --git a/gcc/attribs.c b/gcc/attribs.c
index 5eb19e82795..bf8452a3cec 100644
--- a/gcc/attribs.c
+++ b/gcc/attribs.c
@@ -725,6 +725,9 @@  sorted_attr_string (tree arglist)
     {
       const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
       size_t len = strlen (str);
+      /* Skip empty string.  */
+      if (len == 0)
+	continue;
       str_len_sum += len + 1;
       if (arg != arglist)
 	argnum++;
@@ -739,6 +742,9 @@  sorted_attr_string (tree arglist)
     {
       const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
       size_t len = strlen (str);
+      /* Skip empty string.  */
+      if (len == 0)
+	continue;
       memcpy (attr_str + str_len_sum, str, len);
       attr_str[str_len_sum + len] = TREE_CHAIN (arg) ? ',' : '\0';
       str_len_sum += len + 1;
diff --git a/gcc/testsuite/g++.dg/other/pr81355.C b/gcc/testsuite/g++.dg/other/pr81355.C
new file mode 100644
index 00000000000..d52b444261c
--- /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 foo() {return 2;}
+
+__attribute__((target("sse4.2", "", "")))
+int foo() {return 2;}
+
+int main() {
+    return foo();
+}