diff mbox series

[committed,1b/4] (Partial) OpenMP 5.0 support for GCC 9 (gcc FEs)

Message ID 20181108172528.GQ11625@tucnak
State New
Headers show
Series [committed,1b/4] (Partial) OpenMP 5.0 support for GCC 9 (gcc FEs) | expand

Commit Message

Jakub Jelinek Nov. 8, 2018, 5:25 p.m. UTC
Hi!

This is the gcc/{c-family,c,cp,fortran}/ part of the gomp-5_0-branch
merge to trunk I've just committed.

2018-11-08  Jakub Jelinek  <jakub@redhat.com>

gcc/c-family/
	* c-common.h (c_finish_omp_taskgroup): Add CLAUSES argument.
	(c_finish_omp_atomic): Replace bool SEQ_CST argument with
	enum omp_memory_order MEMORY_ORDER.
	(c_finish_omp_flush): Add MO argument.
	(c_omp_depend_t_p, c_finish_omp_depobj): Declare.
	(c_finish_omp_for): Add FINAL_P argument.
	* c-omp.c: Include memmodel.h.
	(c_finish_omp_taskgroup): Add CLAUSES argument.  Set
	OMP_TASKGROUP_CLAUSES to it.
	(c_finish_omp_atomic): Replace bool SEQ_CST argument with
	enum omp_memory_order MEMORY_ORDER.  Set OMP_ATOMIC_MEMORY_ORDER
	instead of OMP_ATOMIC_SEQ_CST.
	(c_omp_depend_t_p, c_finish_omp_depobj): New functions.
	(c_finish_omp_flush): Add MO argument, if not MEMMODEL_LAST, emit
	__atomic_thread_fence call with the given value.
	(check_omp_for_incr_expr): Formatting fixes.
	(c_finish_omp_for): Add FINAL_P argument.  Allow NE_EXPR
	even in OpenMP loops, diagnose if NE_EXPR and incr expression
	is not constant expression 1 or -1.  Transform NE_EXPR loops
	with iterators pointers to VLA into LT_EXPR or GT_EXPR loops.
	(c_omp_check_loop_iv_r): Look for orig decl of C++ range for
	loops too.
	(c_omp_split_clauses): Add support for combined
	#pragma omp parallel master and
	#pragma omp {,parallel }master taskloop{, simd} constructs.
	Handle OMP_CLAUSE_IN_REDUCTION.  Handle OMP_CLAUSE_REDUCTION_TASK.
	Handle OMP_CLAUSE_NONTEMPORAL.  Handle splitting OMP_CLAUSE_IF
	also to OMP_SIMD.  Copy OMP_CLAUSE_LASTPRIVATE_CONDITIONAL.
	(c_omp_predetermined_sharing): Don't return
	OMP_CLAUSE_DEFAULT_SHARED for const qualified decls.
	* c-pragma.c (omp_pragmas): Add PRAGMA_OMP_DEPOBJ and
	PRAGMA_OMP_REQUIRES.
	* c-pragma.h (enum pragma_kind): Likewise.
	(enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_NONTEMPORAL
	and PRAGMA_OMP_CLAUSE_{IN,TASK}_REDUCTION.
gcc/c/
	* c-parser.c: Include memmode.h.
	(c_parser_omp_depobj, c_parser_omp_requires): New functions.
	(c_parser_pragma): Handle PRAGMA_OMP_DEPOBJ and PRAGMA_OMP_REQUIRES.
	(c_parser_omp_clause_name): Handle nontemporal, in_reduction and
	task_reduction clauses.
	(c_parser_omp_variable_list): Handle OMP_CLAUSE_{IN,TASK}_REDUCTION.
	For OMP_CLAUSE_DEPEND, parse clause operands as either an array
	section, or lvalue assignment expression.
	(c_parser_omp_clause_if): Handle cancel and simd modifiers.
	(c_parser_omp_clause_lastprivate): Parse optional
	conditional: modifier.
	(c_parser_omp_clause_hint): Require constant integer expression rather
	than just integer expression.
	(c_parser_omp_clause_defaultmap): Parse new kinds of defaultmap
	clause.
	(c_parser_omp_clause_reduction): Add IS_OMP and KIND arguments.
	Parse reduction modifiers.  Pass KIND to c_parser_omp_variable_list.
	(c_parser_omp_clause_nontemporal, c_parser_omp_iterators): New
	functions.
	(c_parser_omp_clause_depend): Parse iterator modifier and handle
	iterators.  Parse mutexinoutset and depobj kinds.
	(c_parser_oacc_all_clauses): Adjust c_parser_omp_clause_reduction
	callers.
	(c_parser_omp_all_clauses): Likewise.  Handle
	PRAGMA_OMP_CLAUSE_NONTEMPORAL and
	PRAGMA_OMP_CLAUSE_{IN,TASK}_REDUCTION.
	(c_parser_omp_atomic): Parse hint and memory order clauses.  Handle
	default memory order from requires directive if any.  Adjust
	c_finish_omp_atomic caller.
	(c_parser_omp_critical): Allow comma in between (name) and hint clause.
	(c_parser_omp_flush): Parse flush with memory-order-clause.
	(c_parser_omp_for_loop): Allow NE_EXPR even in
	OpenMP loops, adjust c_finish_omp_for caller.
	(OMP_SIMD_CLAUSE_MASK): Add if and nontemporal clauses.
	(c_parser_omp_master): Add p_name, mask and cclauses arguments.
	Allow to be called while parsing combined parallel master.
	Parse combined master taskloop{, simd}.
	(c_parser_omp_parallel): Parse combined
	parallel master{, taskloop{, simd}} constructs.
	(OMP_TASK_CLAUSE_MASK): Add in_reduction clause.
	(OMP_TASKGROUP_CLAUSE_MASK): Define.
	(c_parser_omp_taskgroup): Add LOC argument.  Parse taskgroup clauses.
	(OMP_TASKWAIT_CLAUSE_MASK): Define.
	(c_parser_omp_taskwait): Handle taskwait with depend clauses.
	(c_parser_omp_teams): Force a BIND_EXPR with BLOCK
	around teams body.  Use SET_EXPR_LOCATION.
	(c_parser_omp_target_data): Allow target data
	with only use_device_ptr clauses.
	(c_parser_omp_target): Use SET_EXPR_LOCATION.  Set
	OMP_REQUIRES_TARGET_USED bit in omp_requires_mask.
	(c_parser_omp_requires): New function.
	(c_finish_taskloop_clauses): New function.
	(OMP_TASKLOOP_CLAUSE_MASK): Add reduction and in_reduction clauses.
	(c_parser_omp_taskloop): Use c_finish_taskloop_clauses.  Add forward
	declaration.  Disallow in_reduction clause when combined with parallel
	master.
	(c_parser_omp_construct): Adjust c_parser_omp_master and
	c_parser_omp_taskgroup callers.
	* c-typeck.c (c_finish_omp_cancel): Diagnose if clause with modifier
	other than cancel.
	(handle_omp_array_sections_1): Handle OMP_CLAUSE_{IN,TASK}_REDUCTION
	like OMP_CLAUSE_REDUCTION.
	(handle_omp_array_sections): Likewise.  Call save_expr on array
	reductions before calling build_index_type.  Handle depend clauses
	with iterators.
	(struct c_find_omp_var_s): New type.
	(c_find_omp_var_r, c_omp_finish_iterators): New functions.
	(c_finish_omp_clauses): Don't diagnose nonmonotonic clause
	with static, runtime or auto schedule kinds.  Call save_expr for whole
	array reduction sizes.  Diagnose reductions with zero sized elements
	or variable length structures.  Diagnose nogroup clause used with
	reduction clause(s).  Handle depend clause with
	OMP_CLAUSE_DEPEND_DEPOBJ.  Diagnose bit-fields.  Require
	omp_depend_t type for OMP_CLAUSE_DEPEND_DEPOBJ kinds and
	some different type for other kinds.  Use build_unary_op with
	ADDR_EXPR and build_indirect_ref instead of c_mark_addressable.
	Handle depend clauses with iterators.  Remove no longer needed special
	case that predetermined const qualified vars may be specified in
	firstprivate clause.  Complain if const qualified vars are mentioned
	in data-sharing clauses other than firstprivate or shared.  Use
	error_at with OMP_CLAUSE_LOCATION (c) as first argument instead of
	error.  Formatting fix.  Handle OMP_CLAUSE_NONTEMPORAL and
	OMP_CLAUSE_{IN,TASK}_REDUCTION.  Allow any lvalue as
	OMP_CLAUSE_DEPEND operand (besides array section), adjust diagnostics.
gcc/cp/
	* constexpr.c (potential_constant_expression_1): Handle OMP_DEPOBJ.
	* cp-gimplify.c (cp_genericize_r): Handle
	OMP_CLAUSE_{IN,TASK}_REDUCTION.
	(cxx_omp_predetermined_sharing_1): Don't return
	OMP_CLAUSE_DEFAULT_SHARED for const qualified decls with no mutable
	member.  Return OMP_CLAUSE_DEFAULT_FIRSTPRIVATE for this pointer.
	* cp-objcp-common.c (cp_common_init_ts): Handle OMP_DEPOBJ.
	* cp-tree.def (OMP_DEPOBJ): New tree code.
	* cp-tree.h (OMP_ATOMIC_DEPENDENT_P): Return true also for first
	argument being OMP_CLAUSE.
	(OMP_DEPOBJ_DEPOBJ, OMP_DEPOBJ_CLAUSES): Define.
	(cp_convert_omp_range_for, cp_finish_omp_range_for): Declare.
	(finish_omp_atomic): Add LOC, CLAUSES and MO arguments.  Remove
	SEQ_CST argument.
	(finish_omp_for_block): Declare.
	(finish_omp_flush): Add MO argument.
	(finish_omp_depobj): Declare.
	* cxx-pretty-print.c (cxx_pretty_printer::statement): Handle
	OMP_DEPOBJ.
	* dump.c (cp_dump_tree): Likewise.
	* lex.c (cxx_init): Likewise.
	* parser.c: Include memmodel.h.
	(cp_parser_for): Pass false as new is_omp argument to
	cp_parser_range_for.
	(cp_parser_range_for): Add IS_OMP argument, return before finalizing
	if it is true.
	(cp_parser_omp_clause_name): Handle nontemporal, in_reduction and
	task_reduction clauses.
        (cp_parser_omp_var_list_no_open): Handle
	OMP_CLAUSE_{IN,TASK}_REDUCTION.  For OMP_CLAUSE_DEPEND, parse clause
	operands as either an array section, or lvalue assignment expression.
	(cp_parser_omp_clause_if): Handle cancel and simd modifiers.
	(cp_parser_omp_clause_defaultmap): Parse new kinds of defaultmap
	clause.
	(cp_parser_omp_clause_reduction): Add IS_OMP and KIND arguments.
	Parse reduction modifiers.  Pass KIND to c_parser_omp_variable_list.
	(cp_parser_omp_clause_lastprivate, cp_parser_omp_iterators): New
	functions.
	(cp_parser_omp_clause_depend): Parse iterator modifier and handle
	iterators.  Parse mutexinoutset and depobj kinds.
	(cp_parser_oacc_all_clauses): Adjust cp_parser_omp_clause_reduction
	callers.
	(cp_parser_omp_all_clauses): Likewise.  Handle
	PRAGMA_OMP_CLAUSE_NONTEMPORAL and
	PRAGMA_OMP_CLAUSE_{IN,TASK}_REDUCTION.  Call
	cp_parser_omp_clause_lastprivate for OpenMP lastprivate clause.
	(cp_parser_omp_atomic): Pass pragma_tok->location as
	LOC to finish_omp_atomic.  Parse hint and memory order clauses.
	Handle default memory order from requires directive if any.  Adjust
	finish_omp_atomic caller.
	(cp_parser_omp_critical): Allow comma in between (name) and hint
	clause.
	(cp_parser_omp_depobj): New function.
	(cp_parser_omp_flush): Parse flush with memory-order-clause.
	(cp_parser_omp_for_cond): Allow NE_EXPR even in OpenMP loops.
	(cp_convert_omp_range_for, cp_finish_omp_range_for): New functions.
	(cp_parser_omp_for_loop): Parse C++11 range for loops among omp
	loops.  Handle OMP_CLAUSE_IN_REDUCTION like OMP_CLAUSE_REDUCTION.
	(OMP_SIMD_CLAUSE_MASK): Add if and nontemporal clauses.
	(cp_parser_omp_simd, cp_parser_omp_for): Call keep_next_level before
	begin_omp_structured_block and call finish_omp_for_block on
	finish_omp_structured_block result.
	(cp_parser_omp_master): Add p_name, mask and cclauses arguments.
	Allow to be called while parsing combined parallel master.
	Parse combined master taskloop{, simd}.
	(cp_parser_omp_parallel): Parse combined
	parallel master{, taskloop{, simd}} constructs.
	(cp_parser_omp_single): Use SET_EXPR_LOCATION.
	(OMP_TASK_CLAUSE_MASK): Add in_reduction clause.
	(OMP_TASKWAIT_CLAUSE_MASK): Define.
	(cp_parser_omp_taskwait): Handle taskwait with depend clauses.
	(OMP_TASKGROUP_CLAUSE_MASK): Define.
	(cp_parser_omp_taskgroup): Parse taskgroup clauses, adjust
	c_finish_omp_taskgroup caller.
	(cp_parser_omp_distribute): Call keep_next_level before
	begin_omp_structured_block and call finish_omp_for_block on
	finish_omp_structured_block result.
	(cp_parser_omp_teams): Force a BIND_EXPR with BLOCK around teams
	body.
	(cp_parser_omp_target_data): Allow target data with only
	use_device_ptr clauses.
	(cp_parser_omp_target): Set OMP_REQUIRES_TARGET_USED bit in
	omp_requires_mask.
	(cp_parser_omp_requires): New function.
	(OMP_TASKLOOP_CLAUSE_MASK): Add reduction and in_reduction clauses.
	(cp_parser_omp_taskloop): Add forward declaration.  Disallow
	in_reduction clause when combined with parallel master.  Call
	keep_next_level before begin_omp_structured_block and call
	finish_omp_for_block on finish_omp_structured_block result.
	(cp_parser_omp_construct): Adjust cp_parser_omp_master caller.
	(cp_parser_pragma): Handle PRAGMA_OMP_DEPOBJ and PRAGMA_OMP_REQUIRES.
	* pt.c (tsubst_omp_clause_decl): Add iterators_cache argument.
	Adjust recursive calls.  Handle iterators.
	(tsubst_omp_clauses): Handle OMP_CLAUSE_{IN,TASK}_REDUCTION and
	OMP_CLAUSE_NONTEMPORAL.  Adjust tsubst_omp_clause_decl callers.
	(tsubst_decomp_names):
	(tsubst_omp_for_iterator): Change orig_declv into a reference.
	Handle range for loops.  Move orig_declv handling after declv/initv
	handling.
	(tsubst_expr): Force a BIND_EXPR with BLOCK around teams body.
	Adjust finish_omp_atomic caller.  Call keep_next_level before
	begin_omp_structured_block.  Call cp_finish_omp_range_for for range
	for loops and use {begin,finish}_omp_structured_block instead of
	{push,pop}_stmt_list if there are any range for loops.  Call
	finish_omp_for_block on finish_omp_structured_block result.
	Handle OMP_DEPOBJ.  Handle taskwait with depend clauses.  For
	OMP_ATOMIC call tsubst_omp_clauses on clauses if any, adjust
	finish_omp_atomic caller.  Use OMP_ATOMIC_MEMORY_ORDER rather
	than OMP_ATOMIC_SEQ_CST.  Handle clauses on OMP_TASKGROUP.
	(dependent_omp_for_p): Always return true for range for loops if
	processing_template_decl.  Return true if class type iterator
	does not have INTEGER_CST increment.
	* semantics.c: Include memmodel.h.
	(handle_omp_array_sections_1): Handle OMP_CLAUSE_{IN,TASK}_REDUCTION
	like OMP_CLAUSE_REDUCTION.
	(handle_omp_array_sections): Likewise.  Call save_expr on array
	reductions before calling build_index_type.  Handle depend clauses
	with iterators.
	(finish_omp_reduction_clause): Call save_expr for whole array
	reduction sizes.  Don't mark OMP_CLAUSE_DECL addressable if it has
	reference type.  Do mark decl_placeholder addressable if needed.
	Use error_at with OMP_CLAUSE_LOCATION (c) as first argument instead
	of error.
	(cp_omp_finish_iterators): New function.
	(finish_omp_clauses): Don't diagnose nonmonotonic clause with static,
	runtime or auto schedule kinds.  Diagnose nogroup clause used with
	reduction clause(s).  Handle depend clause with
	OMP_CLAUSE_DEPEND_DEPOBJ.  Diagnose bit-fields.  Require
	omp_depend_t type for OMP_CLAUSE_DEPEND_DEPOBJ kinds and
	some different type for other kinds.  Use cp_build_addr_expr
	and cp_build_indirect_ref instead of cxx_mark_addressable.
	Handle depend clauses with iterators.  Only handle static data members
	in the special case that const qualified vars may be specified in
	firstprivate clause.  Complain if const qualified vars without mutable
	members are mentioned in data-sharing clauses other than firstprivate
	or shared.  Use error_at with OMP_CLAUSE_LOCATION (c) as first
	argument instead of error.  Diagnose more than one nontemporal clause
	refering to the same variable.  Use error_at rather than error for
	priority and hint clause diagnostics.  Fix pasto for hint clause.
	Diagnose hint expression that doesn't fold into INTEGER_CST.
	Diagnose if clause with modifier other than cancel.  Handle
	OMP_CLAUSE_{IN,TASK}_REDUCTION like OMP_CLAUSE_REDUCTION.  Allow any
	lvalue as OMP_CLAUSE_DEPEND operand (besides array section), adjust
	diagnostics.
	(handle_omp_for_class_iterator): Don't create a new TREE_LIST if one
	has been created already for range for, just fill TREE_PURPOSE and
	TREE_VALUE.  Call cp_fully_fold on incr.
	(finish_omp_for): Don't check cond/incr if cond is global_namespace.
	Pass to c_omp_check_loop_iv_exprs orig_declv if non-NULL.  Don't
	use IS_EMPTY_STMT on NULL pre_body.  Adjust c_finish_omp_for caller.
	(finish_omp_for_block): New function.
	(finish_omp_atomic): Add LOC argument, pass it through
	to c_finish_omp_atomic and set it as location of OMP_ATOMIC* trees.
	Remove SEQ_CST argument.  Add CLAUSES and MO arguments.  Adjust
	c_finish_omp_atomic caller.  Stick clauses if any into first argument
	of wrapping OMP_ATOMIC.
	(finish_omp_depobj): New function.
	(finish_omp_flush): Add MO argument, if not
	MEMMODEL_LAST, emit __atomic_thread_fence call with the given value.
	(finish_omp_cancel): Diagnose if clause with modifier other than
	cancel.
gcc/fortran/
	* trans-openmp.c (gfc_trans_omp_clauses): Use
	OMP_CLAUSE_DEFAULTMAP_SET_KIND.
	(gfc_trans_omp_atomic): Set OMP_ATOMIC_MEMORY_ORDER
	rather than OMP_ATOMIC_SEQ_CST.
	(gfc_trans_omp_taskgroup): Build OMP_TASKGROUP using
	make_node instead of build1_loc.
	* types.def (BT_FN_VOID_BOOL, BT_FN_VOID_SIZE_SIZE_PTR,
	BT_FN_UINT_UINT_PTR_PTR, BT_FN_UINT_OMPFN_PTR_UINT_UINT,
	BT_FN_BOOL_UINT_LONGPTR_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR,
	BT_FN_BOOL_UINT_ULLPTR_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR,
	BT_FN_BOOL_LONG_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR,
	BT_FN_BOOL_BOOL_ULL_ULL_ULL_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR): New.
	(BT_FN_VOID_INT_OMPFN_SIZE_PTR_PTR_PTR_UINT_PTR_PTR): Formatting fix.



	Jakub
diff mbox series

Patch

--- gcc/c/c-parser.c	(.../trunk)	(revision 265884)
+++ gcc/c/c-parser.c	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -68,6 +68,7 @@  along with GCC; see the file COPYING3.
 #include "intl.h"
 #include "c-family/name-hint.h"
 #include "tree-iterator.h"
+#include "memmodel.h"
 
 /* We need to walk over decls with incomplete struct/union/enum types
    after parsing the whole translation unit.
@@ -1450,6 +1451,7 @@  static void c_parser_oacc_update (c_pars
 static void c_parser_omp_construct (c_parser *, bool *);
 static void c_parser_omp_threadprivate (c_parser *);
 static void c_parser_omp_barrier (c_parser *);
+static void c_parser_omp_depobj (c_parser *);
 static void c_parser_omp_flush (c_parser *);
 static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code,
 				   tree, tree *, bool *);
@@ -1464,6 +1466,7 @@  static void c_parser_omp_cancellation_po
 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 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);
 
@@ -11168,6 +11171,15 @@  c_parser_pragma (c_parser *parser, enum
       c_parser_omp_barrier (parser);
       return false;
 
+    case PRAGMA_OMP_DEPOBJ:
+      if (context != pragma_compound)
+	{
+	  construct = "omp depobj";
+	  goto in_compound;
+	}
+      c_parser_omp_depobj (parser);
+      return false;
+
     case PRAGMA_OMP_FLUSH:
       if (context != pragma_compound)
 	{
@@ -11230,6 +11242,10 @@  c_parser_pragma (c_parser *parser, enum
       c_parser_omp_declare (parser, context);
       return false;
 
+    case PRAGMA_OMP_REQUIRES:
+      c_parser_omp_requires (parser);
+      return false;
+
     case PRAGMA_OMP_ORDERED:
       return c_parser_omp_ordered (parser, context, if_p);
 
@@ -11452,6 +11468,8 @@  c_parser_omp_clause_name (c_parser *pars
 	case 'i':
 	  if (!strcmp ("if_present", p))
 	    result = PRAGMA_OACC_CLAUSE_IF_PRESENT;
+	  else if (!strcmp ("in_reduction", p))
+	    result = PRAGMA_OMP_CLAUSE_IN_REDUCTION;
 	  else if (!strcmp ("inbranch", p))
 	    result = PRAGMA_OMP_CLAUSE_INBRANCH;
 	  else if (!strcmp ("independent", p))
@@ -11476,6 +11494,8 @@  c_parser_omp_clause_name (c_parser *pars
 	case 'n':
 	  if (!strcmp ("nogroup", p))
 	    result = PRAGMA_OMP_CLAUSE_NOGROUP;
+	  else if (!strcmp ("nontemporal", p))
+	    result = PRAGMA_OMP_CLAUSE_NONTEMPORAL;
 	  else if (!strcmp ("notinbranch", p))
 	    result = PRAGMA_OMP_CLAUSE_NOTINBRANCH;
 	  else if (!strcmp ("nowait", p))
@@ -11544,7 +11564,9 @@  c_parser_omp_clause_name (c_parser *pars
 	    result = PRAGMA_OMP_CLAUSE_SIMDLEN;
 	  break;
 	case 't':
-	  if (!strcmp ("taskgroup", p))
+	  if (!strcmp ("task_reduction", p))
+	    result = PRAGMA_OMP_CLAUSE_TASK_REDUCTION;
+	  else if (!strcmp ("taskgroup", p))
 	    result = PRAGMA_OMP_CLAUSE_TASKGROUP;
 	  else if (!strcmp ("thread_limit", p))
 	    result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT;
@@ -11671,13 +11693,87 @@  c_parser_omp_variable_list (c_parser *pa
 			    location_t clause_loc,
 			    enum omp_clause_code kind, tree list)
 {
-  if (c_parser_next_token_is_not (parser, CPP_NAME)
-      || c_parser_peek_token (parser)->id_kind != C_ID_ID)
+  auto_vec<c_token> tokens;
+  unsigned int tokens_avail = 0;
+
+  if (kind != OMP_CLAUSE_DEPEND
+      && (c_parser_next_token_is_not (parser, CPP_NAME)
+	  || c_parser_peek_token (parser)->id_kind != C_ID_ID))
     c_parser_error (parser, "expected identifier");
 
-  while (c_parser_next_token_is (parser, CPP_NAME)
-	 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
+  while (kind == OMP_CLAUSE_DEPEND
+	 || (c_parser_next_token_is (parser, CPP_NAME)
+	     && c_parser_peek_token (parser)->id_kind == C_ID_ID))
     {
+      bool array_section_p = false;
+      if (kind == OMP_CLAUSE_DEPEND)
+	{
+	  if (c_parser_next_token_is_not (parser, CPP_NAME)
+	      || c_parser_peek_token (parser)->id_kind != C_ID_ID)
+	    {
+	      struct c_expr expr = c_parser_expr_no_commas (parser, NULL);
+	      if (expr.value != error_mark_node)
+		{
+		  tree u = build_omp_clause (clause_loc, kind);
+		  OMP_CLAUSE_DECL (u) = expr.value;
+		  OMP_CLAUSE_CHAIN (u) = list;
+		  list = u;
+		}
+
+	      if (c_parser_next_token_is_not (parser, CPP_COMMA))
+		break;
+
+	      c_parser_consume_token (parser);
+	      continue;
+	    }
+
+	  tokens.truncate (0);
+	  unsigned int nesting_depth = 0;
+	  while (1)
+	    {
+	      c_token *token = c_parser_peek_token (parser);
+	      switch (token->type)
+		{
+		case CPP_EOF:
+		case CPP_PRAGMA_EOL:
+		  break;
+		case CPP_OPEN_BRACE:
+		case CPP_OPEN_PAREN:
+		case CPP_OPEN_SQUARE:
+		  ++nesting_depth;
+		  goto add;
+		case CPP_CLOSE_BRACE:
+		case CPP_CLOSE_PAREN:
+		case CPP_CLOSE_SQUARE:
+		  if (nesting_depth-- == 0)
+		    break;
+		  goto add;
+		case CPP_COMMA:
+		  if (nesting_depth == 0)
+		    break;
+		  goto add;
+		default:
+		add:
+		  tokens.safe_push (*token);
+		  c_parser_consume_token (parser);
+		  continue;
+		}
+	      break;
+	    }
+
+	  /* Make sure nothing tries to read past the end of the tokens.  */
+	  c_token eof_token;
+	  memset (&eof_token, 0, sizeof (eof_token));
+	  eof_token.type = CPP_EOF;
+	  tokens.safe_push (eof_token);
+	  tokens.safe_push (eof_token);
+
+	  tokens_avail = parser->tokens_avail;
+	  gcc_assert (parser->tokens == &parser->tokens_buf[0]);
+	  parser->tokens = tokens.address ();
+	  parser->tokens_avail = tokens.length ();
+	}
+
       tree t = lookup_name (c_parser_peek_token (parser)->value);
 
       if (t == NULL_TREE)
@@ -11728,6 +11824,8 @@  c_parser_omp_variable_list (c_parser *pa
 	      /* FALLTHROUGH  */
 	    case OMP_CLAUSE_DEPEND:
 	    case OMP_CLAUSE_REDUCTION:
+	    case OMP_CLAUSE_IN_REDUCTION:
+	    case OMP_CLAUSE_TASK_REDUCTION:
 	      while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
 		{
 		  tree low_bound = NULL_TREE, length = NULL_TREE;
@@ -11753,6 +11851,7 @@  c_parser_omp_variable_list (c_parser *pa
 			  t = error_mark_node;
 			  break;
 			}
+		      array_section_p = true;
 		      if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
 			{
 			  location_t expr_loc
@@ -11773,6 +11872,30 @@  c_parser_omp_variable_list (c_parser *pa
 
 		  t = tree_cons (low_bound, length, t);
 		}
+	      if (kind == OMP_CLAUSE_DEPEND
+		  && t != error_mark_node
+		  && parser->tokens_avail != 2)
+		{
+		  if (array_section_p)
+		    {
+		      error_at (c_parser_peek_token (parser)->location,
+				"expected %<)%> or %<,%>");
+		      t = error_mark_node;
+		    }
+		  else
+		    {
+		      parser->tokens = tokens.address ();
+		      parser->tokens_avail = tokens.length ();
+
+		      t = c_parser_expr_no_commas (parser, NULL).value;
+		      if (t != error_mark_node && parser->tokens_avail != 2)
+			{
+			  error_at (c_parser_peek_token (parser)->location,
+				    "expected %<)%> or %<,%>");
+			  t = error_mark_node;
+			}
+		    }
+		}
 	      break;
 	    default:
 	      break;
@@ -11789,6 +11912,11 @@  c_parser_omp_variable_list (c_parser *pa
       else
 	list = tree_cons (t, NULL_TREE, list);
 
+      if (kind == OMP_CLAUSE_DEPEND)
+	{
+	  parser->tokens = &parser->tokens_buf[0];
+	  parser->tokens_avail = tokens_avail;
+	}
       if (c_parser_next_token_is_not (parser, CPP_COMMA))
 	break;
 
@@ -12080,7 +12208,11 @@  c_parser_omp_clause_final (c_parser *par
 
    directive-name-modifier:
      parallel | task | taskloop | target data | target | target update
-     | target enter data | target exit data  */
+     | target enter data | target exit data
+
+   OpenMP 5.0:
+   directive-name-modifier:
+     ... | simd | cancel  */
 
 static tree
 c_parser_omp_clause_if (c_parser *parser, tree list, bool is_omp)
@@ -12096,8 +12228,12 @@  c_parser_omp_clause_if (c_parser *parser
     {
       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
       int n = 2;
-      if (strcmp (p, "parallel") == 0)
+      if (strcmp (p, "cancel") == 0)
+	if_modifier = VOID_CST;
+      else if (strcmp (p, "parallel") == 0)
 	if_modifier = OMP_PARALLEL;
+      else if (strcmp (p, "simd") == 0)
+	if_modifier = OMP_SIMD;
       else if (strcmp (p, "task") == 0)
 	if_modifier = OMP_TASK;
       else if (strcmp (p, "taskloop") == 0)
@@ -12181,7 +12317,9 @@  c_parser_omp_clause_if (c_parser *parser
 	    const char *p = NULL;
 	    switch (if_modifier)
 	      {
+	      case VOID_CST: p = "cancel"; break;
 	      case OMP_PARALLEL: p = "parallel"; break;
+	      case OMP_SIMD: p = "simd"; break;
 	      case OMP_TASK: p = "task"; break;
 	      case OMP_TASKLOOP: p = "taskloop"; break;
 	      case OMP_TARGET_DATA: p = "target data"; break;
@@ -12220,12 +12358,41 @@  c_parser_omp_clause_if (c_parser *parser
 }
 
 /* OpenMP 2.5:
-   lastprivate ( variable-list ) */
+   lastprivate ( variable-list )
+
+   OpenMP 5.0:
+   lastprivate ( [ lastprivate-modifier : ] variable-list ) */
 
 static tree
 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
 {
-  return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
+  /* The clauses location.  */
+  location_t loc = c_parser_peek_token (parser)->location;
+
+  if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+    {
+      bool conditional = false;
+      if (c_parser_next_token_is (parser, CPP_NAME)
+	  && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
+	{
+	  const char *p
+	    = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
+	  if (strcmp (p, "conditional") == 0)
+	    {
+	      conditional = true;
+	      c_parser_consume_token (parser);
+	      c_parser_consume_token (parser);
+	    }
+	}
+      tree nlist = c_parser_omp_variable_list (parser, loc,
+					       OMP_CLAUSE_LASTPRIVATE, list);
+      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+      if (conditional)
+	for (tree c = nlist; c != list; c = OMP_CLAUSE_CHAIN (c))
+	  OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) = 1;
+      return nlist;
+    }
+  return list;
 }
 
 /* OpenMP 3.1:
@@ -12465,9 +12632,10 @@  c_parser_omp_clause_hint (c_parser *pars
 
       parens.skip_until_found_close (parser);
 
-      if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
+      if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
+	  || TREE_CODE (t) != INTEGER_CST)
 	{
-	  c_parser_error (parser, "expected integer expression");
+	  c_parser_error (parser, "expected constant integer expression");
 	  return list;
 	}
 
@@ -12483,7 +12651,10 @@  c_parser_omp_clause_hint (c_parser *pars
 }
 
 /* OpenMP 4.5:
-   defaultmap ( tofrom : scalar ) */
+   defaultmap ( tofrom : scalar )
+
+   OpenMP 5.0:
+   defaultmap ( implicit-behavior [ : variable-category ] ) */
 
 static tree
 c_parser_omp_clause_defaultmap (c_parser *parser, tree list)
@@ -12491,39 +12662,155 @@  c_parser_omp_clause_defaultmap (c_parser
   location_t loc = c_parser_peek_token (parser)->location;
   tree c;
   const char *p;
+  enum omp_clause_defaultmap_kind behavior = OMP_CLAUSE_DEFAULTMAP_DEFAULT;
+  enum omp_clause_defaultmap_kind category
+    = OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED;
 
   matching_parens parens;
   if (!parens.require_open (parser))
     return list;
-  if (!c_parser_next_token_is (parser, CPP_NAME))
-    {
-      c_parser_error (parser, "expected %<tofrom%>");
+  if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
+    p = "default";
+  else if (!c_parser_next_token_is (parser, CPP_NAME))
+    {
+    invalid_behavior:
+      c_parser_error (parser, "expected %<alloc%>, %<to%>, %<from%>, "
+			      "%<tofrom%>, %<firstprivate%>, %<none%> "
+			      "or %<default%>");
       goto out_err;
     }
-  p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
-  if (strcmp (p, "tofrom") != 0)
+  else
+    p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
+
+  switch (p[0])
     {
-      c_parser_error (parser, "expected %<tofrom%>");
-      goto out_err;
+    case 'a':
+      if (strcmp ("alloc", p) == 0)
+	behavior = OMP_CLAUSE_DEFAULTMAP_ALLOC;
+      else
+	goto invalid_behavior;
+      break;
+
+    case 'd':
+      if (strcmp ("default", p) == 0)
+	behavior = OMP_CLAUSE_DEFAULTMAP_DEFAULT;
+      else
+	goto invalid_behavior;
+      break;
+
+    case 'f':
+      if (strcmp ("firstprivate", p) == 0)
+	behavior = OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE;
+      else if (strcmp ("from", p) == 0)
+	behavior = OMP_CLAUSE_DEFAULTMAP_FROM;
+      else
+	goto invalid_behavior;
+      break;
+
+    case 'n':
+      if (strcmp ("none", p) == 0)
+	behavior = OMP_CLAUSE_DEFAULTMAP_NONE;
+      else
+	goto invalid_behavior;
+      break;
+
+    case 't':
+      if (strcmp ("tofrom", p) == 0)
+	behavior = OMP_CLAUSE_DEFAULTMAP_TOFROM;
+      else if (strcmp ("to", p) == 0)
+	behavior = OMP_CLAUSE_DEFAULTMAP_TO;
+      else
+	goto invalid_behavior;
+      break;
+
+    default:
+      goto invalid_behavior;
     }
   c_parser_consume_token (parser);
-  if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
-    goto out_err;
-  if (!c_parser_next_token_is (parser, CPP_NAME))
-    {
-      c_parser_error (parser, "expected %<scalar%>");
-      goto out_err;
-    }
-  p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
-  if (strcmp (p, "scalar") != 0)
+
+  if (!c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
     {
-      c_parser_error (parser, "expected %<scalar%>");
-      goto out_err;
+      if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
+	goto out_err;
+      if (!c_parser_next_token_is (parser, CPP_NAME))
+	{
+	invalid_category:
+	  c_parser_error (parser, "expected %<scalar%>, %<aggregate%> or "
+				  "%<pointer%>");
+	  goto out_err;
+	}
+      p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
+      switch (p[0])
+	{
+	case 'a':
+	  if (strcmp ("aggregate", p) == 0)
+	    category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE;
+	  else
+	    goto invalid_category;
+	  break;
+
+	case 'p':
+	  if (strcmp ("pointer", p) == 0)
+	    category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER;
+	  else
+	    goto invalid_category;
+	  break;
+
+	case 's':
+	  if (strcmp ("scalar", p) == 0)
+	    category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR;
+	  else
+	    goto invalid_category;
+	  break;
+
+	default:
+	  goto invalid_category;
+	}
+
+      c_parser_consume_token (parser);
     }
-  c_parser_consume_token (parser);
   parens.skip_until_found_close (parser);
-  check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULTMAP, "defaultmap");
+
+  for (c = list; c ; c = OMP_CLAUSE_CHAIN (c))
+    if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEFAULTMAP
+	&& (category == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
+	    || OMP_CLAUSE_DEFAULTMAP_CATEGORY (c) == category
+	    || (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c)
+		== OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED)))
+      {
+	enum omp_clause_defaultmap_kind cat = category;
+	location_t loc = OMP_CLAUSE_LOCATION (c);
+	if (cat == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED)
+	  cat = OMP_CLAUSE_DEFAULTMAP_CATEGORY (c);
+	p = NULL;
+	switch (cat)
+	  {
+	  case OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED:
+	    p = NULL;
+	    break;
+	  case OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE:
+	    p = "aggregate";
+	    break;
+	  case OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER:
+	    p = "pointer";
+	    break;
+	  case OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR:
+	    p = "scalar";
+	    break;
+	  default:
+	    gcc_unreachable ();
+	  }
+	if (p)
+	  error_at (loc, "too many %<defaultmap%> clauses with %qs category",
+		    p);
+	else
+	  error_at (loc, "too many %<defaultmap%> clauses with unspecified "
+			 "category");
+	break;
+      }
+
   c = build_omp_clause (loc, OMP_CLAUSE_DEFAULTMAP);
+  OMP_CLAUSE_DEFAULTMAP_SET_KIND (c, behavior, category);
   OMP_CLAUSE_CHAIN (c) = list;
   return c;
 
@@ -12957,18 +13244,51 @@  c_parser_omp_clause_private (c_parser *p
 
    reduction-operator:
      One of: + * - & ^ | && ||
-     identifier  */
+     identifier
+
+   OpenMP 5.0:
+   reduction ( reduction-modifier, reduction-operator : variable-list )
+   in_reduction ( reduction-operator : variable-list )
+   task_reduction ( reduction-operator : variable-list )  */
 
 static tree
-c_parser_omp_clause_reduction (c_parser *parser, tree list)
+c_parser_omp_clause_reduction (c_parser *parser, enum omp_clause_code kind,
+			       bool is_omp, tree list)
 {
   location_t clause_loc = c_parser_peek_token (parser)->location;
   matching_parens parens;
   if (parens.require_open (parser))
     {
+      bool task = false;
+      bool inscan = false;
       enum tree_code code = ERROR_MARK;
       tree reduc_id = NULL_TREE;
 
+      if (kind == OMP_CLAUSE_REDUCTION && is_omp)
+	{
+	  if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)
+	      && c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
+	    {
+	      c_parser_consume_token (parser);
+	      c_parser_consume_token (parser);
+	    }
+	  else if (c_parser_next_token_is (parser, CPP_NAME)
+		   && c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
+	    {
+	      const char *p
+		= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
+	      if (strcmp (p, "task") == 0)
+		task = true;
+	      else if (strcmp (p, "inscan") == 0)
+		inscan = true;
+	      if (task || inscan)
+		{
+		  c_parser_consume_token (parser);
+		  c_parser_consume_token (parser);
+		}
+	    }
+	}
+
       switch (c_parser_peek_token (parser)->type)
 	{
 	case CPP_PLUS:
@@ -13025,8 +13345,7 @@  c_parser_omp_clause_reduction (c_parser
 	{
 	  tree nl, c;
 
-	  nl = c_parser_omp_variable_list (parser, clause_loc,
-					   OMP_CLAUSE_REDUCTION, list);
+	  nl = c_parser_omp_variable_list (parser, clause_loc, kind, list);
 	  for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
 	    {
 	      tree d = OMP_CLAUSE_DECL (c), type;
@@ -13051,6 +13370,10 @@  c_parser_omp_clause_reduction (c_parser
 	      while (TREE_CODE (type) == ARRAY_TYPE)
 		type = TREE_TYPE (type);
 	      OMP_CLAUSE_REDUCTION_CODE (c) = code;
+	      if (task)
+		OMP_CLAUSE_REDUCTION_TASK (c) = 1;
+	      else if (inscan)
+		OMP_CLAUSE_REDUCTION_INSCAN (c) = 1;
 	      if (code == ERROR_MARK
 		  || !(INTEGRAL_TYPE_P (type)
 		       || TREE_CODE (type) == REAL_TYPE
@@ -13510,6 +13833,15 @@  c_parser_omp_clause_linear (c_parser *pa
   return nl;
 }
 
+/* OpenMP 5.0:
+   nontemporal ( variable-list ) */
+
+static tree
+c_parser_omp_clause_nontemporal (c_parser *parser, tree list)
+{
+  return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_NONTEMPORAL, list);
+}
+
 /* OpenMP 4.0:
    safelen ( constant-expression ) */
 
@@ -13670,6 +14002,106 @@  c_parser_omp_clause_depend_sink (c_parse
   return u;
 }
 
+/* OpenMP 5.0:
+   iterators ( iterators-definition )
+
+   iterators-definition:
+     iterator-specifier
+     iterator-specifier , iterators-definition
+
+   iterator-specifier:
+     identifier = range-specification
+     iterator-type identifier = range-specification
+
+   range-specification:
+     begin : end
+     begin : end : step  */
+
+static tree
+c_parser_omp_iterators (c_parser *parser)
+{
+  tree ret = NULL_TREE, *last = &ret;
+  c_parser_consume_token (parser);
+
+  push_scope ();
+
+  matching_parens parens;
+  if (!parens.require_open (parser))
+    return error_mark_node;
+
+  do
+    {
+      tree iter_type = NULL_TREE, type_expr = NULL_TREE;
+      if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
+	{
+	  struct c_type_name *type = c_parser_type_name (parser);
+	  if (type != NULL)
+	    iter_type = groktypename (type, &type_expr, NULL);
+	}
+      if (iter_type == NULL_TREE)
+	iter_type = integer_type_node;
+
+      location_t loc = c_parser_peek_token (parser)->location;
+      if (!c_parser_next_token_is (parser, CPP_NAME))
+	{
+	  c_parser_error (parser, "expected identifier");
+	  break;
+	}
+
+      tree id = c_parser_peek_token (parser)->value;
+      c_parser_consume_token (parser);
+
+      if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
+	break;
+
+      location_t eloc = c_parser_peek_token (parser)->location;
+      c_expr expr = c_parser_expr_no_commas (parser, NULL);
+      expr = convert_lvalue_to_rvalue (eloc, expr, true, false);
+      tree begin = expr.value;
+
+      if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
+	break;
+
+      eloc = c_parser_peek_token (parser)->location;
+      expr = c_parser_expr_no_commas (parser, NULL);
+      expr = convert_lvalue_to_rvalue (eloc, expr, true, false);
+      tree end = expr.value;
+
+      tree step = integer_one_node;
+      if (c_parser_next_token_is (parser, CPP_COLON))
+	{
+	  c_parser_consume_token (parser);
+	  eloc = c_parser_peek_token (parser)->location;
+	  expr = c_parser_expr_no_commas (parser, NULL);
+	  expr = convert_lvalue_to_rvalue (eloc, expr, true, false);
+	  step = expr.value;
+	}
+
+      tree iter_var = build_decl (loc, VAR_DECL, id, iter_type);
+      DECL_ARTIFICIAL (iter_var) = 1;
+      DECL_CONTEXT (iter_var) = current_function_decl;
+      pushdecl (iter_var);
+
+      *last = make_tree_vec (6);
+      TREE_VEC_ELT (*last, 0) = iter_var;
+      TREE_VEC_ELT (*last, 1) = begin;
+      TREE_VEC_ELT (*last, 2) = end;
+      TREE_VEC_ELT (*last, 3) = step;
+      last = &TREE_CHAIN (*last);
+
+      if (c_parser_next_token_is (parser, CPP_COMMA))
+	{
+	  c_parser_consume_token (parser);
+	  continue;
+	}
+      break;
+    }
+  while (1);
+
+  parens.skip_until_found_close (parser);
+  return ret ? ret : error_mark_node;
+}
+
 /* OpenMP 4.0:
    depend ( depend-kind: variable-list )
 
@@ -13679,40 +14111,71 @@  c_parser_omp_clause_depend_sink (c_parse
    OpenMP 4.5:
    depend ( source )
 
-   depend ( sink  : vec )  */
+   depend ( sink  : vec )
+
+   OpenMP 5.0:
+   depend ( depend-modifier , depend-kind: variable-list )
+
+   depend-kind:
+     in | out | inout | mutexinoutset | depobj
+
+   depend-modifier:
+     iterator ( iterators-definition )  */
 
 static tree
 c_parser_omp_clause_depend (c_parser *parser, tree list)
 {
   location_t clause_loc = c_parser_peek_token (parser)->location;
-  enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT;
-  tree nl, c;
+  enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_LAST;
+  tree nl, c, iterators = NULL_TREE;
 
   matching_parens parens;
   if (!parens.require_open (parser))
     return list;
 
-  if (c_parser_next_token_is (parser, CPP_NAME))
+  do
     {
+      if (c_parser_next_token_is_not (parser, CPP_NAME))
+	goto invalid_kind;
+
       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
+      if (strcmp ("iterator", p) == 0 && iterators == NULL_TREE)
+	{
+	  iterators = c_parser_omp_iterators (parser);
+	  c_parser_require (parser, CPP_COMMA, "expected %<,%>");
+	  continue;
+	}
       if (strcmp ("in", p) == 0)
 	kind = OMP_CLAUSE_DEPEND_IN;
       else if (strcmp ("inout", p) == 0)
 	kind = OMP_CLAUSE_DEPEND_INOUT;
+      else if (strcmp ("mutexinoutset", p) == 0)
+	kind = OMP_CLAUSE_DEPEND_MUTEXINOUTSET;
       else if (strcmp ("out", p) == 0)
 	kind = OMP_CLAUSE_DEPEND_OUT;
-      else if (strcmp ("source", p) == 0)
-	kind = OMP_CLAUSE_DEPEND_SOURCE;
+      else if (strcmp ("depobj", p) == 0)
+	kind = OMP_CLAUSE_DEPEND_DEPOBJ;
       else if (strcmp ("sink", p) == 0)
 	kind = OMP_CLAUSE_DEPEND_SINK;
+      else if (strcmp ("source", p) == 0)
+	kind = OMP_CLAUSE_DEPEND_SOURCE;
       else
 	goto invalid_kind;
+      break;
     }
-  else
-    goto invalid_kind;
+  while (1);
 
   c_parser_consume_token (parser);
 
+  if (iterators
+      && (kind == OMP_CLAUSE_DEPEND_SOURCE || kind == OMP_CLAUSE_DEPEND_SINK))
+    {
+      pop_scope ();
+      error_at (clause_loc, "%<iterator%> modifier incompatible with %qs",
+		kind == OMP_CLAUSE_DEPEND_SOURCE ? "source" : "sink");
+      iterators = NULL_TREE;
+    }
+
   if (kind == OMP_CLAUSE_DEPEND_SOURCE)
     {
       c = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND);
@@ -13733,8 +14196,22 @@  c_parser_omp_clause_depend (c_parser *pa
       nl = c_parser_omp_variable_list (parser, clause_loc,
 				       OMP_CLAUSE_DEPEND, list);
 
+      if (iterators)
+	{
+	  tree block = pop_scope ();
+	  if (iterators == error_mark_node)
+	    iterators = NULL_TREE;
+	  else
+	    TREE_VEC_ELT (iterators, 5) = block;
+	}
+
       for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
-	OMP_CLAUSE_DEPEND_KIND (c) = kind;
+	{
+	  OMP_CLAUSE_DEPEND_KIND (c) = kind;
+	  if (iterators)
+	    OMP_CLAUSE_DECL (c)
+	      = build_tree_list (iterators, OMP_CLAUSE_DECL (c));
+	}
     }
 
   parens.skip_until_found_close (parser);
@@ -13744,6 +14221,8 @@  c_parser_omp_clause_depend (c_parser *pa
   c_parser_error (parser, "invalid depend kind");
  resync_fail:
   parens.skip_until_found_close (parser);
+  if (iterators)
+    pop_scope ();
   return list;
 }
 
@@ -14169,12 +14648,14 @@  c_parser_oacc_all_clauses (c_parser *par
 	  c_name = "private";
 	  break;
 	case PRAGMA_OACC_CLAUSE_REDUCTION:
-	  clauses = c_parser_omp_clause_reduction (parser, clauses);
+	  clauses
+	    = c_parser_omp_clause_reduction (parser, OMP_CLAUSE_REDUCTION,
+					     false, clauses);
 	  c_name = "reduction";
 	  break;
 	case PRAGMA_OACC_CLAUSE_SEQ:
 	  clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_SEQ,
-						clauses);
+						 clauses);
 	  c_name = "seq";
 	  break;
 	case PRAGMA_OACC_CLAUSE_TILE:
@@ -14295,6 +14776,12 @@  c_parser_omp_all_clauses (c_parser *pars
 	  clauses = c_parser_omp_clause_if (parser, clauses, true);
 	  c_name = "if";
 	  break;
+	case PRAGMA_OMP_CLAUSE_IN_REDUCTION:
+	  clauses
+	    = c_parser_omp_clause_reduction (parser, OMP_CLAUSE_IN_REDUCTION,
+					     true, clauses);
+	  c_name = "in_reduction";
+	  break;
 	case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
 	  clauses = c_parser_omp_clause_lastprivate (parser, clauses);
 	  c_name = "lastprivate";
@@ -14328,7 +14815,9 @@  c_parser_omp_all_clauses (c_parser *pars
 	  c_name = "private";
 	  break;
 	case PRAGMA_OMP_CLAUSE_REDUCTION:
-	  clauses = c_parser_omp_clause_reduction (parser, clauses);
+	  clauses
+	    = c_parser_omp_clause_reduction (parser, OMP_CLAUSE_REDUCTION,
+					     true, clauses);
 	  c_name = "reduction";
 	  break;
 	case PRAGMA_OMP_CLAUSE_SCHEDULE:
@@ -14339,6 +14828,12 @@  c_parser_omp_all_clauses (c_parser *pars
 	  clauses = c_parser_omp_clause_shared (parser, clauses);
 	  c_name = "shared";
 	  break;
+	case PRAGMA_OMP_CLAUSE_TASK_REDUCTION:
+	  clauses
+	    = c_parser_omp_clause_reduction (parser, OMP_CLAUSE_TASK_REDUCTION,
+					     true, clauses);
+	  c_name = "task_reduction";
+	  break;
 	case PRAGMA_OMP_CLAUSE_UNTIED:
 	  clauses = c_parser_omp_clause_untied (parser, clauses);
 	  c_name = "untied";
@@ -14348,6 +14843,10 @@  c_parser_omp_all_clauses (c_parser *pars
 						clauses);
 	  c_name = "inbranch";
 	  break;
+	case PRAGMA_OMP_CLAUSE_NONTEMPORAL:
+	  clauses = c_parser_omp_clause_nontemporal (parser, clauses);
+	  c_name = "nontemporal";
+	  break;
 	case PRAGMA_OMP_CLAUSE_NOTINBRANCH:
 	  clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH,
 						clauses);
@@ -15252,62 +15751,157 @@  c_parser_omp_atomic (location_t loc, c_p
   tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE;
   tree lhs1 = NULL_TREE, rhs1 = NULL_TREE;
   tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE;
-  enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR;
+  enum tree_code code = ERROR_MARK, opcode = NOP_EXPR;
+  enum omp_memory_order memory_order = OMP_MEMORY_ORDER_UNSPECIFIED;
   struct c_expr expr;
   location_t eloc;
   bool structured_block = false;
   bool swapped = false;
-  bool seq_cst = false;
   bool non_lvalue_p;
+  bool first = true;
+  tree clauses = NULL_TREE;
 
-  if (c_parser_next_token_is (parser, CPP_NAME))
-    {
-      const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
-      if (!strcmp (p, "seq_cst"))
-	{
-	  seq_cst = true;
-	  c_parser_consume_token (parser);
-	  if (c_parser_next_token_is (parser, CPP_COMMA)
-	      && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
-	    c_parser_consume_token (parser);
-	}
-    }
-  if (c_parser_next_token_is (parser, CPP_NAME))
-    {
-      const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
-
-      if (!strcmp (p, "read"))
-	code = OMP_ATOMIC_READ;
-      else if (!strcmp (p, "write"))
-	code = NOP_EXPR;
-      else if (!strcmp (p, "update"))
-	code = OMP_ATOMIC;
-      else if (!strcmp (p, "capture"))
-	code = OMP_ATOMIC_CAPTURE_NEW;
-      else
-	p = NULL;
-      if (p)
-	c_parser_consume_token (parser);
-    }
-  if (!seq_cst)
+  while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
     {
-      if (c_parser_next_token_is (parser, CPP_COMMA)
-	  && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
+      if (!first && c_parser_next_token_is (parser, CPP_COMMA))
 	c_parser_consume_token (parser);
 
+      first = false;
+
       if (c_parser_next_token_is (parser, CPP_NAME))
 	{
 	  const char *p
 	    = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
-	  if (!strcmp (p, "seq_cst"))
+	  location_t cloc = c_parser_peek_token (parser)->location;
+	  enum tree_code new_code = ERROR_MARK;
+	  enum omp_memory_order new_memory_order
+	    = OMP_MEMORY_ORDER_UNSPECIFIED;
+
+	  if (!strcmp (p, "read"))
+	    new_code = OMP_ATOMIC_READ;
+	  else if (!strcmp (p, "write"))
+	    new_code = NOP_EXPR;
+	  else if (!strcmp (p, "update"))
+	    new_code = OMP_ATOMIC;
+	  else if (!strcmp (p, "capture"))
+	    new_code = OMP_ATOMIC_CAPTURE_NEW;
+	  else if (!strcmp (p, "seq_cst"))
+	    new_memory_order = OMP_MEMORY_ORDER_SEQ_CST;
+	  else if (!strcmp (p, "acq_rel"))
+	    new_memory_order = OMP_MEMORY_ORDER_ACQ_REL;
+	  else if (!strcmp (p, "release"))
+	    new_memory_order = OMP_MEMORY_ORDER_RELEASE;
+	  else if (!strcmp (p, "acquire"))
+	    new_memory_order = OMP_MEMORY_ORDER_ACQUIRE;
+	  else if (!strcmp (p, "relaxed"))
+	    new_memory_order = OMP_MEMORY_ORDER_RELAXED;
+	  else if (!strcmp (p, "hint"))
+	    {
+	      c_parser_consume_token (parser);
+	      clauses = c_parser_omp_clause_hint (parser, clauses);
+	      continue;
+	    }
+	  else
 	    {
-	      seq_cst = true;
+	      p = NULL;
+	      error_at (cloc, "expected %<read%>, %<write%>, %<update%>, "
+			      "%<capture%>, %<seq_cst%>, %<acq_rel%>, "
+			      "%<release%>, %<relaxed%> or %<hint%> clause");
+	    }
+	  if (p)
+	    {
+	      if (new_code != ERROR_MARK)
+		{
+		  if (code != ERROR_MARK)
+		    error_at (cloc, "too many atomic clauses");
+		  else
+		    code = new_code;
+		}
+	      else if (new_memory_order != OMP_MEMORY_ORDER_UNSPECIFIED)
+		{
+		  if (memory_order != OMP_MEMORY_ORDER_UNSPECIFIED)
+		    error_at (cloc, "too many memory order clauses");
+		  else
+		    memory_order = new_memory_order;
+		}
 	      c_parser_consume_token (parser);
+	      continue;
 	    }
 	}
+      break;
     }
   c_parser_skip_to_pragma_eol (parser);
 
+  if (code == ERROR_MARK)
+    code = OMP_ATOMIC;
+  if (memory_order == OMP_MEMORY_ORDER_UNSPECIFIED)
+    {
+      omp_requires_mask
+	= (enum omp_requires) (omp_requires_mask
+			       | OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED);
+      switch ((enum omp_memory_order)
+	      (omp_requires_mask & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER))
+	{
+	case OMP_MEMORY_ORDER_UNSPECIFIED:
+	case OMP_MEMORY_ORDER_RELAXED:
+	  memory_order = OMP_MEMORY_ORDER_RELAXED;
+	  break;
+	case OMP_MEMORY_ORDER_SEQ_CST:
+	  memory_order = OMP_MEMORY_ORDER_SEQ_CST;
+	  break;
+	case OMP_MEMORY_ORDER_ACQ_REL:
+	  switch (code)
+	    {
+	    case OMP_ATOMIC_READ:
+	      memory_order = OMP_MEMORY_ORDER_ACQUIRE;
+	      break;
+	    case NOP_EXPR: /* atomic write */
+	    case OMP_ATOMIC:
+	      memory_order = OMP_MEMORY_ORDER_RELEASE;
+	      break;
+	    default:
+	      memory_order = OMP_MEMORY_ORDER_ACQ_REL;
+	      break;
+	    }
+	  break;
+	default:
+	  gcc_unreachable ();
+	}
+    }
+  else
+    switch (code)
+      {
+      case OMP_ATOMIC_READ:
+	if (memory_order == OMP_MEMORY_ORDER_ACQ_REL
+	    || memory_order == OMP_MEMORY_ORDER_RELEASE)
+	  {
+	    error_at (loc, "%<#pragma omp atomic read%> incompatible with "
+			   "%<acq_rel%> or %<release%> clauses");
+	    memory_order = OMP_MEMORY_ORDER_SEQ_CST;
+	  }
+	break;
+      case NOP_EXPR: /* atomic write */
+	if (memory_order == OMP_MEMORY_ORDER_ACQ_REL
+	    || memory_order == OMP_MEMORY_ORDER_ACQUIRE)
+	  {
+	    error_at (loc, "%<#pragma omp atomic write%> incompatible with "
+			   "%<acq_rel%> or %<acquire%> clauses");
+	    memory_order = OMP_MEMORY_ORDER_SEQ_CST;
+	  }
+	break;
+      case OMP_ATOMIC:
+	if (memory_order == OMP_MEMORY_ORDER_ACQ_REL
+	    || memory_order == OMP_MEMORY_ORDER_ACQUIRE)
+	  {
+	    error_at (loc, "%<#pragma omp atomic update%> incompatible with "
+			   "%<acq_rel%> or %<acquire%> clauses");
+	    memory_order = OMP_MEMORY_ORDER_SEQ_CST;
+	  }
+	break;
+      default:
+	break;
+      }
+
   switch (code)
     {
     case OMP_ATOMIC_READ:
@@ -15624,7 +16218,7 @@  done:
     }
   else
     stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1,
-				swapped, seq_cst);
+				swapped, memory_order);
   if (stmt != error_mark_node)
     add_stmt (stmt);
 
@@ -15676,6 +16270,10 @@  c_parser_omp_critical (location_t loc, c
       else
 	c_parser_error (parser, "expected identifier");
 
+      if (c_parser_next_token_is (parser, CPP_COMMA)
+	  && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
+	c_parser_consume_token (parser);
+
       clauses = c_parser_omp_all_clauses (parser,
 					  OMP_CRITICAL_CLAUSE_MASK,
 					  "#pragma omp critical");
@@ -15691,24 +16289,159 @@  c_parser_omp_critical (location_t loc, c
   return c_finish_omp_critical (loc, stmt, name, clauses);
 }
 
+/* OpenMP 5.0:
+   # pragma omp depobj ( depobj ) depobj-clause new-line
+
+   depobj-clause:
+     depend (dependence-type : locator)
+     destroy
+     update (dependence-type)
+
+   dependence-type:
+     in
+     out
+     inout
+     mutexinout  */
+
+static void
+c_parser_omp_depobj (c_parser *parser)
+{
+  location_t loc = c_parser_peek_token (parser)->location;
+  c_parser_consume_pragma (parser);
+  matching_parens parens;
+  if (!parens.require_open (parser))
+    {
+      c_parser_skip_to_pragma_eol (parser);
+      return;
+    }
+
+  tree depobj = c_parser_expr_no_commas (parser, NULL).value;
+  if (depobj != error_mark_node)
+    {
+      if (!lvalue_p (depobj))
+	{
+	  error_at (EXPR_LOC_OR_LOC (depobj, loc),
+		    "%<depobj%> expression is not lvalue expression");
+	  depobj = error_mark_node;
+	}
+      else
+	{
+	  tree addr = build_unary_op (EXPR_LOC_OR_LOC (depobj, loc), ADDR_EXPR,
+				      depobj, false);
+	  if (addr == error_mark_node)
+	    depobj = error_mark_node;
+	  else
+	    depobj = build_indirect_ref (EXPR_LOC_OR_LOC (depobj, loc),
+					 addr, RO_UNARY_STAR);
+	}
+    }
+
+  parens.skip_until_found_close (parser);
+  tree clause = NULL_TREE;
+  enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_SOURCE;
+  location_t c_loc = c_parser_peek_token (parser)->location;
+  if (c_parser_next_token_is (parser, CPP_NAME))
+    {
+      const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
+
+      c_parser_consume_token (parser);
+      if (!strcmp ("depend", p))
+	{
+	  clause = c_parser_omp_clause_depend (parser, NULL_TREE);
+	  clause = c_finish_omp_clauses (clause, C_ORT_OMP);
+	  if (!clause)
+	    clause = error_mark_node;
+	}
+      else if (!strcmp ("destroy", p))
+	kind = OMP_CLAUSE_DEPEND_LAST;
+      else if (!strcmp ("update", p))
+	{
+	  matching_parens c_parens;
+	  if (c_parens.require_open (parser))
+	    {
+	      location_t c2_loc = c_parser_peek_token (parser)->location;
+	      if (c_parser_next_token_is (parser, CPP_NAME))
+		{
+		  const char *p2
+		    = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
+
+		  c_parser_consume_token (parser);
+		  if (!strcmp ("in", p2))
+		    kind = OMP_CLAUSE_DEPEND_IN;
+		  else if (!strcmp ("out", p2))
+		    kind = OMP_CLAUSE_DEPEND_OUT;
+		  else if (!strcmp ("inout", p2))
+		    kind = OMP_CLAUSE_DEPEND_INOUT;
+		  else if (!strcmp ("mutexinoutset", p2))
+		    kind = OMP_CLAUSE_DEPEND_MUTEXINOUTSET;
+		}
+	      if (kind == OMP_CLAUSE_DEPEND_SOURCE)
+		{
+		  clause = error_mark_node;
+		  error_at (c2_loc, "expected %<in%>, %<out%>, %<inout%> or "
+				    "%<mutexinoutset%>");
+		}
+	      c_parens.skip_until_found_close (parser);
+	    }
+	  else
+	    clause = error_mark_node;
+	}
+    }
+  if (!clause && kind == OMP_CLAUSE_DEPEND_SOURCE)
+    {
+      clause = error_mark_node;
+      error_at (c_loc, "expected %<depend%>, %<destroy%> or %<update%> clause");
+    }
+  c_parser_skip_to_pragma_eol (parser);
+
+  c_finish_omp_depobj (loc, depobj, kind, clause);
+}
+
+
 /* OpenMP 2.5:
    # pragma omp flush flush-vars[opt] new-line
 
    flush-vars:
-     ( variable-list ) */
+     ( variable-list )
+
+   OpenMP 5.0:
+   # pragma omp flush memory-order-clause new-line  */
 
 static void
 c_parser_omp_flush (c_parser *parser)
 {
   location_t loc = c_parser_peek_token (parser)->location;
   c_parser_consume_pragma (parser);
+  enum memmodel mo = MEMMODEL_LAST;
+  if (c_parser_next_token_is (parser, CPP_NAME))
+    {
+      const char *p
+	= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
+
+      if (!strcmp (p, "acq_rel"))
+	mo = MEMMODEL_ACQ_REL;
+      else if (!strcmp (p, "release"))
+	mo = MEMMODEL_RELEASE;
+      else if (!strcmp (p, "acquire"))
+	mo = MEMMODEL_ACQUIRE;
+      else
+	error_at (c_parser_peek_token (parser)->location,
+		  "expected %<acq_rel%>, %<release%> or %<acquire%>");
+      c_parser_consume_token (parser);
+    }
   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
-    c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
+    {
+      if (mo != MEMMODEL_LAST)
+	error_at (c_parser_peek_token (parser)->location,
+		  "%<flush%> list specified together with memory order "
+		  "clause");
+      c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
+    }
   else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
     c_parser_error (parser, "expected %<(%> or end of line");
   c_parser_skip_to_pragma_eol (parser);
 
-  c_finish_omp_flush (loc);
+  c_finish_omp_flush (loc, mo);
 }
 
 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
@@ -15880,6 +16613,10 @@  c_parser_omp_for_loop (location_t loc, c
 	    case LT_EXPR:
 	    case LE_EXPR:
 	      break;
+	    case NE_EXPR:
+	      if (code != OACC_LOOP)
+		break;
+	      /* FALLTHRU.  */
 	    default:
 	      /* Can't be cond = error_mark_node, because we want to preserve
 		 the location until c_finish_omp_for.  */
@@ -16011,7 +16748,7 @@  c_parser_omp_for_loop (location_t loc, c
   if (!fail)
     {
       stmt = c_finish_omp_for (loc, code, declv, NULL, initv, condv,
-			       incrv, body, pre_body);
+			       incrv, body, pre_body, true);
 
       /* Check for iterators appearing in lb, b or incr expressions.  */
       if (stmt && !c_omp_check_loop_iv (stmt, declv, NULL))
@@ -16108,7 +16845,9 @@  omp_split_clauses (location_t loc, enum
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
-	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)	\
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NONTEMPORAL))
 
 static tree
 c_parser_omp_simd (location_t loc, c_parser *parser,
@@ -16236,6 +16975,9 @@  c_parser_omp_for (location_t loc, c_pars
   return ret;
 }
 
+static tree c_parser_omp_taskloop (location_t, c_parser *, char *,
+				   omp_clause_mask, tree *, bool *);
+
 /* OpenMP 2.5:
    # pragma omp master new-line
      structured-block
@@ -16244,9 +16986,52 @@  c_parser_omp_for (location_t loc, c_pars
 */
 
 static tree
-c_parser_omp_master (location_t loc, c_parser *parser, bool *if_p)
+c_parser_omp_master (location_t loc, c_parser *parser,
+		     char *p_name, omp_clause_mask mask, tree *cclauses,
+		     bool *if_p)
 {
-  c_parser_skip_to_pragma_eol (parser);
+  tree block, clauses, ret;
+
+  strcat (p_name, " master");
+
+  if (c_parser_next_token_is (parser, CPP_NAME))
+    {
+      const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
+
+      if (strcmp (p, "taskloop") == 0)
+	{
+	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
+	  if (cclauses == NULL)
+	    cclauses = cclauses_buf;
+
+	  c_parser_consume_token (parser);
+	  if (!flag_openmp)  /* flag_openmp_simd  */
+	    return c_parser_omp_taskloop (loc, parser, p_name, mask, cclauses,
+					  if_p);
+	  block = c_begin_compound_stmt (true);
+	  ret = c_parser_omp_taskloop (loc, parser, p_name, mask, cclauses,
+				       if_p);
+	  block = c_end_compound_stmt (loc, block, true);
+	  if (ret == NULL_TREE)
+	    return ret;
+	  ret = c_finish_omp_master (loc, block);
+	  return ret;
+	}
+    }
+  if (!flag_openmp)  /* flag_openmp_simd  */
+    {
+      c_parser_skip_to_pragma_eol (parser, false);
+      return NULL_TREE;
+    }
+
+  if (cclauses)
+    {
+      clauses = c_parser_omp_all_clauses (parser, mask, p_name, false);
+      omp_split_clauses (loc, OMP_MASTER, mask, clauses, cclauses);
+    }
+  else
+    c_parser_skip_to_pragma_eol (parser);
+
   return c_finish_omp_master (loc, c_parser_omp_structured_block (parser,
 								  if_p));
 }
@@ -16508,19 +17293,38 @@  c_parser_omp_parallel (location_t loc, c
       c_parser_skip_to_pragma_eol (parser);
       return NULL_TREE;
     }
-  else if (!flag_openmp)  /* flag_openmp_simd  */
-    {
-      c_parser_skip_to_pragma_eol (parser, false);
-      return NULL_TREE;
-    }
   else if (cclauses == NULL && c_parser_next_token_is (parser, CPP_NAME))
     {
       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
-      if (strcmp (p, "sections") == 0)
+      if (strcmp (p, "master") == 0)
 	{
 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
-	  if (cclauses == NULL)
-	    cclauses = cclauses_buf;
+	  cclauses = cclauses_buf;
+
+	  c_parser_consume_token (parser);
+	  if (!flag_openmp)  /* flag_openmp_simd  */
+	    return c_parser_omp_master (loc, parser, p_name, mask, cclauses,
+					if_p);
+	  block = c_begin_omp_parallel ();
+	  tree ret = c_parser_omp_master (loc, parser, p_name, mask, cclauses,
+					  if_p);
+	  stmt = c_finish_omp_parallel (loc,
+					cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
+					block);
+	  OMP_PARALLEL_COMBINED (stmt) = 1;
+	  if (ret == NULL)
+	    return ret;
+	  return stmt;
+	}
+      else if (!flag_openmp)  /* flag_openmp_simd  */
+	{
+	  c_parser_skip_to_pragma_eol (parser, false);
+	  return NULL_TREE;
+	}
+      else if (strcmp (p, "sections") == 0)
+	{
+	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
+	  cclauses = cclauses_buf;
 
 	  c_parser_consume_token (parser);
 	  block = c_begin_omp_parallel ();
@@ -16532,6 +17336,11 @@  c_parser_omp_parallel (location_t loc, c
 	  return stmt;
 	}
     }
+  else if (!flag_openmp)  /* flag_openmp_simd  */
+    {
+      c_parser_skip_to_pragma_eol (parser, false);
+      return NULL_TREE;
+    }
 
   clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL);
   if (cclauses)
@@ -16591,7 +17400,8 @@  c_parser_omp_single (location_t loc, c_p
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
-	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY)	\
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION))
 
 static tree
 c_parser_omp_task (location_t loc, c_parser *parser, bool *if_p)
@@ -16608,16 +17418,35 @@  c_parser_omp_task (location_t loc, c_par
 
 /* OpenMP 3.0:
    # pragma omp taskwait new-line
+
+   OpenMP 5.0:
+   # pragma omp taskwait taskwait-clause[optseq] new-line
 */
 
+#define OMP_TASKWAIT_CLAUSE_MASK					\
+	(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
+
 static void
 c_parser_omp_taskwait (c_parser *parser)
 {
   location_t loc = c_parser_peek_token (parser)->location;
   c_parser_consume_pragma (parser);
-  c_parser_skip_to_pragma_eol (parser);
 
-  c_finish_omp_taskwait (loc);
+  tree clauses
+    = c_parser_omp_all_clauses (parser, OMP_TASKWAIT_CLAUSE_MASK,
+				"#pragma omp taskwait");
+
+  if (clauses)
+    {
+      tree stmt = make_node (OMP_TASK);
+      TREE_TYPE (stmt) = void_node;
+      OMP_TASK_CLAUSES (stmt) = clauses;
+      OMP_TASK_BODY (stmt) = NULL_TREE;
+      SET_EXPR_LOCATION (stmt, loc);
+      add_stmt (stmt);
+    }
+  else
+    c_finish_omp_taskwait (loc);
 }
 
 /* OpenMP 3.1:
@@ -16636,15 +17465,22 @@  c_parser_omp_taskyield (c_parser *parser
 
 /* OpenMP 4.0:
    # pragma omp taskgroup new-line
+
+   OpenMP 5.0:
+   # pragma omp taskgroup taskgroup-clause[optseq] new-line
 */
 
+#define OMP_TASKGROUP_CLAUSE_MASK				\
+	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASK_REDUCTION))
+
 static tree
-c_parser_omp_taskgroup (c_parser *parser, bool *if_p)
+c_parser_omp_taskgroup (location_t loc, c_parser *parser, bool *if_p)
 {
-  location_t loc = c_parser_peek_token (parser)->location;
-  c_parser_skip_to_pragma_eol (parser);
-  return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser,
-								     if_p));
+  tree clauses = c_parser_omp_all_clauses (parser, OMP_TASKGROUP_CLAUSE_MASK,
+					   "#pragma omp taskgroup");
+
+  tree body = c_parser_omp_structured_block (parser, if_p);
+  return c_finish_omp_taskgroup (loc, body, clauses);
 }
 
 /* OpenMP 4.0:
@@ -16850,7 +17686,7 @@  c_parser_omp_teams (location_t loc, c_pa
 	  if (!flag_openmp)  /* flag_openmp_simd  */
 	    return c_parser_omp_distribute (loc, parser, p_name, mask,
 					    cclauses, if_p);
-	  block = c_begin_compound_stmt (true);
+	  block = c_begin_omp_parallel ();
 	  ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses,
 					 if_p);
 	  block = c_end_compound_stmt (loc, block, true);
@@ -16862,6 +17698,7 @@  c_parser_omp_teams (location_t loc, c_pa
 	  OMP_TEAMS_CLAUSES (ret) = clauses;
 	  OMP_TEAMS_BODY (ret) = block;
 	  OMP_TEAMS_COMBINED (ret) = 1;
+	  SET_EXPR_LOCATION (ret, loc);
 	  return add_stmt (ret);
 	}
     }
@@ -16881,7 +17718,10 @@  c_parser_omp_teams (location_t loc, c_pa
   tree stmt = make_node (OMP_TEAMS);
   TREE_TYPE (stmt) = void_type_node;
   OMP_TEAMS_CLAUSES (stmt) = clauses;
-  OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser, if_p);
+  block = c_begin_omp_parallel ();
+  add_stmt (c_parser_omp_structured_block (parser, if_p));
+  OMP_TEAMS_BODY (stmt) = c_end_compound_stmt (loc, block, true);
+  SET_EXPR_LOCATION (stmt, loc);
 
   return add_stmt (stmt);
 }
@@ -16929,6 +17769,8 @@  c_parser_omp_target_data (location_t loc
 	    *pc = OMP_CLAUSE_CHAIN (*pc);
 	    continue;
 	  }
+      else if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_USE_DEVICE_PTR)
+	map_seen = 3;
       pc = &OMP_CLAUSE_CHAIN (*pc);
     }
 
@@ -16937,7 +17779,7 @@  c_parser_omp_target_data (location_t loc
       if (map_seen == 0)
 	error_at (loc,
 		  "%<#pragma omp target data%> must contain at least "
-		  "one %<map%> clause");
+		  "one %<map%> or %<use_device_ptr%> clause");
       return NULL_TREE;
     }
 
@@ -17196,6 +18038,10 @@  c_parser_omp_target (c_parser *parser, e
       return false;
     }
 
+  if (flag_openmp)
+    omp_requires_mask
+      = (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED);
+
   if (c_parser_next_token_is (parser, CPP_NAME))
     {
       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
@@ -17296,6 +18142,7 @@  c_parser_omp_target (c_parser *parser, e
 	  OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
 	  OMP_TARGET_BODY (stmt) = block;
 	  OMP_TARGET_COMBINED (stmt) = 1;
+	  SET_EXPR_LOCATION (stmt, loc);
 	  add_stmt (stmt);
 	  pc = &OMP_TARGET_CLAUSES (stmt);
 	  goto check_clauses;
@@ -18082,6 +18929,176 @@  c_parser_omp_declare (c_parser *parser,
   c_parser_skip_to_pragma_eol (parser);
 }
 
+/* OpenMP 5.0
+   #pragma omp requires clauses[optseq] new-line  */
+
+static void
+c_parser_omp_requires (c_parser *parser)
+{
+  bool first = true;
+  enum omp_requires new_req = (enum omp_requires) 0;
+
+  c_parser_consume_pragma (parser);
+
+  location_t loc = c_parser_peek_token (parser)->location;
+  while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
+    {
+      if (!first && c_parser_next_token_is (parser, CPP_COMMA))
+	c_parser_consume_token (parser);
+
+      first = false;
+
+      if (c_parser_next_token_is (parser, CPP_NAME))
+	{
+	  const char *p
+	    = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
+	  location_t cloc = c_parser_peek_token (parser)->location;
+	  enum omp_requires this_req = (enum omp_requires) 0;
+
+	  if (!strcmp (p, "unified_address"))
+	    this_req = OMP_REQUIRES_UNIFIED_ADDRESS;
+	  else if (!strcmp (p, "unified_shared_memory"))
+	    this_req = OMP_REQUIRES_UNIFIED_SHARED_MEMORY;
+	  else if (!strcmp (p, "dynamic_allocators"))
+	    this_req = OMP_REQUIRES_DYNAMIC_ALLOCATORS;
+	  else if (!strcmp (p, "reverse_offload"))
+	    this_req = OMP_REQUIRES_REVERSE_OFFLOAD;
+	  else if (!strcmp (p, "atomic_default_mem_order"))
+	    {
+	      c_parser_consume_token (parser);
+
+	      matching_parens parens;
+	      if (parens.require_open (parser))
+		{
+		  if (c_parser_next_token_is (parser, CPP_NAME))
+		    {
+		      tree v = c_parser_peek_token (parser)->value;
+		      p = IDENTIFIER_POINTER (v);
+
+		      if (!strcmp (p, "seq_cst"))
+			this_req
+			  = (enum omp_requires) OMP_MEMORY_ORDER_SEQ_CST;
+		      else if (!strcmp (p, "relaxed"))
+			this_req
+			  = (enum omp_requires) OMP_MEMORY_ORDER_RELAXED;
+		      else if (!strcmp (p, "acq_rel"))
+			this_req
+			  = (enum omp_requires) OMP_MEMORY_ORDER_ACQ_REL;
+		    }
+		  if (this_req == 0)
+		    {
+		      error_at (c_parser_peek_token (parser)->location,
+				"expected %<seq_cst%>, %<relaxed%> or "
+				"%<acq_rel%>");
+		      if (c_parser_peek_2nd_token (parser)->type
+			  == CPP_CLOSE_PAREN)
+			c_parser_consume_token (parser);
+		    }
+		  else
+		    c_parser_consume_token (parser);
+
+		  parens.skip_until_found_close (parser);
+		  if (this_req == 0)
+		    {
+		      c_parser_skip_to_pragma_eol (parser, false);
+		      return;
+		    }
+		}
+	      p = NULL;
+	    }
+	  else
+	    {
+	      error_at (cloc, "expected %<unified_address%>, "
+			      "%<unified_shared_memory%>, "
+			      "%<dynamic_allocators%>, "
+			       "%<reverse_offload%> "
+			       "or %<atomic_default_mem_order%> clause");
+	      c_parser_skip_to_pragma_eol (parser, false);
+	      return;
+	    }
+	  if (p)
+	    c_parser_consume_token (parser);
+	  if (this_req)
+	    {
+	      if ((this_req & ~OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0)
+		{
+		  if ((this_req & new_req) != 0)
+		    error_at (cloc, "too many %qs clauses", p);
+		  if (this_req != OMP_REQUIRES_DYNAMIC_ALLOCATORS
+		      && (omp_requires_mask & OMP_REQUIRES_TARGET_USED) != 0)
+		    error_at (cloc, "%qs clause used lexically after first "
+				    "target construct or offloading API", p);
+		}
+	      else if ((new_req & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0)
+		{
+		  error_at (cloc, "too many %qs clauses",
+			    "atomic_default_mem_order");
+		  this_req = (enum omp_requires) 0;
+		}
+	      else if ((omp_requires_mask
+			& OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0)
+		{
+		  error_at (cloc, "more than one %<atomic_default_mem_order%>"
+				  " clause in a single compilation unit");
+		  this_req
+		    = (enum omp_requires)
+		       (omp_requires_mask
+			& OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER);
+		}
+	      else if ((omp_requires_mask
+			& OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED) != 0)
+		error_at (cloc, "%<atomic_default_mem_order%> clause used "
+				"lexically after first %<atomic%> construct "
+				"without memory order clause");
+	      new_req = (enum omp_requires) (new_req | this_req);
+	      omp_requires_mask
+		= (enum omp_requires) (omp_requires_mask | this_req);
+	      continue;
+	    }
+	}
+      break;
+    }
+  c_parser_skip_to_pragma_eol (parser);
+
+  if (new_req == 0)
+    error_at (loc, "%<pragma omp requires%> requires at least one clause");
+}
+
+/* Helper function for c_parser_omp_taskloop.
+   Disallow zero sized or potentially zero sized task reductions.  */
+
+static tree
+c_finish_taskloop_clauses (tree clauses)
+{
+  tree *pc = &clauses;
+  for (tree c = clauses; c; c = *pc)
+    {
+      bool remove = false;
+      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
+	{
+	  tree type = strip_array_types (TREE_TYPE (OMP_CLAUSE_DECL (c)));
+	  if (integer_zerop (TYPE_SIZE_UNIT (type)))
+	    {
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"zero sized type %qT in %<reduction%> clause", type);
+	      remove = true;
+	    }
+	  else if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
+	    {
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"variable sized type %qT in %<reduction%> clause",
+			type);
+	      remove = true;
+	    }
+	}
+      if (remove)
+	*pc = OMP_CLAUSE_CHAIN (c);
+      else
+	pc = &OMP_CLAUSE_CHAIN (c);
+    }
+  return clauses;
+}
+
 /* OpenMP 4.5:
    #pragma omp taskloop taskloop-clause[optseq] new-line
      for-loop
@@ -18103,7 +19120,9 @@  c_parser_omp_declare (c_parser *parser,
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP)	\
-	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY)	\
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION))
 
 static tree
 c_parser_omp_taskloop (location_t loc, c_parser *parser,
@@ -18114,6 +19133,10 @@  c_parser_omp_taskloop (location_t loc, c
 
   strcat (p_name, " taskloop");
   mask |= OMP_TASKLOOP_CLAUSE_MASK;
+  /* #pragma omp parallel master taskloop{, simd} disallow in_reduction
+     clause.  */
+  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0)
+    mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION);
 
   if (c_parser_next_token_is (parser, CPP_NAME))
     {
@@ -18124,7 +19147,6 @@  c_parser_omp_taskloop (location_t loc, c
 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
 	  if (cclauses == NULL)
 	    cclauses = cclauses_buf;
-	  mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION);
 	  c_parser_consume_token (parser);
 	  if (!flag_openmp)  /* flag_openmp_simd  */
 	    return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
@@ -18138,6 +19160,8 @@  c_parser_omp_taskloop (location_t loc, c
 	  TREE_TYPE (ret) = void_type_node;
 	  OMP_FOR_BODY (ret) = block;
 	  OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
+	  OMP_FOR_CLAUSES (ret)
+	    = c_finish_taskloop_clauses (OMP_FOR_CLAUSES (ret));
 	  SET_EXPR_LOCATION (ret, loc);
 	  add_stmt (ret);
 	  return ret;
@@ -18156,6 +19180,7 @@  c_parser_omp_taskloop (location_t loc, c
       clauses = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
     }
 
+  clauses = c_finish_taskloop_clauses (clauses);
   block = c_begin_compound_stmt (true);
   ret = c_parser_omp_for_loop (loc, parser, OMP_TASKLOOP, clauses, NULL, if_p);
   block = c_end_compound_stmt (loc, block, true);
@@ -18223,7 +19248,8 @@  c_parser_omp_construct (c_parser *parser
       stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL, if_p);
       break;
     case PRAGMA_OMP_MASTER:
-      stmt = c_parser_omp_master (loc, parser, if_p);
+      strcpy (p_name, "#pragma omp");
+      stmt = c_parser_omp_master (loc, parser, p_name, mask, NULL, if_p);
       break;
     case PRAGMA_OMP_PARALLEL:
       strcpy (p_name, "#pragma omp");
@@ -18244,7 +19270,7 @@  c_parser_omp_construct (c_parser *parser
       stmt = c_parser_omp_task (loc, parser, if_p);
       break;
     case PRAGMA_OMP_TASKGROUP:
-      stmt = c_parser_omp_taskgroup (parser, if_p);
+      stmt = c_parser_omp_taskgroup (loc, parser, if_p);
       break;
     case PRAGMA_OMP_TASKLOOP:
       strcpy (p_name, "#pragma omp");
--- gcc/c/c-typeck.c	(.../trunk)	(revision 265884)
+++ gcc/c/c-typeck.c	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -12525,6 +12525,11 @@  c_finish_omp_cancel (location_t loc, tre
   tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
   if (ifc != NULL_TREE)
     {
+      if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
+	  && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
+	error_at (OMP_CLAUSE_LOCATION (ifc),
+		  "expected %<cancel%> %<if%> clause modifier");
+
       tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc));
       ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
 			     boolean_type_node, OMP_CLAUSE_IF_EXPR (ifc),
@@ -12717,7 +12722,9 @@  handle_omp_array_sections_1 (tree c, tre
       if (!integer_nonzerop (length))
 	{
 	  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
-	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
+	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
+	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
 	    {
 	      if (integer_zerop (length))
 		{
@@ -12783,7 +12790,9 @@  handle_omp_array_sections_1 (tree c, tre
 	      if (tree_int_cst_equal (size, low_bound))
 		{
 		  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
-		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
 		    {
 		      error_at (OMP_CLAUSE_LOCATION (c),
 				"zero length array section in %qs clause",
@@ -12802,7 +12811,9 @@  handle_omp_array_sections_1 (tree c, tre
 	  else if (length == NULL_TREE)
 	    {
 	      if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
-		  && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
+		  && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
+		  && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
+		  && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
 		maybe_zero_len = true;
 	      if (first_non_one == types.length ())
 		first_non_one++;
@@ -12838,7 +12849,9 @@  handle_omp_array_sections_1 (tree c, tre
       else if (length == NULL_TREE)
 	{
 	  if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
-	      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
+	      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
+	      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
+	      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
 	    maybe_zero_len = true;
 	  if (first_non_one == types.length ())
 	    first_non_one++;
@@ -12910,7 +12923,13 @@  handle_omp_array_sections (tree c, enum
   bool maybe_zero_len = false;
   unsigned int first_non_one = 0;
   auto_vec<tree, 10> types;
-  tree first = handle_omp_array_sections_1 (c, OMP_CLAUSE_DECL (c), types,
+  tree *tp = &OMP_CLAUSE_DECL (c);
+  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
+      && TREE_CODE (*tp) == TREE_LIST
+      && TREE_PURPOSE (*tp)
+      && TREE_CODE (TREE_PURPOSE (*tp)) == TREE_VEC)
+    tp = &TREE_VALUE (*tp);
+  tree first = handle_omp_array_sections_1 (c, *tp, types,
 					    maybe_zero_len, first_non_one,
 					    ort);
   if (first == error_mark_node)
@@ -12919,7 +12938,7 @@  handle_omp_array_sections (tree c, enum
     return false;
   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
     {
-      tree t = OMP_CLAUSE_DECL (c);
+      tree t = *tp;
       tree tem = NULL_TREE;
       /* Need to evaluate side effects in the length expressions
 	 if any.  */
@@ -12938,7 +12957,7 @@  handle_omp_array_sections (tree c, enum
       if (tem)
 	first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
       first = c_fully_fold (first, false, NULL, true);
-      OMP_CLAUSE_DECL (c) = first;
+      *tp = first;
     }
   else
     {
@@ -13010,7 +13029,9 @@  handle_omp_array_sections (tree c, enum
 
 	      if (i > first_non_one
 		  && ((length && integer_nonzerop (length))
-		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION))
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
 		continue;
 	      if (length)
 		l = fold_convert (sizetype, length);
@@ -13038,7 +13059,9 @@  handle_omp_array_sections (tree c, enum
 		  tree eltype = TREE_TYPE (types[num - 1]);
 		  while (TREE_CODE (eltype) == ARRAY_TYPE)
 		    eltype = TREE_TYPE (eltype);
-		  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
+		  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
 		    {
 		      if (integer_zerop (size)
 			  || integer_zerop (size_in_bytes (eltype)))
@@ -13062,10 +13085,13 @@  handle_omp_array_sections (tree c, enum
 	}
       if (side_effects)
 	size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
-      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
+      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+	  || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
+	  || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
 	{
 	  size = size_binop (MINUS_EXPR, size, size_one_node);
 	  size = c_fully_fold (size, false, NULL);
+	  size = save_expr (size);
 	  tree index_type = build_index_type (size);
 	  tree eltype = TREE_TYPE (first);
 	  while (TREE_CODE (eltype) == ARRAY_TYPE)
@@ -13195,6 +13221,178 @@  c_find_omp_placeholder_r (tree *tp, int
   return NULL_TREE;
 }
 
+/* Similarly, but also walk aggregate fields.  */
+
+struct c_find_omp_var_s { tree var; hash_set<tree> *pset; };
+
+static tree
+c_find_omp_var_r (tree *tp, int *, void *data)
+{
+  if (*tp == ((struct c_find_omp_var_s *) data)->var)
+    return *tp;
+  if (RECORD_OR_UNION_TYPE_P (*tp))
+    {
+      tree field;
+      hash_set<tree> *pset = ((struct c_find_omp_var_s *) data)->pset;
+
+      for (field = TYPE_FIELDS (*tp); field;
+	   field = DECL_CHAIN (field))
+	if (TREE_CODE (field) == FIELD_DECL)
+	  {
+	    tree ret = walk_tree (&DECL_FIELD_OFFSET (field),
+				  c_find_omp_var_r, data, pset);
+	    if (ret)
+	      return ret;
+	    ret = walk_tree (&DECL_SIZE (field), c_find_omp_var_r, data, pset);
+	    if (ret)
+	      return ret;
+	    ret = walk_tree (&DECL_SIZE_UNIT (field), c_find_omp_var_r, data,
+			     pset);
+	    if (ret)
+	      return ret;
+	    ret = walk_tree (&TREE_TYPE (field), c_find_omp_var_r, data, pset);
+	    if (ret)
+	      return ret;
+	  }
+    }
+  else if (INTEGRAL_TYPE_P (*tp))
+    return walk_tree (&TYPE_MAX_VALUE (*tp), c_find_omp_var_r, data,
+		      ((struct c_find_omp_var_s *) data)->pset);
+  return NULL_TREE;
+}
+
+/* Finish OpenMP iterators ITER.  Return true if they are errorneous
+   and clauses containing them should be removed.  */
+
+static bool
+c_omp_finish_iterators (tree iter)
+{
+  bool ret = false;
+  for (tree it = iter; it; it = TREE_CHAIN (it))
+    {
+      tree var = TREE_VEC_ELT (it, 0);
+      tree begin = TREE_VEC_ELT (it, 1);
+      tree end = TREE_VEC_ELT (it, 2);
+      tree step = TREE_VEC_ELT (it, 3);
+      tree orig_step;
+      tree type = TREE_TYPE (var);
+      location_t loc = DECL_SOURCE_LOCATION (var);
+      if (type == error_mark_node)
+	{
+	  ret = true;
+	  continue;
+	}
+      if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
+	{
+	  error_at (loc, "iterator %qD has neither integral nor pointer type",
+		    var);
+	  ret = true;
+	  continue;
+	}
+      else if (TYPE_ATOMIC (type))
+	{
+	  error_at (loc, "iterator %qD has %<_Atomic%> qualified type", var);
+	  ret = true;
+	  continue;
+	}
+      else if (TYPE_READONLY (type))
+	{
+	  error_at (loc, "iterator %qD has const qualified type", var);
+	  ret = true;
+	  continue;
+	}
+      else if (step == error_mark_node
+	       || TREE_TYPE (step) == error_mark_node)
+	{
+	  ret = true;
+	  continue;
+	}
+      else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
+	{
+	  error_at (EXPR_LOC_OR_LOC (step, loc),
+		    "iterator step with non-integral type");
+	  ret = true;
+	  continue;
+	}
+      begin = c_fully_fold (build_c_cast (loc, type, begin), false, NULL);
+      end = c_fully_fold (build_c_cast (loc, type, end), false, NULL);
+      orig_step = save_expr (c_fully_fold (step, false, NULL));
+      tree stype = POINTER_TYPE_P (type) ? sizetype : type;
+      step = c_fully_fold (build_c_cast (loc, stype, orig_step), false, NULL);
+      if (POINTER_TYPE_P (type))
+	{
+	  begin = save_expr (begin);
+	  step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
+	  step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
+				  fold_convert (sizetype, step),
+				  fold_convert (sizetype, begin));
+	  step = fold_convert (ssizetype, step);
+	}
+      if (integer_zerop (step))
+	{
+	  error_at (loc, "iterator %qD has zero step", var);
+	  ret = true;
+	  continue;
+	}
+
+      if (begin == error_mark_node
+	  || end == error_mark_node
+	  || step == error_mark_node
+	  || orig_step == error_mark_node)
+	{
+	  ret = true;
+	  continue;
+	}
+      hash_set<tree> pset;
+      tree it2;
+      for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
+	{
+	  tree var2 = TREE_VEC_ELT (it2, 0);
+	  tree begin2 = TREE_VEC_ELT (it2, 1);
+	  tree end2 = TREE_VEC_ELT (it2, 2);
+	  tree step2 = TREE_VEC_ELT (it2, 3);
+	  tree type2 = TREE_TYPE (var2);
+	  location_t loc2 = DECL_SOURCE_LOCATION (var2);
+	  struct c_find_omp_var_s data = { var, &pset };
+	  if (walk_tree (&type2, c_find_omp_var_r, &data, &pset))
+	    {
+	      error_at (loc2,
+			"type of iterator %qD refers to outer iterator %qD",
+			var2, var);
+	      break;
+	    }
+	  else if (walk_tree (&begin2, c_find_omp_var_r, &data, &pset))
+	    {
+	      error_at (EXPR_LOC_OR_LOC (begin2, loc2),
+			"begin expression refers to outer iterator %qD", var);
+	      break;
+	    }
+	  else if (walk_tree (&end2, c_find_omp_var_r, &data, &pset))
+	    {
+	      error_at (EXPR_LOC_OR_LOC (end2, loc2),
+			"end expression refers to outer iterator %qD", var);
+	      break;
+	    }
+	  else if (walk_tree (&step2, c_find_omp_var_r, &data, &pset))
+	    {
+	      error_at (EXPR_LOC_OR_LOC (step2, loc2),
+			"step expression refers to outer iterator %qD", var);
+	      break;
+	    }
+	}
+      if (it2)
+	{
+	  ret = true;
+	  continue;
+	}
+      TREE_VEC_ELT (it, 1) = begin;
+      TREE_VEC_ELT (it, 2) = end;
+      TREE_VEC_ELT (it, 3) = step;
+      TREE_VEC_ELT (it, 4) = orig_step;
+    }
+  return ret;
+}
+
 /* For all elements of CLAUSES, validate them against their constraints.
    Remove any elements from the list that are invalid.  */
 
@@ -13212,14 +13410,20 @@  c_finish_omp_clauses (tree clauses, enum
   bool ordered_seen = false;
   tree schedule_clause = NULL_TREE;
   bool oacc_async = false;
+  tree last_iterators = NULL_TREE;
+  bool last_iterators_remove = false;
+  tree *nogroup_seen = NULL;
+  bool reduction_seen = false;
 
   bitmap_obstack_initialize (NULL);
   bitmap_initialize (&generic_head, &bitmap_default_obstack);
   bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
   bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
   bitmap_initialize (&aligned_head, &bitmap_default_obstack);
+  /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead.  */
   bitmap_initialize (&map_head, &bitmap_default_obstack);
   bitmap_initialize (&map_field_head, &bitmap_default_obstack);
+  /* If ort == C_ORT_OMP used as nontemporal_head instead.  */
   bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
 
   if (ort & C_ORT_ACC)
@@ -13248,6 +13452,10 @@  c_finish_omp_clauses (tree clauses, enum
 	  goto check_dup_generic;
 
 	case OMP_CLAUSE_REDUCTION:
+	  reduction_seen = true;
+	  /* FALLTHRU */
+	case OMP_CLAUSE_IN_REDUCTION:
+	case OMP_CLAUSE_TASK_REDUCTION:
 	  need_implicitly_determined = true;
 	  t = OMP_CLAUSE_DECL (c);
 	  if (TREE_CODE (t) == TREE_LIST)
@@ -13296,6 +13504,7 @@  c_finish_omp_clauses (tree clauses, enum
 		  break;
 		}
 	      size = size_binop (MINUS_EXPR, size, size_one_node);
+	      size = save_expr (size);
 	      tree index_type = build_index_type (size);
 	      tree atype = build_array_type (type, index_type);
 	      tree ptype = build_pointer_type (type);
@@ -13311,6 +13520,28 @@  c_finish_omp_clauses (tree clauses, enum
 	      remove = true;
 	      break;
 	    }
+	  if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
+	      || OMP_CLAUSE_REDUCTION_TASK (c))
+	    {
+	      /* Disallow zero sized or potentially zero sized task
+		 reductions.  */
+	      if (integer_zerop (TYPE_SIZE_UNIT (type)))
+		{
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			    "zero sized type %qT in %qs clause", type,
+			    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+		  remove = true;
+		  break;
+		}
+	      else if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
+		{
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			    "variable sized type %qT in %qs clause", type,
+			    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+		  remove = true;
+		  break;
+		}
+	    }
 	  if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE
 	      && (FLOAT_TYPE_P (type)
 		  || TREE_CODE (type) == COMPLEX_TYPE))
@@ -13512,7 +13743,7 @@  c_finish_omp_clauses (tree clauses, enum
 	  if (TYPE_ATOMIC (TREE_TYPE (t)))
 	    {
 	      error_at (OMP_CLAUSE_LOCATION (c),
-		    "%<_Atomic%> %qD in %<linear%> clause", t);
+			"%<_Atomic%> %qD in %<linear%> clause", t);
 	      remove = true;
 	      break;
 	    }
@@ -13570,7 +13801,9 @@  c_finish_omp_clauses (tree clauses, enum
 	    {
 	      if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
 		{
-		  error ("%qD appears more than once in reduction clauses", t);
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			    "%qD appears more than once in reduction clauses",
+			    t);
 		  remove = true;
 		}
 	      else
@@ -13588,9 +13821,11 @@  c_finish_omp_clauses (tree clauses, enum
 		   && bitmap_bit_p (&map_head, DECL_UID (t)))
 	    {
 	      if (ort == C_ORT_ACC)
-		error ("%qD appears more than once in data clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears more than once in data clauses", t);
 	      else
-		error ("%qD appears both in data and map clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears both in data and map clauses", t);
 	      remove = true;
 	    }
 	  else
@@ -13617,9 +13852,11 @@  c_finish_omp_clauses (tree clauses, enum
 	  else if (bitmap_bit_p (&map_head, DECL_UID (t)))
 	    {
 	      if (ort == C_ORT_ACC)
-		error ("%qD appears more than once in data clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears more than once in data clauses", t);
 	      else
-		error ("%qD appears both in data and map clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears both in data and map clauses", t);
 	      remove = true;
 	    }
 	  else
@@ -13681,6 +13918,25 @@  c_finish_omp_clauses (tree clauses, enum
 	    bitmap_set_bit (&aligned_head, DECL_UID (t));
 	  break;
 
+	case OMP_CLAUSE_NONTEMPORAL:
+	  t = OMP_CLAUSE_DECL (c);
+	  if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
+	    {
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qE is not a variable in %<nontemporal%> clause", t);
+	      remove = true;
+	    }
+	  else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
+	    {
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qE appears more than once in %<nontemporal%> "
+			"clauses", t);
+	      remove = true;
+	    }
+	  else
+	    bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
+	  break;
+
 	case OMP_CLAUSE_DEPEND:
 	  t = OMP_CLAUSE_DECL (c);
 	  if (t == NULL_TREE)
@@ -13717,22 +13973,89 @@  c_finish_omp_clauses (tree clauses, enum
 		}
 	      break;
 	    }
+	  if (TREE_CODE (t) == TREE_LIST
+	      && TREE_PURPOSE (t)
+	      && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC)
+	    {
+	      if (TREE_PURPOSE (t) != last_iterators)
+		last_iterators_remove
+		  = c_omp_finish_iterators (TREE_PURPOSE (t));
+	      last_iterators = TREE_PURPOSE (t);
+	      t = TREE_VALUE (t);
+	      if (last_iterators_remove)
+		t = error_mark_node;
+	    }
+	  else
+	    last_iterators = NULL_TREE;
 	  if (TREE_CODE (t) == TREE_LIST)
 	    {
 	      if (handle_omp_array_sections (c, ort))
 		remove = true;
+	      else if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
+		{
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			    "%<depend%> clause with %<depobj%> dependence "
+			    "type on array section");
+		  remove = true;
+		}
 	      break;
 	    }
 	  if (t == error_mark_node)
 	    remove = true;
-	  else if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
+	  else if (!lvalue_p (t))
 	    {
 	      error_at (OMP_CLAUSE_LOCATION (c),
-			"%qE is not a variable in %<depend%> clause", t);
+			"%qE is not lvalue expression nor array section in "
+			"%<depend%> clause", t);
 	      remove = true;
 	    }
-	  else if (!c_mark_addressable (t))
-	    remove = true;
+	  else if (TREE_CODE (t) == COMPONENT_REF
+		   && DECL_C_BIT_FIELD (TREE_OPERAND (t, 1)))
+	    {
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"bit-field %qE in %qs clause", t, "depend");
+	      remove = true;
+	    }
+	  else if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
+	    {
+	      if (!c_omp_depend_t_p (TREE_TYPE (t)))
+		{
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			    "%qE does not have %<omp_depend_t%> type in "
+			    "%<depend%> clause with %<depobj%> dependence "
+			    "type", t);
+		  remove = true;
+		}
+	    }
+	  else if (c_omp_depend_t_p (TREE_TYPE (t)))
+	    {
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qE should not have %<omp_depend_t%> type in "
+			"%<depend%> clause with dependence type other than "
+			"%<depobj%>", t);
+	      remove = true;
+	    }
+	  if (!remove)
+	    {
+	      tree addr = build_unary_op (OMP_CLAUSE_LOCATION (c), ADDR_EXPR,
+					  t, false);
+	      if (addr == error_mark_node)
+		remove = true;
+	      else
+		{
+		  t = build_indirect_ref (OMP_CLAUSE_LOCATION (c), addr,
+					  RO_UNARY_STAR);
+		  if (t == error_mark_node)
+		    remove = true;
+		  else if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
+			   && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
+			   && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
+			       == TREE_VEC))
+		    TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
+		  else
+		    OMP_CLAUSE_DECL (c) = t;
+		}
+	    }
 	  break;
 
 	case OMP_CLAUSE_MAP:
@@ -13774,14 +14097,17 @@  c_finish_omp_clauses (tree clauses, enum
 		      if (bitmap_bit_p (&map_head, DECL_UID (t)))
 			{
 			  if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
-			    error ("%qD appears more than once in motion"
-				   " clauses", t);
+			    error_at (OMP_CLAUSE_LOCATION (c),
+				      "%qD appears more than once in motion "
+				      "clauses", t);
 			  else if (ort == C_ORT_ACC)
-			    error ("%qD appears more than once in data"
-				   " clauses", t);
+			    error_at (OMP_CLAUSE_LOCATION (c),
+				      "%qD appears more than once in data "
+				      "clauses", t);
 			  else
-			    error ("%qD appears more than once in map"
-				   " clauses", t);
+			    error_at (OMP_CLAUSE_LOCATION (c),
+				      "%qD appears more than once in map "
+				      "clauses", t);
 			  remove = true;
 			}
 		      else
@@ -13891,15 +14217,18 @@  c_finish_omp_clauses (tree clauses, enum
 	      if (bitmap_bit_p (&generic_head, DECL_UID (t))
 		  || bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
 		{
-		  error ("%qD appears more than once in data clauses", t);
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			    "%qD appears more than once in data clauses", t);
 		  remove = true;
 		}
 	      else if (bitmap_bit_p (&map_head, DECL_UID (t)))
 		{
 		  if (ort == C_ORT_ACC)
-		    error ("%qD appears more than once in data clauses", t);
+		    error_at (OMP_CLAUSE_LOCATION (c),
+			      "%qD appears more than once in data clauses", t);
 		  else
-		    error ("%qD appears both in data and map clauses", t);
+		    error_at (OMP_CLAUSE_LOCATION (c),
+			      "%qD appears both in data and map clauses", t);
 		  remove = true;
 		}
 	      else
@@ -13908,20 +14237,25 @@  c_finish_omp_clauses (tree clauses, enum
 	  else if (bitmap_bit_p (&map_head, DECL_UID (t)))
 	    {
 	      if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
-		error ("%qD appears more than once in motion clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears more than once in motion clauses", t);
 	      else if (ort == C_ORT_ACC)
-		error ("%qD appears more than once in data clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears more than once in data clauses", t);
 	      else
-		error ("%qD appears more than once in map clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears more than once in map clauses", t);
 	      remove = true;
 	    }
 	  else if (bitmap_bit_p (&generic_head, DECL_UID (t))
 		   || bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
 	    {
 	      if (ort == C_ORT_ACC)
-		error ("%qD appears more than once in data clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears more than once in data clauses", t);
 	      else
-		error ("%qD appears both in data and map clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears both in data and map clauses", t);
 	      remove = true;
 	    }
 	  else
@@ -14041,7 +14375,6 @@  c_finish_omp_clauses (tree clauses, enum
 	case OMP_CLAUSE_PRIORITY:
 	case OMP_CLAUSE_GRAINSIZE:
 	case OMP_CLAUSE_NUM_TASKS:
-	case OMP_CLAUSE_NOGROUP:
 	case OMP_CLAUSE_THREADS:
 	case OMP_CLAUSE_SIMD:
 	case OMP_CLAUSE_HINT:
@@ -14063,30 +14396,12 @@  c_finish_omp_clauses (tree clauses, enum
 	  pc = &OMP_CLAUSE_CHAIN (c);
 	  continue;
 
+	case OMP_CLAUSE_NOGROUP:
+	  nogroup_seen = pc;
+	  pc = &OMP_CLAUSE_CHAIN (c);
+	  continue;
+
 	case OMP_CLAUSE_SCHEDULE:
-	  if (OMP_CLAUSE_SCHEDULE_KIND (c) & OMP_CLAUSE_SCHEDULE_NONMONOTONIC)
-	    {
-	      const char *p = NULL;
-	      switch (OMP_CLAUSE_SCHEDULE_KIND (c) & OMP_CLAUSE_SCHEDULE_MASK)
-		{
-		case OMP_CLAUSE_SCHEDULE_STATIC: p = "static"; break;
-		case OMP_CLAUSE_SCHEDULE_DYNAMIC: break;
-		case OMP_CLAUSE_SCHEDULE_GUIDED: break;
-		case OMP_CLAUSE_SCHEDULE_AUTO: p = "auto"; break;
-		case OMP_CLAUSE_SCHEDULE_RUNTIME: p = "runtime"; break;
-		default: gcc_unreachable ();
-		}
-	      if (p)
-		{
-		  error_at (OMP_CLAUSE_LOCATION (c),
-			    "%<nonmonotonic%> modifier specified for %qs "
-			    "schedule kind", p);
-		  OMP_CLAUSE_SCHEDULE_KIND (c)
-		    = (enum omp_clause_schedule_kind)
-		      (OMP_CLAUSE_SCHEDULE_KIND (c)
-		       & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
-		}
-	    }
 	  schedule_clause = c;
 	  pc = &OMP_CLAUSE_CHAIN (c);
 	  continue;
@@ -14145,10 +14460,6 @@  c_finish_omp_clauses (tree clauses, enum
 		case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
 		  break;
 		case OMP_CLAUSE_DEFAULT_SHARED:
-		  /* const vars may be specified in firstprivate clause.  */
-		  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
-		      && TREE_READONLY (t))
-		    break;
 		  share_name = "shared";
 		  break;
 		case OMP_CLAUSE_DEFAULT_PRIVATE:
@@ -14165,6 +14476,15 @@  c_finish_omp_clauses (tree clauses, enum
 			    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
 		  remove = true;
 		}
+	      else if (TREE_READONLY (t)
+		       && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
+		       && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE)
+		{
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			    "%<const%> qualified %qE may appear only in "
+			    "%<shared%> or %<firstprivate%> clauses", t);
+		  remove = true;
+		}
 	    }
 	}
 
@@ -14222,6 +14542,14 @@  c_finish_omp_clauses (tree clauses, enum
 	  pc = &OMP_CLAUSE_CHAIN (c);
       }
 
+  if (nogroup_seen && reduction_seen)
+    {
+      error_at (OMP_CLAUSE_LOCATION (*nogroup_seen),
+		"%<nogroup%> clause must not be used together with "
+		"%<reduction%> clause");
+      *nogroup_seen = OMP_CLAUSE_CHAIN (*nogroup_seen);
+    }
+
   bitmap_obstack_release (NULL);
   return clauses;
 }
--- gcc/c-family/c-common.h	(.../trunk)	(revision 265884)
+++ gcc/c-family/c-common.h	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -1149,18 +1149,21 @@  enum c_omp_region_type
 };
 
 extern tree c_finish_omp_master (location_t, tree);
-extern tree c_finish_omp_taskgroup (location_t, tree);
+extern tree c_finish_omp_taskgroup (location_t, tree, tree);
 extern tree c_finish_omp_critical (location_t, tree, tree, tree);
 extern tree c_finish_omp_ordered (location_t, tree, tree);
 extern void c_finish_omp_barrier (location_t);
 extern tree c_finish_omp_atomic (location_t, enum tree_code, enum tree_code,
-				 tree, tree, tree, tree, tree, bool, bool,
-				 bool = false);
-extern void c_finish_omp_flush (location_t);
+				 tree, tree, tree, tree, tree, bool,
+				 enum omp_memory_order, bool = false);
+extern bool c_omp_depend_t_p (tree);
+extern void c_finish_omp_depobj (location_t, tree, enum omp_clause_depend_kind,
+				 tree);
+extern void c_finish_omp_flush (location_t, int);
 extern void c_finish_omp_taskwait (location_t);
 extern void c_finish_omp_taskyield (location_t);
 extern tree c_finish_omp_for (location_t, enum tree_code, tree, tree, tree,
-			      tree, tree, tree, tree);
+			      tree, tree, tree, tree, bool);
 extern bool c_omp_check_loop_iv (tree, tree, walk_tree_lh);
 extern bool c_omp_check_loop_iv_exprs (location_t, tree, tree, tree, tree,
 				       walk_tree_lh);
--- gcc/c-family/c-omp.c	(.../trunk)	(revision 265884)
+++ gcc/c-family/c-omp.c	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -28,8 +28,10 @@  along with GCC; see the file COPYING3.
 #include "c-common.h"
 #include "gimple-expr.h"
 #include "c-pragma.h"
+#include "stringpool.h"
 #include "omp-general.h"
 #include "gomp-constants.h"
+#include "memmodel.h"
 
 
 /* Complete a #pragma oacc wait construct.  LOC is the location of
@@ -70,7 +72,7 @@  c_finish_oacc_wait (location_t loc, tree
 }
 
 /* Complete a #pragma omp master construct.  STMT is the structured-block
-   that follows the pragma.  LOC is the l*/
+   that follows the pragma.  LOC is the location of the #pragma.  */
 
 tree
 c_finish_omp_master (location_t loc, tree stmt)
@@ -80,18 +82,21 @@  c_finish_omp_master (location_t loc, tre
   return t;
 }
 
-/* Complete a #pragma omp taskgroup construct.  STMT is the structured-block
-   that follows the pragma.  LOC is the l*/
+/* Complete a #pragma omp taskgroup construct.  BODY is the structured-block
+   that follows the pragma.  LOC is the location of the #pragma.  */
 
 tree
-c_finish_omp_taskgroup (location_t loc, tree stmt)
+c_finish_omp_taskgroup (location_t loc, tree body, tree clauses)
 {
-  tree t = add_stmt (build1 (OMP_TASKGROUP, void_type_node, stmt));
-  SET_EXPR_LOCATION (t, loc);
-  return t;
+  tree stmt = make_node (OMP_TASKGROUP);
+  TREE_TYPE (stmt) = void_type_node;
+  OMP_TASKGROUP_BODY (stmt) = body;
+  OMP_TASKGROUP_CLAUSES (stmt) = clauses;
+  SET_EXPR_LOCATION (stmt, loc);
+  return add_stmt (stmt);
 }
 
-/* Complete a #pragma omp critical construct.  STMT is the structured-block
+/* Complete a #pragma omp critical construct.  BODY is the structured-block
    that follows the pragma, NAME is the identifier in the pragma, or null
    if it was omitted.  LOC is the location of the #pragma.  */
 
@@ -181,8 +186,8 @@  c_finish_omp_taskyield (location_t loc)
 tree
 c_finish_omp_atomic (location_t loc, enum tree_code code,
 		     enum tree_code opcode, tree lhs, tree rhs,
-		     tree v, tree lhs1, tree rhs1, bool swapped, bool seq_cst,
-		     bool test)
+		     tree v, tree lhs1, tree rhs1, bool swapped,
+		     enum omp_memory_order memory_order, bool test)
 {
   tree x, type, addr, pre = NULL_TREE;
   HOST_WIDE_INT bitpos = 0, bitsize = 0;
@@ -264,7 +269,7 @@  c_finish_omp_atomic (location_t loc, enu
     {
       x = build1 (OMP_ATOMIC_READ, type, addr);
       SET_EXPR_LOCATION (x, loc);
-      OMP_ATOMIC_SEQ_CST (x) = seq_cst;
+      OMP_ATOMIC_MEMORY_ORDER (x) = memory_order;
       if (blhs)
 	x = build3_loc (loc, BIT_FIELD_REF, TREE_TYPE (blhs), x,
 			bitsize_int (bitsize), bitsize_int (bitpos));
@@ -315,7 +320,7 @@  c_finish_omp_atomic (location_t loc, enu
     type = void_type_node;
   x = build2 (code, type, addr, rhs);
   SET_EXPR_LOCATION (x, loc);
-  OMP_ATOMIC_SEQ_CST (x) = seq_cst;
+  OMP_ATOMIC_MEMORY_ORDER (x) = memory_order;
 
   /* Generally it is hard to prove lhs1 and lhs are the same memory
      location, just diagnose different variables.  */
@@ -413,17 +418,173 @@  c_finish_omp_atomic (location_t loc, enu
 }
 
 
+/* Return true if TYPE is the implementation's omp_depend_t.  */
+
+bool
+c_omp_depend_t_p (tree type)
+{
+  type = TYPE_MAIN_VARIANT (type);
+  return (TREE_CODE (type) == RECORD_TYPE
+	  && TYPE_NAME (type)
+	  && ((TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
+	       ? DECL_NAME (TYPE_NAME (type)) : TYPE_NAME (type))
+	      == get_identifier ("omp_depend_t"))
+	  && (!TYPE_CONTEXT (type)
+	      || TREE_CODE (TYPE_CONTEXT (type)) == TRANSLATION_UNIT_DECL)
+	  && COMPLETE_TYPE_P (type)
+	  && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
+	  && !compare_tree_int (TYPE_SIZE (type),
+				2 * tree_to_uhwi (TYPE_SIZE (ptr_type_node))));
+}
+
+
+/* Complete a #pragma omp depobj construct.  LOC is the location of the
+   #pragma.  */
+
+void
+c_finish_omp_depobj (location_t loc, tree depobj,
+		     enum omp_clause_depend_kind kind, tree clause)
+{
+  tree t = NULL_TREE;
+  if (!error_operand_p (depobj))
+    {
+      if (!c_omp_depend_t_p (TREE_TYPE (depobj)))
+	{
+	  error_at (EXPR_LOC_OR_LOC (depobj, loc),
+		    "type of %<depobj%> expression is not %<omp_depend_t%>");
+	  depobj = error_mark_node;
+	}
+      else if (TYPE_READONLY (TREE_TYPE (depobj)))
+	{
+	  error_at (EXPR_LOC_OR_LOC (depobj, loc),
+		    "%<const%> qualified %<depobj%> expression");
+	  depobj = error_mark_node;
+	}
+    }
+  else
+    depobj = error_mark_node;
+
+  if (clause == error_mark_node)
+    return;
+
+  if (clause)
+    {
+      gcc_assert (TREE_CODE (clause) == OMP_CLAUSE
+		  && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_DEPEND);
+      if (OMP_CLAUSE_CHAIN (clause))
+	error_at (OMP_CLAUSE_LOCATION (clause),
+		  "more than one locator in %<depend%> clause on %<depobj%> "
+		  "construct");
+      switch (OMP_CLAUSE_DEPEND_KIND (clause))
+	{
+	case OMP_CLAUSE_DEPEND_DEPOBJ:
+	  error_at (OMP_CLAUSE_LOCATION (clause),
+		    "%<depobj%> dependence type specified in %<depend%> "
+		    "clause on %<depobj%> construct");
+	  return;
+	case OMP_CLAUSE_DEPEND_SOURCE:
+	case OMP_CLAUSE_DEPEND_SINK:
+	  error_at (OMP_CLAUSE_LOCATION (clause),
+		    "%<depend(%s)%> is only allowed in %<omp ordered%>",
+		    OMP_CLAUSE_DEPEND_KIND (clause) == OMP_CLAUSE_DEPEND_SOURCE
+		    ? "source" : "sink");
+	  return;
+	case OMP_CLAUSE_DEPEND_IN:
+	case OMP_CLAUSE_DEPEND_OUT:
+	case OMP_CLAUSE_DEPEND_INOUT:
+	case OMP_CLAUSE_DEPEND_MUTEXINOUTSET:
+	  kind = OMP_CLAUSE_DEPEND_KIND (clause);
+	  t = OMP_CLAUSE_DECL (clause);
+	  gcc_assert (t);
+	  if (TREE_CODE (t) == TREE_LIST
+	      && TREE_PURPOSE (t)
+	      && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC)
+	    {
+	      error_at (OMP_CLAUSE_LOCATION (clause),
+			"%<iterator%> modifier may not be specified on "
+			"%<depobj%> construct");
+	      return;
+	    }
+	  if (TREE_CODE (t) == COMPOUND_EXPR)
+	    {
+	      tree t1 = build_fold_addr_expr (TREE_OPERAND (t, 1));
+	      t = build2 (COMPOUND_EXPR, TREE_TYPE (t1), TREE_OPERAND (t, 0),
+			  t1);
+	    }
+	  else
+	    t = build_fold_addr_expr (t);
+	  break;
+	default:
+	  gcc_unreachable ();
+	}
+    }
+  else
+    gcc_assert (kind != OMP_CLAUSE_DEPEND_SOURCE);
+
+  if (depobj == error_mark_node)
+    return;
+
+  depobj = build_fold_addr_expr_loc (EXPR_LOC_OR_LOC (depobj, loc), depobj);
+  tree dtype
+    = build_pointer_type_for_mode (ptr_type_node, TYPE_MODE (ptr_type_node),
+				   true);
+  depobj = fold_convert (dtype, depobj);
+  tree r;
+  if (clause)
+    {
+      depobj = save_expr (depobj);
+      r = build_indirect_ref (loc, depobj, RO_UNARY_STAR);
+      add_stmt (build2 (MODIFY_EXPR, void_type_node, r, t));
+    }
+  int k;
+  switch (kind)
+    {
+    case OMP_CLAUSE_DEPEND_IN:
+      k = GOMP_DEPEND_IN;
+      break;
+    case OMP_CLAUSE_DEPEND_OUT:
+      k = GOMP_DEPEND_OUT;
+      break;
+    case OMP_CLAUSE_DEPEND_INOUT:
+      k = GOMP_DEPEND_INOUT;
+      break;
+    case OMP_CLAUSE_DEPEND_MUTEXINOUTSET:
+      k = GOMP_DEPEND_MUTEXINOUTSET;
+      break;
+    case OMP_CLAUSE_DEPEND_LAST:
+      k = -1;
+      break;
+    default:
+      gcc_unreachable ();
+    }
+  t = build_int_cst (ptr_type_node, k);
+  depobj = build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (depobj), depobj,
+		       TYPE_SIZE_UNIT (ptr_type_node));
+  r = build_indirect_ref (loc, depobj, RO_UNARY_STAR);
+  add_stmt (build2 (MODIFY_EXPR, void_type_node, r, t));
+}
+
+
 /* Complete a #pragma omp flush construct.  We don't do anything with
    the variable list that the syntax allows.  LOC is the location of
    the #pragma.  */
 
 void
-c_finish_omp_flush (location_t loc)
+c_finish_omp_flush (location_t loc, int mo)
 {
   tree x;
 
-  x = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
-  x = build_call_expr_loc (loc, x, 0);
+  if (mo == MEMMODEL_LAST)
+    {
+      x = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
+      x = build_call_expr_loc (loc, x, 0);
+    }
+  else
+    {
+      x = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
+      x = build_call_expr_loc (loc, x, 1,
+			       build_int_cst (integer_type_node, mo));
+    }
   add_stmt (x);
 }
 
@@ -454,17 +615,17 @@  check_omp_for_incr_expr (location_t loc,
       t = check_omp_for_incr_expr (loc, TREE_OPERAND (exp, 0), decl);
       if (t != error_mark_node)
         return fold_build2_loc (loc, MINUS_EXPR,
-			    TREE_TYPE (exp), t, TREE_OPERAND (exp, 1));
+				TREE_TYPE (exp), t, TREE_OPERAND (exp, 1));
       break;
     case PLUS_EXPR:
       t = check_omp_for_incr_expr (loc, TREE_OPERAND (exp, 0), decl);
       if (t != error_mark_node)
         return fold_build2_loc (loc, PLUS_EXPR,
-			    TREE_TYPE (exp), t, TREE_OPERAND (exp, 1));
+				TREE_TYPE (exp), t, TREE_OPERAND (exp, 1));
       t = check_omp_for_incr_expr (loc, TREE_OPERAND (exp, 1), decl);
       if (t != error_mark_node)
         return fold_build2_loc (loc, PLUS_EXPR,
-			    TREE_TYPE (exp), TREE_OPERAND (exp, 0), t);
+				TREE_TYPE (exp), TREE_OPERAND (exp, 0), t);
       break;
     case COMPOUND_EXPR:
       {
@@ -530,7 +691,7 @@  c_omp_for_incr_canonicalize_ptr (locatio
 tree
 c_finish_omp_for (location_t locus, enum tree_code code, tree declv,
 		  tree orig_declv, tree initv, tree condv, tree incrv,
-		  tree body, tree pre_body)
+		  tree body, tree pre_body, bool final_p)
 {
   location_t elocus;
   bool fail = false;
@@ -667,7 +828,8 @@  c_finish_omp_for (location_t locus, enum
 		{
 		  if (!INTEGRAL_TYPE_P (TREE_TYPE (decl)))
 		    {
-		      cond_ok = false;
+		      if (code == OACC_LOOP || TREE_CODE (cond) == EQ_EXPR)
+			cond_ok = false;
 		    }
 		  else if (operand_equal_p (TREE_OPERAND (cond, 1),
 					    TYPE_MIN_VALUE (TREE_TYPE (decl)),
@@ -679,7 +841,7 @@  c_finish_omp_for (location_t locus, enum
 					    0))
 		    TREE_SET_CODE (cond, TREE_CODE (cond) == NE_EXPR
 					 ? LT_EXPR : GE_EXPR);
-		  else
+		  else if (code == OACC_LOOP || TREE_CODE (cond) == EQ_EXPR)
 		    cond_ok = false;
 		}
 
@@ -730,6 +892,21 @@  c_finish_omp_for (location_t locus, enum
 		break;
 
 	      incr_ok = true;
+	      if (!fail
+		  && TREE_CODE (cond) == NE_EXPR
+		  && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
+		  && TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl)))
+		  && (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))))
+		      != INTEGER_CST))
+		{
+		  /* For pointer to VLA, transform != into < or >
+		     depending on whether incr is increment or decrement.  */
+		  if (TREE_CODE (incr) == PREINCREMENT_EXPR
+		      || TREE_CODE (incr) == POSTINCREMENT_EXPR)
+		    TREE_SET_CODE (cond, LT_EXPR);
+		  else
+		    TREE_SET_CODE (cond, GT_EXPR);
+		}
 	      incr = c_omp_for_incr_canonicalize_ptr (elocus, decl, incr);
 	      break;
 
@@ -765,6 +942,58 @@  c_finish_omp_for (location_t locus, enum
 		      incr = build2 (MODIFY_EXPR, void_type_node, decl, t);
 		    }
 		}
+	      if (!fail
+		  && incr_ok
+		  && TREE_CODE (cond) == NE_EXPR)
+		{
+		  tree i = TREE_OPERAND (incr, 1);
+		  i = TREE_OPERAND (i, TREE_OPERAND (i, 0) == decl);
+		  i = c_fully_fold (i, false, NULL);
+		  if (!final_p
+		      && TREE_CODE (i) != INTEGER_CST)
+		    ;
+		  else if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE)
+		    {
+		      tree unit
+			= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl)));
+		      if (unit)
+			{
+			  enum tree_code ccode = GT_EXPR;
+			  unit = c_fully_fold (unit, false, NULL);
+			  i = fold_convert (TREE_TYPE (unit), i);
+			  if (operand_equal_p (unit, i, 0))
+			    ccode = LT_EXPR;
+			  if (ccode == GT_EXPR)
+			    {
+			      i = fold_unary (NEGATE_EXPR, TREE_TYPE (i), i);
+			      if (i == NULL_TREE
+				  || !operand_equal_p (unit, i, 0))
+				{
+				  error_at (elocus,
+					    "increment is not constant 1 or "
+					    "-1 for != condition");
+				  fail = true;
+				}
+			    }
+			  if (TREE_CODE (unit) != INTEGER_CST)
+			    /* For pointer to VLA, transform != into < or >
+			       depending on whether the pointer is
+			       incremented or decremented in each
+			       iteration.  */
+			    TREE_SET_CODE (cond, ccode);
+			}
+		    }
+		  else
+		    {
+		      if (!integer_onep (i) && !integer_minus_onep (i))
+			{
+			  error_at (elocus,
+				    "increment is not constant 1 or -1 for"
+				    " != condition");
+			  fail = true;
+			}
+		    }
+		}
 	      break;
 
 	    default:
@@ -829,7 +1058,13 @@  c_omp_check_loop_iv_r (tree *tp, int *wa
       for (i = 0; i < TREE_VEC_LENGTH (d->declv); i++)
 	if (*tp == TREE_VEC_ELT (d->declv, i)
 	    || (TREE_CODE (TREE_VEC_ELT (d->declv, i)) == TREE_LIST
-		&& *tp == TREE_PURPOSE (TREE_VEC_ELT (d->declv, i))))
+		&& *tp == TREE_PURPOSE (TREE_VEC_ELT (d->declv, i)))
+	    || (TREE_CODE (TREE_VEC_ELT (d->declv, i)) == TREE_LIST
+		&& TREE_CHAIN (TREE_VEC_ELT (d->declv, i))
+		&& (TREE_CODE (TREE_CHAIN (TREE_VEC_ELT (d->declv, i)))
+		    == TREE_VEC)
+		&& *tp == TREE_VEC_ELT (TREE_CHAIN (TREE_VEC_ELT (d->declv,
+								  i)), 2)))
 	  {
 	    location_t loc = d->expr_loc;
 	    if (loc == UNKNOWN_LOCATION)
@@ -1025,18 +1260,24 @@  c_oacc_split_loop_clauses (tree clauses,
 }
 
 /* This function attempts to split or duplicate clauses for OpenMP
-   combined/composite constructs.  Right now there are 21 different
+   combined/composite constructs.  Right now there are 26 different
    constructs.  CODE is the innermost construct in the combined construct,
    and MASK allows to determine which constructs are combined together,
    as every construct has at least one clause that no other construct
-   has (except for OMP_SECTIONS, but that can be only combined with parallel).
+   has (except for OMP_SECTIONS, but that can be only combined with parallel,
+   and OMP_MASTER, which doesn't have any clauses at all).
    OpenMP combined/composite constructs are:
    #pragma omp distribute parallel for
    #pragma omp distribute parallel for simd
    #pragma omp distribute simd
    #pragma omp for simd
+   #pragma omp master taskloop
+   #pragma omp master taskloop simd
    #pragma omp parallel for
    #pragma omp parallel for simd
+   #pragma omp parallel master
+   #pragma omp parallel master taskloop
+   #pragma omp parallel master taskloop simd
    #pragma omp parallel sections
    #pragma omp target parallel
    #pragma omp target parallel for
@@ -1070,8 +1311,9 @@  c_omp_split_clauses (location_t loc, enu
       {
       case OMP_FOR:
       case OMP_SIMD:
-        cclauses[C_OMP_CLAUSE_SPLIT_FOR]
-	  = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
+	if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)) != 0)
+	  cclauses[C_OMP_CLAUSE_SPLIT_FOR]
+	    = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
 	break;
       case OMP_SECTIONS:
 	cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS]
@@ -1118,6 +1360,7 @@  c_omp_split_clauses (location_t loc, enu
 	case OMP_CLAUSE_SAFELEN:
 	case OMP_CLAUSE_SIMDLEN:
 	case OMP_CLAUSE_ALIGNED:
+	case OMP_CLAUSE_NONTEMPORAL:
 	  s = C_OMP_CLAUSE_SPLIT_SIMD;
 	  break;
 	case OMP_CLAUSE_GRAINSIZE:
@@ -1175,8 +1418,8 @@  c_omp_split_clauses (location_t loc, enu
 	  else
 	    s = C_OMP_CLAUSE_SPLIT_DISTRIBUTE;
 	  break;
-	/* Private clause is supported on all constructs,
-	   it is enough to put it on the innermost one.  For
+	/* Private clause is supported on all constructs but master,
+	   it is enough to put it on the innermost one other than master.  For
 	   #pragma omp {for,sections} put it on parallel though,
 	   as that's what we did for OpenMP 3.1.  */
 	case OMP_CLAUSE_PRIVATE:
@@ -1187,12 +1430,14 @@  c_omp_split_clauses (location_t loc, enu
 	    case OMP_PARALLEL: s = C_OMP_CLAUSE_SPLIT_PARALLEL; break;
 	    case OMP_DISTRIBUTE: s = C_OMP_CLAUSE_SPLIT_DISTRIBUTE; break;
 	    case OMP_TEAMS: s = C_OMP_CLAUSE_SPLIT_TEAMS; break;
+	    case OMP_MASTER: s = C_OMP_CLAUSE_SPLIT_PARALLEL; break;
+	    case OMP_TASKLOOP: s = C_OMP_CLAUSE_SPLIT_TASKLOOP; break;
 	    default: gcc_unreachable ();
 	    }
 	  break;
 	/* Firstprivate clause is supported on all constructs but
-	   simd.  Put it on the outermost of those and duplicate on teams
-	   and parallel.  */
+	   simd and master.  Put it on the outermost of those and duplicate on
+	   teams and parallel.  */
 	case OMP_CLAUSE_FIRSTPRIVATE:
 	  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP))
 	      != 0)
@@ -1231,6 +1476,11 @@  c_omp_split_clauses (location_t loc, enu
 		  else
 		    s = C_OMP_CLAUSE_SPLIT_DISTRIBUTE;
 		}
+	      else if ((mask & (OMP_CLAUSE_MASK_1
+				<< PRAGMA_OMP_CLAUSE_NOGROUP)) != 0)
+		/* This must be
+		   #pragma omp parallel master taskloop{, simd}.  */
+		s = C_OMP_CLAUSE_SPLIT_TASKLOOP;
 	      else
 		/* This must be
 		   #pragma omp parallel{, for{, simd}, sections}
@@ -1260,8 +1510,10 @@  c_omp_split_clauses (location_t loc, enu
 	  else if ((mask & (OMP_CLAUSE_MASK_1
 			    << PRAGMA_OMP_CLAUSE_NOGROUP)) != 0)
 	    {
-	      /* This must be #pragma omp taskloop simd.  */
-	      gcc_assert (code == OMP_SIMD);
+	      /* This must be #pragma omp {,{,parallel }master }taskloop simd
+		 or
+		 #pragma omp {,parallel }master taskloop.  */
+	      gcc_assert (code == OMP_SIMD || code == OMP_TASKLOOP);
 	      s = C_OMP_CLAUSE_SPLIT_TASKLOOP;
 	    }
 	  else
@@ -1271,9 +1523,9 @@  c_omp_split_clauses (location_t loc, enu
 	      s = C_OMP_CLAUSE_SPLIT_FOR;
 	    }
 	  break;
-	/* Lastprivate is allowed on distribute, for, sections and simd.  In
-	   parallel {for{, simd},sections} we actually want to put it on
-	   parallel rather than for or sections.  */
+	/* Lastprivate is allowed on distribute, for, sections, taskloop and
+	   simd.  In parallel {for{, simd},sections} we actually want to put
+	   it on parallel rather than for or sections.  */
 	case OMP_CLAUSE_LASTPRIVATE:
 	  if (code == OMP_DISTRIBUTE)
 	    {
@@ -1287,6 +1539,8 @@  c_omp_split_clauses (location_t loc, enu
 				    OMP_CLAUSE_LASTPRIVATE);
 	      OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses);
 	      OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
+	      OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c)
+		= OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (clauses);
 	      cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE] = c;
 	    }
 	  if (code == OMP_FOR || code == OMP_SECTIONS)
@@ -1298,12 +1552,19 @@  c_omp_split_clauses (location_t loc, enu
 		s = C_OMP_CLAUSE_SPLIT_FOR;
 	      break;
 	    }
+	  if (code == OMP_TASKLOOP)
+	    {
+	      s = C_OMP_CLAUSE_SPLIT_TASKLOOP;
+	      break;
+	    }
 	  gcc_assert (code == OMP_SIMD);
 	  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)) != 0)
 	    {
 	      c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
 				    OMP_CLAUSE_LASTPRIVATE);
 	      OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses);
+	      OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c)
+		= OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (clauses);
 	      if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS))
 		  != 0)
 		s = C_OMP_CLAUSE_SPLIT_PARALLEL;
@@ -1312,6 +1573,16 @@  c_omp_split_clauses (location_t loc, enu
 	      OMP_CLAUSE_CHAIN (c) = cclauses[s];
 	      cclauses[s] = c;
 	    }
+	  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP)) != 0)
+	    {
+	      c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
+				    OMP_CLAUSE_LASTPRIVATE);
+	      OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses);
+	      OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c)
+		= OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (clauses);
+	      OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
+	      cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP] = c;
+	    }
 	  s = C_OMP_CLAUSE_SPLIT_SIMD;
 	  break;
 	/* Shared and default clauses are allowed on parallel, teams and
@@ -1321,6 +1592,19 @@  c_omp_split_clauses (location_t loc, enu
 	  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP))
 	      != 0)
 	    {
+	      if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS))
+		  != 0)
+		{
+		  c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
+					OMP_CLAUSE_CODE (clauses));
+		  if (OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_SHARED)
+		    OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses);
+		  else
+		    OMP_CLAUSE_DEFAULT_KIND (c)
+		      = OMP_CLAUSE_DEFAULT_KIND (clauses);
+		  OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL];
+		  cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] = c;
+		}
 	      s = C_OMP_CLAUSE_SPLIT_TASKLOOP;
 	      break;
 	    }
@@ -1345,10 +1629,33 @@  c_omp_split_clauses (location_t loc, enu
 	    }
 	  s = C_OMP_CLAUSE_SPLIT_PARALLEL;
 	  break;
-	/* Reduction is allowed on simd, for, parallel, sections and teams.
-	   Duplicate it on all of them, but omit on for or sections if
-	   parallel is present.  */
+	/* Reduction is allowed on simd, for, parallel, sections, taskloop
+	   and teams.  Duplicate it on all of them, but omit on for or
+	   sections if parallel is present.  If taskloop is combined with
+	   parallel, omit it on parallel.  */
 	case OMP_CLAUSE_REDUCTION:
+	  if (OMP_CLAUSE_REDUCTION_TASK (clauses))
+	    {
+	      if (code == OMP_SIMD /* || code == OMP_LOOP */)
+		{
+		  error_at (OMP_CLAUSE_LOCATION (clauses),
+			    "invalid %<task%> reduction modifier on construct "
+			    "combined with %<simd%>" /* or %<loop%> */);
+		  OMP_CLAUSE_REDUCTION_TASK (clauses) = 0;
+		}
+	      else if (code != OMP_SECTIONS
+		       && (mask & (OMP_CLAUSE_MASK_1
+				   << PRAGMA_OMP_CLAUSE_SCHEDULE)) == 0
+		       && (mask & (OMP_CLAUSE_MASK_1
+				   << PRAGMA_OMP_CLAUSE_SCHEDULE)) == 0)
+		{
+		  error_at (OMP_CLAUSE_LOCATION (clauses),
+			    "invalid %<task%> reduction modifier on construct "
+			    "not combined with %<parallel%>, %<for%> or "
+			    "%<sections%>");
+		  OMP_CLAUSE_REDUCTION_TASK (clauses) = 0;
+		}
+	    }
 	  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)) != 0)
 	    {
 	      if (code == OMP_SIMD)
@@ -1377,9 +1684,9 @@  c_omp_split_clauses (location_t loc, enu
 		    = OMP_CLAUSE_REDUCTION_PLACEHOLDER (clauses);
 		  OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c)
 		    = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clauses);
-		  OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL];
-		  cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] = c;
-		  s = C_OMP_CLAUSE_SPLIT_TEAMS;
+		  OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
+		  cclauses[C_OMP_CLAUSE_SPLIT_TEAMS] = c;
+		  s = C_OMP_CLAUSE_SPLIT_PARALLEL;
 		}
 	      else if ((mask & (OMP_CLAUSE_MASK_1
 				<< PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0)
@@ -1387,46 +1694,154 @@  c_omp_split_clauses (location_t loc, enu
 	      else
 		s = C_OMP_CLAUSE_SPLIT_FOR;
 	    }
-	  else if (code == OMP_SECTIONS || code == OMP_PARALLEL)
+	  else if (code == OMP_SECTIONS
+		   || code == OMP_PARALLEL
+		   || code == OMP_MASTER)
 	    s = C_OMP_CLAUSE_SPLIT_PARALLEL;
+	  else if (code == OMP_TASKLOOP)
+	    s = C_OMP_CLAUSE_SPLIT_TASKLOOP;
 	  else if (code == OMP_SIMD)
-	    s = C_OMP_CLAUSE_SPLIT_SIMD;
+	    {
+	      if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP))
+		  != 0)
+		{
+		  c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
+					OMP_CLAUSE_REDUCTION);
+		  OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses);
+		  OMP_CLAUSE_REDUCTION_CODE (c)
+		    = OMP_CLAUSE_REDUCTION_CODE (clauses);
+		  OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
+		    = OMP_CLAUSE_REDUCTION_PLACEHOLDER (clauses);
+		  OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c)
+		    = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clauses);
+		  OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
+		  cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP] = c;
+		}
+	      s = C_OMP_CLAUSE_SPLIT_SIMD;
+	    }
 	  else
 	    s = C_OMP_CLAUSE_SPLIT_TEAMS;
 	  break;
+	case OMP_CLAUSE_IN_REDUCTION:
+	  /* in_reduction on taskloop simd becomes reduction on the simd
+	     and keeps being in_reduction on taskloop.  */
+	  if (code == OMP_SIMD)
+	    {
+	      c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
+				    OMP_CLAUSE_REDUCTION);
+	      OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses);
+	      OMP_CLAUSE_REDUCTION_CODE (c)
+		= OMP_CLAUSE_REDUCTION_CODE (clauses);
+	      OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
+		= OMP_CLAUSE_REDUCTION_PLACEHOLDER (clauses);
+	      OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c)
+		= OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clauses);
+	      OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_SIMD];
+	      cclauses[C_OMP_CLAUSE_SPLIT_SIMD] = c;
+	    }
+	  s = C_OMP_CLAUSE_SPLIT_TASKLOOP;
+	  break;
 	case OMP_CLAUSE_IF:
+	  if (OMP_CLAUSE_IF_MODIFIER (clauses) != ERROR_MARK)
+	    {
+	      s = C_OMP_CLAUSE_SPLIT_COUNT;
+	      switch (OMP_CLAUSE_IF_MODIFIER (clauses))
+		{
+		case OMP_PARALLEL:
+		  if ((mask & (OMP_CLAUSE_MASK_1
+			       << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0)
+		    s = C_OMP_CLAUSE_SPLIT_PARALLEL;
+		  break;
+		case OMP_SIMD:
+		  if (code == OMP_SIMD)
+		    s = C_OMP_CLAUSE_SPLIT_SIMD;
+		  break;
+		case OMP_TASKLOOP:
+		  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP))
+		      != 0)
+		    s = C_OMP_CLAUSE_SPLIT_TASKLOOP;
+		  break;
+		case OMP_TARGET:
+		  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP))
+		      != 0)
+		    s = C_OMP_CLAUSE_SPLIT_TARGET;
+		  break;
+		default:
+		  break;
+		}
+	      if (s != C_OMP_CLAUSE_SPLIT_COUNT)
+		break;
+	      /* Error-recovery here, invalid if-modifier specified, add the
+		 clause to just one construct.  */
+	      if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) != 0)
+		s = C_OMP_CLAUSE_SPLIT_TARGET;
+	      else if ((mask & (OMP_CLAUSE_MASK_1
+				<< PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0)
+		s = C_OMP_CLAUSE_SPLIT_PARALLEL;
+	      else if ((mask & (OMP_CLAUSE_MASK_1
+				<< PRAGMA_OMP_CLAUSE_NOGROUP)) != 0)
+		s = C_OMP_CLAUSE_SPLIT_TASKLOOP;
+	      else if (code == OMP_SIMD)
+		s = C_OMP_CLAUSE_SPLIT_SIMD;
+	      else
+		gcc_unreachable ();
+	      break;
+	    }
+	  /* Otherwise, duplicate if clause to all constructs.  */
+	  if (code == OMP_SIMD)
+	    {
+	      if ((mask & ((OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)
+			   | (OMP_CLAUSE_MASK_1
+			      << PRAGMA_OMP_CLAUSE_NUM_THREADS)
+			   | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP)))
+		  != 0)
+		{
+		  c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
+					OMP_CLAUSE_IF);
+		  OMP_CLAUSE_IF_MODIFIER (c)
+		    = OMP_CLAUSE_IF_MODIFIER (clauses);
+		  OMP_CLAUSE_IF_EXPR (c) = OMP_CLAUSE_IF_EXPR (clauses);
+		  OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_SIMD];
+		  cclauses[C_OMP_CLAUSE_SPLIT_SIMD] = c;
+		}
+	      else
+		{
+		  s = C_OMP_CLAUSE_SPLIT_SIMD;
+		  break;
+		}
+	    }
 	  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP))
 	      != 0)
-	    s = C_OMP_CLAUSE_SPLIT_TASKLOOP;
+	    {
+	      if ((mask & (OMP_CLAUSE_MASK_1
+			   << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0)
+		{
+		  c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
+					OMP_CLAUSE_IF);
+		  OMP_CLAUSE_IF_MODIFIER (c)
+		    = OMP_CLAUSE_IF_MODIFIER (clauses);
+		  OMP_CLAUSE_IF_EXPR (c) = OMP_CLAUSE_IF_EXPR (clauses);
+		  OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
+		  cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP] = c;
+		  s = C_OMP_CLAUSE_SPLIT_PARALLEL;
+		}
+	      else
+		s = C_OMP_CLAUSE_SPLIT_TASKLOOP;
+	    }
 	  else if ((mask & (OMP_CLAUSE_MASK_1
 			    << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0)
 	    {
 	      if ((mask & (OMP_CLAUSE_MASK_1
 			   << PRAGMA_OMP_CLAUSE_MAP)) != 0)
 		{
-		  if (OMP_CLAUSE_IF_MODIFIER (clauses) == OMP_PARALLEL)
-		    s = C_OMP_CLAUSE_SPLIT_PARALLEL;
-		  else if (OMP_CLAUSE_IF_MODIFIER (clauses) == OMP_TARGET)
-		    s = C_OMP_CLAUSE_SPLIT_TARGET;
-		  else if (OMP_CLAUSE_IF_MODIFIER (clauses) == ERROR_MARK)
-		    {
-		      c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
-					    OMP_CLAUSE_IF);
-		      OMP_CLAUSE_IF_MODIFIER (c)
-			= OMP_CLAUSE_IF_MODIFIER (clauses);
-		      OMP_CLAUSE_IF_EXPR (c) = OMP_CLAUSE_IF_EXPR (clauses);
-		      OMP_CLAUSE_CHAIN (c)
-			= cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
-		      cclauses[C_OMP_CLAUSE_SPLIT_TARGET] = c;
-		      s = C_OMP_CLAUSE_SPLIT_PARALLEL;
-		    }
-		  else
-		    {
-		      error_at (OMP_CLAUSE_LOCATION (clauses),
-				"expected %<parallel%> or %<target%> %<if%> "
-				"clause modifier");
-		      continue;
-		    }
+		  c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
+					OMP_CLAUSE_IF);
+		  OMP_CLAUSE_IF_MODIFIER (c)
+		    = OMP_CLAUSE_IF_MODIFIER (clauses);
+		  OMP_CLAUSE_IF_EXPR (c) = OMP_CLAUSE_IF_EXPR (clauses);
+		  OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
+		  cclauses[C_OMP_CLAUSE_SPLIT_TARGET] = c;
+		  s = C_OMP_CLAUSE_SPLIT_PARALLEL;
 		}
 	      else
 		s = C_OMP_CLAUSE_SPLIT_PARALLEL;
@@ -1610,11 +2025,6 @@  c_omp_declare_simd_clauses_to_decls (tre
 enum omp_clause_default_kind
 c_omp_predetermined_sharing (tree decl)
 {
-  /* Variables with const-qualified type having no mutable member
-     are predetermined shared.  */
-  if (TREE_READONLY (decl))
-    return OMP_CLAUSE_DEFAULT_SHARED;
-
   /* Predetermine artificial variables holding integral values, those
      are usually result of gimplify_one_sizepos or SAVE_EXPR
      gimplification.  */
--- gcc/c-family/c-pragma.c	(.../trunk)	(revision 265884)
+++ gcc/c-family/c-pragma.c	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -1286,9 +1286,11 @@  static const struct omp_pragma_def omp_p
   { "cancel", PRAGMA_OMP_CANCEL },
   { "cancellation", PRAGMA_OMP_CANCELLATION_POINT },
   { "critical", PRAGMA_OMP_CRITICAL },
+  { "depobj", PRAGMA_OMP_DEPOBJ },
   { "end", PRAGMA_OMP_END_DECLARE_TARGET },
   { "flush", PRAGMA_OMP_FLUSH },
   { "master", PRAGMA_OMP_MASTER },
+  { "requires", PRAGMA_OMP_REQUIRES },
   { "section", PRAGMA_OMP_SECTION },
   { "sections", PRAGMA_OMP_SECTIONS },
   { "single", PRAGMA_OMP_SINGLE },
--- gcc/c-family/c-pragma.h	(.../trunk)	(revision 265884)
+++ gcc/c-family/c-pragma.h	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -47,6 +47,7 @@  enum pragma_kind {
   PRAGMA_OMP_CANCELLATION_POINT,
   PRAGMA_OMP_CRITICAL,
   PRAGMA_OMP_DECLARE,
+  PRAGMA_OMP_DEPOBJ,
   PRAGMA_OMP_DISTRIBUTE,
   PRAGMA_OMP_END_DECLARE_TARGET,
   PRAGMA_OMP_FLUSH,
@@ -54,6 +55,7 @@  enum pragma_kind {
   PRAGMA_OMP_MASTER,
   PRAGMA_OMP_ORDERED,
   PRAGMA_OMP_PARALLEL,
+  PRAGMA_OMP_REQUIRES,
   PRAGMA_OMP_SECTION,
   PRAGMA_OMP_SECTIONS,
   PRAGMA_OMP_SIMD,
@@ -75,8 +77,8 @@  enum pragma_kind {
 };
 
 
-/* All clauses defined by OpenACC 2.0, and OpenMP 2.5, 3.0, 3.1, 4.0 and 4.5.
-   Used internally by both C and C++ parsers.  */
+/* All clauses defined by OpenACC 2.0, and OpenMP 2.5, 3.0, 3.1, 4.0, 4.5
+   and 5.0.  Used internally by both C and C++ parsers.  */
 enum pragma_omp_clause {
   PRAGMA_OMP_CLAUSE_NONE = 0,
 
@@ -96,6 +98,7 @@  enum pragma_omp_clause {
   PRAGMA_OMP_CLAUSE_GRAINSIZE,
   PRAGMA_OMP_CLAUSE_HINT,
   PRAGMA_OMP_CLAUSE_IF,
+  PRAGMA_OMP_CLAUSE_IN_REDUCTION,
   PRAGMA_OMP_CLAUSE_INBRANCH,
   PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR,
   PRAGMA_OMP_CLAUSE_LASTPRIVATE,
@@ -104,6 +107,7 @@  enum pragma_omp_clause {
   PRAGMA_OMP_CLAUSE_MAP,
   PRAGMA_OMP_CLAUSE_MERGEABLE,
   PRAGMA_OMP_CLAUSE_NOGROUP,
+  PRAGMA_OMP_CLAUSE_NONTEMPORAL,
   PRAGMA_OMP_CLAUSE_NOTINBRANCH,
   PRAGMA_OMP_CLAUSE_NOWAIT,
   PRAGMA_OMP_CLAUSE_NUM_TASKS,
@@ -121,6 +125,7 @@  enum pragma_omp_clause {
   PRAGMA_OMP_CLAUSE_SHARED,
   PRAGMA_OMP_CLAUSE_SIMD,
   PRAGMA_OMP_CLAUSE_SIMDLEN,
+  PRAGMA_OMP_CLAUSE_TASK_REDUCTION,
   PRAGMA_OMP_CLAUSE_TASKGROUP,
   PRAGMA_OMP_CLAUSE_THREAD_LIMIT,
   PRAGMA_OMP_CLAUSE_THREADS,
--- gcc/cp/constexpr.c	(.../trunk)	(revision 265884)
+++ gcc/cp/constexpr.c	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -5917,6 +5917,7 @@  potential_constant_expression_1 (tree t,
     case OMP_ATOMIC_READ:
     case OMP_ATOMIC_CAPTURE_OLD:
     case OMP_ATOMIC_CAPTURE_NEW:
+    case OMP_DEPOBJ:
     case OACC_PARALLEL:
     case OACC_KERNELS:
     case OACC_DATA:
--- gcc/cp/cp-gimplify.c	(.../trunk)	(revision 265884)
+++ gcc/cp/cp-gimplify.c	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -1178,6 +1178,8 @@  cp_genericize_r (tree *stmt_p, int *walk
 	    *walk_subtrees = 0;
 	  break;
 	case OMP_CLAUSE_REDUCTION:
+	case OMP_CLAUSE_IN_REDUCTION:
+	case OMP_CLAUSE_TASK_REDUCTION:
 	  /* Don't dereference an invisiref in reduction clause's
 	     OMP_CLAUSE_DECL either.  OMP_CLAUSE_REDUCTION_{INIT,MERGE}
 	     still needs to be genericized.  */
@@ -1986,10 +1988,10 @@  cxx_omp_predetermined_sharing_1 (tree de
 	return OMP_CLAUSE_DEFAULT_SHARED;
     }
 
-  /* Const qualified vars having no mutable member are predetermined
-     shared.  */
-  if (cxx_omp_const_qual_no_mutable (decl))
-    return OMP_CLAUSE_DEFAULT_SHARED;
+  /* this may not be specified in data-sharing clauses, still we need
+     to predetermined it firstprivate.  */
+  if (decl == current_class_ptr)
+    return OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
 
   return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
 }
--- gcc/cp/cp-objcp-common.c	(.../trunk)	(revision 265884)
+++ gcc/cp/cp-objcp-common.c	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -446,6 +446,7 @@  cp_common_init_ts (void)
   MARK_TS_TYPED (UNARY_RIGHT_FOLD_EXPR);
   MARK_TS_TYPED (BINARY_LEFT_FOLD_EXPR);
   MARK_TS_TYPED (BINARY_RIGHT_FOLD_EXPR);
+  MARK_TS_TYPED (OMP_DEPOBJ);
 }
 
 #include "gt-cp-cp-objcp-common.h"
--- gcc/cp/cp-tree.def	(.../trunk)	(revision 265884)
+++ gcc/cp/cp-tree.def	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -499,6 +499,11 @@  DEFTREECODE (BASES, "bases", tcc_type, 0
    instantiation time.  */
 DEFTREECODE (TEMPLATE_INFO, "template_info", tcc_exceptional, 0)
 
+/* OpenMP - #pragma omp depobj
+   Operand 0: OMP_DEPOBJ_DEPOBJ: Depobj expression
+   Operand 1: OMP_DEPOBJ_CLAUSES: List of clauses.  */
+DEFTREECODE (OMP_DEPOBJ, "omp_depobj", tcc_statement, 2)
+
 /* Extensions for Concepts. */
 
 /* Used to represent information associated with constrained declarations. */
--- gcc/cp/cp-tree.h	(.../trunk)	(revision 265884)
+++ gcc/cp/cp-tree.h	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -4874,9 +4874,10 @@  more_aggr_init_expr_args_p (const aggr_i
   (TREE_LANG_FLAG_1 (SCOPE_REF_CHECK (NODE)))
 
 /* True for an OMP_ATOMIC that has dependent parameters.  These are stored
-   as an expr in operand 1, and integer_zero_node in operand 0.  */
+   as an expr in operand 1, and integer_zero_node or clauses in operand 0.  */
 #define OMP_ATOMIC_DEPENDENT_P(NODE) \
-  (TREE_CODE (TREE_OPERAND (OMP_ATOMIC_CHECK (NODE), 0)) == INTEGER_CST)
+  (TREE_CODE (TREE_OPERAND (OMP_ATOMIC_CHECK (NODE), 0)) == INTEGER_CST \
+   || TREE_CODE (TREE_OPERAND (OMP_ATOMIC_CHECK (NODE), 0)) == OMP_CLAUSE)
 
 /* Used while gimplifying continue statements bound to OMP_FOR nodes.  */
 #define OMP_FOR_GIMPLIFYING_P(NODE) \
@@ -5016,6 +5017,13 @@  more_aggr_init_expr_args_p (const aggr_i
 #define ALIGNOF_EXPR_STD_P(NODE) \
   TREE_LANG_FLAG_0 (ALIGNOF_EXPR_CHECK (NODE))
 
+/* OMP_DEPOBJ accessors. These give access to the depobj expression of the
+   #pragma omp depobj directive and the clauses, respectively.  If
+   OMP_DEPOBJ_CLAUSES is INTEGER_CST, it is instead the update clause kind
+   or OMP_CLAUSE_DEPEND_LAST for destroy clause.  */
+#define OMP_DEPOBJ_DEPOBJ(NODE)	 TREE_OPERAND (OMP_DEPOBJ_CHECK (NODE), 0)
+#define OMP_DEPOBJ_CLAUSES(NODE) TREE_OPERAND (OMP_DEPOBJ_CHECK (NODE), 1)
+
 /* An enumeration of the kind of tags that C++ accepts.  */
 enum tag_types {
   none_type = 0, /* Not a tag type.  */
@@ -6630,6 +6638,9 @@  extern bool maybe_clone_body			(tree);
 /* In parser.c */
 extern tree cp_convert_range_for (tree, tree, tree, tree, unsigned int, bool,
 				  unsigned short);
+extern void cp_convert_omp_range_for (tree &, vec<tree, va_gc> *, tree &,
+				      tree &, tree &, tree &, tree &, tree &);
+extern void cp_finish_omp_range_for (tree, tree);
 extern bool parsing_nsdmi (void);
 extern bool parsing_default_capturing_generic_lambda_in_template (void);
 extern void inject_this_parameter (tree, cp_cv_quals);
@@ -7054,11 +7065,16 @@  extern tree finish_omp_task			(tree, tre
 extern tree finish_omp_for			(location_t, enum tree_code,
 						 tree, tree, tree, tree, tree,
 						 tree, tree, vec<tree> *, tree);
-extern void finish_omp_atomic			(enum tree_code, enum tree_code,
-						 tree, tree, tree, tree, tree,
-						 bool);
+extern tree finish_omp_for_block		(tree, tree);
+extern void finish_omp_atomic			(location_t, enum tree_code,
+						 enum tree_code, tree, tree,
+						 tree, tree, tree, tree,
+						 enum omp_memory_order);
 extern void finish_omp_barrier			(void);
-extern void finish_omp_flush			(void);
+extern void finish_omp_depobj			(location_t, tree,
+						 enum omp_clause_depend_kind,
+						 tree);
+extern void finish_omp_flush			(int);
 extern void finish_omp_taskwait			(void);
 extern void finish_omp_taskyield		(void);
 extern void finish_omp_cancel			(tree);
--- gcc/cp/cxx-pretty-print.c	(.../trunk)	(revision 265884)
+++ gcc/cp/cxx-pretty-print.c	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -2112,6 +2112,42 @@  cxx_pretty_printer::statement (tree t)
       declaration (t);
       break;
 
+    case OMP_DEPOBJ:
+      pp_cxx_ws_string (this, "#pragma omp depobj");
+      pp_space (this);
+      pp_cxx_left_paren (this);
+      expression (OMP_DEPOBJ_DEPOBJ (t));
+      pp_cxx_right_paren (this);
+      if (OMP_DEPOBJ_CLAUSES (t) && OMP_DEPOBJ_CLAUSES (t) != error_mark_node)
+	{
+	  if (TREE_CODE (OMP_DEPOBJ_CLAUSES (t)) == OMP_CLAUSE)
+	    dump_omp_clauses (this, OMP_DEPOBJ_CLAUSES (t),
+			      pp_indentation (this), TDF_NONE);
+	  else
+	    switch (tree_to_uhwi (OMP_DEPOBJ_CLAUSES (t)))
+	      {
+	      case OMP_CLAUSE_DEPEND_IN:
+		pp_cxx_ws_string (this, " update(in)");
+		break;
+	      case OMP_CLAUSE_DEPEND_INOUT:
+		pp_cxx_ws_string (this, " update(inout)");
+		break;
+	      case OMP_CLAUSE_DEPEND_OUT:
+		pp_cxx_ws_string (this, " update(out)");
+		break;
+	      case OMP_CLAUSE_DEPEND_MUTEXINOUTSET:
+		pp_cxx_ws_string (this, " update(mutexinoutset)");
+		break;
+	      case OMP_CLAUSE_DEPEND_LAST:
+		pp_cxx_ws_string (this, " destroy");
+		break;
+	      default:
+		break;
+	      }
+	}
+      pp_needs_newline (this) = true;
+      break;
+
     default:
       c_pretty_printer::statement (t);
       break;
--- gcc/cp/dump.c	(.../trunk)	(revision 265884)
+++ gcc/cp/dump.c	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -328,6 +328,12 @@  cp_dump_tree (void* dump_info, tree t)
       dump_child ("expr", EXPR_STMT_EXPR (t));
       break;
 
+    case OMP_DEPOBJ:
+      dump_stmt (di, t);
+      dump_child ("depobj", OMP_DEPOBJ_DEPOBJ (t));
+      dump_child ("clauses", OMP_DEPOBJ_CLAUSES (t));
+      break;
+
     default:
       break;
     }
--- gcc/cp/lex.c	(.../trunk)	(revision 265884)
+++ gcc/cp/lex.c	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -293,7 +293,7 @@  cxx_init (void)
    IF_STMT,		CLEANUP_STMT,	FOR_STMT,
    RANGE_FOR_STMT,	WHILE_STMT,	DO_STMT,
    BREAK_STMT,		CONTINUE_STMT,	SWITCH_STMT,
-   EXPR_STMT
+   EXPR_STMT,		OMP_DEPOBJ
   };
 
   memset (&statement_code_p, 0, sizeof (statement_code_p));
--- gcc/cp/parser.c	(.../trunk)	(revision 265884)
+++ gcc/cp/parser.c	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -44,6 +44,7 @@  along with GCC; see the file COPYING3.
 #include "gcc-rich-location.h"
 #include "tree-iterator.h"
 #include "cp-name-hint.h"
+#include "memmodel.h"
 
 
 /* The lexer.  */
@@ -2110,7 +2111,7 @@  static tree cp_parser_for
 static tree cp_parser_c_for
   (cp_parser *, tree, tree, bool, unsigned short);
 static tree cp_parser_range_for
-  (cp_parser *, tree, tree, tree, bool, unsigned short);
+  (cp_parser *, tree, tree, tree, bool, unsigned short, bool);
 static void do_range_for_auto_deduction
   (tree, tree);
 static tree cp_parser_perform_range_for_lookup
@@ -11843,7 +11844,8 @@  cp_parser_for (cp_parser *parser, bool i
   is_range_for = cp_parser_init_statement (parser, &decl);
 
   if (is_range_for)
-    return cp_parser_range_for (parser, scope, init, decl, ivdep, unroll);
+    return cp_parser_range_for (parser, scope, init, decl, ivdep, unroll,
+				false);
   else
     return cp_parser_c_for (parser, scope, init, ivdep, unroll);
 }
@@ -11901,7 +11903,7 @@  cp_parser_c_for (cp_parser *parser, tree
 
 static tree
 cp_parser_range_for (cp_parser *parser, tree scope, tree init, tree range_decl,
-		     bool ivdep, unsigned short unroll)
+		     bool ivdep, unsigned short unroll, bool is_omp)
 {
   tree stmt, range_expr;
   auto_vec <cxx_binding *, 16> bindings;
@@ -11961,6 +11963,11 @@  cp_parser_range_for (cp_parser *parser,
       IDENTIFIER_BINDING (names[i]) = binding;
     }
 
+  /* finish_omp_for has its own code for the following, so just
+     return the range_expr instead.  */
+  if (is_omp)
+    return range_expr;
+
   /* If in template, STMT is converted to a normal for-statement
      at instantiation. If not, it is done just ahead. */
   if (processing_template_decl)
@@ -31490,7 +31497,7 @@  cp_parser_objc_at_dynamic_declaration (c
 }
 
 
-/* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines.  */
+/* OpenMP 2.5 / 3.0 / 3.1 / 4.0 / 4.5 / 5.0 parsing routines.  */
 
 /* Returns name of the next clause.
    If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
@@ -31580,6 +31587,8 @@  cp_parser_omp_clause_name (cp_parser *pa
 	case 'i':
 	  if (!strcmp ("if_present", p))
 	    result = PRAGMA_OACC_CLAUSE_IF_PRESENT;
+	  else if (!strcmp ("in_reduction", p))
+	    result = PRAGMA_OMP_CLAUSE_IN_REDUCTION;
 	  else if (!strcmp ("inbranch", p))
 	    result = PRAGMA_OMP_CLAUSE_INBRANCH;
 	  else if (!strcmp ("independent", p))
@@ -31604,6 +31613,8 @@  cp_parser_omp_clause_name (cp_parser *pa
 	case 'n':
 	  if (!strcmp ("nogroup", p))
 	    result = PRAGMA_OMP_CLAUSE_NOGROUP;
+	  else if (!strcmp ("nontemporal", p))
+	    result = PRAGMA_OMP_CLAUSE_NONTEMPORAL;
 	  else if (!strcmp ("notinbranch", p))
 	    result = PRAGMA_OMP_CLAUSE_NOTINBRANCH;
 	  else if (!strcmp ("nowait", p))
@@ -31668,7 +31679,9 @@  cp_parser_omp_clause_name (cp_parser *pa
 	    result = PRAGMA_OMP_CLAUSE_SIMDLEN;
 	  break;
 	case 't':
-	  if (!strcmp ("taskgroup", p))
+	  if (!strcmp ("task_reduction", p))
+	    result = PRAGMA_OMP_CLAUSE_TASK_REDUCTION;
+	  else if (!strcmp ("taskgroup", p))
 	    result = PRAGMA_OMP_CLAUSE_TASKGROUP;
 	  else if (!strcmp ("thread_limit", p))
 	    result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT;
@@ -31759,6 +31772,8 @@  cp_parser_omp_var_list_no_open (cp_parse
     {
       tree name, decl;
 
+      if (kind == OMP_CLAUSE_DEPEND)
+	cp_parser_parse_tentatively (parser);
       token = cp_lexer_peek_token (parser->lexer);
       if (kind != 0
 	  && current_class_ptr
@@ -31778,15 +31793,25 @@  cp_parser_omp_var_list_no_open (cp_parse
 					  /*declarator_p=*/false,
 					  /*optional_p=*/false);
 	  if (name == error_mark_node)
-	    goto skip_comma;
+	    {
+	      if (kind == OMP_CLAUSE_DEPEND
+		  && cp_parser_simulate_error (parser))
+		goto depend_lvalue;
+	      goto skip_comma;
+	    }
 
 	  if (identifier_p (name))
 	    decl = cp_parser_lookup_name_simple (parser, name, token->location);
 	  else
 	    decl = name;
 	  if (decl == error_mark_node)
-	    cp_parser_name_lookup_error (parser, name, decl, NLE_NULL,
-					 token->location);
+	    {
+	      if (kind == OMP_CLAUSE_DEPEND
+		  && cp_parser_simulate_error (parser))
+		goto depend_lvalue;
+	      cp_parser_name_lookup_error (parser, name, decl, NLE_NULL,
+					   token->location);
+	    }
 	}
       if (decl == error_mark_node)
 	;
@@ -31822,6 +31847,8 @@  cp_parser_omp_var_list_no_open (cp_parse
 	      /* FALLTHROUGH.  */
 	    case OMP_CLAUSE_DEPEND:
 	    case OMP_CLAUSE_REDUCTION:
+	    case OMP_CLAUSE_IN_REDUCTION:
+	    case OMP_CLAUSE_TASK_REDUCTION:
 	      while (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_SQUARE))
 		{
 		  tree low_bound = NULL_TREE, length = NULL_TREE;
@@ -31839,7 +31866,14 @@  cp_parser_omp_var_list_no_open (cp_parse
 		    {
 		      /* Look for `:'.  */
 		      if (!cp_parser_require (parser, CPP_COLON, RT_COLON))
-			goto skip_comma;
+			{
+			  if (kind == OMP_CLAUSE_DEPEND
+			      && cp_parser_simulate_error (parser))
+			    goto depend_lvalue;
+			  goto skip_comma;
+			}
+		      if (kind == OMP_CLAUSE_DEPEND)
+			cp_parser_commit_to_tentative_parse (parser);
 		      if (!cp_lexer_next_token_is (parser->lexer,
 						   CPP_CLOSE_SQUARE))
 			length = cp_parser_expression (parser);
@@ -31847,7 +31881,12 @@  cp_parser_omp_var_list_no_open (cp_parse
 		  /* Look for the closing `]'.  */
 		  if (!cp_parser_require (parser, CPP_CLOSE_SQUARE,
 					  RT_CLOSE_SQUARE))
-		    goto skip_comma;
+		    {
+		      if (kind == OMP_CLAUSE_DEPEND
+			  && cp_parser_simulate_error (parser))
+			goto depend_lvalue;
+		      goto skip_comma;
+		    }
 
 		  decl = tree_cons (low_bound, length, decl);
 		}
@@ -31856,6 +31895,21 @@  cp_parser_omp_var_list_no_open (cp_parse
 	      break;
 	    }
 
+	  if (kind == OMP_CLAUSE_DEPEND)
+	    {
+	      if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA)
+		  && cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN)
+		  && cp_parser_simulate_error (parser))
+		{
+		depend_lvalue:
+		  cp_parser_abort_tentative_parse (parser);
+		  decl = cp_parser_assignment_expression (parser, NULL,
+							  false, false);
+		}
+	      else
+		cp_parser_parse_definitely (parser);
+	    }
+
 	  tree u = build_omp_clause (token->location, kind);
 	  OMP_CLAUSE_DECL (u) = decl;
 	  OMP_CLAUSE_CHAIN (u) = list;
@@ -32440,7 +32494,11 @@  cp_parser_omp_clause_final (cp_parser *p
 
    directive-name-modifier:
      parallel | task | taskloop | target data | target | target update
-     | target enter data | target exit data  */
+     | target enter data | target exit data
+
+   OpenMP 5.0:
+   directive-name-modifier:
+     ... | simd | cancel  */
 
 static tree
 cp_parser_omp_clause_if (cp_parser *parser, tree list, location_t location,
@@ -32459,8 +32517,12 @@  cp_parser_omp_clause_if (cp_parser *pars
       const char *p = IDENTIFIER_POINTER (id);
       int n = 2;
 
-      if (strcmp ("parallel", p) == 0)
+      if (strcmp ("cancel", p) == 0)
+	if_modifier = VOID_CST;
+      else if (strcmp ("parallel", p) == 0)
 	if_modifier = OMP_PARALLEL;
+      else if (strcmp ("simd", p) == 0)
+	if_modifier = OMP_SIMD;
       else if (strcmp ("task", p) == 0)
 	if_modifier = OMP_TASK;
       else if (strcmp ("taskloop", p) == 0)
@@ -32547,7 +32609,9 @@  cp_parser_omp_clause_if (cp_parser *pars
 	    const char *p = NULL;
 	    switch (if_modifier)
 	      {
+	      case VOID_CST: p = "cancel"; break;
 	      case OMP_PARALLEL: p = "parallel"; break;
+	      case OMP_SIMD: p = "simd"; break;
 	      case OMP_TASK: p = "task"; break;
 	      case OMP_TASKLOOP: p = "taskloop"; break;
 	      case OMP_TARGET_DATA: p = "target data"; break;
@@ -32774,7 +32838,10 @@  cp_parser_omp_clause_hint (cp_parser *pa
 }
 
 /* OpenMP 4.5:
-   defaultmap ( tofrom : scalar ) */
+   defaultmap ( tofrom : scalar )
+
+   OpenMP 5.0:
+   defaultmap ( implicit-behavior [ : variable-category ] ) */
 
 static tree
 cp_parser_omp_clause_defaultmap (cp_parser *parser, tree list,
@@ -32782,47 +32849,163 @@  cp_parser_omp_clause_defaultmap (cp_pars
 {
   tree c, id;
   const char *p;
+  enum omp_clause_defaultmap_kind behavior = OMP_CLAUSE_DEFAULTMAP_DEFAULT;
+  enum omp_clause_defaultmap_kind category
+    = OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED;
 
   matching_parens parens;
   if (!parens.require_open (parser))
     return list;
 
-  if (!cp_lexer_next_token_is (parser->lexer, CPP_NAME))
-    {
-      cp_parser_error (parser, "expected %<tofrom%>");
+  if (cp_lexer_next_token_is_keyword (parser->lexer, RID_DEFAULT))
+    p = "default";
+  else if (!cp_lexer_next_token_is (parser->lexer, CPP_NAME))
+    {
+    invalid_behavior:
+      cp_parser_error (parser, "expected %<alloc%>, %<to%>, %<from%>, "
+			       "%<tofrom%>, %<firstprivate%>, %<none%> "
+			       "or %<default%>");
       goto out_err;
     }
-  id = cp_lexer_peek_token (parser->lexer)->u.value;
-  p = IDENTIFIER_POINTER (id);
-  if (strcmp (p, "tofrom") != 0)
+  else
     {
-      cp_parser_error (parser, "expected %<tofrom%>");
-      goto out_err;
+      id = cp_lexer_peek_token (parser->lexer)->u.value;
+      p = IDENTIFIER_POINTER (id);
     }
-  cp_lexer_consume_token (parser->lexer);
-  if (!cp_parser_require (parser, CPP_COLON, RT_COLON))
-    goto out_err;
 
-  if (!cp_lexer_next_token_is (parser->lexer, CPP_NAME))
+  switch (p[0])
     {
-      cp_parser_error (parser, "expected %<scalar%>");
-      goto out_err;
+    case 'a':
+      if (strcmp ("alloc", p) == 0)
+	behavior = OMP_CLAUSE_DEFAULTMAP_ALLOC;
+      else
+	goto invalid_behavior;
+      break;
+
+    case 'd':
+      if (strcmp ("default", p) == 0)
+	behavior = OMP_CLAUSE_DEFAULTMAP_DEFAULT;
+      else
+	goto invalid_behavior;
+      break;
+
+    case 'f':
+      if (strcmp ("firstprivate", p) == 0)
+	behavior = OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE;
+      else if (strcmp ("from", p) == 0)
+	behavior = OMP_CLAUSE_DEFAULTMAP_FROM;
+      else
+	goto invalid_behavior;
+      break;
+
+    case 'n':
+      if (strcmp ("none", p) == 0)
+	behavior = OMP_CLAUSE_DEFAULTMAP_NONE;
+      else
+	goto invalid_behavior;
+      break;
+
+    case 't':
+      if (strcmp ("tofrom", p) == 0)
+	behavior = OMP_CLAUSE_DEFAULTMAP_TOFROM;
+      else if (strcmp ("to", p) == 0)
+	behavior = OMP_CLAUSE_DEFAULTMAP_TO;
+      else
+	goto invalid_behavior;
+      break;
+
+    default:
+      goto invalid_behavior;
     }
-  id = cp_lexer_peek_token (parser->lexer)->u.value;
-  p = IDENTIFIER_POINTER (id);
-  if (strcmp (p, "scalar") != 0)
+  cp_lexer_consume_token (parser->lexer);
+
+  if (!cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_PAREN))
     {
-      cp_parser_error (parser, "expected %<scalar%>");
-      goto out_err;
+      if (!cp_parser_require (parser, CPP_COLON, RT_COLON))
+	goto out_err;
+
+      if (!cp_lexer_next_token_is (parser->lexer, CPP_NAME))
+	{
+	invalid_category:
+	  cp_parser_error (parser, "expected %<scalar%>, %<aggregate%> or "
+				   "%<pointer%>");
+	  goto out_err;
+	}
+      id = cp_lexer_peek_token (parser->lexer)->u.value;
+      p = IDENTIFIER_POINTER (id);
+
+      switch (p[0])
+	{
+	case 'a':
+	  if (strcmp ("aggregate", p) == 0)
+	    category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE;
+	  else
+	    goto invalid_category;
+	  break;
+
+	case 'p':
+	  if (strcmp ("pointer", p) == 0)
+	    category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER;
+	  else
+	    goto invalid_category;
+	  break;
+
+	case 's':
+	  if (strcmp ("scalar", p) == 0)
+	    category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR;
+	  else
+	    goto invalid_category;
+	  break;
+
+	default:
+	  goto invalid_category;
+	}
+
+      cp_lexer_consume_token (parser->lexer);
     }
-  cp_lexer_consume_token (parser->lexer);
   if (!parens.require_close (parser))
     goto out_err;
 
-  check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULTMAP, "defaultmap",
-			     location);
+  for (c = list; c ; c = OMP_CLAUSE_CHAIN (c))
+    if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEFAULTMAP
+	&& (category == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
+	    || OMP_CLAUSE_DEFAULTMAP_CATEGORY (c) == category
+	    || (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c)
+		== OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED)))
+      {
+	enum omp_clause_defaultmap_kind cat = category;
+	location_t loc = OMP_CLAUSE_LOCATION (c);
+	if (cat == OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED)
+	  cat = OMP_CLAUSE_DEFAULTMAP_CATEGORY (c);
+	p = NULL;
+	switch (cat)
+	  {
+	  case OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED:
+	    p = NULL;
+	    break;
+	  case OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE:
+	    p = "aggregate";
+	    break;
+	  case OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER:
+	    p = "pointer";
+	    break;
+	  case OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR:
+	    p = "scalar";
+	    break;
+	  default:
+	    gcc_unreachable ();
+	  }
+	if (p)
+	  error_at (loc, "too many %<defaultmap%> clauses with %qs category",
+		    p);
+	else
+	  error_at (loc, "too many %<defaultmap%> clauses with unspecified "
+			 "category");
+	break;
+      }
 
   c = build_omp_clause (location, OMP_CLAUSE_DEFAULTMAP);
+  OMP_CLAUSE_DEFAULTMAP_SET_KIND (c, behavior, category);
   OMP_CLAUSE_CHAIN (c) = list;
   return c;
 
@@ -32897,17 +33080,50 @@  cp_parser_omp_clause_ordered (cp_parser
 
    reduction-operator:
      One of: + * - & ^ | && ||
-     id-expression  */
+     id-expression
+
+   OpenMP 5.0:
+   reduction ( reduction-modifier, reduction-operator : variable-list )
+   in_reduction ( reduction-operator : variable-list )
+   task_reduction ( reduction-operator : variable-list )  */
 
 static tree
-cp_parser_omp_clause_reduction (cp_parser *parser, tree list)
+cp_parser_omp_clause_reduction (cp_parser *parser, enum omp_clause_code kind,
+				bool is_omp, tree list)
 {
   enum tree_code code = ERROR_MARK;
   tree nlist, c, id = NULL_TREE;
+  bool task = false;
+  bool inscan = false;
 
   if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
     return list;
 
+  if (kind == OMP_CLAUSE_REDUCTION && is_omp)
+    {
+      if (cp_lexer_next_token_is_keyword (parser->lexer, RID_DEFAULT)
+	  && cp_lexer_nth_token_is (parser->lexer, 2, CPP_COMMA))
+	{
+	  cp_lexer_consume_token (parser->lexer);
+	  cp_lexer_consume_token (parser->lexer);
+	}
+      else if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)
+	       && cp_lexer_nth_token_is (parser->lexer, 2, CPP_COMMA))
+	{
+	  tree id = cp_lexer_peek_token (parser->lexer)->u.value;
+	  const char *p = IDENTIFIER_POINTER (id);
+	  if (strcmp (p, "task") == 0)
+	    task = true;
+	  else if (strcmp (p, "inscan") == 0)
+	    inscan = true;
+	  if (task || inscan)
+	    {
+	      cp_lexer_consume_token (parser->lexer);
+	      cp_lexer_consume_token (parser->lexer);
+	    }
+	}
+    }
+
   switch (cp_lexer_peek_token (parser->lexer)->type)
     {
     case CPP_PLUS: code = PLUS_EXPR; break;
@@ -32980,11 +33196,15 @@  cp_parser_omp_clause_reduction (cp_parse
   if (!cp_parser_require (parser, CPP_COLON, RT_COLON))
     goto resync_fail;
 
-  nlist = cp_parser_omp_var_list_no_open (parser, OMP_CLAUSE_REDUCTION, list,
+  nlist = cp_parser_omp_var_list_no_open (parser, kind, list,
 					  NULL);
   for (c = nlist; c != list; c = OMP_CLAUSE_CHAIN (c))
     {
       OMP_CLAUSE_REDUCTION_CODE (c) = code;
+      if (task)
+	OMP_CLAUSE_REDUCTION_TASK (c) = 1;
+      else if (inscan)
+	OMP_CLAUSE_REDUCTION_INSCAN (c) = 1;
       OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = id;
     }
 
@@ -33303,6 +33523,43 @@  cp_parser_omp_clause_aligned (cp_parser
   return nlist;
 }
 
+/* OpenMP 2.5:
+   lastprivate ( variable-list )
+
+   OpenMP 5.0:
+   lastprivate ( [ lastprivate-modifier : ] variable-list )  */
+
+static tree
+cp_parser_omp_clause_lastprivate (cp_parser *parser, tree list)
+{
+  bool conditional = false;
+
+  if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+    return list;
+
+  if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)
+      && cp_lexer_nth_token_is (parser->lexer, 2, CPP_COLON))
+    {
+      tree id = cp_lexer_peek_token (parser->lexer)->u.value;
+      const char *p = IDENTIFIER_POINTER (id);
+
+      if (strcmp ("conditional", p) == 0)
+	{
+	  conditional = true;
+	  cp_lexer_consume_token (parser->lexer);
+	  cp_lexer_consume_token (parser->lexer);
+	}
+    }
+
+  tree nlist = cp_parser_omp_var_list_no_open (parser, OMP_CLAUSE_LASTPRIVATE,
+					       list, NULL);
+
+  if (conditional)
+    for (tree c = nlist; c != list; c = OMP_CLAUSE_CHAIN (c))
+      OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) = 1;
+  return nlist;
+}
+
 /* OpenMP 4.0:
    linear ( variable-list )
    linear ( variable-list : expression )
@@ -33545,6 +33802,118 @@  cp_parser_omp_clause_depend_sink (cp_par
   return list;
 }
 
+/* OpenMP 5.0:
+   iterators ( iterators-definition )
+
+   iterators-definition:
+     iterator-specifier
+     iterator-specifier , iterators-definition
+
+   iterator-specifier:
+     identifier = range-specification
+     iterator-type identifier = range-specification
+
+   range-specification:
+     begin : end
+     begin : end : step  */
+
+static tree
+cp_parser_omp_iterators (cp_parser *parser)
+{
+  tree ret = NULL_TREE, *last = &ret;
+  cp_lexer_consume_token (parser->lexer);
+
+  matching_parens parens;
+  if (!parens.require_open (parser))
+    return error_mark_node;
+
+  bool saved_colon_corrects_to_scope_p
+    = parser->colon_corrects_to_scope_p;
+  bool saved_colon_doesnt_start_class_def_p
+    = parser->colon_doesnt_start_class_def_p;
+
+  do
+    {
+      tree iter_type;
+      if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)
+	  && cp_lexer_nth_token_is (parser->lexer, 2, CPP_EQ))
+	iter_type = integer_type_node;
+      else
+	{
+	  const char *saved_message
+	    = parser->type_definition_forbidden_message;
+	  parser->type_definition_forbidden_message
+	    = G_("types may not be defined in iterator type");
+
+	  iter_type = cp_parser_type_id (parser);
+
+	  parser->type_definition_forbidden_message = saved_message;
+	}
+
+      location_t loc = cp_lexer_peek_token (parser->lexer)->location;
+      if (cp_lexer_next_token_is_not (parser->lexer, CPP_NAME))
+	{
+	  cp_parser_error (parser, "expected identifier");
+	  break;
+	}
+
+      tree id = cp_parser_identifier (parser);
+      if (id == error_mark_node)
+	break;
+
+      if (!cp_parser_require (parser, CPP_EQ, RT_EQ))
+	break;
+
+      parser->colon_corrects_to_scope_p = false;
+      parser->colon_doesnt_start_class_def_p = true;
+      tree begin = cp_parser_assignment_expression (parser);
+
+      if (!cp_parser_require (parser, CPP_COLON, RT_COLON))
+	break;
+
+      tree end = cp_parser_assignment_expression (parser);
+
+      tree step = integer_one_node;
+      if (cp_lexer_next_token_is (parser->lexer, CPP_COLON))
+	{
+	  cp_lexer_consume_token (parser->lexer);
+	  step = cp_parser_assignment_expression (parser);
+	}
+
+      tree iter_var = build_decl (loc, VAR_DECL, id, iter_type);
+      DECL_ARTIFICIAL (iter_var) = 1;
+      DECL_CONTEXT (iter_var) = current_function_decl;
+      pushdecl (iter_var);
+
+      *last = make_tree_vec (6);
+      TREE_VEC_ELT (*last, 0) = iter_var;
+      TREE_VEC_ELT (*last, 1) = begin;
+      TREE_VEC_ELT (*last, 2) = end;
+      TREE_VEC_ELT (*last, 3) = step;
+      last = &TREE_CHAIN (*last);
+
+      if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
+	{
+	  cp_lexer_consume_token (parser->lexer);
+	  continue;
+	}
+      break;
+    }
+  while (1);
+
+  parser->colon_corrects_to_scope_p = saved_colon_corrects_to_scope_p;
+  parser->colon_doesnt_start_class_def_p
+    = saved_colon_doesnt_start_class_def_p;
+
+  if (!parens.require_close (parser))
+    cp_parser_skip_to_closing_parenthesis (parser,
+					   /*recovering=*/true,
+					   /*or_comma=*/false,
+					   /*consume_paren=*/true);
+
+  return ret ? ret : error_mark_node;
+}
+
 /* OpenMP 4.0:
    depend ( depend-kind : variable-list )
 
@@ -33554,41 +33923,73 @@  cp_parser_omp_clause_depend_sink (cp_par
    OpenMP 4.5:
    depend ( source )
 
-   depend ( sink : vec ) */
+   depend ( sink : vec )
+
+   OpenMP 5.0:
+   depend ( depend-modifier , depend-kind: variable-list )
+
+   depend-kind:
+     in | out | inout | mutexinoutset | depobj
+
+   depend-modifier:
+     iterator ( iterators-definition )  */
 
 static tree
 cp_parser_omp_clause_depend (cp_parser *parser, tree list, location_t loc)
 {
-  tree nlist, c;
-  enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT;
+  tree nlist, c, iterators = NULL_TREE;
+  enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_LAST;
 
   matching_parens parens;
   if (!parens.require_open (parser))
     return list;
 
-  if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
+  do
     {
+      if (cp_lexer_next_token_is_not (parser->lexer, CPP_NAME))
+	goto invalid_kind;
+
       tree id = cp_lexer_peek_token (parser->lexer)->u.value;
       const char *p = IDENTIFIER_POINTER (id);
 
+      if (strcmp ("iterator", p) == 0 && iterators == NULL_TREE)
+	{
+	  begin_scope (sk_omp, NULL);
+	  iterators = cp_parser_omp_iterators (parser);
+	  cp_parser_require (parser, CPP_COMMA, RT_COMMA);
+	  continue;
+	}
       if (strcmp ("in", p) == 0)
 	kind = OMP_CLAUSE_DEPEND_IN;
       else if (strcmp ("inout", p) == 0)
 	kind = OMP_CLAUSE_DEPEND_INOUT;
+      else if (strcmp ("mutexinoutset", p) == 0)
+	kind = OMP_CLAUSE_DEPEND_MUTEXINOUTSET;
       else if (strcmp ("out", p) == 0)
 	kind = OMP_CLAUSE_DEPEND_OUT;
-      else if (strcmp ("source", p) == 0)
-	kind = OMP_CLAUSE_DEPEND_SOURCE;
+      else if (strcmp ("depobj", p) == 0)
+	kind = OMP_CLAUSE_DEPEND_DEPOBJ;
       else if (strcmp ("sink", p) == 0)
 	kind = OMP_CLAUSE_DEPEND_SINK;
+      else if (strcmp ("source", p) == 0)
+	kind = OMP_CLAUSE_DEPEND_SOURCE;
       else
 	goto invalid_kind;
+      break;
     }
-  else
-    goto invalid_kind;
+  while (1);
 
   cp_lexer_consume_token (parser->lexer);
 
+  if (iterators
+      && (kind == OMP_CLAUSE_DEPEND_SOURCE || kind == OMP_CLAUSE_DEPEND_SINK))
+    {
+      poplevel (0, 1, 0);
+      error_at (loc, "%<iterator%> modifier incompatible with %qs",
+		kind == OMP_CLAUSE_DEPEND_SOURCE ? "source" : "sink");
+      iterators = NULL_TREE;
+    }
+
   if (kind == OMP_CLAUSE_DEPEND_SOURCE)
     {
       c = build_omp_clause (loc, OMP_CLAUSE_DEPEND);
@@ -33612,14 +34013,30 @@  cp_parser_omp_clause_depend (cp_parser *
       nlist = cp_parser_omp_var_list_no_open (parser, OMP_CLAUSE_DEPEND,
 					      list, NULL);
 
+      if (iterators)
+	{
+	  tree block = poplevel (1, 1, 0);
+	  if (iterators == error_mark_node)
+	    iterators = NULL_TREE;
+	  else
+	    TREE_VEC_ELT (iterators, 5) = block;
+	}
+
       for (c = nlist; c != list; c = OMP_CLAUSE_CHAIN (c))
-	OMP_CLAUSE_DEPEND_KIND (c) = kind;
+	{
+	  OMP_CLAUSE_DEPEND_KIND (c) = kind;
+	  if (iterators)
+	    OMP_CLAUSE_DECL (c)
+	      = build_tree_list (iterators, OMP_CLAUSE_DECL (c));
+	}
     }
   return nlist;
 
  invalid_kind:
   cp_parser_error (parser, "invalid depend kind");
  resync_fail:
+  if (iterators)
+    poplevel (0, 1, 0);
   cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
 					 /*or_comma=*/false,
 					 /*consume_paren=*/true);
@@ -34022,7 +34439,9 @@  cp_parser_oacc_all_clauses (cp_parser *p
 	  c_name = "private";
 	  break;
 	case PRAGMA_OACC_CLAUSE_REDUCTION:
-	  clauses = cp_parser_omp_clause_reduction (parser, clauses);
+	  clauses
+	    = cp_parser_omp_clause_reduction (parser, OMP_CLAUSE_REDUCTION,
+					      false, clauses);
 	  c_name = "reduction";
 	  break;
 	case PRAGMA_OACC_CLAUSE_SEQ:
@@ -34169,9 +34588,14 @@  cp_parser_omp_all_clauses (cp_parser *pa
 					     true);
 	  c_name = "if";
 	  break;
+	case PRAGMA_OMP_CLAUSE_IN_REDUCTION:
+	  clauses
+	    = cp_parser_omp_clause_reduction (parser, OMP_CLAUSE_IN_REDUCTION,
+					      true, clauses);
+	  c_name = "in_reduction";
+	  break;
 	case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
-	  clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_LASTPRIVATE,
-					    clauses);
+	  clauses = cp_parser_omp_clause_lastprivate (parser, clauses);
 	  c_name = "lastprivate";
 	  break;
 	case PRAGMA_OMP_CLAUSE_MERGEABLE:
@@ -34209,7 +34633,9 @@  cp_parser_omp_all_clauses (cp_parser *pa
 	  c_name = "private";
 	  break;
 	case PRAGMA_OMP_CLAUSE_REDUCTION:
-	  clauses = cp_parser_omp_clause_reduction (parser, clauses);
+	  clauses
+	    = cp_parser_omp_clause_reduction (parser, OMP_CLAUSE_REDUCTION,
+					      true, clauses);
 	  c_name = "reduction";
 	  break;
 	case PRAGMA_OMP_CLAUSE_SCHEDULE:
@@ -34222,6 +34648,13 @@  cp_parser_omp_all_clauses (cp_parser *pa
 					    clauses);
 	  c_name = "shared";
 	  break;
+	case PRAGMA_OMP_CLAUSE_TASK_REDUCTION:
+	  clauses
+	    = cp_parser_omp_clause_reduction (parser,
+					      OMP_CLAUSE_TASK_REDUCTION,
+					      true, clauses);
+	  c_name = "task_reduction";
+	  break;
 	case PRAGMA_OMP_CLAUSE_UNTIED:
 	  clauses = cp_parser_omp_clause_untied (parser, clauses,
 						 token->location);
@@ -34232,6 +34665,11 @@  cp_parser_omp_all_clauses (cp_parser *pa
 						 clauses, token->location);
 	  c_name = "inbranch";
 	  break;
+	case PRAGMA_OMP_CLAUSE_NONTEMPORAL:
+	  clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_NONTEMPORAL,
+					    clauses);
+	  c_name = "nontemporal";
+	  break;
 	case PRAGMA_OMP_CLAUSE_NOTINBRANCH:
 	  clauses = cp_parser_omp_clause_branch (parser,
 						 OMP_CLAUSE_NOTINBRANCH,
@@ -34494,62 +34932,154 @@  cp_parser_omp_atomic (cp_parser *parser,
 {
   tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE, lhs1 = NULL_TREE;
   tree rhs1 = NULL_TREE, orig_lhs;
-  enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR;
+  location_t loc = pragma_tok->location;
+  enum tree_code code = ERROR_MARK, opcode = NOP_EXPR;
+  enum omp_memory_order memory_order = OMP_MEMORY_ORDER_UNSPECIFIED;
   bool structured_block = false;
-  bool seq_cst = false;
-
-  if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
-    {
-      tree id = cp_lexer_peek_token (parser->lexer)->u.value;
-      const char *p = IDENTIFIER_POINTER (id);
-
-      if (!strcmp (p, "seq_cst"))
-	{
-	  seq_cst = true;
-	  cp_lexer_consume_token (parser->lexer);
-	  if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)
-	      && cp_lexer_peek_nth_token (parser->lexer, 2)->type == CPP_NAME)
-	    cp_lexer_consume_token (parser->lexer);
-	}
-    }
-  if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
-    {
-      tree id = cp_lexer_peek_token (parser->lexer)->u.value;
-      const char *p = IDENTIFIER_POINTER (id);
+  bool first = true;
+  tree clauses = NULL_TREE;
 
-      if (!strcmp (p, "read"))
-	code = OMP_ATOMIC_READ;
-      else if (!strcmp (p, "write"))
-	code = NOP_EXPR;
-      else if (!strcmp (p, "update"))
-	code = OMP_ATOMIC;
-      else if (!strcmp (p, "capture"))
-	code = OMP_ATOMIC_CAPTURE_NEW;
-      else
-	p = NULL;
-      if (p)
-	cp_lexer_consume_token (parser->lexer);
-    }
-  if (!seq_cst)
+  while (cp_lexer_next_token_is_not (parser->lexer, CPP_PRAGMA_EOL))
     {
-      if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)
-	  && cp_lexer_peek_nth_token (parser->lexer, 2)->type == CPP_NAME)
+      if (!first && cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
 	cp_lexer_consume_token (parser->lexer);
 
+      first = false;
+
       if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
 	{
 	  tree id = cp_lexer_peek_token (parser->lexer)->u.value;
+	  location_t cloc = cp_lexer_peek_token (parser->lexer)->location;
 	  const char *p = IDENTIFIER_POINTER (id);
-
-	  if (!strcmp (p, "seq_cst"))
+	  enum tree_code new_code = ERROR_MARK;
+	  enum omp_memory_order new_memory_order
+	    = OMP_MEMORY_ORDER_UNSPECIFIED;
+
+	  if (!strcmp (p, "read"))
+	    new_code = OMP_ATOMIC_READ;
+	  else if (!strcmp (p, "write"))
+	    new_code = NOP_EXPR;
+	  else if (!strcmp (p, "update"))
+	    new_code = OMP_ATOMIC;
+	  else if (!strcmp (p, "capture"))
+	    new_code = OMP_ATOMIC_CAPTURE_NEW;
+	  else if (!strcmp (p, "seq_cst"))
+	    new_memory_order = OMP_MEMORY_ORDER_SEQ_CST;
+	  else if (!strcmp (p, "acq_rel"))
+	    new_memory_order = OMP_MEMORY_ORDER_ACQ_REL;
+	  else if (!strcmp (p, "release"))
+	    new_memory_order = OMP_MEMORY_ORDER_RELEASE;
+	  else if (!strcmp (p, "acquire"))
+	    new_memory_order = OMP_MEMORY_ORDER_ACQUIRE;
+	  else if (!strcmp (p, "relaxed"))
+	    new_memory_order = OMP_MEMORY_ORDER_RELAXED;
+	  else if (!strcmp (p, "hint"))
+	    {
+	      cp_lexer_consume_token (parser->lexer);
+	      clauses = cp_parser_omp_clause_hint (parser, clauses, cloc);
+	      continue;
+	    }
+	  else
+	    {
+	      p = NULL;
+	      error_at (cloc, "expected %<read%>, %<write%>, %<update%>, "
+			      "%<capture%>, %<seq_cst%>, %<acq_rel%>, "
+			      "%<release%>, %<relaxed%> or %<hint%> clause");
+	    }
+	  if (p)
 	    {
-	      seq_cst = true;
+	      if (new_code != ERROR_MARK)
+		{
+		  if (code != ERROR_MARK)
+		    error_at (cloc, "too many atomic clauses");
+		  else
+		    code = new_code;
+		}
+	      else if (new_memory_order != OMP_MEMORY_ORDER_UNSPECIFIED)
+		{
+		  if (memory_order != OMP_MEMORY_ORDER_UNSPECIFIED)
+		    error_at (cloc, "too many memory order clauses");
+		  else
+		    memory_order = new_memory_order;
+		}
 	      cp_lexer_consume_token (parser->lexer);
+	      continue;
 	    }
 	}
+      break;
     }
   cp_parser_require_pragma_eol (parser, pragma_tok);
 
+  if (code == ERROR_MARK)
+    code = OMP_ATOMIC;
+  if (memory_order == OMP_MEMORY_ORDER_UNSPECIFIED)
+    {
+      omp_requires_mask
+	= (enum omp_requires) (omp_requires_mask
+			       | OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED);
+      switch ((enum omp_memory_order)
+	      (omp_requires_mask & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER))
+	{
+	case OMP_MEMORY_ORDER_UNSPECIFIED:
+	case OMP_MEMORY_ORDER_RELAXED:
+	  memory_order = OMP_MEMORY_ORDER_RELAXED;
+	  break;
+	case OMP_MEMORY_ORDER_SEQ_CST:
+	  memory_order = OMP_MEMORY_ORDER_SEQ_CST;
+	  break;
+	case OMP_MEMORY_ORDER_ACQ_REL:
+	  switch (code)
+	    {
+	    case OMP_ATOMIC_READ:
+	      memory_order = OMP_MEMORY_ORDER_ACQUIRE;
+	      break;
+	    case NOP_EXPR: /* atomic write */
+	    case OMP_ATOMIC:
+	      memory_order = OMP_MEMORY_ORDER_RELEASE;
+	      break;
+	    default:
+	      memory_order = OMP_MEMORY_ORDER_ACQ_REL;
+	      break;
+	    }
+	  break;
+	default:
+	  gcc_unreachable ();
+	}
+    }
+  else
+    switch (code)
+      {
+      case OMP_ATOMIC_READ:
+	if (memory_order == OMP_MEMORY_ORDER_ACQ_REL
+	    || memory_order == OMP_MEMORY_ORDER_RELEASE)
+	  {
+	    error_at (loc, "%<#pragma omp atomic read%> incompatible with "
+			   "%<acq_rel%> or %<release%> clauses");
+	    memory_order = OMP_MEMORY_ORDER_SEQ_CST;
+	  }
+	break;
+      case NOP_EXPR: /* atomic write */
+	if (memory_order == OMP_MEMORY_ORDER_ACQ_REL
+	    || memory_order == OMP_MEMORY_ORDER_ACQUIRE)
+	  {
+	    error_at (loc, "%<#pragma omp atomic write%> incompatible with "
+			   "%<acq_rel%> or %<acquire%> clauses");
+	    memory_order = OMP_MEMORY_ORDER_SEQ_CST;
+	  }
+	break;
+      case OMP_ATOMIC:
+	if (memory_order == OMP_MEMORY_ORDER_ACQ_REL
+	    || memory_order == OMP_MEMORY_ORDER_ACQUIRE)
+	  {
+	    error_at (loc, "%<#pragma omp atomic update%> incompatible with "
+			   "%<acq_rel%> or %<acquire%> clauses");
+	    memory_order = OMP_MEMORY_ORDER_SEQ_CST;
+	  }
+	break;
+      default:
+	break;
+      }
+
   switch (code)
     {
     case OMP_ATOMIC_READ:
@@ -34849,7 +35379,9 @@  stmt_done:
       cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
     }
 done:
-  finish_omp_atomic (code, opcode, lhs, rhs, v, lhs1, rhs1, seq_cst);
+  clauses = finish_omp_clauses (clauses, C_ORT_OMP);
+  finish_omp_atomic (pragma_tok->location, code, opcode, lhs, rhs, v, lhs1,
+		     rhs1, clauses, memory_order);
   if (!structured_block)
     cp_parser_consume_semicolon_at_end_of_statement (parser);
   return;
@@ -34911,6 +35443,10 @@  cp_parser_omp_critical (cp_parser *parse
       if (name == error_mark_node)
 	name = NULL;
 
+      if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)
+	  && cp_lexer_nth_token_is (parser->lexer, 2, CPP_NAME))
+	cp_lexer_consume_token (parser->lexer);
+
       clauses = cp_parser_omp_all_clauses (parser,
 					   OMP_CRITICAL_CLAUSE_MASK,
 					   "#pragma omp critical", pragma_tok);
@@ -34922,26 +35458,151 @@  cp_parser_omp_critical (cp_parser *parse
   return c_finish_omp_critical (input_location, stmt, name, clauses);
 }
 
+/* OpenMP 5.0:
+   # pragma omp depobj ( depobj ) depobj-clause new-line
+
+   depobj-clause:
+     depend (dependence-type : locator)
+     destroy
+     update (dependence-type)
+
+   dependence-type:
+     in
+     out
+     inout
+     mutexinout  */
+
+static void
+cp_parser_omp_depobj (cp_parser *parser, cp_token *pragma_tok)
+{
+  location_t loc = pragma_tok->location;
+  matching_parens parens;
+  if (!parens.require_open (parser))
+    {
+      cp_parser_skip_to_pragma_eol (parser, pragma_tok);
+      return;
+    }
+
+  tree depobj = cp_parser_assignment_expression (parser);
+
+  if (!parens.require_close (parser))
+    cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
+					   /*or_comma=*/false,
+					   /*consume_paren=*/true);
+
+  tree clause = NULL_TREE;
+  enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_SOURCE;
+  location_t c_loc = cp_lexer_peek_token (parser->lexer)->location;
+  if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
+    {
+      tree id = cp_lexer_peek_token (parser->lexer)->u.value;
+      const char *p = IDENTIFIER_POINTER (id);
+
+      cp_lexer_consume_token (parser->lexer);
+      if (!strcmp ("depend", p))
+	{
+	  clause = cp_parser_omp_clause_depend (parser, NULL_TREE, c_loc);
+	  if (clause)
+	    clause = finish_omp_clauses (clause, C_ORT_OMP);
+	  if (!clause)
+	    clause = error_mark_node;
+	}
+      else if (!strcmp ("destroy", p))
+	kind = OMP_CLAUSE_DEPEND_LAST;
+      else if (!strcmp ("update", p))
+	{
+	  matching_parens c_parens;
+	  if (c_parens.require_open (parser))
+	    {
+	      location_t c2_loc
+		= cp_lexer_peek_token (parser->lexer)->location;
+	      if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
+		{
+		  tree id2 = cp_lexer_peek_token (parser->lexer)->u.value;
+		  const char *p2 = IDENTIFIER_POINTER (id2);
+
+		  cp_lexer_consume_token (parser->lexer);
+		  if (!strcmp ("in", p2))
+		    kind = OMP_CLAUSE_DEPEND_IN;
+		  else if (!strcmp ("out", p2))
+		    kind = OMP_CLAUSE_DEPEND_OUT;
+		  else if (!strcmp ("inout", p2))
+		    kind = OMP_CLAUSE_DEPEND_INOUT;
+		  else if (!strcmp ("mutexinoutset", p2))
+		    kind = OMP_CLAUSE_DEPEND_MUTEXINOUTSET;
+		}
+	      if (kind == OMP_CLAUSE_DEPEND_SOURCE)
+		{
+		  clause = error_mark_node;
+		  error_at (c2_loc, "expected %<in%>, %<out%>, %<inout%> or "
+				    "%<mutexinoutset%>");
+		}
+	      if (!c_parens.require_close (parser))
+		cp_parser_skip_to_closing_parenthesis (parser,
+						       /*recovering=*/true,
+						       /*or_comma=*/false,
+						       /*consume_paren=*/true);
+	    }
+	  else
+	    clause = error_mark_node;
+	}
+    }
+  if (!clause && kind == OMP_CLAUSE_DEPEND_SOURCE)
+    {
+      clause = error_mark_node;
+      error_at (c_loc, "expected %<depend%>, %<destroy%> or %<update%> clause");
+    }
+  cp_parser_require_pragma_eol (parser, pragma_tok);
+
+  finish_omp_depobj (loc, depobj, kind, clause);
+}
+
+
 /* OpenMP 2.5:
    # pragma omp flush flush-vars[opt] new-line
 
    flush-vars:
-     ( variable-list ) */
+     ( variable-list )
+
+   OpenMP 5.0:
+   # pragma omp flush memory-order-clause new-line  */
 
 static void
 cp_parser_omp_flush (cp_parser *parser, cp_token *pragma_tok)
 {
+  enum memmodel mo = MEMMODEL_LAST;
+  if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
+    {
+      tree id = cp_lexer_peek_token (parser->lexer)->u.value;
+      const char *p = IDENTIFIER_POINTER (id);
+      if (!strcmp (p, "acq_rel"))
+	mo = MEMMODEL_ACQ_REL;
+      else if (!strcmp (p, "release"))
+	mo = MEMMODEL_RELEASE;
+      else if (!strcmp (p, "acquire"))
+	mo = MEMMODEL_ACQUIRE;
+      else
+	error_at (cp_lexer_peek_token (parser->lexer)->location,
+		  "expected %<acq_rel%>, %<release%> or %<acquire%>");
+      cp_lexer_consume_token (parser->lexer);
+    }
   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
-    (void) cp_parser_omp_var_list (parser, OMP_CLAUSE_ERROR, NULL);
+    {
+      if (mo != MEMMODEL_LAST)
+	error_at (cp_lexer_peek_token (parser->lexer)->location,
+		  "%<flush%> list specified together with memory order "
+		  "clause");
+      (void) cp_parser_omp_var_list (parser, OMP_CLAUSE_ERROR, NULL);
+    }
   cp_parser_require_pragma_eol (parser, pragma_tok);
 
-  finish_omp_flush ();
+  finish_omp_flush (mo);
 }
 
 /* Helper function, to parse omp for increment expression.  */
 
 static tree
-cp_parser_omp_for_cond (cp_parser *parser, tree decl)
+cp_parser_omp_for_cond (cp_parser *parser, tree decl, enum tree_code code)
 {
   tree cond = cp_parser_binary_expression (parser, false, true,
 					   PREC_NOT_OPERATOR, NULL);
@@ -34960,7 +35621,8 @@  cp_parser_omp_for_cond (cp_parser *parse
     case LE_EXPR:
       break;
     case NE_EXPR:
-      /* Fall through: OpenMP disallows NE_EXPR.  */
+      if (code != OACC_LOOP)
+	break;
       gcc_fallthrough ();
     default:
       return error_mark_node;
@@ -35304,6 +35966,192 @@  cp_parser_omp_for_loop_init (cp_parser *
   return add_private_clause;
 }
 
+/* Helper for cp_parser_omp_for_loop, handle one range-for loop.  */
+
+void
+cp_convert_omp_range_for (tree &this_pre_body, vec<tree, va_gc> *for_block,
+			  tree &decl, tree &orig_decl, tree &init,
+			  tree &orig_init, tree &cond, tree &incr)
+{
+  tree begin, end, range_temp_decl = NULL_TREE;
+  tree iter_type, begin_expr, end_expr;
+
+  if (processing_template_decl)
+    {
+      if (check_for_bare_parameter_packs (init))
+	init = error_mark_node;
+      if (!type_dependent_expression_p (init)
+	  /* do_auto_deduction doesn't mess with template init-lists.  */
+	  && !BRACE_ENCLOSED_INITIALIZER_P (init))
+	{
+	  tree d = decl;
+	  if (decl != error_mark_node && DECL_HAS_VALUE_EXPR_P (decl))
+	    {
+	      tree v = DECL_VALUE_EXPR (decl);
+	      if (TREE_CODE (v) == ARRAY_REF
+		  && VAR_P (TREE_OPERAND (v, 0))
+		  && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0)))
+		d = TREE_OPERAND (v, 0);
+	    }
+	  do_range_for_auto_deduction (d, init);
+	}
+      cond = global_namespace;
+      incr = NULL_TREE;
+      orig_init = init;
+      if (this_pre_body)
+	this_pre_body = pop_stmt_list (this_pre_body);
+      return;
+    }
+
+  init = mark_lvalue_use (init);
+
+  if (decl == error_mark_node || init == error_mark_node)
+    /* If an error happened previously do nothing or else a lot of
+       unhelpful errors would be issued.  */
+    begin_expr = end_expr = iter_type = error_mark_node;
+  else
+    {
+      tree range_temp;
+
+      if (VAR_P (init)
+	  && array_of_runtime_bound_p (TREE_TYPE (init)))
+	/* Can't bind a reference to an array of runtime bound.  */
+	range_temp = init;
+      else
+	{
+	  range_temp = build_range_temp (init);
+	  DECL_NAME (range_temp) = NULL_TREE;
+	  pushdecl (range_temp);
+	  cp_finish_decl (range_temp, init,
+			  /*is_constant_init*/false, NULL_TREE,
+			  LOOKUP_ONLYCONVERTING);
+	  range_temp_decl = range_temp;
+	  range_temp = convert_from_reference (range_temp);
+	}
+      iter_type = cp_parser_perform_range_for_lookup (range_temp,
+						      &begin_expr, &end_expr);
+    }
+
+  tree end_iter_type = iter_type;
+  if (cxx_dialect >= cxx17)
+    end_iter_type = cv_unqualified (TREE_TYPE (end_expr));
+  end = build_decl (input_location, VAR_DECL, NULL_TREE, end_iter_type);
+  TREE_USED (end) = 1;
+  DECL_ARTIFICIAL (end) = 1;
+  pushdecl (end);
+  cp_finish_decl (end, end_expr,
+		  /*is_constant_init*/false, NULL_TREE,
+		  LOOKUP_ONLYCONVERTING);
+
+  /* The new for initialization statement.  */
+  begin = build_decl (input_location, VAR_DECL, NULL_TREE, iter_type);
+  TREE_USED (begin) = 1;
+  DECL_ARTIFICIAL (begin) = 1;
+  pushdecl (begin);
+  orig_init = init;
+  if (CLASS_TYPE_P (iter_type))
+    init = NULL_TREE;
+  else
+    {
+      init = begin_expr;
+      begin_expr = NULL_TREE;
+    }
+  cp_finish_decl (begin, begin_expr,
+		  /*is_constant_init*/false, NULL_TREE,
+		  LOOKUP_ONLYCONVERTING);
+
+  /* The new for condition.  */
+  if (CLASS_TYPE_P (iter_type))
+    cond = build2 (NE_EXPR, boolean_type_node, begin, end);
+  else
+    cond = build_x_binary_op (input_location, NE_EXPR,
+			      begin, ERROR_MARK,
+			      end, ERROR_MARK,
+			      NULL, tf_warning_or_error);
+
+  /* The new increment expression.  */
+  if (CLASS_TYPE_P (iter_type))
+    incr = build2 (PREINCREMENT_EXPR, iter_type, begin, NULL_TREE);
+  else
+    incr = finish_unary_op_expr (input_location,
+				 PREINCREMENT_EXPR, begin,
+				 tf_warning_or_error);
+
+  orig_decl = decl;
+  decl = begin;
+  if (for_block)
+    {
+      vec_safe_push (for_block, this_pre_body);
+      this_pre_body = NULL_TREE;
+    }
+
+  tree decomp_first_name = NULL_TREE;
+  unsigned decomp_cnt = 0;
+  if (orig_decl != error_mark_node && DECL_HAS_VALUE_EXPR_P (orig_decl))
+    {
+      tree v = DECL_VALUE_EXPR (orig_decl);
+      if (TREE_CODE (v) == ARRAY_REF
+	  && VAR_P (TREE_OPERAND (v, 0))
+	  && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0)))
+	{
+	  tree d = orig_decl;
+	  orig_decl = TREE_OPERAND (v, 0);
+	  decomp_cnt = tree_to_uhwi (TREE_OPERAND (v, 1)) + 1;
+	  decomp_first_name = d;
+	}
+    }
+
+  tree auto_node = type_uses_auto (TREE_TYPE (orig_decl));
+  if (auto_node)
+    {
+      tree t = build_x_indirect_ref (input_location, begin, RO_UNARY_STAR,
+				     tf_none);
+      if (!error_operand_p (t))
+	TREE_TYPE (orig_decl) = do_auto_deduction (TREE_TYPE (orig_decl),
+						   t, auto_node);
+    }
+
+  tree v = make_tree_vec (decomp_cnt + 3);
+  TREE_VEC_ELT (v, 0) = range_temp_decl;
+  TREE_VEC_ELT (v, 1) = end;
+  TREE_VEC_ELT (v, 2) = orig_decl;
+  for (unsigned i = 0; i < decomp_cnt; i++)
+    {
+      TREE_VEC_ELT (v, i + 3) = decomp_first_name;
+      decomp_first_name = DECL_CHAIN (decomp_first_name);
+    }
+  orig_decl = tree_cons (NULL_TREE, NULL_TREE, v);
+}
+
+/* Helper for cp_parser_omp_for_loop, finalize part of range for
+   inside of the collapsed body.  */
+
+void
+cp_finish_omp_range_for (tree orig, tree begin)
+{
+  gcc_assert (TREE_CODE (orig) == TREE_LIST
+	      && TREE_CODE (TREE_CHAIN (orig)) == TREE_VEC);
+  tree decl = TREE_VEC_ELT (TREE_CHAIN (orig), 2);
+  tree decomp_first_name = NULL_TREE;
+  unsigned int decomp_cnt = 0;
+
+  if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl))
+    {
+      decomp_first_name = TREE_VEC_ELT (TREE_CHAIN (orig), 3);
+      decomp_cnt = TREE_VEC_LENGTH (TREE_CHAIN (orig)) - 3;
+      cp_maybe_mangle_decomp (decl, decomp_first_name, decomp_cnt);
+    }
+
+  /* The declaration is initialized with *__begin inside the loop body.  */
+  cp_finish_decl (decl,
+		  build_x_indirect_ref (input_location, begin, RO_UNARY_STAR,
+					tf_warning_or_error),
+		  /*is_constant_init*/false, NULL_TREE,
+		  LOOKUP_ONLYCONVERTING);
+  if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl))
+    cp_finish_decomp (decl, decomp_first_name, decomp_cnt);
+}
+
 /* Parse the restricted form of the for statement allowed by OpenMP.  */
 
 static tree
@@ -35311,7 +36159,8 @@  cp_parser_omp_for_loop (cp_parser *parse
 			tree *cclauses, bool *if_p)
 {
   tree init, orig_init, cond, incr, body, decl, pre_body = NULL_TREE, ret;
-  tree real_decl, initv, condv, incrv, declv;
+  tree orig_decl;
+  tree real_decl, initv, condv, incrv, declv, orig_declv;
   tree this_pre_body, cl, ordered_cl = NULL_TREE;
   location_t loc_first;
   bool collapse_err = false;
@@ -35364,6 +36213,7 @@  cp_parser_omp_for_loop (cp_parser *parse
   initv = make_tree_vec (count);
   condv = make_tree_vec (count);
   incrv = make_tree_vec (count);
+  orig_declv = NULL_TREE;
 
   loc_first = cp_lexer_peek_token (parser->lexer)->location;
 
@@ -35385,9 +36235,71 @@  cp_parser_omp_for_loop (cp_parser *parse
       if (!parens.require_open (parser))
 	return NULL;
 
-      init = orig_init = decl = real_decl = NULL;
+      init = orig_init = decl = real_decl = orig_decl = NULL_TREE;
       this_pre_body = push_stmt_list ();
 
+      if (code != OACC_LOOP && cxx_dialect >= cxx11)
+	{
+	  /* Save tokens so that we can put them back.  */
+	  cp_lexer_save_tokens (parser->lexer);
+
+	  /* Look for ':' that is not nested in () or {}.  */
+	  bool is_range_for
+	    = (cp_parser_skip_to_closing_parenthesis_1 (parser,
+							/*recovering=*/false,
+							CPP_COLON,
+							/*consume_paren=*/
+							false) == -1);
+
+	  /* Roll back the tokens we skipped.  */
+	  cp_lexer_rollback_tokens (parser->lexer);
+
+	  if (is_range_for)
+	    {
+	      bool saved_colon_corrects_to_scope_p
+		= parser->colon_corrects_to_scope_p;
+
+	      /* A colon is used in range-based for.  */
+	      parser->colon_corrects_to_scope_p = false;
+
+	      /* Parse the declaration.  */
+	      cp_parser_simple_declaration (parser,
+					    /*function_definition_allowed_p=*/
+					    false, &decl);
+	      parser->colon_corrects_to_scope_p
+		= saved_colon_corrects_to_scope_p;
+
+	      cp_parser_require (parser, CPP_COLON, RT_COLON);
+
+	      init = cp_parser_range_for (parser, NULL_TREE, NULL_TREE, decl,
+					  false, 0, true);
+
+	      cp_convert_omp_range_for (this_pre_body, for_block, decl,
+					orig_decl, init, orig_init,
+					cond, incr);
+	      if (this_pre_body)
+		{
+		  if (pre_body)
+		    {
+		      tree t = pre_body;
+		      pre_body = push_stmt_list ();
+		      add_stmt (t);
+		      add_stmt (this_pre_body);
+		      pre_body = pop_stmt_list (pre_body);
+		    }
+		  else
+		    pre_body = this_pre_body;
+		}
+
+	      if (ordered_cl)
+		error_at (OMP_CLAUSE_LOCATION (ordered_cl),
+			  "%<ordered%> clause with parameter on "
+			  "range-based %<for%> loop");
+
+	      goto parse_close_paren;
+	    }
+	}
+
       add_private_clause
 	= cp_parser_omp_for_loop_init (parser, this_pre_body, for_block,
 				       init, orig_init, decl, real_decl);
@@ -35464,7 +36376,8 @@  cp_parser_omp_for_loop (cp_parser *parse
 		error_at (loc, "iteration variable %qD "
 			  "should not be firstprivate",
 			  decl);
-	      else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+	      else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+			|| OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
 		       && OMP_CLAUSE_DECL (c) == decl)
 		error_at (loc, "iteration variable %qD should not be reduction",
 			  decl);
@@ -35493,7 +36406,7 @@  cp_parser_omp_for_loop (cp_parser *parse
 
       cond = NULL;
       if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
-	cond = cp_parser_omp_for_cond (parser, decl);
+	cond = cp_parser_omp_for_cond (parser, decl, code);
       cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
 
       incr = NULL;
@@ -35513,6 +36426,7 @@  cp_parser_omp_for_loop (cp_parser *parse
 	    protected_set_expr_location (incr, input_location);
 	}
 
+    parse_close_paren:
       if (!parens.require_close (parser))
 	cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
 					       /*or_comma=*/false,
@@ -35527,6 +36441,14 @@  cp_parser_omp_for_loop (cp_parser *parse
 	  orig_inits.safe_grow_cleared (i + 1);
 	  orig_inits[i] = orig_init;
 	}
+      if (orig_decl)
+	{
+	  if (!orig_declv)
+	    orig_declv = copy_node (declv);
+	  TREE_VEC_ELT (orig_declv, i) = orig_decl;
+	}
+      else if (orig_declv)
+	TREE_VEC_ELT (orig_declv, i) = decl;
 
       if (i == count - 1)
 	break;
@@ -35575,15 +36497,27 @@  cp_parser_omp_for_loop (cp_parser *parse
 
   /* Note that the grammar doesn't call for a structured block here,
      though the loop as a whole is a structured block.  */
-  body = push_stmt_list ();
+  if (orig_declv)
+    {
+      body = begin_omp_structured_block ();
+      for (i = 0; i < count; i++)
+	if (TREE_VEC_ELT (orig_declv, i) != TREE_VEC_ELT (declv, i))
+	  cp_finish_omp_range_for (TREE_VEC_ELT (orig_declv, i),
+				   TREE_VEC_ELT (declv, i));
+    }
+  else
+    body = push_stmt_list ();
   cp_parser_statement (parser, NULL_TREE, false, if_p);
-  body = pop_stmt_list (body);
+  if (orig_declv)
+    body = finish_omp_structured_block (body);
+  else
+    body = pop_stmt_list (body);
 
   if (declv == NULL_TREE)
     ret = NULL_TREE;
   else
-    ret = finish_omp_for (loc_first, code, declv, NULL, initv, condv, incrv,
-			  body, pre_body, &orig_inits, clauses);
+    ret = finish_omp_for (loc_first, code, declv, orig_declv, initv, condv,
+			  incrv, body, pre_body, &orig_inits, clauses);
 
   while (nbraces)
     {
@@ -35647,7 +36581,9 @@  cp_omp_split_clauses (location_t loc, en
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
-	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)	\
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)		\
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NONTEMPORAL))
 
 static tree
 cp_parser_omp_simd (cp_parser *parser, cp_token *pragma_tok,
@@ -35678,13 +36614,14 @@  cp_parser_omp_simd (cp_parser *parser, c
 	}
     }
 
+  keep_next_level (true);
   sb = begin_omp_structured_block ();
   save = cp_parser_begin_omp_structured_block (parser);
 
   ret = cp_parser_omp_for_loop (parser, OMP_SIMD, clauses, cclauses, if_p);
 
   cp_parser_end_omp_structured_block (parser, save);
-  add_stmt (finish_omp_structured_block (sb));
+  add_stmt (finish_omp_for_block (finish_omp_structured_block (sb), ret));
 
   return ret;
 }
@@ -35777,26 +36714,78 @@  cp_parser_omp_for (cp_parser *parser, cp
       clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
     }
 
+  keep_next_level (true);
   sb = begin_omp_structured_block ();
   save = cp_parser_begin_omp_structured_block (parser);
 
   ret = cp_parser_omp_for_loop (parser, OMP_FOR, clauses, cclauses, if_p);
 
   cp_parser_end_omp_structured_block (parser, save);
-  add_stmt (finish_omp_structured_block (sb));
+  add_stmt (finish_omp_for_block (finish_omp_structured_block (sb), ret));
 
   return ret;
 }
 
+static tree cp_parser_omp_taskloop (cp_parser *, cp_token *, char *,
+				    omp_clause_mask, tree *, bool *);
+
 /* OpenMP 2.5:
    # pragma omp master new-line
      structured-block  */
 
 static tree
-cp_parser_omp_master (cp_parser *parser, cp_token *pragma_tok, bool *if_p)
+cp_parser_omp_master (cp_parser *parser, cp_token *pragma_tok,
+		      char *p_name, omp_clause_mask mask, tree *cclauses,
+		      bool *if_p)
 {
-  cp_parser_require_pragma_eol (parser, pragma_tok);
-  return c_finish_omp_master (input_location,
+  tree clauses, sb, ret;
+  unsigned int save;
+  location_t loc = cp_lexer_peek_token (parser->lexer)->location;
+
+  strcat (p_name, " master");
+
+  if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
+    {
+      tree id = cp_lexer_peek_token (parser->lexer)->u.value;
+      const char *p = IDENTIFIER_POINTER (id);
+
+      if (strcmp (p, "taskloop") == 0)
+	{
+	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
+	  if (cclauses == NULL)
+	    cclauses = cclauses_buf;
+
+	  cp_lexer_consume_token (parser->lexer);
+	  if (!flag_openmp)  /* flag_openmp_simd  */
+	    return cp_parser_omp_taskloop (parser, pragma_tok, p_name, mask,
+					   cclauses, if_p);
+	  sb = begin_omp_structured_block ();
+	  save = cp_parser_begin_omp_structured_block (parser);
+	  ret = cp_parser_omp_taskloop (parser, pragma_tok, p_name, mask,
+					cclauses, if_p);
+	  cp_parser_end_omp_structured_block (parser, save);
+	  tree body = finish_omp_structured_block (sb);
+	  if (ret == NULL)
+	    return ret;
+	  return c_finish_omp_master (loc, body);
+	}
+    }
+  if (!flag_openmp)  /* flag_openmp_simd  */
+    {
+      cp_parser_skip_to_pragma_eol (parser, pragma_tok);
+      return NULL_TREE;
+    }
+
+  if (cclauses)
+    {
+      clauses = cp_parser_omp_all_clauses (parser, mask, p_name, pragma_tok,
+					   false);
+      cp_omp_split_clauses (loc, OMP_MASTER, mask, clauses, cclauses);
+    }
+  else
+    cp_parser_require_pragma_eol (parser, pragma_tok);
+
+  return c_finish_omp_master (loc,
 			      cp_parser_omp_structured_block (parser, if_p));
 }
 
@@ -36038,16 +37027,34 @@  cp_parser_omp_parallel (cp_parser *parse
       cp_parser_skip_to_pragma_eol (parser, pragma_tok);
       return NULL_TREE;
     }
-  else if (!flag_openmp)  /* flag_openmp_simd  */
-    {
-      cp_parser_skip_to_pragma_eol (parser, pragma_tok);
-      return NULL_TREE;
-    }
   else if (cclauses == NULL && cp_lexer_next_token_is (parser->lexer, CPP_NAME))
     {
       tree id = cp_lexer_peek_token (parser->lexer)->u.value;
       const char *p = IDENTIFIER_POINTER (id);
-      if (strcmp (p, "sections") == 0)
+      if (strcmp (p, "master") == 0)
+	{
+	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
+	  cclauses = cclauses_buf;
+
+	  cp_lexer_consume_token (parser->lexer);
+	  block = begin_omp_parallel ();
+	  save = cp_parser_begin_omp_structured_block (parser);
+	  tree ret = cp_parser_omp_master (parser, pragma_tok, p_name, mask,
+					   cclauses, if_p);
+	  cp_parser_end_omp_structured_block (parser, save);
+	  stmt = finish_omp_parallel (cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
+				      block);
+	  OMP_PARALLEL_COMBINED (stmt) = 1;
+	  if (ret == NULL_TREE)
+	    return ret;
+	  return stmt;
+	}
+      else if (!flag_openmp)  /* flag_openmp_simd  */
+	{
+	  cp_parser_skip_to_pragma_eol (parser, pragma_tok);
+	  return NULL_TREE;
+	}
+      else if (strcmp (p, "sections") == 0)
 	{
 	  tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT];
 	  cclauses = cclauses_buf;
@@ -36063,6 +37070,11 @@  cp_parser_omp_parallel (cp_parser *parse
 	  return stmt;
 	}
     }
+  else if (!flag_openmp)  /* flag_openmp_simd  */
+    {
+      cp_parser_skip_to_pragma_eol (parser, pragma_tok);
+      return NULL_TREE;
+    }
 
   clauses = cp_parser_omp_all_clauses (parser, mask, p_name, pragma_tok,
 				       cclauses == NULL);
@@ -36095,6 +37107,7 @@  cp_parser_omp_single (cp_parser *parser,
 {
   tree stmt = make_node (OMP_SINGLE);
   TREE_TYPE (stmt) = void_type_node;
+  SET_EXPR_LOCATION (stmt, pragma_tok->location);
 
   OMP_SINGLE_CLAUSES (stmt)
     = cp_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
@@ -36118,7 +37131,8 @@  cp_parser_omp_single (cp_parser *parser,
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)	\
-	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY)	\
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION))
 
 static tree
 cp_parser_omp_task (cp_parser *parser, cp_token *pragma_tok, bool *if_p)
@@ -36136,13 +37150,32 @@  cp_parser_omp_task (cp_parser *parser, c
 }
 
 /* OpenMP 3.0:
-   # pragma omp taskwait new-line  */
+   # pragma omp taskwait new-line
+
+   OpenMP 5.0:
+   # pragma omp taskwait taskwait-clause[opt] new-line  */
+
+#define OMP_TASKWAIT_CLAUSE_MASK				\
+	(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
 
 static void
 cp_parser_omp_taskwait (cp_parser *parser, cp_token *pragma_tok)
 {
-  cp_parser_require_pragma_eol (parser, pragma_tok);
-  finish_omp_taskwait ();
+  tree clauses
+    = cp_parser_omp_all_clauses (parser, OMP_TASKWAIT_CLAUSE_MASK,
+				 "#pragma omp taskwait", pragma_tok);
+
+  if (clauses)
+    {
+      tree stmt = make_node (OMP_TASK);
+      TREE_TYPE (stmt) = void_node;
+      OMP_TASK_CLAUSES (stmt) = clauses;
+      OMP_TASK_BODY (stmt) = NULL_TREE;
+      SET_EXPR_LOCATION (stmt, pragma_tok->location);
+      add_stmt (stmt);
+    }
+  else
+    finish_omp_taskwait ();
 }
 
 /* OpenMP 3.1:
@@ -36157,15 +37190,24 @@  cp_parser_omp_taskyield (cp_parser *pars
 
 /* OpenMP 4.0:
    # pragma omp taskgroup new-line
-     structured-block  */
+     structured-block
+
+   OpenMP 5.0:
+   # pragma omp taskgroup taskgroup-clause[optseq] new-line  */
+
+#define OMP_TASKGROUP_CLAUSE_MASK				\
+	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASK_REDUCTION))
 
 static tree
 cp_parser_omp_taskgroup (cp_parser *parser, cp_token *pragma_tok, bool *if_p)
 {
-  cp_parser_require_pragma_eol (parser, pragma_tok);
+  tree clauses
+    = cp_parser_omp_all_clauses (parser, OMP_TASKGROUP_CLAUSE_MASK,
+				 "#pragma omp taskgroup", pragma_tok);
   return c_finish_omp_taskgroup (input_location,
 				 cp_parser_omp_structured_block (parser,
-								 if_p));
+								 if_p),
+				 clauses);
 }
 
 
@@ -36338,13 +37380,14 @@  cp_parser_omp_distribute (cp_parser *par
       clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
     }
 
+  keep_next_level (true);
   sb = begin_omp_structured_block ();
   save = cp_parser_begin_omp_structured_block (parser);
 
   ret = cp_parser_omp_for_loop (parser, OMP_DISTRIBUTE, clauses, NULL, if_p);
 
   cp_parser_end_omp_structured_block (parser, save);
-  add_stmt (finish_omp_structured_block (sb));
+  add_stmt (finish_omp_for_block (finish_omp_structured_block (sb), ret));
 
   return ret;
 }
@@ -36388,6 +37431,7 @@  cp_parser_omp_teams (cp_parser *parser,
 	  if (!flag_openmp)  /* flag_openmp_simd  */
 	    return cp_parser_omp_distribute (parser, pragma_tok, p_name, mask,
 					     cclauses, if_p);
+	  keep_next_level (true);
 	  sb = begin_omp_structured_block ();
 	  save = cp_parser_begin_omp_structured_block (parser);
 	  ret = cp_parser_omp_distribute (parser, pragma_tok, p_name, mask,
@@ -36423,6 +37467,7 @@  cp_parser_omp_teams (cp_parser *parser,
   tree stmt = make_node (OMP_TEAMS);
   TREE_TYPE (stmt) = void_type_node;
   OMP_TEAMS_CLAUSES (stmt) = clauses;
+  keep_next_level (true);
   OMP_TEAMS_BODY (stmt) = cp_parser_omp_structured_block (parser, if_p);
   SET_EXPR_LOCATION (stmt, loc);
 
@@ -36473,6 +37518,8 @@  cp_parser_omp_target_data (cp_parser *pa
 	    *pc = OMP_CLAUSE_CHAIN (*pc);
 	    continue;
 	  }
+      else if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_USE_DEVICE_PTR)
+	map_seen = 3;
       pc = &OMP_CLAUSE_CHAIN (*pc);
     }
 
@@ -36481,7 +37528,7 @@  cp_parser_omp_target_data (cp_parser *pa
       if (map_seen == 0)
 	error_at (pragma_tok->location,
 		  "%<#pragma omp target data%> must contain at least "
-		  "one %<map%> clause");
+		  "one %<map%> or %<use_device_ptr%> clause");
       return NULL_TREE;
     }
 
@@ -36739,6 +37786,10 @@  cp_parser_omp_target (cp_parser *parser,
 {
   tree *pc = NULL, stmt;
 
+  if (flag_openmp)
+    omp_requires_mask
+      = (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED);
+
   if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
     {
       tree id = cp_lexer_peek_token (parser->lexer)->u.value;
@@ -38092,6 +39143,147 @@  cp_parser_omp_declare (cp_parser *parser
   return false;
 }
 
+/* OpenMP 5.0
+   #pragma omp requires clauses[optseq] new-line  */
+
+static bool
+cp_parser_omp_requires (cp_parser *parser, cp_token *pragma_tok)
+{
+  bool first = true;
+  enum omp_requires new_req = (enum omp_requires) 0;
+
+  location_t loc = pragma_tok->location;
+  while (cp_lexer_next_token_is_not (parser->lexer, CPP_PRAGMA_EOL))
+    {
+      if (!first && cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
+	cp_lexer_consume_token (parser->lexer);
+
+      first = false;
+
+      if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
+	{
+	  tree id = cp_lexer_peek_token (parser->lexer)->u.value;
+	  const char *p = IDENTIFIER_POINTER (id);
+	  location_t cloc = cp_lexer_peek_token (parser->lexer)->location;
+	  enum omp_requires this_req = (enum omp_requires) 0;
+
+	  if (!strcmp (p, "unified_address"))
+	    this_req = OMP_REQUIRES_UNIFIED_ADDRESS;
+	  else if (!strcmp (p, "unified_shared_memory"))
+	    this_req = OMP_REQUIRES_UNIFIED_SHARED_MEMORY;
+	  else if (!strcmp (p, "dynamic_allocators"))
+	    this_req = OMP_REQUIRES_DYNAMIC_ALLOCATORS;
+	  else if (!strcmp (p, "reverse_offload"))
+	    this_req = OMP_REQUIRES_REVERSE_OFFLOAD;
+	  else if (!strcmp (p, "atomic_default_mem_order"))
+	    {
+	      cp_lexer_consume_token (parser->lexer);
+
+	      matching_parens parens;
+	      if (parens.require_open (parser))
+		{
+		  if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
+		    {
+		      id = cp_lexer_peek_token (parser->lexer)->u.value;
+		      p = IDENTIFIER_POINTER (id);
+
+		      if (!strcmp (p, "seq_cst"))
+			this_req
+			  = (enum omp_requires) OMP_MEMORY_ORDER_SEQ_CST;
+		      else if (!strcmp (p, "relaxed"))
+			this_req
+			  = (enum omp_requires) OMP_MEMORY_ORDER_RELAXED;
+		      else if (!strcmp (p, "acq_rel"))
+			this_req
+			  = (enum omp_requires) OMP_MEMORY_ORDER_ACQ_REL;
+		    }
+		  if (this_req == 0)
+		    {
+		      error_at (cp_lexer_peek_token (parser->lexer)->location,
+				"expected %<seq_cst%>, %<relaxed%> or "
+				"%<acq_rel%>");
+		      if (cp_lexer_nth_token_is (parser->lexer, 2,
+						 CPP_CLOSE_PAREN))
+			cp_lexer_consume_token (parser->lexer);
+		    }
+		  else
+		    cp_lexer_consume_token (parser->lexer);
+
+		  if (!parens.require_close (parser))
+		    cp_parser_skip_to_closing_parenthesis (parser,
+							   /*recovering=*/true,
+							   /*or_comma=*/false,
+							   /*consume_paren=*/
+							   true);
+
+		  if (this_req == 0)
+		    {
+		      cp_parser_require_pragma_eol (parser, pragma_tok);
+		      return false;
+		    }
+		}
+	      p = NULL;
+	    }
+	  else
+	    {
+	      error_at (cloc, "expected %<unified_address%>, "
+			      "%<unified_shared_memory%>, "
+			      "%<dynamic_allocators%>, "
+			       "%<reverse_offload%> "
+			       "or %<atomic_default_mem_order%> clause");
+	      cp_parser_skip_to_pragma_eol (parser, pragma_tok);
+	      return false;
+	    }
+	  if (p)
+	    cp_lexer_consume_token (parser->lexer);
+	  if (this_req)
+	    {
+	      if ((this_req & ~OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0)
+		{
+		  if ((this_req & new_req) != 0)
+		    error_at (cloc, "too many %qs clauses", p);
+		  if (this_req != OMP_REQUIRES_DYNAMIC_ALLOCATORS
+		      && (omp_requires_mask & OMP_REQUIRES_TARGET_USED) != 0)
+		    error_at (cloc, "%qs clause used lexically after first "
+				    "target construct or offloading API", p);
+		}
+	      else if ((new_req & OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0)
+		{
+		  error_at (cloc, "too many %qs clauses",
+			    "atomic_default_mem_order");
+		  this_req = (enum omp_requires) 0;
+		}
+	      else if ((omp_requires_mask
+			& OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER) != 0)
+		{
+		  error_at (cloc, "more than one %<atomic_default_mem_order%>"
+				  " clause in a single compilation unit");
+		  this_req
+		    = (enum omp_requires)
+		       (omp_requires_mask
+			& OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER);
+		}
+	      else if ((omp_requires_mask
+			& OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED) != 0)
+		error_at (cloc, "%<atomic_default_mem_order%> clause used "
+				"lexically after first %<atomic%> construct "
+				"without memory order clause");
+	      new_req = (enum omp_requires) (new_req | this_req);
+	      omp_requires_mask
+		= (enum omp_requires) (omp_requires_mask | this_req);
+	      continue;
+	    }
+	}
+      break;
+    }
+  cp_parser_require_pragma_eol (parser, pragma_tok);
+
+  if (new_req == 0)
+    error_at (loc, "%<pragma omp requires%> requires at least one clause");
+  return false;
+}
+
+
 /* OpenMP 4.5:
    #pragma omp taskloop taskloop-clause[optseq] new-line
      for-loop
@@ -38113,7 +39305,9 @@  cp_parser_omp_declare (cp_parser *parser
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP)	\
-	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY)	\
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION)	\
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION))
 
 static tree
 cp_parser_omp_taskloop (cp_parser *parser, cp_token *pragma_tok,
@@ -38126,6 +39320,10 @@  cp_parser_omp_taskloop (cp_parser *parse
 
   strcat (p_name, " taskloop");
   mask |= OMP_TASKLOOP_CLAUSE_MASK;
+  /* #pragma omp parallel master taskloop{, simd} disallow in_reduction
+     clause.  */
+  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0)
+    mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IN_REDUCTION);
 
   if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
     {
@@ -38173,6 +39371,7 @@  cp_parser_omp_taskloop (cp_parser *parse
       clauses = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
     }
 
+  keep_next_level (true);
   sb = begin_omp_structured_block ();
   save = cp_parser_begin_omp_structured_block (parser);
 
@@ -38180,7 +39379,7 @@  cp_parser_omp_taskloop (cp_parser *parse
 				if_p);
 
   cp_parser_end_omp_structured_block (parser, save);
-  add_stmt (finish_omp_structured_block (sb));
+  add_stmt (finish_omp_for_block (finish_omp_structured_block (sb), ret));
 
   return ret;
 }
@@ -38487,7 +39686,9 @@  cp_parser_omp_construct (cp_parser *pars
 				if_p);
       break;
     case PRAGMA_OMP_MASTER:
-      stmt = cp_parser_omp_master (parser, pragma_tok, if_p);
+      strcpy (p_name, "#pragma omp");
+      stmt = cp_parser_omp_master (parser, pragma_tok, p_name, mask, NULL,
+				   if_p);
       break;
     case PRAGMA_OMP_PARALLEL:
       strcpy (p_name, "#pragma omp");
@@ -38947,6 +40148,21 @@  cp_parser_pragma (cp_parser *parser, enu
 	}
       break;
 
+    case PRAGMA_OMP_DEPOBJ:
+      switch (context)
+	{
+	case pragma_compound:
+	  cp_parser_omp_depobj (parser, pragma_tok);
+	  return false;
+	case pragma_stmt:
+	  error_at (pragma_tok->location, "%<#pragma %s%> may only be "
+		    "used in compound statements", "omp depobj");
+	  break;
+	default:
+	  goto bad_stmt;
+	}
+      break;
+
     case PRAGMA_OMP_FLUSH:
       switch (context)
 	{
@@ -39114,6 +40330,9 @@  cp_parser_pragma (cp_parser *parser, enu
       pop_omp_privatization_clauses (stmt);
       return true;
 
+    case PRAGMA_OMP_REQUIRES:
+      return cp_parser_omp_requires (parser, pragma_tok);
+
     case PRAGMA_OMP_ORDERED:
       if (context != pragma_stmt && context != pragma_compound)
 	goto bad_stmt;
--- gcc/cp/pt.c	(.../trunk)	(revision 265884)
+++ gcc/cp/pt.c	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -16097,11 +16097,49 @@  tsubst_copy (tree t, tree args, tsubst_f
 
 static tree
 tsubst_omp_clause_decl (tree decl, tree args, tsubst_flags_t complain,
-			tree in_decl)
+			tree in_decl, tree *iterator_cache)
 {
   if (decl == NULL_TREE)
     return NULL_TREE;
 
+  /* Handle OpenMP iterators.  */
+  if (TREE_CODE (decl) == TREE_LIST
+      && TREE_PURPOSE (decl)
+      && TREE_CODE (TREE_PURPOSE (decl)) == TREE_VEC)
+    {
+      tree ret;
+      if (iterator_cache[0] == TREE_PURPOSE (decl))
+	ret = iterator_cache[1];
+      else
+	{
+	  tree *tp = &ret;
+	  begin_scope (sk_omp, NULL);
+	  for (tree it = TREE_PURPOSE (decl); it; it = TREE_CHAIN (it))
+	    {
+	      *tp = copy_node (it);
+	      TREE_VEC_ELT (*tp, 0)
+		= tsubst_decl (TREE_VEC_ELT (it, 0), args, complain);
+	      TREE_VEC_ELT (*tp, 1)
+		= tsubst_expr (TREE_VEC_ELT (it, 1), args, complain, in_decl,
+			       /*integral_constant_expression_p=*/false);
+	      TREE_VEC_ELT (*tp, 2)
+		= tsubst_expr (TREE_VEC_ELT (it, 2), args, complain, in_decl,
+			       /*integral_constant_expression_p=*/false);
+	      TREE_VEC_ELT (*tp, 3)
+		= tsubst_expr (TREE_VEC_ELT (it, 3), args, complain, in_decl,
+			       /*integral_constant_expression_p=*/false);
+	      TREE_CHAIN (*tp) = NULL_TREE;
+	      tp = &TREE_CHAIN (*tp);
+	    }
+	  TREE_VEC_ELT (ret, 5) = poplevel (1, 1, 0);
+	  iterator_cache[0] = TREE_PURPOSE (decl);
+	  iterator_cache[1] = ret;
+	}
+      return build_tree_list (ret, tsubst_omp_clause_decl (TREE_VALUE (decl),
+							   args, complain,
+							   in_decl, NULL));
+    }
+
   /* Handle an OpenMP array section represented as a TREE_LIST (or
      OMP_CLAUSE_DEPEND_KIND).  An OMP_CLAUSE_DEPEND (with a depend
      kind of OMP_CLAUSE_DEPEND_SINK) can also be represented as a
@@ -16116,7 +16154,7 @@  tsubst_omp_clause_decl (tree decl, tree
       tree length = tsubst_expr (TREE_VALUE (decl), args, complain, in_decl,
 				 /*integral_constant_expression_p=*/false);
       tree chain = tsubst_omp_clause_decl (TREE_CHAIN (decl), args, complain,
-					   in_decl);
+					   in_decl, NULL);
       if (TREE_PURPOSE (decl) == low_bound
 	  && TREE_VALUE (decl) == length
 	  && TREE_CHAIN (decl) == chain)
@@ -16144,6 +16182,7 @@  tsubst_omp_clauses (tree clauses, enum c
 {
   tree new_clauses = NULL_TREE, nc, oc;
   tree linear_no_step = NULL_TREE;
+  tree iterator_cache[2] = { NULL_TREE, NULL_TREE };
 
   for (oc = clauses; oc ; oc = OMP_CLAUSE_CHAIN (oc))
     {
@@ -16173,11 +16212,12 @@  tsubst_omp_clauses (tree clauses, enum c
 	case OMP_CLAUSE_FROM:
 	case OMP_CLAUSE_TO:
 	case OMP_CLAUSE_MAP:
+	case OMP_CLAUSE_NONTEMPORAL:
 	case OMP_CLAUSE_USE_DEVICE_PTR:
 	case OMP_CLAUSE_IS_DEVICE_PTR:
 	  OMP_CLAUSE_DECL (nc)
 	    = tsubst_omp_clause_decl (OMP_CLAUSE_DECL (oc), args, complain,
-				      in_decl);
+				      in_decl, iterator_cache);
 	  break;
 	case OMP_CLAUSE_TILE:
 	case OMP_CLAUSE_IF:
@@ -16208,6 +16248,8 @@  tsubst_omp_clauses (tree clauses, enum c
 			   in_decl, /*integral_constant_expression_p=*/false);
 	  break;
 	case OMP_CLAUSE_REDUCTION:
+	case OMP_CLAUSE_IN_REDUCTION:
+	case OMP_CLAUSE_TASK_REDUCTION:
 	  if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (oc))
 	    {
 	      tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (oc);
@@ -16225,13 +16267,13 @@  tsubst_omp_clauses (tree clauses, enum c
 	    }
 	  OMP_CLAUSE_DECL (nc)
 	    = tsubst_omp_clause_decl (OMP_CLAUSE_DECL (oc), args, complain,
-				      in_decl);
+				      in_decl, NULL);
 	  break;
 	case OMP_CLAUSE_GANG:
 	case OMP_CLAUSE_ALIGNED:
 	  OMP_CLAUSE_DECL (nc)
 	    = tsubst_omp_clause_decl (OMP_CLAUSE_DECL (oc), args, complain,
-				      in_decl);
+				      in_decl, NULL);
 	  OMP_CLAUSE_OPERAND (nc, 1)
 	    = tsubst_expr (OMP_CLAUSE_OPERAND (oc, 1), args, complain,
 			   in_decl, /*integral_constant_expression_p=*/false);
@@ -16239,7 +16281,7 @@  tsubst_omp_clauses (tree clauses, enum c
 	case OMP_CLAUSE_LINEAR:
 	  OMP_CLAUSE_DECL (nc)
 	    = tsubst_omp_clause_decl (OMP_CLAUSE_DECL (oc), args, complain,
-				      in_decl);
+				      in_decl, NULL);
 	  if (OMP_CLAUSE_LINEAR_STEP (oc) == NULL_TREE)
 	    {
 	      gcc_assert (!linear_no_step);
@@ -16248,7 +16290,7 @@  tsubst_omp_clauses (tree clauses, enum c
 	  else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (oc))
 	    OMP_CLAUSE_LINEAR_STEP (nc)
 	      = tsubst_omp_clause_decl (OMP_CLAUSE_LINEAR_STEP (oc), args,
-					complain, in_decl);
+					complain, in_decl, NULL);
 	  else
 	    OMP_CLAUSE_LINEAR_STEP (nc)
 	      = tsubst_expr (OMP_CLAUSE_LINEAR_STEP (oc), args, complain,
@@ -16289,6 +16331,8 @@  tsubst_omp_clauses (tree clauses, enum c
 	  case OMP_CLAUSE_COPYPRIVATE:
 	  case OMP_CLAUSE_LINEAR:
 	  case OMP_CLAUSE_REDUCTION:
+	  case OMP_CLAUSE_IN_REDUCTION:
+	  case OMP_CLAUSE_TASK_REDUCTION:
 	  case OMP_CLAUSE_USE_DEVICE_PTR:
 	  case OMP_CLAUSE_IS_DEVICE_PTR:
 	    /* tsubst_expr on SCOPE_REF results in returning
@@ -16403,10 +16447,13 @@  tsubst_copy_asm_operands (tree t, tree a
 
 static tree *omp_parallel_combined_clauses;
 
+static tree tsubst_decomp_names (tree, tree, tree, tsubst_flags_t, tree,
+				 tree *, unsigned int *);
+
 /* Substitute one OMP_FOR iterator.  */
 
-static void
-tsubst_omp_for_iterator (tree t, int i, tree declv, tree orig_declv,
+static bool
+tsubst_omp_for_iterator (tree t, int i, tree declv, tree &orig_declv,
 			 tree initv, tree condv, tree incrv, tree *clauses,
 			 tree args, tsubst_flags_t complain, tree in_decl,
 			 bool integral_constant_expression_p)
@@ -16414,26 +16461,56 @@  tsubst_omp_for_iterator (tree t, int i,
 #define RECUR(NODE)				\
   tsubst_expr ((NODE), args, complain, in_decl,	\
 	       integral_constant_expression_p)
-  tree decl, init, cond, incr;
+  tree decl, init, cond = NULL_TREE, incr = NULL_TREE;
+  bool ret = false;
 
   init = TREE_VEC_ELT (OMP_FOR_INIT (t), i);
   gcc_assert (TREE_CODE (init) == MODIFY_EXPR);
 
-  if (orig_declv && OMP_FOR_ORIG_DECLS (t))
-    {
-      tree o = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (t), i);
-      if (TREE_CODE (o) == TREE_LIST)
-	TREE_VEC_ELT (orig_declv, i)
-	  = tree_cons (RECUR (TREE_PURPOSE (o)),
-		       RECUR (TREE_VALUE (o)), NULL_TREE);
-      else
-	TREE_VEC_ELT (orig_declv, i) = RECUR (o);
-    }
-
   decl = TREE_OPERAND (init, 0);
   init = TREE_OPERAND (init, 1);
   tree decl_expr = NULL_TREE;
-  if (init && TREE_CODE (init) == DECL_EXPR)
+  bool range_for = TREE_VEC_ELT (OMP_FOR_COND (t), i) == global_namespace;
+  if (range_for)
+    {
+      bool decomp = false;
+      if (decl != error_mark_node && DECL_HAS_VALUE_EXPR_P (decl))
+	{
+	  tree v = DECL_VALUE_EXPR (decl);
+	  if (TREE_CODE (v) == ARRAY_REF
+	      && VAR_P (TREE_OPERAND (v, 0))
+	      && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0)))
+	    {
+	      tree decomp_first = NULL_TREE;
+	      unsigned decomp_cnt = 0;
+	      tree d = tsubst_decl (TREE_OPERAND (v, 0), args, complain);
+	      maybe_push_decl (d);
+	      d = tsubst_decomp_names (d, TREE_OPERAND (v, 0), args, complain,
+				       in_decl, &decomp_first, &decomp_cnt);
+	      decomp = true;
+	      if (d == error_mark_node)
+		decl = error_mark_node;
+	      else
+		for (unsigned int i = 0; i < decomp_cnt; i++)
+		  {
+		    if (!DECL_HAS_VALUE_EXPR_P (decomp_first))
+		      {
+			tree v = build_nt (ARRAY_REF, d,
+					   size_int (decomp_cnt - i - 1),
+					   NULL_TREE, NULL_TREE);
+			SET_DECL_VALUE_EXPR (decomp_first, v);
+			DECL_HAS_VALUE_EXPR_P (decomp_first) = 1;
+		      }
+		    fit_decomposition_lang_decl (decomp_first, d);
+		    decomp_first = DECL_CHAIN (decomp_first);
+		  }
+	    }
+	}
+      decl = tsubst_decl (decl, args, complain);
+      if (!decomp)
+	maybe_push_decl (decl);
+    }
+  else if (init && TREE_CODE (init) == DECL_EXPR)
     {
       /* We need to jump through some hoops to handle declarations in the
 	 init-statement, since we might need to handle auto deduction,
@@ -16480,14 +16557,44 @@  tsubst_omp_for_iterator (tree t, int i,
     }
   init = RECUR (init);
 
+  if (orig_declv && OMP_FOR_ORIG_DECLS (t))
+    {
+      tree o = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (t), i);
+      if (TREE_CODE (o) == TREE_LIST)
+	TREE_VEC_ELT (orig_declv, i)
+	  = tree_cons (RECUR (TREE_PURPOSE (o)),
+		       RECUR (TREE_VALUE (o)),
+		       NULL_TREE);
+      else
+	TREE_VEC_ELT (orig_declv, i) = RECUR (o);
+    }
+
+  if (range_for)
+    {
+      tree this_pre_body = NULL_TREE;
+      tree orig_init = NULL_TREE;
+      tree orig_decl = NULL_TREE;
+      cp_convert_omp_range_for (this_pre_body, NULL, decl, orig_decl, init,
+				orig_init, cond, incr);
+      if (orig_decl)
+	{
+	  if (orig_declv == NULL_TREE)
+	    orig_declv = copy_node (declv);
+	  TREE_VEC_ELT (orig_declv, i) = orig_decl;
+	  ret = true;
+	}
+      else if (orig_declv)
+	TREE_VEC_ELT (orig_declv, i) = decl;
+    }
+
   tree auto_node = type_uses_auto (TREE_TYPE (decl));
-  if (auto_node && init)
+  if (!range_for && auto_node && init)
     TREE_TYPE (decl)
       = do_auto_deduction (TREE_TYPE (decl), init, auto_node, complain);
 
   gcc_assert (!type_dependent_expression_p (decl));
 
-  if (!CLASS_TYPE_P (TREE_TYPE (decl)))
+  if (!CLASS_TYPE_P (TREE_TYPE (decl)) || range_for)
     {
       if (decl_expr)
 	{
@@ -16498,22 +16605,27 @@  tsubst_omp_for_iterator (tree t, int i,
 	  DECL_INITIAL (DECL_EXPR_DECL (decl_expr)) = init_sav;
 	}
 
-      cond = RECUR (TREE_VEC_ELT (OMP_FOR_COND (t), i));
-      incr = TREE_VEC_ELT (OMP_FOR_INCR (t), i);
-      if (TREE_CODE (incr) == MODIFY_EXPR)
+      if (!range_for)
 	{
-	  tree lhs = RECUR (TREE_OPERAND (incr, 0));
-	  tree rhs = RECUR (TREE_OPERAND (incr, 1));
-	  incr = build_x_modify_expr (EXPR_LOCATION (incr), lhs,
-				      NOP_EXPR, rhs, complain);
+	  cond = RECUR (TREE_VEC_ELT (OMP_FOR_COND (t), i));
+	  incr = TREE_VEC_ELT (OMP_FOR_INCR (t), i);
+	  if (TREE_CODE (incr) == MODIFY_EXPR)
+	    {
+	      tree lhs = RECUR (TREE_OPERAND (incr, 0));
+	      tree rhs = RECUR (TREE_OPERAND (incr, 1));
+	      incr = build_x_modify_expr (EXPR_LOCATION (incr), lhs,
+					  NOP_EXPR, rhs, complain);
+	    }
+	  else
+	    incr = RECUR (incr);
+	  if (orig_declv && !OMP_FOR_ORIG_DECLS (t))
+	    TREE_VEC_ELT (orig_declv, i) = decl;
 	}
-      else
-	incr = RECUR (incr);
       TREE_VEC_ELT (declv, i) = decl;
       TREE_VEC_ELT (initv, i) = init;
       TREE_VEC_ELT (condv, i) = cond;
       TREE_VEC_ELT (incrv, i) = incr;
-      return;
+      return ret;
     }
 
   if (decl_expr)
@@ -16640,10 +16752,13 @@  tsubst_omp_for_iterator (tree t, int i,
       break;
     }
 
+  if (orig_declv && !OMP_FOR_ORIG_DECLS (t))
+    TREE_VEC_ELT (orig_declv, i) = decl;
   TREE_VEC_ELT (declv, i) = decl;
   TREE_VEC_ELT (initv, i) = init;
   TREE_VEC_ELT (condv, i) = cond;
   TREE_VEC_ELT (incrv, i) = incr;
+  return false;
 #undef RECUR
 }
 
@@ -17254,6 +17369,15 @@  tsubst_expr (tree t, tree args, tsubst_f
       break;
 
     case OMP_TASK:
+      if (OMP_TASK_BODY (t) == NULL_TREE)
+	{
+	  tmp = tsubst_omp_clauses (OMP_TASK_CLAUSES (t), C_ORT_OMP, args,
+				    complain, in_decl);
+	  t = copy_node (t);
+	  OMP_TASK_CLAUSES (t) = tmp;
+	  add_stmt (t);
+	  break;
+	}
       r = push_omp_privatization_clauses (false);
       tmp = tsubst_omp_clauses (OMP_TASK_CLAUSES (t), C_ORT_OMP, args,
 				complain, in_decl);
@@ -17274,6 +17398,7 @@  tsubst_expr (tree t, tree args, tsubst_f
 	tree orig_declv = NULL_TREE;
 	tree incrv = NULL_TREE;
 	enum c_omp_region_type ort = C_ORT_OMP;
+	bool any_range_for = false;
 	int i;
 
 	if (TREE_CODE (t) == OACC_LOOP)
@@ -17292,6 +17417,7 @@  tsubst_expr (tree t, tree args, tsubst_f
 	    incrv = make_tree_vec (TREE_VEC_LENGTH (OMP_FOR_INIT (t)));
 	  }
 
+	keep_next_level (true);
 	stmt = begin_omp_structured_block ();
 
 	pre_body = push_stmt_list ();
@@ -17300,14 +17426,31 @@  tsubst_expr (tree t, tree args, tsubst_f
 
 	if (OMP_FOR_INIT (t) != NULL_TREE)
 	  for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (t)); i++)
-	    tsubst_omp_for_iterator (t, i, declv, orig_declv, initv, condv,
-				     incrv, &clauses, args, complain, in_decl,
-				     integral_constant_expression_p);
+	    any_range_for
+	      |= tsubst_omp_for_iterator (t, i, declv, orig_declv, initv,
+					  condv, incrv, &clauses, args,
+					  complain, in_decl,
+					  integral_constant_expression_p);
 	omp_parallel_combined_clauses = NULL;
 
-	body = push_stmt_list ();
+	if (any_range_for)
+	  {
+	    gcc_assert (orig_declv);
+	    body = begin_omp_structured_block ();
+	    for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (t)); i++)
+	      if (TREE_VEC_ELT (orig_declv, i) != TREE_VEC_ELT (declv, i)
+		  && TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST
+		  && TREE_CHAIN (TREE_VEC_ELT (orig_declv, i)))
+		cp_finish_omp_range_for (TREE_VEC_ELT (orig_declv, i),
+					 TREE_VEC_ELT (declv, i));
+	  }
+	else
+	  body = push_stmt_list ();
 	RECUR (OMP_FOR_BODY (t));
-	body = pop_stmt_list (body);
+	if (any_range_for)
+	  body = finish_omp_structured_block (body);
+	else
+	  body = pop_stmt_list (body);
 
 	if (OMP_FOR_INIT (t) != NULL_TREE)
 	  t = finish_omp_for (EXPR_LOCATION (t), TREE_CODE (t), declv,
@@ -17324,7 +17467,8 @@  tsubst_expr (tree t, tree args, tsubst_f
 	    add_stmt (t);
 	  }
 
-	add_stmt (finish_omp_structured_block (stmt));
+	add_stmt (finish_omp_for_block (finish_omp_structured_block (stmt),
+					t));
 	pop_omp_privatization_clauses (r);
       }
       break;
@@ -17335,13 +17479,24 @@  tsubst_expr (tree t, tree args, tsubst_f
     case OMP_SINGLE:
     case OMP_TEAMS:
     case OMP_CRITICAL:
+    case OMP_TASKGROUP:
       r = push_omp_privatization_clauses (TREE_CODE (t) == OMP_TEAMS
 					  && OMP_TEAMS_COMBINED (t));
       tmp = tsubst_omp_clauses (OMP_CLAUSES (t), C_ORT_OMP, args, complain,
 				in_decl);
-      stmt = push_stmt_list ();
-      RECUR (OMP_BODY (t));
-      stmt = pop_stmt_list (stmt);
+      if (TREE_CODE (t) == OMP_TEAMS)
+	{
+	  keep_next_level (true);
+	  stmt = begin_omp_structured_block ();
+	  RECUR (OMP_BODY (t));
+	  stmt = finish_omp_structured_block (stmt);
+	}
+      else
+	{
+	  stmt = push_stmt_list ();
+	  RECUR (OMP_BODY (t));
+	  stmt = pop_stmt_list (stmt);
+	}
 
       t = copy_node (t);
       OMP_BODY (t) = stmt;
@@ -17350,6 +17505,32 @@  tsubst_expr (tree t, tree args, tsubst_f
       pop_omp_privatization_clauses (r);
       break;
 
+    case OMP_DEPOBJ:
+      r = RECUR (OMP_DEPOBJ_DEPOBJ (t));
+      if (OMP_DEPOBJ_CLAUSES (t) && OMP_DEPOBJ_CLAUSES (t) != error_mark_node)
+	{
+	  enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_SOURCE;
+	  if (TREE_CODE (OMP_DEPOBJ_CLAUSES (t)) == OMP_CLAUSE)
+	    {
+	      tmp = tsubst_omp_clauses (OMP_DEPOBJ_CLAUSES (t), C_ORT_OMP,
+					args, complain, in_decl);
+	      if (tmp == NULL_TREE)
+		tmp = error_mark_node;
+	    }
+	  else
+	    {
+	      kind = (enum omp_clause_depend_kind)
+		     tree_to_uhwi (OMP_DEPOBJ_CLAUSES (t));
+	      tmp = NULL_TREE;
+	    }
+	  finish_omp_depobj (EXPR_LOCATION (t), r, kind, tmp);
+	}
+      else
+	finish_omp_depobj (EXPR_LOCATION (t), r,
+			   OMP_CLAUSE_DEPEND_SOURCE,
+			   OMP_DEPOBJ_CLAUSES (t));
+      break;
+
     case OACC_DATA:
     case OMP_TARGET_DATA:
     case OMP_TARGET:
@@ -17441,7 +17622,6 @@  tsubst_expr (tree t, tree args, tsubst_f
 
     case OMP_SECTION:
     case OMP_MASTER:
-    case OMP_TASKGROUP:
       stmt = push_stmt_list ();
       RECUR (OMP_BODY (t));
       stmt = pop_stmt_list (stmt);
@@ -17453,6 +17633,10 @@  tsubst_expr (tree t, tree args, tsubst_f
 
     case OMP_ATOMIC:
       gcc_assert (OMP_ATOMIC_DEPENDENT_P (t));
+      tmp = NULL_TREE;
+      if (TREE_CODE (TREE_OPERAND (t, 0)) == OMP_CLAUSE)
+	tmp = tsubst_omp_clauses (TREE_OPERAND (t, 0), C_ORT_OMP, args,
+				  complain, in_decl);
       if (TREE_CODE (TREE_OPERAND (t, 1)) != MODIFY_EXPR)
 	{
 	  tree op1 = TREE_OPERAND (t, 1);
@@ -17465,9 +17649,9 @@  tsubst_expr (tree t, tree args, tsubst_f
 	    }
 	  lhs = RECUR (TREE_OPERAND (op1, 0));
 	  rhs = RECUR (TREE_OPERAND (op1, 1));
-	  finish_omp_atomic (OMP_ATOMIC, TREE_CODE (op1), lhs, rhs,
-			     NULL_TREE, NULL_TREE, rhs1,
-			     OMP_ATOMIC_SEQ_CST (t));
+	  finish_omp_atomic (EXPR_LOCATION (t), OMP_ATOMIC, TREE_CODE (op1),
+			     lhs, rhs, NULL_TREE, NULL_TREE, rhs1, tmp,
+			     OMP_ATOMIC_MEMORY_ORDER (t));
 	}
       else
 	{
@@ -17504,8 +17688,8 @@  tsubst_expr (tree t, tree args, tsubst_f
 	      lhs = RECUR (TREE_OPERAND (op1, 0));
 	      rhs = RECUR (TREE_OPERAND (op1, 1));
 	    }
-	  finish_omp_atomic (code, opcode, lhs, rhs, v, lhs1, rhs1,
-			     OMP_ATOMIC_SEQ_CST (t));
+	  finish_omp_atomic (EXPR_LOCATION (t), code, opcode, lhs, rhs, v,
+			     lhs1, rhs1, tmp, OMP_ATOMIC_MEMORY_ORDER (t));
 	}
       break;
 
@@ -25865,6 +26049,9 @@  dependent_omp_for_p (tree declv, tree in
       if (init && type_dependent_expression_p (init))
 	return true;
 
+      if (cond == global_namespace)
+	return true;
+
       if (type_dependent_expression_p (cond))
 	return true;
 
@@ -25891,6 +26078,20 @@  dependent_omp_for_p (tree declv, tree in
 	      if (type_dependent_expression_p (TREE_OPERAND (t, 0))
 		  || type_dependent_expression_p (TREE_OPERAND (t, 1)))
 		return true;
+
+	      /* If this loop has a class iterator with != comparison
+		 with increment other than i++/++i/i--/--i, make sure the
+		 increment is constant.  */
+	      if (CLASS_TYPE_P (TREE_TYPE (decl))
+		  && TREE_CODE (cond) == NE_EXPR)
+		{
+		  if (TREE_OPERAND (t, 0) == decl)
+		    t = TREE_OPERAND (t, 1);
+		  else
+		    t = TREE_OPERAND (t, 0);
+		  if (TREE_CODE (t) != INTEGER_CST)
+		    return true;
+		}
 	    }
 	}
     }
--- gcc/cp/semantics.c	(.../trunk)	(revision 265884)
+++ gcc/cp/semantics.c	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -44,6 +44,7 @@  along with GCC; see the file COPYING3.
 #include "attribs.h"
 #include "gomp-constants.h"
 #include "predict.h"
+#include "memmodel.h"
 
 /* There routines provide a modular interface to perform many parsing
    operations.  They may therefore be used during actual parsing, or
@@ -4634,7 +4635,9 @@  handle_omp_array_sections_1 (tree c, tre
     }
 
   if (ort == C_ORT_OMP
-      && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+      && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+	  || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
+	  || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
       && TREE_CODE (TREE_CHAIN (t)) == FIELD_DECL)
     TREE_CHAIN (t) = omp_privatize_field (TREE_CHAIN (t), false);
   ret = handle_omp_array_sections_1 (c, TREE_CHAIN (t), types,
@@ -4693,7 +4696,9 @@  handle_omp_array_sections_1 (tree c, tre
       if (!integer_nonzerop (length))
 	{
 	  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
-	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
+	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
+	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
 	    {
 	      if (integer_zerop (length))
 		{
@@ -4759,7 +4764,9 @@  handle_omp_array_sections_1 (tree c, tre
 	      if (tree_int_cst_equal (size, low_bound))
 		{
 		  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
-		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
 		    {
 		      error_at (OMP_CLAUSE_LOCATION (c),
 				"zero length array section in %qs clause",
@@ -4778,7 +4785,9 @@  handle_omp_array_sections_1 (tree c, tre
 	  else if (length == NULL_TREE)
 	    {
 	      if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
-		  && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
+		  && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
+		  && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
+		  && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
 		maybe_zero_len = true;
 	      if (first_non_one == types.length ())
 		first_non_one++;
@@ -4814,7 +4823,9 @@  handle_omp_array_sections_1 (tree c, tre
       else if (length == NULL_TREE)
 	{
 	  if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
-	      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
+	      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
+	      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
+	      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
 	    maybe_zero_len = true;
 	  if (first_non_one == types.length ())
 	    first_non_one++;
@@ -4886,7 +4897,13 @@  handle_omp_array_sections (tree c, enum
   bool maybe_zero_len = false;
   unsigned int first_non_one = 0;
   auto_vec<tree, 10> types;
-  tree first = handle_omp_array_sections_1 (c, OMP_CLAUSE_DECL (c), types,
+  tree *tp = &OMP_CLAUSE_DECL (c);
+  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
+      && TREE_CODE (*tp) == TREE_LIST
+      && TREE_PURPOSE (*tp)
+      && TREE_CODE (TREE_PURPOSE (*tp)) == TREE_VEC)
+    tp = &TREE_VALUE (*tp);
+  tree first = handle_omp_array_sections_1 (c, *tp, types,
 					    maybe_zero_len, first_non_one,
 					    ort);
   if (first == error_mark_node)
@@ -4895,7 +4912,7 @@  handle_omp_array_sections (tree c, enum
     return false;
   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
     {
-      tree t = OMP_CLAUSE_DECL (c);
+      tree t = *tp;
       tree tem = NULL_TREE;
       if (processing_template_decl)
 	return false;
@@ -4915,7 +4932,7 @@  handle_omp_array_sections (tree c, enum
 	}
       if (tem)
 	first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
-      OMP_CLAUSE_DECL (c) = first;
+      *tp = first;
     }
   else
     {
@@ -4992,7 +5009,9 @@  handle_omp_array_sections (tree c, enum
 
 	      if (i > first_non_one
 		  && ((length && integer_nonzerop (length))
-		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION))
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
 		continue;
 	      if (length)
 		l = fold_convert (sizetype, length);
@@ -5020,7 +5039,9 @@  handle_omp_array_sections (tree c, enum
 		  tree eltype = TREE_TYPE (types[num - 1]);
 		  while (TREE_CODE (eltype) == ARRAY_TYPE)
 		    eltype = TREE_TYPE (eltype);
-		  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
+		  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
+		      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
 		    size = size_binop (EXACT_DIV_EXPR, size,
 				       size_in_bytes (eltype));
 		  size = size_binop (MULT_EXPR, size, l);
@@ -5036,9 +5057,12 @@  handle_omp_array_sections (tree c, enum
 	{
 	  if (side_effects)
 	    size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
-	  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
+	  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
+	      || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
 	    {
 	      size = size_binop (MINUS_EXPR, size, size_one_node);
+	      size = save_expr (size);
 	      tree index_type = build_index_type (size);
 	      tree eltype = TREE_TYPE (first);
 	      while (TREE_CODE (eltype) == ARRAY_TYPE)
@@ -5576,11 +5600,13 @@  finish_omp_reduction_clause (tree c, boo
 				  TYPE_SIZE_UNIT (type));
 	  if (integer_zerop (size))
 	    {
-	      error ("%qE in %<reduction%> clause is a zero size array",
-		     omp_clause_printable_decl (t));
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qE in %<reduction%> clause is a zero size array",
+			omp_clause_printable_decl (t));
 	      return true;
 	    }
 	  size = size_binop (MINUS_EXPR, size, size_one_node);
+	  size = save_expr (size);
 	  tree index_type = build_index_type (size);
 	  tree atype = build_array_type (type, index_type);
 	  tree ptype = build_pointer_type (type);
@@ -5624,8 +5650,9 @@  finish_omp_reduction_clause (tree c, boo
       }
   else if (TYPE_READONLY (type))
     {
-      error ("%qE has const type for %<reduction%>",
-	     omp_clause_printable_decl (t));
+      error_at (OMP_CLAUSE_LOCATION (c),
+		"%qE has const type for %<reduction%>",
+		omp_clause_printable_decl (t));
       return true;
     }
   else if (!processing_template_decl)
@@ -5699,7 +5726,8 @@  finish_omp_reduction_clause (tree c, boo
 	      if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
 		cxx_mark_addressable (placeholder);
 	      if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
-		  && !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c))))
+		  && (decl_placeholder
+		      || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
 		cxx_mark_addressable (decl_placeholder ? decl_placeholder
 				      : OMP_CLAUSE_DECL (c));
 	      tree omp_out = placeholder;
@@ -5725,7 +5753,9 @@  finish_omp_reduction_clause (tree c, boo
 	    {
 	      gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
 			  && TREE_CODE (stmts[4]) == DECL_EXPR);
-	      if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3])))
+	      if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
+		  && (decl_placeholder
+		      || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
 		cxx_mark_addressable (decl_placeholder ? decl_placeholder
 				      : OMP_CLAUSE_DECL (c));
 	      if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
@@ -5786,8 +5816,9 @@  finish_omp_reduction_clause (tree c, boo
     *need_dtor = true;
   else
     {
-      error ("user defined reduction not found for %qE",
-	     omp_clause_printable_decl (t));
+      error_at (OMP_CLAUSE_LOCATION (c),
+		"user defined reduction not found for %qE",
+		omp_clause_printable_decl (t));
       return true;
     }
   if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
@@ -5868,6 +5899,155 @@  cp_finish_omp_clause_depend_sink (tree s
   return false;
 }
 
+/* Finish OpenMP iterators ITER.  Return true if they are errorneous
+   and clauses containing them should be removed.  */
+
+static bool
+cp_omp_finish_iterators (tree iter)
+{
+  bool ret = false;
+  for (tree it = iter; it; it = TREE_CHAIN (it))
+    {
+      tree var = TREE_VEC_ELT (it, 0);
+      tree begin = TREE_VEC_ELT (it, 1);
+      tree end = TREE_VEC_ELT (it, 2);
+      tree step = TREE_VEC_ELT (it, 3);
+      tree orig_step;
+      tree type = TREE_TYPE (var);
+      location_t loc = DECL_SOURCE_LOCATION (var);
+      if (type == error_mark_node)
+	{
+	  ret = true;
+	  continue;
+	}
+      if (type_dependent_expression_p (var))
+	continue;
+      if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
+	{
+	  error_at (loc, "iterator %qD has neither integral nor pointer type",
+		    var);
+	  ret = true;
+	  continue;
+	}
+      else if (TYPE_READONLY (type))
+	{
+	  error_at (loc, "iterator %qD has const qualified type", var);
+	  ret = true;
+	  continue;
+	}
+      if (type_dependent_expression_p (begin)
+	  || type_dependent_expression_p (end)
+	  || type_dependent_expression_p (step))
+	continue;
+      else if (error_operand_p (step))
+	{
+	  ret = true;
+	  continue;
+	}
+      else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
+	{
+	  error_at (EXPR_LOC_OR_LOC (step, loc),
+		    "iterator step with non-integral type");
+	  ret = true;
+	  continue;
+	}
+
+      begin = mark_rvalue_use (begin);
+      end = mark_rvalue_use (end);
+      step = mark_rvalue_use (step);
+      begin = cp_build_c_cast (type, begin, tf_warning_or_error);
+      end = cp_build_c_cast (type, end, tf_warning_or_error);
+      orig_step = step;
+      if (!processing_template_decl)
+	step = orig_step = save_expr (step);
+      tree stype = POINTER_TYPE_P (type) ? sizetype : type;
+      step = cp_build_c_cast (stype, step, tf_warning_or_error);
+      if (POINTER_TYPE_P (type) && !processing_template_decl)
+	{
+	  begin = save_expr (begin);
+	  step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
+	  step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
+				  fold_convert (sizetype, step),
+				  fold_convert (sizetype, begin));
+	  step = fold_convert (ssizetype, step);
+	}
+      if (!processing_template_decl)
+	{
+	  begin = maybe_constant_value (begin);
+	  end = maybe_constant_value (end);
+	  step = maybe_constant_value (step);
+	  orig_step = maybe_constant_value (orig_step);
+	}
+      if (integer_zerop (step))
+	{
+	  error_at (loc, "iterator %qD has zero step", var);
+	  ret = true;
+	  continue;
+	}
+
+      if (begin == error_mark_node
+	  || end == error_mark_node
+	  || step == error_mark_node
+	  || orig_step == error_mark_node)
+	{
+	  ret = true;
+	  continue;
+	}
+
+      if (!processing_template_decl)
+	{
+	  begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
+	  end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
+	  step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
+	  orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
+						     orig_step);
+	}
+      hash_set<tree> pset;
+      tree it2;
+      for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
+	{
+	  tree var2 = TREE_VEC_ELT (it2, 0);
+	  tree begin2 = TREE_VEC_ELT (it2, 1);
+	  tree end2 = TREE_VEC_ELT (it2, 2);
+	  tree step2 = TREE_VEC_ELT (it2, 3);
+	  location_t loc2 = DECL_SOURCE_LOCATION (var2);
+	  if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
+	    {
+	      error_at (EXPR_LOC_OR_LOC (begin2, loc2),
+			"begin expression refers to outer iterator %qD", var);
+	      break;
+	    }
+	  else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
+	    {
+	      error_at (EXPR_LOC_OR_LOC (end2, loc2),
+			"end expression refers to outer iterator %qD", var);
+	      break;
+	    }
+	  else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
+	    {
+	      error_at (EXPR_LOC_OR_LOC (step2, loc2),
+			"step expression refers to outer iterator %qD", var);
+	      break;
+	    }
+	}
+      if (it2)
+	{
+	  ret = true;
+	  continue;
+	}
+      TREE_VEC_ELT (it, 1) = begin;
+      TREE_VEC_ELT (it, 2) = end;
+      if (processing_template_decl)
+	TREE_VEC_ELT (it, 3) = orig_step;
+      else
+	{
+	  TREE_VEC_ELT (it, 3) = step;
+	  TREE_VEC_ELT (it, 4) = orig_step;
+	}
+    }
+  return ret;
+}
+
 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
    Remove any elements from the list that are invalid.  */
 
@@ -5882,14 +6062,19 @@  finish_omp_clauses (tree clauses, enum c
   bool copyprivate_seen = false;
   bool ordered_seen = false;
   bool oacc_async = false;
+  tree last_iterators = NULL_TREE;
+  bool last_iterators_remove = false;
+  bool reduction_seen = false;
 
   bitmap_obstack_initialize (NULL);
   bitmap_initialize (&generic_head, &bitmap_default_obstack);
   bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
   bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
   bitmap_initialize (&aligned_head, &bitmap_default_obstack);
+  /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead.  */
   bitmap_initialize (&map_head, &bitmap_default_obstack);
   bitmap_initialize (&map_field_head, &bitmap_default_obstack);
+  /* If ort == C_ORT_OMP used as nontemporal_head instead.  */
   bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
 
   if (ort & C_ORT_ACC)
@@ -5914,6 +6099,10 @@  finish_omp_clauses (tree clauses, enum c
 	  field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
 	  goto check_dup_generic;
 	case OMP_CLAUSE_REDUCTION:
+	  reduction_seen = true;
+	  /* FALLTHRU */
+	case OMP_CLAUSE_IN_REDUCTION:
+	case OMP_CLAUSE_TASK_REDUCTION:
 	  field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
 	  t = OMP_CLAUSE_DECL (c);
 	  if (TREE_CODE (t) == TREE_LIST)
@@ -5971,10 +6160,11 @@  finish_omp_clauses (tree clauses, enum c
 		   || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
 		  && !TYPE_REF_P (type))
 		{
-		  error ("linear clause with %qs modifier applied to "
-			 "non-reference variable with %qT type",
-			 OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
-			 ? "ref" : "uval", TREE_TYPE (t));
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			    "linear clause with %qs modifier applied to "
+			    "non-reference variable with %qT type",
+			    OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
+			    ? "ref" : "uval", TREE_TYPE (t));
 		  remove = true;
 		  break;
 		}
@@ -5985,8 +6175,10 @@  finish_omp_clauses (tree clauses, enum c
 		  if (!INTEGRAL_TYPE_P (type)
 		      && !TYPE_PTR_P (type))
 		    {
-		      error ("linear clause applied to non-integral non-pointer"
-			     " variable with %qT type", TREE_TYPE (t));
+		      error_at (OMP_CLAUSE_LOCATION (c),
+				"linear clause applied to non-integral "
+				"non-pointer variable with %qT type",
+				TREE_TYPE (t));
 		      remove = true;
 		      break;
 		    }
@@ -6007,7 +6199,8 @@  finish_omp_clauses (tree clauses, enum c
 		       || !TYPE_REF_P (TREE_TYPE (t))
 		       || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
 	    {
-	      error ("linear step expression must be integral");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"linear step expression must be integral");
 	      remove = true;
 	      break;
 	    }
@@ -6099,8 +6292,9 @@  finish_omp_clauses (tree clauses, enum c
 		  || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
 		      && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
 	    {
-	      error ("%<this%> allowed in OpenMP only in %<declare simd%>"
-		     " clauses");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<this%> allowed in OpenMP only in %<declare simd%>"
+			" clauses");
 	      remove = true;
 	      break;
 	    }
@@ -6110,11 +6304,13 @@  finish_omp_clauses (tree clauses, enum c
 	      if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
 		break;
 	      if (DECL_P (t))
-		error ("%qD is not a variable in clause %qs", t,
-		       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD is not a variable in clause %qs", t,
+			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
 	      else
-		error ("%qE is not a variable in clause %qs", t,
-		       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qE is not a variable in clause %qs", t,
+			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
 	      remove = true;
 	    }
 	  else if (ort == C_ORT_ACC
@@ -6122,7 +6318,9 @@  finish_omp_clauses (tree clauses, enum c
 	    {
 	      if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
 		{
-		  error ("%qD appears more than once in reduction clauses", t);
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			    "%qD appears more than once in reduction clauses",
+			    t);
 		  remove = true;
 		}
 	      else
@@ -6132,16 +6330,19 @@  finish_omp_clauses (tree clauses, enum c
 		   || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
 		   || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
 	    {
-	      error ("%qD appears more than once in data clauses", t);
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qD appears more than once in data clauses", t);
 	      remove = true;
 	    }
 	  else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
 		   && bitmap_bit_p (&map_head, DECL_UID (t)))
 	    {
 	      if (ort == C_ORT_ACC)
-		error ("%qD appears more than once in data clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears more than once in data clauses", t);
 	      else
-		error ("%qD appears both in data and map clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears both in data and map clauses", t);
 	      remove = true;
 	    }
 	  else
@@ -6170,8 +6371,9 @@  finish_omp_clauses (tree clauses, enum c
 	    t = OMP_CLAUSE_DECL (c);
 	  if (ort != C_ORT_ACC && t == current_class_ptr)
 	    {
-	      error ("%<this%> allowed in OpenMP only in %<declare simd%>"
-		     " clauses");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<this%> allowed in OpenMP only in %<declare simd%>"
+			" clauses");
 	      remove = true;
 	      break;
 	    }
@@ -6182,23 +6384,30 @@  finish_omp_clauses (tree clauses, enum c
 	      if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
 		break;
 	      if (DECL_P (t))
-		error ("%qD is not a variable in clause %<firstprivate%>", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD is not a variable in clause %<firstprivate%>",
+			  t);
 	      else
-		error ("%qE is not a variable in clause %<firstprivate%>", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qE is not a variable in clause %<firstprivate%>",
+			  t);
 	      remove = true;
 	    }
 	  else if (bitmap_bit_p (&generic_head, DECL_UID (t))
 		   || bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
 	    {
-	      error ("%qD appears more than once in data clauses", t);
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qD appears more than once in data clauses", t);
 	      remove = true;
 	    }
 	  else if (bitmap_bit_p (&map_head, DECL_UID (t)))
 	    {
 	      if (ort == C_ORT_ACC)
-		error ("%qD appears more than once in data clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears more than once in data clauses", t);
 	      else
-		error ("%qD appears both in data and map clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears both in data and map clauses", t);
 	      remove = true;
 	    }
 	  else
@@ -6213,8 +6422,9 @@  finish_omp_clauses (tree clauses, enum c
 	    t = OMP_CLAUSE_DECL (c);
 	  if (t == current_class_ptr)
 	    {
-	      error ("%<this%> allowed in OpenMP only in %<declare simd%>"
-		     " clauses");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<this%> allowed in OpenMP only in %<declare simd%>"
+			" clauses");
 	      remove = true;
 	      break;
 	    }
@@ -6225,15 +6435,20 @@  finish_omp_clauses (tree clauses, enum c
 	      if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
 		break;
 	      if (DECL_P (t))
-		error ("%qD is not a variable in clause %<lastprivate%>", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD is not a variable in clause %<lastprivate%>",
+			  t);
 	      else
-		error ("%qE is not a variable in clause %<lastprivate%>", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qE is not a variable in clause %<lastprivate%>",
+			  t);
 	      remove = true;
 	    }
 	  else if (bitmap_bit_p (&generic_head, DECL_UID (t))
 		   || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
 	    {
-	      error ("%qD appears more than once in data clauses", t);
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qD appears more than once in data clauses", t);
 	      remove = true;
 	    }
 	  else
@@ -6270,7 +6485,8 @@  finish_omp_clauses (tree clauses, enum c
 	      else if (!type_dependent_expression_p (t)
 		       && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
 		{
-		  error ("%<gang%> static expression must be integral");
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			    "%<gang%> static expression must be integral");
 		  remove = true;
 		}
 	      else
@@ -6374,30 +6590,6 @@  finish_omp_clauses (tree clauses, enum c
 	  break;
 
 	case OMP_CLAUSE_SCHEDULE:
-	  if (OMP_CLAUSE_SCHEDULE_KIND (c) & OMP_CLAUSE_SCHEDULE_NONMONOTONIC)
-	    {
-	      const char *p = NULL;
-	      switch (OMP_CLAUSE_SCHEDULE_KIND (c) & OMP_CLAUSE_SCHEDULE_MASK)
-		{
-		case OMP_CLAUSE_SCHEDULE_STATIC: p = "static"; break;
-		case OMP_CLAUSE_SCHEDULE_DYNAMIC: break;
-		case OMP_CLAUSE_SCHEDULE_GUIDED: break;
-		case OMP_CLAUSE_SCHEDULE_AUTO: p = "auto"; break;
-		case OMP_CLAUSE_SCHEDULE_RUNTIME: p = "runtime"; break;
-		default: gcc_unreachable ();
-		}
-	      if (p)
-		{
-		  error_at (OMP_CLAUSE_LOCATION (c),
-			    "%<nonmonotonic%> modifier specified for %qs "
-			    "schedule kind", p);
-		  OMP_CLAUSE_SCHEDULE_KIND (c)
-		    = (enum omp_clause_schedule_kind)
-		      (OMP_CLAUSE_SCHEDULE_KIND (c)
-		       & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
-		}
-	    }
-
 	  t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
 	  if (t == NULL)
 	    ;
@@ -6406,7 +6598,8 @@  finish_omp_clauses (tree clauses, enum c
 	  else if (!type_dependent_expression_p (t)
 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
 	    {
-	      error ("schedule chunk size expression must be integral");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"schedule chunk size expression must be integral");
 	      remove = true;
 	    }
 	  else
@@ -6436,8 +6629,9 @@  finish_omp_clauses (tree clauses, enum c
 	  else if (!type_dependent_expression_p (t)
 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
 	    {
-	      error ("%qs length expression must be integral",
-		     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qs length expression must be integral",
+			omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
 	      remove = true;
 	    }
 	  else
@@ -6449,9 +6643,10 @@  finish_omp_clauses (tree clauses, enum c
 		  if (TREE_CODE (t) != INTEGER_CST
 		      || tree_int_cst_sgn (t) != 1)
 		    {
-		      error ("%qs length expression must be positive constant"
-			     " integer expression",
-			     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+		      error_at (OMP_CLAUSE_LOCATION (c),
+				"%qs length expression must be positive "
+				"constant integer expression",
+				omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
 		      remove = true;
 		    }
 		}
@@ -6468,7 +6663,8 @@  finish_omp_clauses (tree clauses, enum c
 	  else if (!type_dependent_expression_p (t)
 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
 	    {
-	      error ("%<async%> expression must be integral");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<async%> expression must be integral");
 	      remove = true;
 	    }
 	  else
@@ -6496,7 +6692,8 @@  finish_omp_clauses (tree clauses, enum c
 	  else if (!type_dependent_expression_p (t)
 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
 	    {
-	      error ("%<thread_limit%> expression must be integral");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<thread_limit%> expression must be integral");
 	      remove = true;
 	    }
 	  else
@@ -6525,7 +6722,8 @@  finish_omp_clauses (tree clauses, enum c
 	  else if (!type_dependent_expression_p (t)
 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
 	    {
-	      error ("%<device%> id must be integral");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<device%> id must be integral");
 	      remove = true;
 	    }
 	  else
@@ -6546,14 +6744,15 @@  finish_omp_clauses (tree clauses, enum c
 	  else if (!type_dependent_expression_p (t)
 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
 	    {
-	      error ("%<dist_schedule%> chunk size expression must be "
-		     "integral");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<dist_schedule%> chunk size expression must be "
+			"integral");
 	      remove = true;
 	    }
 	  else
 	    {
 	      t = mark_rvalue_use (t);
-	      if (!processing_template_decl)
+ 	      if (!processing_template_decl)
 		t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
 	      OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
 	    }
@@ -6563,8 +6762,9 @@  finish_omp_clauses (tree clauses, enum c
 	  t = OMP_CLAUSE_DECL (c);
 	  if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
 	    {
-	      error ("%<this%> allowed in OpenMP only in %<declare simd%>"
-		     " clauses");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<this%> allowed in OpenMP only in %<declare simd%>"
+			" clauses");
 	      remove = true;
 	      break;
 	    }
@@ -6573,9 +6773,11 @@  finish_omp_clauses (tree clauses, enum c
 	      if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
 		break;
 	      if (DECL_P (t))
-		error ("%qD is not a variable in %<aligned%> clause", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD is not a variable in %<aligned%> clause", t);
 	      else
-		error ("%qE is not a variable in %<aligned%> clause", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qE is not a variable in %<aligned%> clause", t);
 	      remove = true;
 	    }
 	  else if (!type_dependent_expression_p (t)
@@ -6593,7 +6795,9 @@  finish_omp_clauses (tree clauses, enum c
 	    }
 	  else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
 	    {
-	      error ("%qD appears more than once in %<aligned%> clauses", t);
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qD appears more than once in %<aligned%> clauses",
+			t);
 	      remove = true;
 	    }
 	  else
@@ -6606,8 +6810,9 @@  finish_omp_clauses (tree clauses, enum c
 	  else if (!type_dependent_expression_p (t)
 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
 	    {
-	      error ("%<aligned%> clause alignment expression must "
-		     "be integral");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<aligned%> clause alignment expression must "
+			"be integral");
 	      remove = true;
 	    }
 	  else
@@ -6619,15 +6824,45 @@  finish_omp_clauses (tree clauses, enum c
 		  if (TREE_CODE (t) != INTEGER_CST
 		      || tree_int_cst_sgn (t) != 1)
 		    {
-		      error ("%<aligned%> clause alignment expression must be "
-			     "positive constant integer expression");
+		      error_at (OMP_CLAUSE_LOCATION (c),
+				"%<aligned%> clause alignment expression must "
+				"be positive constant integer expression");
 		      remove = true;
 		    }
+		  else
+		    t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
 		}
 	      OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
 	    }
 	  break;
 
+	case OMP_CLAUSE_NONTEMPORAL:
+	  t = OMP_CLAUSE_DECL (c);
+	  if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
+	    {
+	      if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
+		break;
+	      if (DECL_P (t))
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD is not a variable in %<nontemporal%> clause",
+			  t);
+	      else
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qE is not a variable in %<nontemporal%> clause",
+			  t);
+	      remove = true;
+	    }
+	  else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
+	    {
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qD appears more than once in %<nontemporal%> "
+			"clauses", t);
+	      remove = true;
+	    }
+	  else
+	    bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
+	  break;
+
 	case OMP_CLAUSE_DEPEND:
 	  t = OMP_CLAUSE_DECL (c);
 	  if (t == NULL_TREE)
@@ -6642,33 +6877,108 @@  finish_omp_clauses (tree clauses, enum c
 		remove = true;
 	      break;
 	    }
+	  if (TREE_CODE (t) == TREE_LIST
+	      && TREE_PURPOSE (t)
+	      && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC)
+	    {
+	      if (TREE_PURPOSE (t) != last_iterators)
+		last_iterators_remove
+		  = cp_omp_finish_iterators (TREE_PURPOSE (t));
+	      last_iterators = TREE_PURPOSE (t);
+	      t = TREE_VALUE (t);
+	      if (last_iterators_remove)
+		t = error_mark_node;
+	    }
+	  else
+	    last_iterators = NULL_TREE;
+
 	  if (TREE_CODE (t) == TREE_LIST)
 	    {
 	      if (handle_omp_array_sections (c, ort))
 		remove = true;
+	      else if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
+		{
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			    "%<depend%> clause with %<depobj%> dependence "
+			    "type on array section");
+		  remove = true;
+		}
 	      break;
 	    }
 	  if (t == error_mark_node)
 	    remove = true;
-	  else if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
+	  else if (t == current_class_ptr)
+	    {
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<this%> allowed in OpenMP only in %<declare simd%>"
+			" clauses");
+	      remove = true;
+	    }
+	  else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
+	    break;
+	  else if (!lvalue_p (t))
 	    {
-	      if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
-		break;
 	      if (DECL_P (t))
-		error ("%qD is not a variable in %<depend%> clause", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD is not lvalue expression nor array section "
+			  "in %<depend%> clause", t);
 	      else
-		error ("%qE is not a variable in %<depend%> clause", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qE is not lvalue expression nor array section "
+			  "in %<depend%> clause", t);
 	      remove = true;
 	    }
-	  else if (t == current_class_ptr)
+	  else if (TREE_CODE (t) == COMPONENT_REF
+		   && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
+		   && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
 	    {
-	      error ("%<this%> allowed in OpenMP only in %<declare simd%>"
-		     " clauses");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"bit-field %qE in %qs clause", t, "depend");
 	      remove = true;
 	    }
-	  else if (!processing_template_decl
-		   && !cxx_mark_addressable (t))
-	    remove = true;
+	  else if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
+	    {
+	      if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
+				     ? TREE_TYPE (TREE_TYPE (t))
+				     : TREE_TYPE (t)))
+		{
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			    "%qE does not have %<omp_depend_t%> type in "
+			    "%<depend%> clause with %<depobj%> dependence "
+			    "type", t);
+		  remove = true;
+		}
+	    }
+	  else if (c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
+				     ? TREE_TYPE (TREE_TYPE (t))
+				     : TREE_TYPE (t)))
+	    {
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qE should not have %<omp_depend_t%> type in "
+			"%<depend%> clause with dependence type other than "
+			"%<depobj%>", t);
+	      remove = true;
+	    }
+	  if (!remove)
+	    {
+	      tree addr = cp_build_addr_expr (t, tf_warning_or_error);
+	      if (addr == error_mark_node)
+		remove = true;
+	      else
+		{
+		  t = cp_build_indirect_ref (addr, RO_UNARY_STAR,
+					     tf_warning_or_error);
+		  if (t == error_mark_node)
+		    remove = true;
+		  else if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
+			   && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
+			   && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
+			       == TREE_VEC))
+		    TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
+		  else
+		    OMP_CLAUSE_DECL (c) = t;
+		}
+	    }
 	  break;
 
 	case OMP_CLAUSE_MAP:
@@ -6707,14 +7017,17 @@  finish_omp_clauses (tree clauses, enum c
 		      if (bitmap_bit_p (&map_head, DECL_UID (t)))
 			{
 			  if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
-			    error ("%qD appears more than once in motion"
-				   " clauses", t);
+			    error_at (OMP_CLAUSE_LOCATION (c),
+				      "%qD appears more than once in motion"
+				      " clauses", t);
 			  else if (ort == C_ORT_ACC)
-			    error ("%qD appears more than once in data"
-				   " clauses", t);
+			    error_at (OMP_CLAUSE_LOCATION (c),
+				      "%qD appears more than once in data"
+				      " clauses", t);
 			  else
-			    error ("%qD appears more than once in map"
-				   " clauses", t);
+			    error_at (OMP_CLAUSE_LOCATION (c),
+				      "%qD appears more than once in map"
+				      " clauses", t);
 			  remove = true;
 			}
 		      else
@@ -6790,23 +7103,27 @@  finish_omp_clauses (tree clauses, enum c
 		      || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER))
 		break;
 	      if (DECL_P (t))
-		error ("%qD is not a variable in %qs clause", t,
-		       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD is not a variable in %qs clause", t,
+			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
 	      else
-		error ("%qE is not a variable in %qs clause", t,
-		       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qE is not a variable in %qs clause", t,
+			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
 	      remove = true;
 	    }
 	  else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
 	    {
-	      error ("%qD is threadprivate variable in %qs clause", t,
-		     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qD is threadprivate variable in %qs clause", t,
+			omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
 	      remove = true;
 	    }
 	  else if (ort != C_ORT_ACC && t == current_class_ptr)
 	    {
-	      error ("%<this%> allowed in OpenMP only in %<declare simd%>"
-		     " clauses");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<this%> allowed in OpenMP only in %<declare simd%>"
+			" clauses");
 	      remove = true;
 	      break;
 	    }
@@ -6837,7 +7154,8 @@  finish_omp_clauses (tree clauses, enum c
 		   && !type_dependent_expression_p (t)
 		   && !INDIRECT_TYPE_P (TREE_TYPE (t)))
 	    {
-	      error ("%qD is not a pointer variable", t);
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qD is not a pointer variable", t);
 	      remove = true;
 	    }
 	  else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
@@ -6846,15 +7164,18 @@  finish_omp_clauses (tree clauses, enum c
 	      if (bitmap_bit_p (&generic_head, DECL_UID (t))
 		  || bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
 		{
-		  error ("%qD appears more than once in data clauses", t);
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			    "%qD appears more than once in data clauses", t);
 		  remove = true;
 		}
 	      else if (bitmap_bit_p (&map_head, DECL_UID (t)))
 		{
 		  if (ort == C_ORT_ACC)
-		    error ("%qD appears more than once in data clauses", t);
+		    error_at (OMP_CLAUSE_LOCATION (c),
+			      "%qD appears more than once in data clauses", t);
 		  else
-		    error ("%qD appears both in data and map clauses", t);
+		    error_at (OMP_CLAUSE_LOCATION (c),
+			      "%qD appears both in data and map clauses", t);
 		  remove = true;
 		}
 	      else
@@ -6863,20 +7184,25 @@  finish_omp_clauses (tree clauses, enum c
 	  else if (bitmap_bit_p (&map_head, DECL_UID (t)))
 	    {
 	      if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
-		error ("%qD appears more than once in motion clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears more than once in motion clauses", t);
 	      if (ort == C_ORT_ACC)
-		error ("%qD appears more than once in data clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears more than once in data clauses", t);
 	      else
-		error ("%qD appears more than once in map clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears more than once in map clauses", t);
 	      remove = true;
 	    }
 	  else if (bitmap_bit_p (&generic_head, DECL_UID (t))
 		   || bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
 	    {
 	      if (ort == C_ORT_ACC)
-		error ("%qD appears more than once in data clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears more than once in data clauses", t);
 	      else
-		error ("%qD appears both in data and map clauses", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD appears both in data and map clauses", t);
 	      remove = true;
 	    }
 	  else
@@ -6991,9 +7317,11 @@  finish_omp_clauses (tree clauses, enum c
 	      if (processing_template_decl)
 		break;
 	      if (DECL_P (t))
-		error ("%qD is not an argument in %<uniform%> clause", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qD is not an argument in %<uniform%> clause", t);
 	      else
-		error ("%qE is not an argument in %<uniform%> clause", t);
+		error_at (OMP_CLAUSE_LOCATION (c),
+			  "%qE is not an argument in %<uniform%> clause", t);
 	      remove = true;
 	      break;
 	    }
@@ -7008,7 +7336,8 @@  finish_omp_clauses (tree clauses, enum c
 	  else if (!type_dependent_expression_p (t)
 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
 	    {
-	      error ("%<grainsize%> expression must be integral");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<grainsize%> expression must be integral");
 	      remove = true;
 	    }
 	  else
@@ -7037,7 +7366,8 @@  finish_omp_clauses (tree clauses, enum c
 	  else if (!type_dependent_expression_p (t)
 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
 	    {
-	      error ("%<priority%> expression must be integral");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<priority%> expression must be integral");
 	      remove = true;
 	    }
 	  else
@@ -7066,7 +7396,8 @@  finish_omp_clauses (tree clauses, enum c
 	  else if (!type_dependent_expression_p (t)
 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
 	    {
-	      error ("%<num_tasks%> expression must be integral");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<hint%> expression must be integral");
 	      remove = true;
 	    }
 	  else
@@ -7076,6 +7407,13 @@  finish_omp_clauses (tree clauses, enum c
 		{
 		  t = maybe_constant_value (t);
 		  t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
+		  if (TREE_CODE (t) != INTEGER_CST)
+		    {
+		      error_at (OMP_CLAUSE_LOCATION (c),
+				"%<hint%> expression must be constant integer "
+				"expression");
+		      remove = true;
+		    }
 		}
 	      OMP_CLAUSE_HINT_EXPR (c) = t;
 	    }
@@ -7172,8 +7510,9 @@  finish_omp_clauses (tree clauses, enum c
 	case OMP_CLAUSE_NOTINBRANCH:
 	  if (branch_seen)
 	    {
-	      error ("%<inbranch%> clause is incompatible with "
-		     "%<notinbranch%>");
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<inbranch%> clause is incompatible with "
+			"%<notinbranch%>");
 	      remove = true;
 	    }
 	  branch_seen = true;
@@ -7224,6 +7563,8 @@  finish_omp_clauses (tree clauses, enum c
 	  need_implicitly_determined = true;
 	  break;
 	case OMP_CLAUSE_REDUCTION:
+	case OMP_CLAUSE_IN_REDUCTION:
+	case OMP_CLAUSE_TASK_REDUCTION:
 	  need_implicitly_determined = true;
 	  break;
 	case OMP_CLAUSE_LINEAR:
@@ -7276,6 +7617,17 @@  finish_omp_clauses (tree clauses, enum c
 	    }
 	  pc = &OMP_CLAUSE_CHAIN (c);
 	  continue;
+	case OMP_CLAUSE_NOGROUP:
+	  if (reduction_seen)
+	    {
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<nogroup%> clause must not be used together with "
+			"%<reduction%> clause");
+	      *pc = OMP_CLAUSE_CHAIN (c);
+	      continue;
+	    }
+	  pc = &OMP_CLAUSE_CHAIN (c);
+	  continue;
 	case OMP_CLAUSE_NOWAIT:
 	  if (copyprivate_seen)
 	    {
@@ -7310,6 +7662,8 @@  finish_omp_clauses (tree clauses, enum c
 	  break;
 
 	case OMP_CLAUSE_REDUCTION:
+	case OMP_CLAUSE_IN_REDUCTION:
+	case OMP_CLAUSE_TASK_REDUCTION:
 	  if (finish_omp_reduction_clause (c, &need_default_ctor,
 					   &need_dtor))
 	    remove = true;
@@ -7320,7 +7674,8 @@  finish_omp_clauses (tree clauses, enum c
 	case OMP_CLAUSE_COPYIN:
 	  if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
 	    {
-	      error ("%qE must be %<threadprivate%> for %<copyin%>", t);
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qE must be %<threadprivate%> for %<copyin%>", t);
 	      remove = true;
 	    }
 	  break;
@@ -7349,10 +7704,17 @@  finish_omp_clauses (tree clauses, enum c
 	    case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
 	      break;
 	    case OMP_CLAUSE_DEFAULT_SHARED:
-	      /* const vars may be specified in firstprivate clause.  */
-	      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
+	      if (VAR_P (t)
+		  && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
+		  && TREE_STATIC (t)
 		  && cxx_omp_const_qual_no_mutable (t))
-		break;
+		{
+		  tree ctx = CP_DECL_CONTEXT (t);
+		  /* const qualified static data members without mutable
+		     member may be specified in firstprivate clause.  */
+		  if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
+		    break;
+		}
 	      share_name = "shared";
 	      break;
 	    case OMP_CLAUSE_DEFAULT_PRIVATE:
@@ -7363,9 +7725,20 @@  finish_omp_clauses (tree clauses, enum c
 	    }
 	  if (share_name)
 	    {
-	      error ("%qE is predetermined %qs for %qs",
-		     omp_clause_printable_decl (t), share_name,
-		     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qE is predetermined %qs for %qs",
+			omp_clause_printable_decl (t), share_name,
+			omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+	      remove = true;
+	    }
+	  else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
+		   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
+		   && cxx_omp_const_qual_no_mutable (t))
+	    {
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%<const%> qualified %qE without %<mutable%> member "
+			"may appear only in %<shared%> or %<firstprivate%> "
+			"clauses", omp_clause_printable_decl (t));
 	      remove = true;
 	    }
 	}
@@ -7374,7 +7747,9 @@  finish_omp_clauses (tree clauses, enum c
       inner_type = type = TREE_TYPE (t);
       if ((need_complete_type
 	   || need_copy_assignment
-	   || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
+	   || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+	   || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
+	   || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
 	  && TYPE_REF_P (inner_type))
 	inner_type = TREE_TYPE (inner_type);
       while (TREE_CODE (inner_type) == ARRAY_TYPE)
@@ -7876,6 +8251,7 @@  handle_omp_for_class_iterator (int i, lo
     }
 
   incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
+  incr = cp_fully_fold (incr);
   bool taskloop_iv_seen = false;
   for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
     if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
@@ -8011,12 +8387,22 @@  handle_omp_for_class_iterator (int i, lo
 	= pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
     }
 
+  if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
+    {
+      tree t = TREE_VEC_ELT (orig_declv, i);
+      gcc_assert (TREE_PURPOSE (t) == NULL_TREE
+		  && TREE_VALUE (t) == NULL_TREE
+		  && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
+      TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
+      TREE_VALUE (t) = last;
+    }
+  else
+    TREE_VEC_ELT (orig_declv, i)
+      = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
   TREE_VEC_ELT (declv, i) = decl;
   TREE_VEC_ELT (initv, i) = init;
   TREE_VEC_ELT (condv, i) = cond;
   TREE_VEC_ELT (incrv, i) = incr;
-  TREE_VEC_ELT (orig_declv, i)
-    = tree_cons (TREE_VEC_ELT (orig_declv, i), last, NULL_TREE);
 
   return false;
 }
@@ -8098,6 +8484,9 @@  finish_omp_for (location_t locus, enum t
       if (init && EXPR_HAS_LOCATION (init))
 	elocus = EXPR_LOCATION (init);
 
+      if (cond == global_namespace)
+	continue;
+
       if (cond == NULL)
 	{
 	  error_at (elocus, "missing controlling predicate");
@@ -8120,7 +8509,8 @@  finish_omp_for (location_t locus, enum t
       tree orig_init;
       FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
 	if (orig_init
-	    && !c_omp_check_loop_iv_exprs (locus, declv,
+	    && !c_omp_check_loop_iv_exprs (locus, orig_declv
+						  ? orig_declv : declv,
 					   TREE_VEC_ELT (declv, i), orig_init,
 					   NULL_TREE, cp_walk_subtrees))
 	  fail = true;
@@ -8253,11 +8643,12 @@  finish_omp_for (location_t locus, enum t
       i++;
     }
 
-  if (IS_EMPTY_STMT (pre_body))
+  if (pre_body && IS_EMPTY_STMT (pre_body))
     pre_body = NULL;
 
   omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
-			      incrv, body, pre_body);
+			      incrv, body, pre_body,
+			      !processing_template_decl);
 
   /* Check for iterators appearing in lb, b or incr expressions.  */
   if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
@@ -8369,9 +8760,55 @@  finish_omp_for (location_t locus, enum t
   return omp_for;
 }
 
+/* Fix up range for decls.  Those decls were pushed into BIND's BIND_EXPR_VARS
+   and need to be moved into the BIND_EXPR inside of the OMP_FOR's body.  */
+
+tree
+finish_omp_for_block (tree bind, tree omp_for)
+{
+  if (omp_for == NULL_TREE
+      || !OMP_FOR_ORIG_DECLS (omp_for)
+      || bind == NULL_TREE
+      || TREE_CODE (bind) != BIND_EXPR)
+    return bind;
+  tree b = NULL_TREE;
+  for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
+    if (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)) == TREE_LIST
+	&& TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
+      {
+	tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
+	gcc_assert (BIND_EXPR_BLOCK (bind)
+		    && (BIND_EXPR_VARS (bind)
+			== BLOCK_VARS (BIND_EXPR_BLOCK (bind))));
+	for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
+	  for (tree *p = &BIND_EXPR_VARS (bind); *p; p = &DECL_CHAIN (*p))
+	    {
+	      if (*p == TREE_VEC_ELT (v, j))
+		{
+		  tree var = *p;
+		  *p = DECL_CHAIN (*p);
+		  if (b == NULL_TREE)
+		    {
+		      b = make_node (BLOCK);
+		      b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
+				  OMP_FOR_BODY (omp_for), b);
+		      TREE_SIDE_EFFECTS (b) = 1;
+		      OMP_FOR_BODY (omp_for) = b;
+		    }
+		  DECL_CHAIN (var) = BIND_EXPR_VARS (b);
+		  BIND_EXPR_VARS (b) = var;
+		  BLOCK_VARS (BIND_EXPR_BLOCK (b)) = var;
+		}
+	    }
+	BLOCK_VARS (BIND_EXPR_BLOCK (bind)) = BIND_EXPR_VARS (bind);
+      }
+  return bind;
+}
+
 void
-finish_omp_atomic (enum tree_code code, enum tree_code opcode, tree lhs,
-		   tree rhs, tree v, tree lhs1, tree rhs1, bool seq_cst)
+finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
+		   tree lhs, tree rhs, tree v, tree lhs1, tree rhs1,
+		   tree clauses, enum omp_memory_order mo)
 {
   tree orig_lhs;
   tree orig_rhs;
@@ -8398,6 +8835,15 @@  finish_omp_atomic (enum tree_code code,
 		     || (v && type_dependent_expression_p (v))
 		     || (lhs1 && type_dependent_expression_p (lhs1))
 		     || (rhs1 && type_dependent_expression_p (rhs1)));
+      if (clauses)
+	{
+	  gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
+		      && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
+		      && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
+	  if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
+	      || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
+	    dependent_p = true;
+	}
       if (!dependent_p)
 	{
 	  lhs = build_non_dependent_expr (lhs);
@@ -8439,8 +8885,8 @@  finish_omp_atomic (enum tree_code code,
 		   "expressions for memory");
 	  return;
 	}
-      stmt = c_finish_omp_atomic (input_location, code, opcode, lhs, rhs,
-				  v, lhs1, rhs1, swapped, seq_cst,
+      stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
+				  v, lhs1, rhs1, swapped, mo,
 				  processing_template_decl != 0);
       if (stmt == error_mark_node)
 	return;
@@ -8449,9 +8895,8 @@  finish_omp_atomic (enum tree_code code,
     {
       if (code == OMP_ATOMIC_READ)
 	{
-	  stmt = build_min_nt_loc (EXPR_LOCATION (orig_lhs),
-				   OMP_ATOMIC_READ, orig_lhs);
-	  OMP_ATOMIC_SEQ_CST (stmt) = seq_cst;
+	  stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
+	  OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
 	  stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
 	}
       else
@@ -8465,14 +8910,15 @@  finish_omp_atomic (enum tree_code code,
 				     COMPOUND_EXPR, orig_rhs1, stmt);
 	  if (code != OMP_ATOMIC)
 	    {
-	      stmt = build_min_nt_loc (EXPR_LOCATION (orig_lhs1),
-				       code, orig_lhs1, stmt);
-	      OMP_ATOMIC_SEQ_CST (stmt) = seq_cst;
+	      stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
+	      OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
 	      stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
 	    }
 	}
-      stmt = build2 (OMP_ATOMIC, void_type_node, integer_zero_node, stmt);
-      OMP_ATOMIC_SEQ_CST (stmt) = seq_cst;
+      stmt = build2 (OMP_ATOMIC, void_type_node,
+		     clauses ? clauses : integer_zero_node, stmt);
+      OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
+      SET_EXPR_LOCATION (stmt, loc);
     }
   finish_expr_stmt (stmt);
 }
@@ -8488,10 +8934,50 @@  finish_omp_barrier (void)
 }
 
 void
-finish_omp_flush (void)
+finish_omp_depobj (location_t loc, tree depobj,
+		   enum omp_clause_depend_kind kind, tree clause)
+{
+  if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
+    {
+      if (!lvalue_p (depobj))
+	{
+	  error_at (EXPR_LOC_OR_LOC (depobj, loc),
+		    "%<depobj%> expression is not lvalue expression");
+	  depobj = error_mark_node;
+	}
+    }
+
+  if (processing_template_decl)
+    {
+      if (clause == NULL_TREE)
+	clause = build_int_cst (integer_type_node, kind);
+      add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
+      return;
+    }
+
+  if (!error_operand_p (depobj))
+    {
+      tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
+      if (addr == error_mark_node)
+	depobj = error_mark_node;
+      else
+	depobj = cp_build_indirect_ref (addr, RO_UNARY_STAR,
+					tf_warning_or_error);
+    }
+
+  c_finish_omp_depobj (loc, depobj, kind, clause);
+}
+
+void
+finish_omp_flush (int mo)
 {
   tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
   vec<tree, va_gc> *vec = make_tree_vector ();
+  if (mo != MEMMODEL_LAST)
+    {
+      fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
+      vec->quick_push (build_int_cst (integer_type_node, mo));
+    }
   tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
   release_tree_vector (vec);
   finish_expr_stmt (stmt);
@@ -8540,6 +9026,11 @@  finish_omp_cancel (tree clauses)
   tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
   if (ifc != NULL_TREE)
     {
+      if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
+	  && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
+	error_at (OMP_CLAUSE_LOCATION (ifc),
+		  "expected %<cancel%> %<if%> clause modifier");
+
       tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc));
       ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
 			     boolean_type_node, OMP_CLAUSE_IF_EXPR (ifc),
--- gcc/fortran/trans-openmp.c	(.../trunk)	(revision 265884)
+++ gcc/fortran/trans-openmp.c	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -2866,6 +2866,8 @@  gfc_trans_omp_clauses (stmtblock_t *bloc
   if (clauses->defaultmap)
     {
       c = build_omp_clause (where.lb->location, OMP_CLAUSE_DEFAULTMAP);
+      OMP_CLAUSE_DEFAULTMAP_SET_KIND (c, OMP_CLAUSE_DEFAULTMAP_TOFROM,
+				      OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR);
       omp_clauses = gfc_trans_add_clause (c, omp_clauses);
     }
   if (clauses->depend_source)
@@ -3166,7 +3168,9 @@  gfc_trans_omp_atomic (gfc_code *code)
   enum tree_code op = ERROR_MARK;
   enum tree_code aop = OMP_ATOMIC;
   bool var_on_left = false;
-  bool seq_cst = (atomic_code->ext.omp_atomic & GFC_OMP_ATOMIC_SEQ_CST) != 0;
+  enum omp_memory_order mo
+    = ((atomic_code->ext.omp_atomic & GFC_OMP_ATOMIC_SEQ_CST)
+       ? OMP_MEMORY_ORDER_SEQ_CST : OMP_MEMORY_ORDER_RELAXED);
 
   code = code->block->next;
   gcc_assert (code->op == EXEC_ASSIGN);
@@ -3198,7 +3202,7 @@  gfc_trans_omp_atomic (gfc_code *code)
       lhsaddr = gfc_build_addr_expr (NULL, lse.expr);
 
       x = build1 (OMP_ATOMIC_READ, type, lhsaddr);
-      OMP_ATOMIC_SEQ_CST (x) = seq_cst;
+      OMP_ATOMIC_MEMORY_ORDER (x) = mo;
       x = convert (TREE_TYPE (vse.expr), x);
       gfc_add_modify (&block, vse.expr, x);
 
@@ -3398,7 +3402,7 @@  gfc_trans_omp_atomic (gfc_code *code)
   if (aop == OMP_ATOMIC)
     {
       x = build2_v (OMP_ATOMIC, lhsaddr, convert (type, x));
-      OMP_ATOMIC_SEQ_CST (x) = seq_cst;
+      OMP_ATOMIC_MEMORY_ORDER (x) = mo;
       gfc_add_expr_to_block (&block, x);
     }
   else
@@ -3421,7 +3425,7 @@  gfc_trans_omp_atomic (gfc_code *code)
 	  gfc_add_block_to_block (&block, &lse.pre);
 	}
       x = build2 (aop, type, lhsaddr, convert (type, x));
-      OMP_ATOMIC_SEQ_CST (x) = seq_cst;
+      OMP_ATOMIC_MEMORY_ORDER (x) = mo;
       x = convert (TREE_TYPE (vse.expr), x);
       gfc_add_modify (&block, vse.expr, x);
     }
@@ -4586,8 +4590,12 @@  gfc_trans_omp_task (gfc_code *code)
 static tree
 gfc_trans_omp_taskgroup (gfc_code *code)
 {
-  tree stmt = gfc_trans_code (code->block->next);
-  return build1_loc (input_location, OMP_TASKGROUP, void_type_node, stmt);
+  tree body = gfc_trans_code (code->block->next);
+  tree stmt = make_node (OMP_TASKGROUP);
+  TREE_TYPE (stmt) = void_type_node;
+  OMP_TASKGROUP_BODY (stmt) = body;
+  OMP_TASKGROUP_CLAUSES (stmt) = NULL_TREE;
+  return stmt;
 }
 
 static tree
--- gcc/fortran/types.def	(.../trunk)	(revision 265884)
+++ gcc/fortran/types.def	(.../branches/gomp-5_0-branch)	(revision 265887)
@@ -86,6 +86,7 @@  DEF_FUNCTION_TYPE_1 (BT_FN_INT_INT, BT_I
 DEF_FUNCTION_TYPE_1 (BT_FN_UINT_UINT, BT_UINT, BT_UINT)
 DEF_FUNCTION_TYPE_1 (BT_FN_PTR_PTR, BT_PTR, BT_PTR)
 DEF_FUNCTION_TYPE_1 (BT_FN_VOID_INT, BT_VOID, BT_INT)
+DEF_FUNCTION_TYPE_1 (BT_FN_VOID_BOOL, BT_VOID, BT_BOOL)
 DEF_FUNCTION_TYPE_1 (BT_FN_BOOL_INT, BT_BOOL, BT_INT)
 
 DEF_POINTER_TYPE (BT_PTR_FN_VOID_PTR, BT_FN_VOID_PTR)
@@ -145,9 +146,14 @@  DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I2_
 DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I4_INT, BT_VOID, BT_VOLATILE_PTR, BT_I4, BT_INT)
 DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I8_INT, BT_VOID, BT_VOLATILE_PTR, BT_I8, BT_INT)
 DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I16_INT, BT_VOID, BT_VOLATILE_PTR, BT_I16, BT_INT)
+DEF_FUNCTION_TYPE_3 (BT_FN_VOID_SIZE_SIZE_PTR, BT_VOID, BT_SIZE, BT_SIZE,
+		     BT_PTR)
+DEF_FUNCTION_TYPE_3 (BT_FN_UINT_UINT_PTR_PTR, BT_UINT, BT_UINT, BT_PTR, BT_PTR)
 
 DEF_FUNCTION_TYPE_4 (BT_FN_VOID_OMPFN_PTR_UINT_UINT,
                      BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, BT_UINT, BT_UINT)
+DEF_FUNCTION_TYPE_4 (BT_FN_UINT_OMPFN_PTR_UINT_UINT,
+		     BT_UINT, BT_PTR_FN_VOID_PTR, BT_PTR, BT_UINT, BT_UINT)
 DEF_FUNCTION_TYPE_4 (BT_FN_VOID_PTR_WORD_WORD_PTR,
 		     BT_VOID, BT_PTR, BT_WORD, BT_WORD, BT_PTR)
 DEF_FUNCTION_TYPE_4 (BT_FN_VOID_SIZE_VPTR_PTR_INT, BT_VOID, BT_SIZE,
@@ -217,14 +223,28 @@  DEF_FUNCTION_TYPE_7 (BT_FN_VOID_INT_SIZE
 DEF_FUNCTION_TYPE_8 (BT_FN_VOID_OMPFN_PTR_UINT_LONG_LONG_LONG_LONG_UINT,
 		     BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, BT_UINT,
 		     BT_LONG, BT_LONG, BT_LONG, BT_LONG, BT_UINT)
+DEF_FUNCTION_TYPE_8 (BT_FN_BOOL_UINT_LONGPTR_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR,
+		     BT_BOOL, BT_UINT, BT_PTR_LONG, BT_LONG, BT_LONG,
+		     BT_PTR_LONG, BT_PTR_LONG, BT_PTR, BT_PTR)
+DEF_FUNCTION_TYPE_8 (BT_FN_BOOL_UINT_ULLPTR_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR,
+		     BT_BOOL, BT_UINT, BT_PTR_ULONGLONG, BT_LONG, BT_ULONGLONG,
+		     BT_PTR_ULONGLONG, BT_PTR_ULONGLONG, BT_PTR, BT_PTR)
 
 DEF_FUNCTION_TYPE_9 (BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT,
 		     BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR,
 		     BT_PTR_FN_VOID_PTR_PTR, BT_LONG, BT_LONG,
 		     BT_BOOL, BT_UINT, BT_PTR, BT_INT)
 DEF_FUNCTION_TYPE_9 (BT_FN_VOID_INT_OMPFN_SIZE_PTR_PTR_PTR_UINT_PTR_PTR,
-		      BT_VOID, BT_INT, BT_PTR_FN_VOID_PTR, BT_SIZE, BT_PTR,
-		      BT_PTR, BT_PTR, BT_UINT, BT_PTR, BT_PTR)
+		     BT_VOID, BT_INT, BT_PTR_FN_VOID_PTR, BT_SIZE, BT_PTR,
+		     BT_PTR, BT_PTR, BT_UINT, BT_PTR, BT_PTR)
+DEF_FUNCTION_TYPE_9 (BT_FN_BOOL_LONG_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR,
+		     BT_BOOL, BT_LONG, BT_LONG, BT_LONG, BT_LONG, BT_LONG,
+		     BT_PTR_LONG, BT_PTR_LONG, BT_PTR, BT_PTR)
+
+DEF_FUNCTION_TYPE_10 (BT_FN_BOOL_BOOL_ULL_ULL_ULL_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR,
+		      BT_BOOL, BT_BOOL, BT_ULONGLONG, BT_ULONGLONG,
+		      BT_ULONGLONG, BT_LONG, BT_ULONGLONG, BT_PTR_ULONGLONG,
+		      BT_PTR_ULONGLONG, BT_PTR, BT_PTR)
 
 DEF_FUNCTION_TYPE_11 (BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_UINT_LONG_INT_LONG_LONG_LONG,
 		      BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR,