[committed] openmp: Actually ignore pragma_stmt pragmas for which c_parser_pragma returns false

Jakub Jelinek jakub@redhat.com
Wed Aug 18 08:29:51 GMT 2021


Hi!

Unlike the C++ FE, the C FE ignored pragmas (as if they weren't there) in
pragma_stmt contexts if c*_parser_pragma returns false only when after labels,
not inside of substatements of selection or loop statements.
After making just that change, several gomp/goacc testcases started failing,
because extra diagnostics has been emitted (in C, in C++ it was emitted
already before).  Say
void
foo (int x)
{
  if (x)
    #pragma omp barrier
}
used to in C emit just an error that the pragma is not allowed in such
contexts, but in C++ emitted both that and a parsing error that
  if (x)
}
is invalid.  So, the rest of this patch is mostly about returning true
after we report that that certain pragma is not allowed in pragma_stmt
contexts, because for error-recovery it seems better to treat the
pragma in that case as something that is the substatement of such if etc.
c*_parser_pragma return value is only ever used for pragma_stmt context,
in which false means act as if the pragma isn't there (e.g. has been handled
already by preprocessor etc.), and true which means it was there.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2021-08-18  Jakub Jelinek  <jakub@redhat.com>

gcc/c/
	* c-parser.c (c_parser_statement_after_labels): Add restart label
	near the start of the function.  If c_parser_pragma returns false,
	goto restart.
	(c_parser_pragma): For PRAGMA_OMP_CANCELLATION_POINT return what
	c_parser_omp_cancellation_point returned.  For PRAGMA_OMP_DECLARE
	return what c_parser_omp_declare returned.  Return true instead of
	false after emitting errors that the directive is not allowed in
	pragma_stmt context.
	(c_parser_omp_ordered): Return true instead of
	false after emitting errors that the directive is not allowed in
	pragma_stmt context.
	(c_parser_omp_target_update): Likewise.
	(c_parser_omp_target_enter_data, c_parser_omp_target_exit_data):
	Change return type from tree to bool, return false if the
	directive should be ignored in pragma_stmt contexts.
	(c_parser_omp_target): Adjust callers of c_parser_omp_target_*_data,
	return their result directly.
	(c_parser_omp_cancellation_point): Change return type from void to
	bool, return false if the directive should be ignored in pragma_stmt
	contexts.
	(c_parser_omp_declare): Likewise.
gcc/cp/
	* parser.c (cp_parser_omp_ordered): Return true instead of
	false after emitting errors that the directive is not allowed in
	pragma_stmt context.
	(cp_parser_omp_target_update): Likewise.
	(cp_parser_omp_cancellation_point): Change return type from void to
	bool, return false if the directive should be ignored in pragma_stmt
	contexts.
	(cp_parser_omp_target_enter_data, cp_parser_omp_target_exit_data):
	Change return type from tree to bool, return false if the
	directive should be ignored in pragma_stmt contexts.
	(cp_parser_omp_target): Adjust callers of cp_parser_omp_target_*_data,
	return their result directly.
	(cp_parser_pragma): For PRAGMA_OMP_CANCELLATION_POINT return what
	cp_parser_omp_cancellation_point returned.  Return true instead of
	false after emitting errors that the directive is not allowed in
	pragma_stmt context.
gcc/testsuite/
	* c-c++-common/gomp/pr63326.c: Don't expect extra "before" errors
	in C++.
	* g++.dg/gomp/attrs-7.C: Don't expect one extra error.
	* g++.dg/gomp/barrier-2.C: Likewise.
	* gcc.dg/gomp/declare-simd-5.c: Likewise.
	* gcc.dg/gomp/barrier-2.c: Likewise.
	* gcc.dg/gomp/declare-variant-2.c: Likewise.

--- gcc/c/c-parser.c.jj	2021-08-16 23:11:24.947184006 +0200
+++ gcc/c/c-parser.c	2021-08-17 17:56:34.005226310 +0200
@@ -1582,10 +1582,10 @@ static void c_parser_omp_cancel (c_parse
 enum pragma_context { pragma_external, pragma_struct, pragma_param,
 		      pragma_stmt, pragma_compound };
 static bool c_parser_pragma (c_parser *, enum pragma_context, bool *);
-static void c_parser_omp_cancellation_point (c_parser *, enum pragma_context);
+static bool c_parser_omp_cancellation_point (c_parser *, enum pragma_context);
 static bool c_parser_omp_target (c_parser *, enum pragma_context, bool *);
 static void c_parser_omp_end_declare_target (c_parser *);
-static void c_parser_omp_declare (c_parser *, enum pragma_context);
+static bool c_parser_omp_declare (c_parser *, enum pragma_context);
 static void c_parser_omp_requires (c_parser *);
 static bool c_parser_omp_ordered (c_parser *, enum pragma_context, bool *);
 static void c_parser_oacc_routine (c_parser *, enum pragma_context);
@@ -6100,6 +6100,7 @@ c_parser_statement_after_labels (c_parse
   if (c_parser_peek_token (parser)->type != CPP_OPEN_BRACE)
     add_debug_begin_stmt (loc);
 
+ restart:
   switch (c_parser_peek_token (parser)->type)
     {
     case CPP_OPEN_BRACE:
@@ -6246,7 +6247,8 @@ c_parser_statement_after_labels (c_parse
       c_parser_consume_token (parser);
       break;
     case CPP_PRAGMA:
-      c_parser_pragma (parser, pragma_stmt, if_p);
+      if (!c_parser_pragma (parser, pragma_stmt, if_p))
+        goto restart;
       break;
     default:
     expr_stmt:
@@ -12346,7 +12348,7 @@ c_parser_pragma (c_parser *parser, enum
 			"%<#pragma %s%> may only be used in compound "
 			"statements", construct);
 	      c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
-	      return false;
+	      return true;
 	    }
 	  goto bad_stmt;
 	}
@@ -12437,8 +12439,7 @@ c_parser_pragma (c_parser *parser, enum
       return false;
 
     case PRAGMA_OMP_CANCELLATION_POINT:
-      c_parser_omp_cancellation_point (parser, context);
-      return false;
+      return c_parser_omp_cancellation_point (parser, context);
 
     case PRAGMA_OMP_THREADPRIVATE:
       c_parser_omp_threadprivate (parser);
@@ -12466,8 +12467,7 @@ c_parser_pragma (c_parser *parser, enum
       return false;
 
     case PRAGMA_OMP_DECLARE:
-      c_parser_omp_declare (parser, context);
-      return false;
+      return c_parser_omp_declare (parser, context);
 
     case PRAGMA_OMP_REQUIRES:
       if (context != pragma_external)
@@ -12505,7 +12505,7 @@ c_parser_pragma (c_parser *parser, enum
 	else
 	  c_parser_do_statement (parser, ivdep, unroll);
       }
-      return false;
+      return true;
 
     case PRAGMA_UNROLL:
       {
@@ -12529,7 +12529,7 @@ c_parser_pragma (c_parser *parser, enum
 	else
 	  c_parser_do_statement (parser, ivdep, unroll);
       }
-      return false;
+      return true;
 
     case PRAGMA_GCC_PCH_PREPROCESS:
       c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
@@ -19125,7 +19125,7 @@ c_parser_omp_ordered (c_parser *parser,
 			"%<#pragma omp ordered%> with %<depend%> clause may "
 			"only be used in compound statements");
 	      c_parser_skip_to_pragma_eol (parser, false);
-	      return false;
+	      return true;
 	    }
 
 	  tree clauses
@@ -19655,7 +19655,7 @@ c_parser_omp_cancel (c_parser *parser)
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
 
-static void
+static bool
 c_parser_omp_cancellation_point (c_parser *parser, enum pragma_context context)
 {
   location_t loc = c_parser_peek_token (parser)->location;
@@ -19676,7 +19676,7 @@ c_parser_omp_cancellation_point (c_parse
     {
       c_parser_error (parser, "expected %<point%>");
       c_parser_skip_to_pragma_eol (parser);
-      return;
+      return false;
     }
 
   if (context != pragma_compound)
@@ -19688,7 +19688,7 @@ c_parser_omp_cancellation_point (c_parse
       else
 	c_parser_error (parser, "expected declaration specifiers");
       c_parser_skip_to_pragma_eol (parser, false);
-      return;
+      return true;
     }
 
   clauses
@@ -19696,6 +19696,7 @@ c_parser_omp_cancellation_point (c_parse
 				"#pragma omp cancellation point");
 
   c_finish_omp_cancellation_point (loc, clauses);
+  return true;
 }
 
 /* OpenMP 4.0:
@@ -19981,7 +19982,7 @@ c_parser_omp_target_update (location_t l
       error_at (loc, "%<#pragma %s%> may only be used in compound statements",
 		"omp target update");
       c_parser_skip_to_pragma_eol (parser, false);
-      return false;
+      return true;
     }
 
   tree clauses
@@ -20014,7 +20015,7 @@ c_parser_omp_target_update (location_t l
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
 
-static tree
+static bool
 c_parser_omp_target_enter_data (location_t loc, c_parser *parser,
 				enum pragma_context context)
 {
@@ -20032,7 +20033,7 @@ c_parser_omp_target_enter_data (location
     {
       c_parser_error (parser, "expected %<data%>");
       c_parser_skip_to_pragma_eol (parser);
-      return NULL_TREE;
+      return false;
     }
 
   if (context == pragma_stmt)
@@ -20040,7 +20041,7 @@ c_parser_omp_target_enter_data (location
       error_at (loc, "%<#pragma %s%> may only be used in compound statements",
 		"omp target enter data");
       c_parser_skip_to_pragma_eol (parser, false);
-      return NULL_TREE;
+      return true;
     }
 
   tree clauses
@@ -20079,7 +20080,7 @@ c_parser_omp_target_enter_data (location
 	error_at (loc,
 		  "%<#pragma omp target enter data%> must contain at least "
 		  "one %<map%> clause");
-      return NULL_TREE;
+      return true;
     }
 
   tree stmt = make_node (OMP_TARGET_ENTER_DATA);
@@ -20087,7 +20088,7 @@ c_parser_omp_target_enter_data (location
   OMP_TARGET_ENTER_DATA_CLAUSES (stmt) = clauses;
   SET_EXPR_LOCATION (stmt, loc);
   add_stmt (stmt);
-  return stmt;
+  return true;
 }
 
 /* OpenMP 4.5:
@@ -20100,7 +20101,7 @@ c_parser_omp_target_enter_data (location
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
 
-static tree
+static bool
 c_parser_omp_target_exit_data (location_t loc, c_parser *parser,
 			       enum pragma_context context)
 {
@@ -20118,7 +20119,7 @@ c_parser_omp_target_exit_data (location_
     {
       c_parser_error (parser, "expected %<data%>");
       c_parser_skip_to_pragma_eol (parser);
-      return NULL_TREE;
+      return false;
     }
 
   if (context == pragma_stmt)
@@ -20126,7 +20127,7 @@ c_parser_omp_target_exit_data (location_
       error_at (loc, "%<#pragma %s%> may only be used in compound statements",
 		"omp target exit data");
       c_parser_skip_to_pragma_eol (parser, false);
-      return NULL_TREE;
+      return true;
     }
 
   tree clauses
@@ -20167,7 +20168,7 @@ c_parser_omp_target_exit_data (location_
 	error_at (loc,
 		  "%<#pragma omp target exit data%> must contain at least one "
 		  "%<map%> clause");
-      return NULL_TREE;
+      return true;
     }
 
   tree stmt = make_node (OMP_TARGET_EXIT_DATA);
@@ -20175,7 +20176,7 @@ c_parser_omp_target_exit_data (location_
   OMP_TARGET_EXIT_DATA_CLAUSES (stmt) = clauses;
   SET_EXPR_LOCATION (stmt, loc);
   add_stmt (stmt);
-  return stmt;
+  return true;
 }
 
 /* OpenMP 4.0:
@@ -20333,14 +20334,12 @@ c_parser_omp_target (c_parser *parser, e
       else if (strcmp (p, "enter") == 0)
 	{
 	  c_parser_consume_token (parser);
-	  c_parser_omp_target_enter_data (loc, parser, context);
-	  return false;
+	  return c_parser_omp_target_enter_data (loc, parser, context);
 	}
       else if (strcmp (p, "exit") == 0)
 	{
 	  c_parser_consume_token (parser);
-	  c_parser_omp_target_exit_data (loc, parser, context);
-	  return false;
+	  return c_parser_omp_target_exit_data (loc, parser, context);
 	}
       else if (strcmp (p, "update") == 0)
 	{
@@ -21599,7 +21598,7 @@ c_parser_omp_declare_reduction (c_parser
    OpenMP 5.0
    #pragma omp declare variant (identifier) match (context-selector)  */
 
-static void
+static bool
 c_parser_omp_declare (c_parser *parser, enum pragma_context context)
 {
   c_parser_consume_pragma (parser);
@@ -21611,37 +21610,38 @@ c_parser_omp_declare (c_parser *parser,
 	  /* c_parser_consume_token (parser); done in
 	     c_parser_omp_declare_simd.  */
 	  c_parser_omp_declare_simd (parser, context);
-	  return;
+	  return true;
 	}
       if (strcmp (p, "reduction") == 0)
 	{
 	  c_parser_consume_token (parser);
 	  c_parser_omp_declare_reduction (parser, context);
-	  return;
+	  return false;
 	}
       if (!flag_openmp)  /* flag_openmp_simd  */
 	{
 	  c_parser_skip_to_pragma_eol (parser, false);
-	  return;
+	  return false;
 	}
       if (strcmp (p, "target") == 0)
 	{
 	  c_parser_consume_token (parser);
 	  c_parser_omp_declare_target (parser);
-	  return;
+	  return false;
 	}
       if (strcmp (p, "variant") == 0)
 	{
 	  /* c_parser_consume_token (parser); done in
 	     c_parser_omp_declare_simd.  */
 	  c_parser_omp_declare_simd (parser, context);
-	  return;
+	  return true;
 	}
     }
 
   c_parser_error (parser, "expected %<simd%>, %<reduction%>, "
 			  "%<target%> or %<variant%>");
   c_parser_skip_to_pragma_eol (parser);
+  return false;
 }
 
 /* OpenMP 5.0
--- gcc/cp/parser.c.jj	2021-08-16 23:11:24.951183952 +0200
+++ gcc/cp/parser.c	2021-08-17 17:25:31.560858826 +0200
@@ -42132,7 +42132,7 @@ cp_parser_omp_ordered (cp_parser *parser
 			"%<depend%> clause may only be used in compound "
 			"statements");
 	      cp_parser_skip_to_pragma_eol (parser, pragma_tok);
-	      return false;
+	      return true;
 	    }
 	  tree clauses
 	    = cp_parser_omp_all_clauses (parser,
@@ -42656,7 +42656,7 @@ cp_parser_omp_cancel (cp_parser *parser,
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
 
-static void
+static bool
 cp_parser_omp_cancellation_point (cp_parser *parser, cp_token *pragma_tok,
 				  enum pragma_context context)
 {
@@ -42678,7 +42678,7 @@ cp_parser_omp_cancellation_point (cp_par
     {
       cp_parser_error (parser, "expected %<point%>");
       cp_parser_skip_to_pragma_eol (parser, pragma_tok);
-      return;
+      return false;
     }
 
   if (context != pragma_compound)
@@ -42690,7 +42690,7 @@ cp_parser_omp_cancellation_point (cp_par
       else
 	cp_parser_error (parser, "expected declaration specifiers");
       cp_parser_skip_to_pragma_eol (parser, pragma_tok);
-      return;
+      return true;
     }
 
   clauses = cp_parser_omp_all_clauses (parser,
@@ -42698,6 +42698,7 @@ cp_parser_omp_cancellation_point (cp_par
 				       "#pragma omp cancellation point",
 				       pragma_tok);
   finish_omp_cancellation_point (clauses);
+  return true;
 }
 
 /* OpenMP 4.0:
@@ -42993,7 +42994,7 @@ cp_parser_omp_target_data (cp_parser *pa
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
 
-static tree
+static bool
 cp_parser_omp_target_enter_data (cp_parser *parser, cp_token *pragma_tok,
 				 enum pragma_context context)
 {
@@ -43013,7 +43014,7 @@ cp_parser_omp_target_enter_data (cp_pars
     {
       cp_parser_error (parser, "expected %<data%>");
       cp_parser_skip_to_pragma_eol (parser, pragma_tok);
-      return NULL_TREE;
+      return false;
     }
 
   if (context == pragma_stmt)
@@ -43022,7 +43023,7 @@ cp_parser_omp_target_enter_data (cp_pars
 		"%<#pragma %s%> may only be used in compound statements",
 		"omp target enter data");
       cp_parser_skip_to_pragma_eol (parser, pragma_tok);
-      return NULL_TREE;
+      return true;
     }
 
   tree clauses
@@ -43062,14 +43063,15 @@ cp_parser_omp_target_enter_data (cp_pars
 	error_at (pragma_tok->location,
 		  "%<#pragma omp target enter data%> must contain at least "
 		  "one %<map%> clause");
-      return NULL_TREE;
+      return true;
     }
 
   tree stmt = make_node (OMP_TARGET_ENTER_DATA);
   TREE_TYPE (stmt) = void_type_node;
   OMP_TARGET_ENTER_DATA_CLAUSES (stmt) = clauses;
   SET_EXPR_LOCATION (stmt, pragma_tok->location);
-  return add_stmt (stmt);
+  add_stmt (stmt);
+  return true;
 }
 
 /* OpenMP 4.5:
@@ -43083,7 +43085,7 @@ cp_parser_omp_target_enter_data (cp_pars
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
 
-static tree
+static bool
 cp_parser_omp_target_exit_data (cp_parser *parser, cp_token *pragma_tok,
 				enum pragma_context context)
 {
@@ -43103,7 +43105,7 @@ cp_parser_omp_target_exit_data (cp_parse
     {
       cp_parser_error (parser, "expected %<data%>");
       cp_parser_skip_to_pragma_eol (parser, pragma_tok);
-      return NULL_TREE;
+      return false;
     }
 
   if (context == pragma_stmt)
@@ -43112,7 +43114,7 @@ cp_parser_omp_target_exit_data (cp_parse
 		"%<#pragma %s%> may only be used in compound statements",
 		"omp target exit data");
       cp_parser_skip_to_pragma_eol (parser, pragma_tok);
-      return NULL_TREE;
+      return true;
     }
 
   tree clauses
@@ -43154,14 +43156,15 @@ cp_parser_omp_target_exit_data (cp_parse
 	error_at (pragma_tok->location,
 		  "%<#pragma omp target exit data%> must contain at least "
 		  "one %<map%> clause");
-      return NULL_TREE;
+      return true;
     }
 
   tree stmt = make_node (OMP_TARGET_EXIT_DATA);
   TREE_TYPE (stmt) = void_type_node;
   OMP_TARGET_EXIT_DATA_CLAUSES (stmt) = clauses;
   SET_EXPR_LOCATION (stmt, pragma_tok->location);
-  return add_stmt (stmt);
+  add_stmt (stmt);
+  return true;
 }
 
 /* OpenMP 4.0:
@@ -43185,7 +43188,7 @@ cp_parser_omp_target_update (cp_parser *
 		"%<#pragma %s%> may only be used in compound statements",
 		"omp target update");
       cp_parser_skip_to_pragma_eol (parser, pragma_tok);
-      return false;
+      return true;
     }
 
   tree clauses
@@ -43197,7 +43200,7 @@ cp_parser_omp_target_update (cp_parser *
       error_at (pragma_tok->location,
 		"%<#pragma omp target update%> must contain at least one "
 		"%<from%> or %<to%> clauses");
-      return false;
+      return true;
     }
 
   tree stmt = make_node (OMP_TARGET_UPDATE);
@@ -43205,7 +43208,7 @@ cp_parser_omp_target_update (cp_parser *
   OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses;
   SET_EXPR_LOCATION (stmt, pragma_tok->location);
   add_stmt (stmt);
-  return false;
+  return true;
 }
 
 /* OpenMP 4.0:
@@ -43359,14 +43362,12 @@ cp_parser_omp_target (cp_parser *parser,
       else if (strcmp (p, "enter") == 0)
 	{
 	  cp_lexer_consume_token (parser->lexer);
-	  cp_parser_omp_target_enter_data (parser, pragma_tok, context);
-	  return false;
+	  return cp_parser_omp_target_enter_data (parser, pragma_tok, context);
 	}
       else if (strcmp (p, "exit") == 0)
 	{
 	  cp_lexer_consume_token (parser->lexer);
-	  cp_parser_omp_target_exit_data (parser, pragma_tok, context);
-	  return false;
+	  return cp_parser_omp_target_exit_data (parser, pragma_tok, context);
 	}
       else if (strcmp (p, "update") == 0)
 	{
@@ -46427,7 +46428,7 @@ cp_parser_pragma (cp_parser *parser, enu
   cp_token *pragma_tok;
   unsigned int id;
   tree stmt;
-  bool ret;
+  bool ret = false;
 
   pragma_tok = cp_lexer_consume_token (parser->lexer);
   gcc_assert (pragma_tok->type == CPP_PRAGMA);
@@ -46452,6 +46453,7 @@ cp_parser_pragma (cp_parser *parser, enu
 	case pragma_stmt:
 	  error_at (pragma_tok->location, "%<#pragma %s%> may only be "
 		    "used in compound statements", "omp barrier");
+	  ret = true;
 	  break;
 	default:
 	  goto bad_stmt;
@@ -46467,6 +46469,7 @@ cp_parser_pragma (cp_parser *parser, enu
 	case pragma_stmt:
 	  error_at (pragma_tok->location, "%<#pragma %s%> may only be "
 		    "used in compound statements", "omp depobj");
+	  ret = true;
 	  break;
 	default:
 	  goto bad_stmt;
@@ -46482,6 +46485,7 @@ cp_parser_pragma (cp_parser *parser, enu
 	case pragma_stmt:
 	  error_at (pragma_tok->location, "%<#pragma %s%> may only be "
 		    "used in compound statements", "omp flush");
+	  ret = true;
 	  break;
 	default:
 	  goto bad_stmt;
@@ -46498,6 +46502,7 @@ cp_parser_pragma (cp_parser *parser, enu
 	  error_at (pragma_tok->location,
 		    "%<#pragma %s%> may only be used in compound statements",
 		    "omp taskwait");
+	  ret = true;
 	  break;
 	default:
 	  goto bad_stmt;
@@ -46514,6 +46519,7 @@ cp_parser_pragma (cp_parser *parser, enu
 	  error_at (pragma_tok->location,
 		    "%<#pragma %s%> may only be used in compound statements",
 		    "omp taskyield");
+	  ret = true;
 	  break;
 	default:
 	  goto bad_stmt;
@@ -46530,6 +46536,7 @@ cp_parser_pragma (cp_parser *parser, enu
 	  error_at (pragma_tok->location,
 		    "%<#pragma %s%> may only be used in compound statements",
 		    "omp cancel");
+	  ret = true;
 	  break;
 	default:
 	  goto bad_stmt;
@@ -46537,8 +46544,7 @@ cp_parser_pragma (cp_parser *parser, enu
       break;
 
     case PRAGMA_OMP_CANCELLATION_POINT:
-      cp_parser_omp_cancellation_point (parser, pragma_tok, context);
-      return false;
+      return cp_parser_omp_cancellation_point (parser, pragma_tok, context);
 
     case PRAGMA_OMP_THREADPRIVATE:
       cp_parser_omp_threadprivate (parser, pragma_tok);
@@ -46557,6 +46563,7 @@ cp_parser_pragma (cp_parser *parser, enu
 	  error_at (pragma_tok->location,
 		    "%<#pragma %s%> may only be used in compound statements",
 		    "acc enter data");
+	  ret = true;
 	  break;
 	}
       else if (context != pragma_compound)
@@ -46570,6 +46577,7 @@ cp_parser_pragma (cp_parser *parser, enu
 	  error_at (pragma_tok->location,
 		    "%<#pragma %s%> may only be used in compound statements",
 		    "acc exit data");
+	  ret = true;
 	  break;
 	}
       else if (context != pragma_compound)
@@ -46582,6 +46590,7 @@ cp_parser_pragma (cp_parser *parser, enu
 	{
 	  error_at (pragma_tok->location,
 		    "%<#pragma acc routine%> must be at file scope");
+	  ret = true;
 	  break;
 	}
       cp_parser_oacc_routine (parser, pragma_tok, context);
@@ -46593,6 +46602,7 @@ cp_parser_pragma (cp_parser *parser, enu
 	  error_at (pragma_tok->location,
 		    "%<#pragma %s%> may only be used in compound statements",
 		    "acc update");
+	  ret = true;
 	  break;
 	}
       else if (context != pragma_compound)
@@ -46606,6 +46616,7 @@ cp_parser_pragma (cp_parser *parser, enu
 	  error_at (pragma_tok->location,
 		    "%<#pragma %s%> may only be used in compound statements",
 		    "acc wait");
+	  ret = true;
 	  break;
 	}
       else if (context != pragma_compound)
@@ -46652,6 +46663,7 @@ cp_parser_pragma (cp_parser *parser, enu
 	  error_at (pragma_tok->location,
 		    "%<#pragma omp requires%> may only be used at file or "
 		    "namespace scope");
+	  ret = true;
 	  break;
 	}
       return cp_parser_omp_requires (parser, pragma_tok);
@@ -46764,7 +46776,7 @@ cp_parser_pragma (cp_parser *parser, enu
     }
 
   cp_parser_skip_to_pragma_eol (parser, pragma_tok);
-  return false;
+  return ret;
 }
 
 /* The interface the pragma parsers have to the lexer.  */
--- gcc/testsuite/c-c++-common/gomp/pr63326.c.jj	2020-01-14 20:02:46.662611646 +0100
+++ gcc/testsuite/c-c++-common/gomp/pr63326.c	2021-08-17 17:43:05.624354118 +0200
@@ -156,64 +156,64 @@ f4 (int x)
   {
     do
       #pragma omp barrier			/* { dg-error "may only be used in compound statements" } */
-    while (0); /* { dg-error "before" "" { target c++ } } */
-  } /* { dg-error "before" "" { target c++ } } */
+    while (0);
+  }
   {
     do
       #pragma omp flush				/* { dg-error "may only be used in compound statements" } */
-    while (0); /* { dg-error "before" "" { target c++ } } */
-  } /* { dg-error "before" "" { target c++ } } */
+    while (0);
+  }
   {
     do
       #pragma omp taskwait			/* { dg-error "may only be used in compound statements" } */
-    while (0); /* { dg-error "before" "" { target c++ } } */
-  } /* { dg-error "before" "" { target c++ } } */
+    while (0);
+  }
   {
     do
       #pragma omp taskyield			/* { dg-error "may only be used in compound statements" } */
-    while (0); /* { dg-error "before" "" { target c++ } } */
-  } /* { dg-error "before" "" { target c++ } } */
+    while (0);
+  }
   #pragma omp parallel
   {
     do
       #pragma omp cancel parallel		/* { dg-error "may only be used in compound statements" } */
-    while (0); /* { dg-error "before" "" { target c++ } } */
-  } /* { dg-error "before" "" { target c++ } } */
+    while (0);
+  }
   #pragma omp parallel
   {
     do
       #pragma omp cancellation point parallel	/* { dg-error "may only be used in compound statements" } */
-    while (0); /* { dg-error "before" "" { target c++ } } */
-  } /* { dg-error "before" "" { target c++ } } */
+    while (0);
+  }
   #pragma omp for ordered(1)
   for (i = 0; i < 16; i++)
     {
       {
 	do
 	  #pragma omp ordered depend(source)	/* { dg-error "may only be used in compound statements" } */
-	while (0); /* { dg-error "before" "" { target c++ } } */
-      } /* { dg-error "before" "" { target c++ } } */
+	while (0);
+      }
       {
 	do
 	  #pragma omp ordered depend(sink: i-1)	/* { dg-error "may only be used in compound statements" } */
-	while (0); /* { dg-error "before" "" { target c++ } } */
-      } /* { dg-error "before" "" { target c++ } } */
+	while (0);
+      }
     }
   {
     do
       #pragma omp target enter data map(to:i)	/* { dg-error "may only be used in compound statements" } */
-    while (0); /* { dg-error "before" "" { target c++ } } */
-  } /* { dg-error "before" "" { target c++ } } */
+    while (0);
+  }
   {
     do
       #pragma omp target update to(i)		/* { dg-error "may only be used in compound statements" } */
-    while (0); /* { dg-error "before" "" { target c++ } } */
-  } /* { dg-error "before" "" { target c++ } } */
+    while (0);
+  }
   {
     do
       #pragma omp target exit data map(from:i)	/* { dg-error "may only be used in compound statements" } */
-    while (0); /* { dg-error "before" "" { target c++ } } */
-  } /* { dg-error "before" "" { target c++ } } */
+    while (0);
+  }
 }
 
 void
--- gcc/testsuite/g++.dg/gomp/attrs-7.C.jj	2021-07-26 09:13:37.132731100 +0200
+++ gcc/testsuite/g++.dg/gomp/attrs-7.C	2021-08-17 17:44:11.426447671 +0200
@@ -11,8 +11,7 @@ foo ()
 									// { dg-error "#pragma omp section" "" { target *-*-* } .-1 }
 									// { dg-error "#pragma omp flush" "" { target *-*-* } .-2 }
     [[omp::sequence (directive (flush), omp::directive (section))]];	// { dg-error "must be the only specified attribute on a statement" }
-									// { dg-error "#pragma omp section" "" { target *-*-* } .-1 }
-									// { dg-error "#pragma omp flush" "" { target *-*-* } .-2 }
+									// { dg-error "#pragma omp flush" "" { target *-*-* } .-1 }
     [[gnu::cold, omp::directive (section)]];				// { dg-error "must be the only specified attribute on a statement" }
 									// { dg-error "#pragma omp section" "" { target *-*-* } .-1 }
     [[omp::directive (section)]] [[gnu::cold]];				// { dg-error "must be the only specified attribute on a statement" }
--- gcc/testsuite/g++.dg/gomp/barrier-2.C.jj	2020-01-14 20:02:46.847608875 +0100
+++ gcc/testsuite/g++.dg/gomp/barrier-2.C	2021-08-17 17:52:24.029661902 +0200
@@ -9,4 +9,4 @@ void f3(bool p)
 {
   if (p)
     #pragma omp barrier		// { dg-error "compound statements" }
-}				// { dg-error "" }
+}
--- gcc/testsuite/gcc.dg/gomp/declare-simd-5.c.jj	2020-11-08 23:07:45.317963554 +0100
+++ gcc/testsuite/gcc.dg/gomp/declare-simd-5.c	2021-08-17 18:08:43.214209864 +0200
@@ -15,7 +15,7 @@ f1 (int x)
 lab:
     #pragma omp declare simd simdlen (8) aligned (b : 8 * sizeof (int))
     extern int f5 (int a, int *b, int c);	/* { dg-error "must be followed by function declaration or definition" } */
-    x++;					/* { dg-error "a label can only be part of a statement and a declaration is not a statement" "" { target *-*-* } .-1 } */
+    x++;
   }
   return x;
 }
--- gcc/testsuite/gcc.dg/gomp/barrier-2.c.jj	2020-11-08 23:07:45.317963554 +0100
+++ gcc/testsuite/gcc.dg/gomp/barrier-2.c	2021-08-17 17:51:35.419331529 +0200
@@ -16,8 +16,7 @@ void f1(void)
 
 void f2(void)
 {
-  label:       /* { dg-error "label at end of compound statement" } */
-    /* { dg-warning "defined but not used" "" { target *-*-* } .-1 } */
+  label:			/* { dg-warning "defined but not used" } */
     #pragma omp barrier		/* { dg-error "may only be used in compound statements" } */
 }
 
--- gcc/testsuite/gcc.dg/gomp/declare-variant-2.c.jj	2020-11-08 23:07:45.317963554 +0100
+++ gcc/testsuite/gcc.dg/gomp/declare-variant-2.c	2021-08-17 18:08:58.806995680 +0200
@@ -17,7 +17,7 @@ f1 (int x)
 lab:
     #pragma omp declare variant (fn0) match (user={condition(0)})
     extern int f5 (int a, int *b, int c);	/* { dg-error "must be followed by function declaration or definition" } */
-    x++;					/* { dg-error "a label can only be part of a statement and a declaration is not a statement" "" { target *-*-* } .-1 } */
+    x++;
   }
   return x;
 }

	Jakub



More information about the Gcc-patches mailing list