c-parser.c (c_parser_declaration_or_fndef): Set DECL_ARGUMENTS of a FUNCTION_DECL...
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 22 Aug 2019 17:31:02 +0000 (17:31 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Thu, 22 Aug 2019 17:31:02 +0000 (17:31 +0000)
* c-parser.c (c_parser_declaration_or_fndef): Set DECL_ARGUMENTS of a
FUNCTION_DECL to the right value in the presence of nested declarators.

From-SVN: r274828

gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/dump-ada-spec-15.c

index 4d2897e54edb231b1c6ef2e3bc1be590ddca611d..0b3dc74f50f87f66e457b4545cb57a8f6eef7732 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-22  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * c-parser.c (c_parser_declaration_or_fndef): Set DECL_ARGUMENTS of a
+       FUNCTION_DECL to the right value in the presence of nested declarators.
+
 2019-08-13  Richard Sandiford  <richard.sandiford@arm.com>
 
        PR middle-end/91421
index 81919a89cc66bf15a4766f86ea2d7cebd911c246..7397f536032e643dd75ffc0017a4c35141379f7c 100644 (file)
@@ -2161,10 +2161,41 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
                                            all_prefix_attrs));
              if (d
                  && TREE_CODE (d) == FUNCTION_DECL
-                 && declarator->kind == cdk_function
                  && DECL_ARGUMENTS (d) == NULL_TREE
                  && DECL_INITIAL (d) == NULL_TREE)
-               DECL_ARGUMENTS (d) = declarator->u.arg_info->parms;
+               {
+                 /* Find the innermost declarator that is neither cdk_id
+                    nor cdk_attrs.  */
+                 const struct c_declarator *decl = declarator;
+                 const struct c_declarator *last_non_id_attrs = NULL;
+
+                 while (decl)
+                   switch (decl->kind)
+                     {
+                     case cdk_array:
+                     case cdk_function:
+                     case cdk_pointer:
+                       last_non_id_attrs = decl;
+                       decl = decl->declarator;
+                       break;
+
+                     case cdk_attrs:
+                       decl = decl->declarator;
+                       break;
+
+                     case cdk_id:
+                       decl = 0;
+                       break;
+
+                     default:
+                       gcc_unreachable ();
+                     }
+
+                 /* If it exists and is cdk_function, use its parameters.  */
+                 if (last_non_id_attrs
+                     && last_non_id_attrs->kind == cdk_function)
+                   DECL_ARGUMENTS (d) = last_non_id_attrs->u.arg_info->parms;
+               }
              if (omp_declare_simd_clauses.exists ())
                {
                  tree parms = NULL_TREE;
index 46b63d52f0d32098ec44b6137b7a51ad47da10e6..f8a806578ef222a8ca47c29a5e0a340d887706a4 100644 (file)
@@ -1,3 +1,7 @@
+2019-08-22  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * c-c++-common/dump-ada-spec-15.c: Check that the parameters are named.
+
 2019-08-22  Kyrylo Tkachov <kyrylo.tkachov@arm.com>
 
        * gcc.target/arm/acle/crc_hf_1.c: New test.
index a4b54a6a8459aab8fa4b7febf87006a7fbf9fc5e..c51c3e2dd0b783b0725f0b42e30ef4b6c7979d7a 100644 (file)
@@ -3,4 +3,6 @@
 
 extern void (*signal (int __sig, void (*__handler)(int)))(int);
 
+/* { dg-final { scan-ada-spec "uu_sig" } } */
+/* { dg-final { scan-ada-spec "uu_handler" } } */
 /* { dg-final { cleanup-ada-spec } } */