This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch for grokdeclarator bug
On Mon, 16 Aug 2004, I wrote:
> Bootstrapped with no regressions on i686-pc-linux-gnu. Applied to
> mainline. Will also be applied to 3.4 branch as a regression fix
> after testing there.
Now applied in to 3.4 branch in the following form after bootstrap with no
regressions on i686-pc-linux-gnu.
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)
2004-08-17 Joseph S. Myers <jsm@polyomino.org.uk>
* c-decl.c (grokdeclarator): Allow for function definition where
innermost declarator has attributes.
testsuite:
2004-08-17 Joseph S. Myers <jsm@polyomino.org.uk>
* gcc.dg/funcdef-attr-1.c: New test.
diff -rupN GCC.orig/gcc/c-decl.c GCC/gcc/c-decl.c
--- GCC.orig/gcc/c-decl.c 2004-08-16 09:32:37.000000000 +0000
+++ GCC/gcc/c-decl.c 2004-08-16 11:47:26.000000000 +0000
@@ -4176,12 +4176,17 @@ grokdeclarator (tree declarator, tree de
}
else if (TREE_CODE (declarator) == CALL_EXPR)
{
- /* Say it's a definition only for the CALL_EXPR closest to
- the identifier. */
- bool really_funcdef = (funcdef_flag
- && (TREE_CODE (TREE_OPERAND (declarator, 0))
- == IDENTIFIER_NODE));
+ /* Say it's a definition only for the declarator closest to
+ the identifier, apart possibly from some attributes. */
+ bool really_funcdef = false;
tree arg_types;
+ if (funcdef_flag)
+ {
+ tree t = TREE_OPERAND (declarator, 0);
+ while (TREE_CODE (t) == TREE_LIST)
+ t = TREE_VALUE (t);
+ really_funcdef = (TREE_CODE (t) == IDENTIFIER_NODE);
+ }
/* Declaring a function type.
Make sure we have a valid type for the function to return. */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/funcdef-attr-1.c GCC/gcc/testsuite/gcc.dg/funcdef-attr-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/funcdef-attr-1.c 1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/funcdef-attr-1.c 2004-08-15 11:22:50.000000000 +0000
@@ -0,0 +1,14 @@
+/* The declarator in a function definition should be able to take the
+ form of an attributed function declarator, not just a plain
+ function declarator. This was formerly allowed by some of the code
+ but then the wrong constraint checks were made because other code
+ didn't recognise the declarator as being that of the function
+ definition. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk>. */
+
+int (__attribute__((const)) x) (a, b)
+ int a;
+ int b;
+{
+ return a + b;
+}