Re: Rework C/C++ OpenACC routine parsing (was: C/C++: Simplify handling of location information for OpenACC routine directives)

2016-07-22 Thread Jakub Jelinek
On Wed, Jul 13, 2016 at 04:10:31PM +0200, Thomas Schwinge wrote:
> @@ -14029,29 +14032,32 @@ c_parser_oacc_kernels_parallel (location_t loc, 
> c_parser *parser,
>  static void
>  c_parser_oacc_routine (c_parser *parser, enum pragma_context context)
>  {
> -  tree decl = NULL_TREE;
> +  gcc_checking_assert (context == pragma_external);
> +
>oacc_routine_data data;
> +  data.error_seen = false;
> +  data.fndecl_seen = false;
>data.clauses = NULL_TREE;
>data.loc = c_parser_peek_token (parser)->location;
> -  
> -  if (context != pragma_external)
> -c_parser_error (parser, "%<#pragma acc routine%> not at file scope");
>  
>c_parser_consume_pragma (parser);
>  
> -  /* Scan for optional '( name )'.  */
> +  /* Look for optional '( name )'.  */
>if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN)

Can you please change this to
  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
?
Ok for trunk with that change.

Jakub


Rework C/C++ OpenACC routine parsing (was: C/C++: Simplify handling of location information for OpenACC routine directives)

2016-07-13 Thread Thomas Schwinge
Hi!

On Wed, 13 Jul 2016 11:25:46 +0200, I wrote:
> Working on something else regarding the C/C++ OpenACC routine directive,
> I couldn't but untangle [...]

> (Another C/C++ OpenACC routine
> cleanup patch is emerging, depending on this one.)

Here it is; likewise, OK for trunk?  (Further cleanup especially of C++
OpenACC routine handling seems to be possible, but I want to synchronize
my work at this point.)

commit 0bd30acaf4dd634499b1c695ddee555e7675aa18
Author: Thomas Schwinge 
Date:   Thu Jun 23 13:28:09 2016 +0200

Rework C/C++ OpenACC routine parsing

gcc/c/
* c-parser.c (struct oacc_routine_data): Add error_seen and
fndecl_seen members.
(c_finish_oacc_routine): Use these.
(c_parser_declaration_or_fndef): Adjust.
(c_parser_oacc_routine): Likewise.  Support more C language
constructs, and improve diagnostics.  Move pragma context
checking...
(c_parser_pragma): ... here.
gcc/cp/
* parser.c (cp_ensure_no_oacc_routine): Improve diagnostics.
(cp_parser_late_parsing_cilk_simd_fn_info): Fix diagnostics.
(cp_parser_late_parsing_oacc_routine, cp_finalize_oacc_routine):
Simplify code, and improve diagnostics.
(cp_parser_oacc_routine): Likewise.  Move pragma context
checking...
(cp_parser_pragma): ... here.
gcc/testsuite/
* c-c++-common/goacc/routine-5.c: Update.
---
 gcc/c/c-parser.c | 161 +++---
 gcc/cp/parser.c  | 182 +++-
 gcc/testsuite/c-c++-common/goacc/routine-5.c | 199 +++
 3 files changed, 369 insertions(+), 173 deletions(-)

diff --git gcc/c/c-parser.c gcc/c/c-parser.c
index 7f84ce9..809118a 100644
--- gcc/c/c-parser.c
+++ gcc/c/c-parser.c
@@ -1273,6 +1273,8 @@ enum c_parser_prec {
 
 /* Helper data structure for parsing #pragma acc routine.  */
 struct oacc_routine_data {
+  bool error_seen; /* Set if error has been reported.  */
+  bool fndecl_seen; /* Set if one fn decl/definition has been seen already.  */
   tree clauses;
   location_t loc;
 };
@@ -1565,8 +1567,7 @@ c_parser_external_declaration (c_parser *parser)
 }
 
 static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec);
-static void c_finish_oacc_routine (struct oacc_routine_data *, tree, bool,
-  bool, bool);
+static void c_finish_oacc_routine (struct oacc_routine_data *, tree, bool);
 
 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
6.7, 6.9.1).  If FNDEF_OK is true, a function definition is
@@ -1751,8 +1752,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool 
fndef_ok,
}
   c_parser_consume_token (parser);
   if (oacc_routine_data)
-   c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false, true,
-  false);
+   c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false);
   return;
 }
 
@@ -1850,7 +1850,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool 
fndef_ok,
   prefix_attrs = specs->attrs;
   all_prefix_attrs = prefix_attrs;
   specs->attrs = NULL_TREE;
-  for (bool first = true;; first = false)
+  while (true)
 {
   struct c_declarator *declarator;
   bool dummy = false;
@@ -1870,8 +1870,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool 
fndef_ok,
c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE,
   omp_declare_simd_clauses);
  if (oacc_routine_data)
-   c_finish_oacc_routine (oacc_routine_data, NULL_TREE,
-  false, first, false);
+   c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false);
  c_parser_skip_to_end_of_block_or_statement (parser);
  return;
}
@@ -1987,8 +1986,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool 
fndef_ok,
  finish_init ();
}
  if (oacc_routine_data)
-   c_finish_oacc_routine (oacc_routine_data, d,
-  false, first, false);
+   c_finish_oacc_routine (oacc_routine_data, d, false);
  if (d != error_mark_node)
{
  maybe_warn_string_init (init_loc, TREE_TYPE (d), init);
@@ -2033,8 +2031,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool 
fndef_ok,
temp_pop_parm_decls ();
}
  if (oacc_routine_data)
-   c_finish_oacc_routine (oacc_routine_data, d,
-  false, first, false);
+   c_finish_oacc_routine (oacc_routine_data, d, false);
  if (d)
finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
 NULL_TREE, asm_name);
@@ -2146,8 +2143,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool 
fndef_ok,