This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix attribute parsing after PR28152 (PR c/37171)


Hi!

Manuel's PR28152 change broke parsing of __attribute__((__const))
and similar, which, while perhaps an undocumented extension, is apparently
widely used in glibc and elsewhere.
This patch restores previous behavior, by using the canonical keyword
spelling for attribute names.

Ok for trunk?

2008-08-20  Jakub Jelinek  <jakub@redhat.com>

	PR c/37171
	* c-parser.c (c_parser_attributes): For keywords use canonical
	spelling for attr_name.

	* gcc.dg/pr37171.c: New test.
	* g++.dg/ext/attrib34.C: New test.

--- gcc/c-parser.c.jj	2008-08-19 14:20:31.000000000 +0200
+++ gcc/c-parser.c	2008-08-20 16:58:20.000000000 +0200
@@ -2828,8 +2828,13 @@ c_parser_attributes (c_parser *parser)
 		}
 	      if (!ok)
 		break;
+	      /* Accept __attribute__((__const)) as __attribute__((const))
+		 etc.  */
+	      attr_name
+		= ridpointers[(int) c_parser_peek_token (parser)->keyword];
 	    }
-	  attr_name = c_parser_peek_token (parser)->value;
+	  else
+	    attr_name = c_parser_peek_token (parser)->value;
 	  c_parser_consume_token (parser);
 	  if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
 	    {
--- gcc/testsuite/gcc.dg/pr37171.c.jj	2008-08-20 17:00:46.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr37171.c	2008-08-20 17:01:58.000000000 +0200
@@ -0,0 +1,19 @@
+/* PR c/37171 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+unsigned int f1 (void) __attribute__((const));
+unsigned int f2 (void) __attribute__((__const));
+unsigned int f3 (void) __attribute__((__const__));
+
+unsigned int f4 (void)
+{
+  return f1 () + f1 () + f1 () + f1 ()
+	 + f2 () + f2 () + f2 () + f2 ()
+	 + f3 () + f3 () + f3 () + f3 ();
+}
+
+/* { dg-final { scan-tree-dump-times "= f1 \\(\\)" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "= f2 \\(\\)" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "= f3 \\(\\)" 1 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
--- gcc/testsuite/g++.dg/ext/attrib34.C.jj	2008-08-20 17:02:44.000000000 +0200
+++ gcc/testsuite/g++.dg/ext/attrib34.C	2008-08-20 17:03:11.000000000 +0200
@@ -0,0 +1,19 @@
+// PR c/37171
+// { dg-do compile }
+// { dg-options "-O2 -fdump-tree-optimized" }
+
+unsigned int f1 () __attribute__((const));
+unsigned int f2 () __attribute__((__const));
+unsigned int f3 () __attribute__((__const__));
+
+unsigned int f4 ()
+{
+  return f1 () + f1 () + f1 () + f1 ()
+	 + f2 () + f2 () + f2 () + f2 ()
+	 + f3 () + f3 () + f3 () + f3 ();
+}
+
+// { dg-final { scan-tree-dump-times "= f1 \\(\\)" 1 "optimized" } }
+// { dg-final { scan-tree-dump-times "= f2 \\(\\)" 1 "optimized" } }
+// { dg-final { scan-tree-dump-times "= f3 \\(\\)" 1 "optimized" } }
+// { dg-final { cleanup-tree-dump "optimized" } }

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]