public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Fix handling of C++11 attributes (PR c++/67767)
@ 2016-02-18 17:20 Jakub Jelinek
  2016-02-19 15:43 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2016-02-18 17:20 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

While this likely isn't a regression, it looks severe enough that IMHO we
should fix this even in stage4 - apparently cp_parser_std_attribute_spec_seq
can drop some of the attributes on the floor, by blindly assuming that
there is just a single attribute inside of [[ ]], but there could be many,
and the list is already in the right order (chained and nreversed at the
end).  So, we need to chainon the sequences, but either that would be
quadratic, or we'd need to nreverse each chain again, then chainon and then
nreverse again.  So IMHO remembering instead also the last chain element
and chaining that way is cleanest and cheapest.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-02-18  Jakub Jelinek  <jakub@redhat.com>

	PR c++/67767
	* parser.c (cp_parser_std_attribute_spec_seq): Don't assume
	attr_spec is always single element chain, chain all the attributes
	properly together in the right order.

	* g++.dg/cpp0x/pr67767.C: New test.

--- gcc/cp/parser.c.jj	2016-02-17 23:26:00.000000000 +0100
+++ gcc/cp/parser.c	2016-02-18 09:48:52.896766040 +0100
@@ -24104,7 +24104,8 @@ cp_parser_std_attribute_spec (cp_parser
 static tree
 cp_parser_std_attribute_spec_seq (cp_parser *parser)
 {
-  tree attr_specs = NULL;
+  tree attr_specs = NULL_TREE;
+  tree attr_last = NULL_TREE;
 
   while (true)
     {
@@ -24114,11 +24115,13 @@ cp_parser_std_attribute_spec_seq (cp_par
       if (attr_spec == error_mark_node)
 	return error_mark_node;
 
-      TREE_CHAIN (attr_spec) = attr_specs;
-      attr_specs = attr_spec;
+      if (attr_last)
+	TREE_CHAIN (attr_last) = attr_spec;
+      else
+	attr_specs = attr_last = attr_spec;
+      attr_last = tree_last (attr_last);
     }
 
-  attr_specs = nreverse (attr_specs);
   return attr_specs;
 }
 
--- gcc/testsuite/g++.dg/cpp0x/pr67767.C.jj	2016-02-18 09:53:12.808187281 +0100
+++ gcc/testsuite/g++.dg/cpp0x/pr67767.C	2016-02-18 09:53:39.311822349 +0100
@@ -0,0 +1,10 @@
+// PR c++/67767
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wsuggest-attribute=noreturn" }
+
+void foo [[gnu::cold, gnu::noreturn]] ();
+
+void foo ()	// { dg-bogus "function might be candidate for attribute" }
+{
+  throw 1;
+}

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C++ PATCH] Fix handling of C++11 attributes (PR c++/67767)
  2016-02-18 17:20 [C++ PATCH] Fix handling of C++11 attributes (PR c++/67767) Jakub Jelinek
@ 2016-02-19 15:43 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2016-02-19 15:43 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

OK.

Jason

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-19 15:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-18 17:20 [C++ PATCH] Fix handling of C++11 attributes (PR c++/67767) Jakub Jelinek
2016-02-19 15:43 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).