public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/omp/gcc-11] openmp: Diagnose another case of mixing parameter and attribute syntax
@ 2021-08-12 10:00 Tobias Burnus
  0 siblings, 0 replies; only message in thread
From: Tobias Burnus @ 2021-08-12 10:00 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3fa54e0209e97d56b14c8488ce1ef1afa3f8c2cb

commit 3fa54e0209e97d56b14c8488ce1ef1afa3f8c2cb
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Aug 12 11:23:51 2021 +0200

    openmp: Diagnose another case of mixing parameter and attribute syntax
    
    This patch diagnoses cases like:
      #pragma omp parallel
      [[omp::directive (declare simd)]] int foo ();
    or
      #pragma omp taskgroup
      int bar [[omp::directive (declare simd)]] (int);
    where the pragma is on the same declaration statement as the declare simd
    attribute.
    
    2021-08-12  Jakub Jelinek  <jakub@redhat.com>
    
            * parser.c (cp_parser_lambda_body): Add temp overrides
            for parser->{omp_declare_simd,oacc_routine,omp_attrs_forbidden_p}.
            (cp_parser_statement): Restore parser->omp_attrs_forbidden_p for
            cp_parser_declaration_statement.
            (cp_parser_default_argument): Add temp override for
            parser->omp_attrs_forbidden_p.
            (cp_parser_late_parsing_omp_declare_simd): Diagnose declare simd
            or declare variant in attribute syntax on a declaration immediately
            following an OpenMP construct in pragma syntax.
    
            * g++.dg/gomp/attrs-11.C: Add new tests.
    
    (cherry picked from commit ef07b918a7ad4f64e0e1e3db21d861f2e79de92a)

Diff:
---
 gcc/cp/ChangeLog.omp                 | 17 +++++++++++++++++
 gcc/cp/parser.c                      | 15 +++++++++++++++
 gcc/testsuite/ChangeLog.omp          |  7 +++++++
 gcc/testsuite/g++.dg/gomp/attrs-11.C | 12 ++++++++++++
 4 files changed, 51 insertions(+)

diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index 93811091094..1daae13533a 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,3 +1,20 @@
+2021-08-12  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backported from master:
+	2021-08-12  Jakub Jelinek  <jakub@redhat.com>
+
+	* parser.c (cp_parser_lambda_body): Add temp overrides
+	for parser->{omp_declare_simd,oacc_routine,omp_attrs_forbidden_p}.
+	(cp_parser_statement): Restore parser->omp_attrs_forbidden_p for
+	cp_parser_declaration_statement.
+	(cp_parser_default_argument): Add temp override for
+	parser->omp_attrs_forbidden_p.
+	(cp_parser_late_parsing_omp_declare_simd): Diagnose declare simd
+	or declare variant in attribute syntax on a declaration immediately
+	following an OpenMP construct in pragma syntax.
+
+	* g++.dg/gomp/attrs-11.C: Add new tests.
+
 2021-08-12  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backported from master:
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index b5192a40875..88415805aa3 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -11594,6 +11594,9 @@ cp_parser_lambda_body (cp_parser* parser, tree lambda_expr)
        middle of an expression.  */
     ++function_depth;
 
+  auto odsd = make_temp_override (parser->omp_declare_simd, NULL);
+  auto ord = make_temp_override (parser->oacc_routine, NULL);
+  auto oafp = make_temp_override (parser->omp_attrs_forbidden_p, false);
   vec<tree> omp_privatization_save;
   save_omp_privatization_clauses (omp_privatization_save);
   /* Clear this in case we're in the middle of a default argument.  */
@@ -12237,9 +12240,11 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
 	       so let's un-parse them.  */
 	    saved_tokens.rollback();
 
+	  parser->omp_attrs_forbidden_p = omp_attrs_forbidden_p;
 	  cp_parser_parse_tentatively (parser);
 	  /* Try to parse the declaration-statement.  */
 	  cp_parser_declaration_statement (parser);
+	  parser->omp_attrs_forbidden_p = false;
 	  /* If that worked, we're done.  */
 	  if (cp_parser_parse_definitely (parser))
 	    return;
@@ -24568,6 +24573,8 @@ cp_parser_default_argument (cp_parser *parser, bool template_parm_p)
   parser->greater_than_is_operator_p = !template_parm_p;
   auto odsd = make_temp_override (parser->omp_declare_simd, NULL);
   auto ord = make_temp_override (parser->oacc_routine, NULL);
+  auto oafp = make_temp_override (parser->omp_attrs_forbidden_p, false);
+
   /* Local variable names (and the `this' keyword) may not
      appear in a default argument.  */
   saved_local_variables_forbidden_p = parser->local_variables_forbidden_p;
@@ -44294,6 +44301,14 @@ cp_parser_late_parsing_omp_declare_simd (cp_parser *parser, tree attrs)
 		    continue;
 		  }
 
+		if (parser->omp_attrs_forbidden_p)
+		  {
+		    error_at (first->location,
+			      "mixing OpenMP directives with attribute and "
+			      "pragma syntax on the same statement");
+		    parser->omp_attrs_forbidden_p = false;
+		  }
+
 		if (!flag_openmp && strcmp (directive[1], "simd") != 0)
 		  continue;
 		if (lexer == NULL)
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index a9aeb55a10a..a8f0c77b003 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,10 @@
+2021-08-12  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backported from master:
+	2021-08-12  Jakub Jelinek  <jakub@redhat.com>
+
+	* g++.dg/gomp/attrs-11.C: Add new tests.
+
 2021-08-12  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backported from master:
diff --git a/gcc/testsuite/g++.dg/gomp/attrs-11.C b/gcc/testsuite/g++.dg/gomp/attrs-11.C
index 009bcb2d87f..44e025e7540 100644
--- a/gcc/testsuite/g++.dg/gomp/attrs-11.C
+++ b/gcc/testsuite/g++.dg/gomp/attrs-11.C
@@ -72,3 +72,15 @@ int f28 [[omp::directive (declare simd), omp::directive (foobar)]] (int);	// { d
 int f29 [[omp::directive (foobar), omp::directive (declare simd)]] (int);	// { dg-error "unknown OpenMP directive name" }
 int f30 [[omp::directive (threadprivate (t7)), omp::directive (declare simd)]] (int);	// { dg-error "OpenMP directive other than 'declare simd' or 'declare variant' appertains to a declaration" }
 int f31 [[omp::directive (declare simd), omp::directive (threadprivate (t8))]] (int);	// { dg-error "OpenMP directive other than 'declare simd' or 'declare variant' appertains to a declaration" }
+
+void
+baz ()
+{
+  #pragma omp parallel
+  [[omp::directive (declare simd)]] extern int f32 (int);	// { dg-error "mixing OpenMP directives with attribute and pragma syntax on the same statement" }
+  #pragma omp parallel
+  extern int f33 [[omp::directive (declare simd)]] (int);	// { dg-error "mixing OpenMP directives with attribute and pragma syntax on the same statement" }
+  [[omp::directive (parallel)]]
+  #pragma omp declare simd	// { dg-error "mixing OpenMP directives with attribute and pragma syntax on the same statement" }
+  extern int f34 (int);
+}


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

only message in thread, other threads:[~2021-08-12 10:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12 10:00 [gcc/devel/omp/gcc-11] openmp: Diagnose another case of mixing parameter and attribute syntax Tobias Burnus

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