public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5451] openacc: Fix up C++ #pragma acc routine handling [PR101731]
@ 2021-11-22 16:07 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-11-22 16:07 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1aedb3920a45bfe75db4514502b4e7f83e108f63

commit r12-5451-g1aedb3920a45bfe75db4514502b4e7f83e108f63
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Nov 22 17:06:12 2021 +0100

    openacc: Fix up C++ #pragma acc routine handling [PR101731]
    
    The following testcase ICEs because two function declarations are nested in
    each other and the acc routine handling code isn't prepared to put the
    pragma on both.
    
    The fix is similar to what #pragma omp declare {simd,variant} does,
    in particular set the fndecl_seen flag already in cp_parser_late_parsing*
    when we encounter it rather than only after we finalize it.
    
    In cp_finalize_oacc_routine I had to move the fndecl_seen diagnostics to
    non-FUNCTION_DECL block, because for FUNCTION_DECLs the flag is already
    known to be set from cp_parser_late_parsing_oacc_routine, but can't be
    removed altogether, because that regresses quality of 2 goacc/routine-5.c
    diagnostics - we drop "a single " from the
    '#pragma acc routine' not immediately followed by a single function declaration or definition
    diagnostic say on
     #pragma acc routine
     int foo (), b;
    if we drop it altogether.
    
    2021-11-22  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/101731
            * parser.c (cp_parser_late_parsing_oacc_routine): Set
            parser->oacc_routine->fndecl_seen here, rather than ...
            (cp_finalize_oacc_routine): ... here.  Don't error if
            parser->oacc_routine->fndecl_seen is set for FUNCTION_DECLs.
    
            * c-c++-common/goacc/routine-6.c: New test.

Diff:
---
 gcc/cp/parser.c                              | 26 +++++++++++---------------
 gcc/testsuite/c-c++-common/goacc/routine-6.c |  4 ++++
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index aa7f0e4b526..e2b5d6842fc 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -46852,8 +46852,8 @@ cp_parser_late_parsing_oacc_routine (cp_parser *parser, tree attrs)
      emission easier.  */
   parser->oacc_routine->clauses = nreverse (parser->oacc_routine->clauses);
   cp_parser_pop_lexer (parser);
-  /* Later, cp_finalize_oacc_routine will process the clauses, and then set
-     fndecl_seen.  */
+  /* Later, cp_finalize_oacc_routine will process the clauses.  */
+  parser->oacc_routine->fndecl_seen = true;
 
   return attrs;
 }
@@ -46871,16 +46871,17 @@ cp_finalize_oacc_routine (cp_parser *parser, tree fndecl, bool is_defn)
 	  || fndecl == error_mark_node)
 	return;
 
-      if (parser->oacc_routine->fndecl_seen)
-	{
-	  error_at (parser->oacc_routine->loc,
-		    "%<#pragma acc routine%> not immediately followed by"
-		    " a single function declaration or definition");
-	  parser->oacc_routine = NULL;
-	  return;
-	}
       if (TREE_CODE (fndecl) != FUNCTION_DECL)
 	{
+	  if (parser->oacc_routine->fndecl_seen)
+	    {
+	      error_at (parser->oacc_routine->loc,
+			"%<#pragma acc routine%> not immediately followed by"
+			" a single function declaration or definition");
+	      parser->oacc_routine = NULL;
+	      return;
+	    }
+
 	  cp_ensure_no_oacc_routine (parser);
 	  return;
 	}
@@ -46921,11 +46922,6 @@ cp_finalize_oacc_routine (cp_parser *parser, tree fndecl, bool is_defn)
 			 parser->oacc_routine->clauses,
 			 DECL_ATTRIBUTES (fndecl));
 	}
-
-      /* Don't unset parser->oacc_routine here: we may still need it to
-	 diagnose wrong usage.  But, remember that we've used this "#pragma acc
-	 routine".  */
-      parser->oacc_routine->fndecl_seen = true;
     }
 }
 
diff --git a/gcc/testsuite/c-c++-common/goacc/routine-6.c b/gcc/testsuite/c-c++-common/goacc/routine-6.c
new file mode 100644
index 00000000000..0a231a015a7
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/goacc/routine-6.c
@@ -0,0 +1,4 @@
+/* PR c++/101731 */
+
+#pragma acc routine	/* { dg-error "not immediately followed by a single function declaration or definition" "" { target c++ } } */
+int foo (int bar ());


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-22 16:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-22 16:07 [gcc r12-5451] openacc: Fix up C++ #pragma acc routine handling [PR101731] Jakub Jelinek

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).