]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
* builtin-types.def (BT_FN_VOID_BOOL, BT_FN_VOID_SIZE_SIZE_PTR,
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 8 Nov 2018 17:13:04 +0000 (17:13 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 8 Nov 2018 17:13:04 +0000 (17:13 +0000)
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.
* gengtype.c (open_base_files): Add omp-general.h.
* gimple.c (gimple_build_omp_critical):
(gimple_build_omp_taskgroup): Add CLAUSES argument.  Call
gimple_omp_taskgroup_set_clauses.
(gimple_build_omp_atomic_load): Add mo argument, call
gimple_omp_atomic_set_memory_order.
(gimple_build_omp_atomic_store): Likewise.
(gimple_copy): Adjust handling of GIMPLE_OMP_TASKGROUP.
* gimple.def (GIMPLE_OMP_TASKGROUP): Use GSS_OMP_SINGLE_LAYOUT
instead of GSS_OMP.
(GIMPLE_OMP_TEAMS): Use GSS_OMP_PARALLEL_LAYOUT instead
of GSS_OMP_SINGLE_LAYOUT, adjust comments.
* gimple.h (enum gf_mask): Add GF_OMP_TEAMS_HOST, GF_OMP_TASK_TASKWAIT
and GF_OMP_ATOMIC_MEMORY_ORDER.  Remove GF_OMP_ATOMIC_SEQ_CST, use
different value for GF_OMP_ATOMIC_NEED_VALUE.
(struct gimple_statement_omp_taskreg): Add GIMPLE_OMP_TEAMS to
comments.
(struct gimple_statement_omp_single_layout): And remove here.
(struct gomp_teams): Inherit from gimple_statement_omp_taskreg rather
than gimple_statement_omp_single_layout.
(is_a_helper <gimple_statement_omp_taskreg *>::test): Allow
GIMPLE_OMP_TEAMS.
(is_a_helper <const gimple_statement_omp_taskreg *>::test): Likewise.
(gimple_omp_subcode): Formatting fix.
(gimple_omp_teams_child_fn, gimple_omp_teams_child_fn_ptr,
gimple_omp_teams_set_child_fn, gimple_omp_teams_data_arg,
gimple_omp_teams_data_arg_ptr, gimple_omp_teams_set_data_arg,
gimple_omp_teams_host, gimple_omp_teams_set_host,
gimple_omp_task_taskwait_p, gimple_omp_task_set_taskwait_p,
gimple_omp_taskgroup_clauses, gimple_omp_taskgroup_clauses_ptr,
gimple_omp_taskgroup_set_clauses): New inline functions.
(gimple_build_omp_atomic_load): Add enum omp_memory_order argument.
(gimple_build_omp_atomic_store): Likewise.
(gimple_omp_atomic_seq_cst_p): Remove.
(gimple_omp_atomic_memory_order): New function.
(gimple_omp_atomic_set_seq_cst): Remove.
(gimple_omp_atomic_set_memory_order): New function.
(gimple_build_omp_taskgroup): Add clauses argument.
* gimple-pretty-print.c (dump_gimple_omp_taskgroup): New function.
(dump_gimple_omp_task): Print taskwait with depend clauses.
(dump_gimple_omp_atomic_load, dump_gimple_omp_atomic_store): Use
dump_omp_atomic_memory_order.
(pp_gimple_stmt_1): Handle GIMPLE_OMP_TASKGROUP.
* gimplify.c (enum gimplify_omp_var_data): Add GOVD_MAP_ALLOC_ONLY,
GOVD_MAP_FROM_ONLY and GOVD_NONTEMPORAL.
(enum omp_region_type): Reserve bits 1 and 2 for auxiliary flags,
renumber values of most of ORT_* enumerators, add ORT_HOST_TEAMS,
ORT_COMBINED_HOST_TEAMS, ORT_TASKGROUP, ORT_TASKLOOP and
ORT_UNTIED_TASKLOOP enumerators.
(enum gimplify_defaultmap_kind): New.
(struct gimplify_omp_ctx): Remove target_map_scalars_firstprivate and
target_map_pointers_as_0len_arrays members, add defaultmap.
(new_omp_context): Initialize defaultmap member.
(gimple_add_tmp_var): Handle ORT_TASKGROUP like ORT_WORKSHARE.
(maybe_fold_stmt): Don't fold even in host teams regions.
(omp_firstprivatize_variable): Handle ORT_TASKGROUP like
ORT_WORKSHARE.  Test ctx->defaultmap[GDMK_SCALAR] instead of
ctx->omp_firstprivatize_variable.
(omp_add_variable): Don't add private/firstprivate for VLAs in
ORT_TASKGROUP.
(omp_default_clause): Print "taskloop" rather than "task" if
ORT_*TASKLOOP.
(omp_notice_variable): Handle ORT_TASKGROUP like ORT_WORKSHARE.
Handle new defaultmap clause kinds.
(omp_is_private): Handle ORT_TASKGROUP like ORT_WORKSHARE.  Allow simd
iterator to be lastprivate or private.  Fix up diagnostics if linear
is used on collapse>1 simd iterator.
(omp_check_private): Handle ORT_TASKGROUP like ORT_WORKSHARE.
(gimplify_omp_depend): New function.
(gimplify_scan_omp_clauses): Add shared clause on parallel for
combined parallel master taskloop{, simd} if taskloop has
firstprivate, lastprivate or reduction clause.  Handle
OMP_CLAUSE_REDUCTION_TASK diagnostics.  Adjust tests for
ORT_COMBINED_TEAMS.  Gimplify depend clauses with iterators.  Handle
cancel and simd OMP_CLAUSE_IF_MODIFIERs.  Handle
OMP_CLAUSE_NONTEMPORAL.  Handle new defaultmap clause kinds.  Handle
OMP_CLAUSE_{TASK,IN}_REDUCTION.  Diagnose invalid conditional
lastprivate.
(gimplify_adjust_omp_clauses_1): Ignore GOVD_NONTEMPORAL.  Handle
GOVD_MAP_ALLOC_ONLY and GOVD_MAP_FROM_ONLY.
(gimplify_adjust_omp_clauses): Handle OMP_CLAUSE_NONTEMPORAL.  Handle
OMP_CLAUSE_{TASK,IN}_REDUCTION.
(gimplify_omp_task): Handle taskwait with depend clauses.
(gimplify_omp_for): Add shared clause on parallel for combined
parallel master taskloop{, simd} if taskloop has firstprivate,
lastprivate or reduction clause.  Use ORT_TASKLOOP or
ORT_UNTIED_TASKLOOP instead of ORT_TASK or ORT_UNTIED_TASK.  Adjust
tests for ORT_COMBINED_TEAMS.  Handle C++ range for loops with
NULL TREE_PURPOSE in OMP_FOR_ORIG_DECLS.  Firstprivatize
__for_end and __for_range temporaries on OMP_PARALLEL for
distribute parallel for{, simd}.  Move OMP_CLAUSE_REDUCTION
and OMP_CLAUSE_IN_REDUCTION from taskloop to the task construct
sandwiched in between two taskloops.
(computable_teams_clause): Test ctx->defaultmap[GDMK_SCALAR]
instead of ctx->omp_firstprivatize_variable.
(gimplify_omp_workshare): Set ort to ORT_HOST_TEAMS or
ORT_COMBINED_HOST_TEAMS if not inside of target construct.  If
host teams, use gimplify_and_return_first etc. for body like
for target or target data constructs, and at the end call
gimple_omp_teams_set_host on the GIMPLE_OMP_TEAMS object.
(gimplify_omp_atomic): Use OMP_ATOMIC_MEMORY_ORDER instead
of OMP_ATOMIC_SEQ_CST, pass it as new argument to
gimple_build_omp_atomic_load and gimple_build_omp_atomic_store, remove
gimple_omp_atomic_set_seq_cst calls.
(gimplify_expr) <case OMP_TASKGROUP>: Move handling into a separate
case, handle taskgroup clauses.
* lto-streamer-out.c (hash_tree): Handle
OMP_CLAUSE_{TASK,IN}_REDUCTION.
* Makefile.in (GTFILES): Add omp-general.h.
* omp-builtins.def (BUILT_IN_GOMP_TASKWAIT_DEPEND,
BUILT_IN_GOMP_LOOP_NONMONOTONIC_RUNTIME_START,
BUILT_IN_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_START,
BUILT_IN_GOMP_LOOP_START, BUILT_IN_GOMP_LOOP_ORDERED_START,
BUILT_IN_GOMP_LOOP_DOACROSS_START,
BUILT_IN_GOMP_LOOP_NONMONOTONIC_RUNTIME_NEXT,
BUILT_IN_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_NEXT,
BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_START,
BUILT_IN_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_START,
BUILT_IN_GOMP_LOOP_ULL_START, BUILT_IN_GOMP_LOOP_ULL_ORDERED_START,
BUILT_IN_GOMP_LOOP_ULL_DOACROSS_START,
BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_NEXT,
BUILT_IN_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_NEXT,
BUILT_IN_GOMP_PARALLEL_LOOP_NONMONOTONIC_RUNTIME,
BUILT_IN_GOMP_PARALLEL_LOOP_MAYBE_NONMONOTONIC_RUNTIME,
BUILT_IN_GOMP_PARALLEL_REDUCTIONS, BUILT_IN_GOMP_SECTIONS2_START,
BUILT_IN_GOMP_TEAMS_REG, BUILT_IN_GOMP_TASKGROUP_REDUCTION_REGISTER,
BUILT_IN_GOMP_TASKGROUP_REDUCTION_UNREGISTER,
BUILT_IN_GOMP_TASK_REDUCTION_REMAP,
BUILT_IN_GOMP_WORKSHARE_TASK_REDUCTION_UNREGISTER): New builtins.
* omp-expand.c (workshare_safe_to_combine_p): Return false for
non-worksharing loops.
(omp_adjust_chunk_size): Don't adjust anything if chunk_size is zero.
(determine_parallel_type): Don't combine parallel with worksharing
which has _reductemp_ clause.
(expand_parallel_call): Emit the GOMP_*nonmonotonic_runtime* or
GOMP_*maybe_nonmonotonic_runtime* builtins instead of GOMP_*runtime*
if there is nonmonotonic modifier or if there is no modifier and no
ordered clause.  For dynamic and guided schedule without monotonic
and nonmonotonic modifier, default to nonmonotonic.
(expand_omp_for): Likewise.  Adjust expand_omp_for_generic caller, use
GOMP_loop{,_ull}{,_ordered,_doacross}_start builtins if there are
task reductions.
(expand_task_call): Add GOMP_TASK_FLAG_REDUCTION flag to flags if
there are any reduction clauses.
(expand_taskwait_call): New function.
(expand_teams_call): New function.
(expand_omp_taskreg): Allow GIMPLE_OMP_TEAMS and call
expand_teams_call for it.  Formatting fix.  Handle taskwait with
depend clauses.
(expand_omp_for_generic): Add SCHED_ARG argument.  Handle expansion
of worksharing loops with task reductions.
(expand_omp_for_static_nochunk, expand_omp_for_static_chunk): Handle
expansion of worksharing loops with task reductions.
(expand_omp_sections): Handle expansion of sections with task
reductions.
(expand_omp_synch): For host teams call expand_omp_taskreg.
(omp_memory_order_to_memmodel): New function.
(expand_omp_atomic_load, expand_omp_atomic_store,
expand_omp_atomic_fetch_op): Use it and gimple_omp_atomic_memory_order
instead of gimple_omp_atomic_seq_cst_p.
(build_omp_regions_1, omp_make_gimple_edges): Treat taskwait with
depend clauses as a standalone directive.
* omp-general.c (enum omp_requires): New variable.
(omp_extract_for_data): Initialize have_reductemp member.  Allow
NE_EXPR even in OpenMP loops, transform them into LT_EXPR or
GT_EXPR loops depending on incr sign.  Formatting fixes.
* omp-general.h (struct omp_for_data): Add have_reductemp member.
(enum omp_requires): New enum.
(omp_requires_mask): Declare.
* omp-grid.c (grid_eliminate_combined_simd_part): Formatting fix.
Fix comment typos.
* omp-low.c (struct omp_context): Add task_reductions and
task_reduction_map fields.
(is_host_teams_ctx): New function.
(is_taskreg_ctx): Return true also if is_host_teams_ctx.
(use_pointer_for_field): Use is_global_var instead of
TREE_STATIC || DECL_EXTERNAL, and apply only if not privatized
in outer contexts.
(build_outer_var_ref): Ignore taskgroup outer contexts.
(delete_omp_context): Release task_reductions and task_reduction_map.
(scan_sharing_clauses): Don't add any fields for reduction clause on
taskloop.  Handle OMP_CLAUSE__REDUCTEMP_.  Handle
OMP_CLAUSE_{IN,TASK}_REDUCTION and OMP_CLAUSE_REDUCTION with task
modifier.  Don't ignore shared clauses in is_host_teams_ctx contexts.
Handle OMP_CLAUSE_NONTEMPORAL.
(add_taskreg_looptemp_clauses): Add OMP_CLAUSE__REDUCTEMP_ clause if
needed.
(scan_omp_parallel): Add _reductemp_ clause if there are any reduction
clauses with task modifier.
(scan_omp_task): Handle taskwait with depend clauses.
(finish_taskreg_scan): Move field corresponding to _reductemp_ clause
first.  Move also OMP_CLAUSE__REDUCTEMP_ clause in front if present.
Handle GIMPLE_OMP_TEAMS like GIMPLE_OMP_PARALLEL.
(scan_omp_for): Fix comment formatting.
(scan_omp_teams): Handle host teams constructs.
(check_omp_nesting_restrictions): Allow teams with no outer
OpenMP context.  Adjust diagnostics for teams strictly nested into
some explicit OpenMP construct other than target.  Allow OpenMP atomics
inside of simd regions.
(scan_omp_1_stmt): Call scan_sharing_clauses for taskgroups.
(scan_omp_1_stmt) <case GIMPLE_OMP_TEAMS>: Temporarily bump
taskreg_nesting_level while scanning host teams construct.
(task_reduction_read): New function.
(lower_rec_input_clauses): Handle OMP_CLAUSE_REDUCTION on taskloop
construct.  Handle OMP_CLAUSE_IN_REDUCTION and OMP_CLAUSE__REDUCTEMP_
clauses.  Handle OMP_CLAUSE_REDUCTION with task modifier.  Remove
second argument create_tmp_var if it is NULL.  Don't ignore shared
clauses in is_host_teams_ctx contexts.  Handle
OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE on OMP_CLAUSE_FIRSTPRIVATE
clauses.
(lower_reduction_clauses): Ignore reduction clauses with task
modifier.  Remove second argument create_tmp_var if it is NULL.
Initialize OMP_ATOMIC_MEMORY_ORDER to relaxed.
(lower_send_clauses): Ignore reduction clauses with task modifier.
Handle OMP_CLAUSE__REDUCTEMP_.  Don't send anything for
OMP_CLAUSE_REDUCTION on taskloop.  Handle OMP_CLAUSE_IN_REDUCTION.
(maybe_add_implicit_barrier_cancel): Add OMP_RETURN argument, don't
rely that it is the last stmt in body so far.  Ignore outer taskgroup
contexts.
(omp_task_reductions_find_first, omp_task_reduction_iterate,
lower_omp_task_reductions): New functions.
(lower_omp_sections): Handle reduction clauses with taskgroup
modifiers.  Adjust maybe_add_implicit_barrier_cancel caller.
(lower_omp_single): Adjust maybe_add_implicit_barrier_cancel caller.
(lower_omp_for): Likewise.  Handle reduction clauses with taskgroup
modifiers.
(lower_omp_taskgroup): Handle taskgroup reductions.
(create_task_copyfn): Copy over OMP_CLAUSE__REDUCTEMP_ pointer.
Handle OMP_CLAUSE_IN_REDUCTION and OMP_CLAUSE_REDUCTION clauses.
(lower_depend_clauses): If there are any
OMP_CLAUSE_DEPEND_DEPOBJ or OMP_CLAUSE_DEPEND_MUTEXINOUTSET
depend clauses, use a new array format.  If OMP_CLAUSE_DEPEND_LAST is
seen, assume lowering is done already and return early.  Set kind
on artificial depend clause to OMP_CLAUSE_DEPEND_LAST.
(lower_omp_taskreg): Handle reduction clauses with task modifier on
parallel construct.  Handle reduction clause on taskloop construct.
Handle taskwait with depend clauses.
(lower_omp_1): Use lower_omp_taskreg instead of lower_omp_teams
for host teams constructs.
* tree.c (omp_clause_num_ops): Add in_reduction, task_reduction,
nontemporal and _reductemp_ clause entries.
(omp_clause_code_name): Likewise.
(walk_tree_1): Handle OMP_CLAUSE_{IN,TASK}_REDUCTION,
OMP_CLAUSE_NONTEMPORAL and OMP_CLAUSE__REDUCTEMP_.
* tree-core.h (enum omp_clause_code): Add
OMP_CLAUSE_{{IN,TASK}_REDUCTION,NONTEMPORAL,_REDUCTEMP_}.
(enum omp_clause_defaultmap_kind, enum omp_memory_order): New.
(struct tree_base): Add omp_atomic_memory_order field into union.
Remove OMP_ATOMIC_SEQ_CST comment.
(enum omp_clause_depend_kind): Add OMP_CLAUSE_DEPEND_MUTEXINOUTSET
and OMP_CLAUSE_DEPEND_DEPOBJ.
(struct tree_omp_clause): Add subcode.defaultmap_kind.
* tree.def (OMP_TASKGROUP): Add another operand, move next to other
OpenMP constructs with body and clauses operands.
* tree.h (OMP_BODY): Use OMP_MASTER instead of OMP_TASKGROUP.
(OMP_CLAUSES): Use OMP_TASKGROUP instead of OMP_SINGLE.
(OMP_TASKGROUP_CLAUSES): Define.
(OMP_CLAUSE_DECL): Use OMP_CLAUSE__REDUCTEMP_ instead of
OMP_CLAUSE__LOOPTEMP_.
(OMP_ATOMIC_SEQ_CST): Remove.
(OMP_ATOMIC_MEMORY_ORDER, OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE,
OMP_CLAUSE_LASTPRIVATE_CONDITIONAL): Define.
(OMP_CLAUSE_REDUCTION_CODE, OMP_CLAUSE_REDUCTION_INIT,
OMP_CLAUSE_REDUCTION_MERGE, OMP_CLAUSE_REDUCTION_PLACEHOLDER,
OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER,
OMP_CLAUSE_REDUCTION_OMP_ORIG_REF): Handle
OMP_CLAUSE_{,IN_,TASK_}REDUCTION.
(OMP_CLAUSE_REDUCTION_TASK, OMP_CLAUSE_REDUCTION_INSCAN,
OMP_CLAUSE_DEFAULTMAP_KIND, OMP_CLAUSE_DEFAULTMAP_CATEGORY,
OMP_CLAUSE_DEFAULTMAP_BEHAVIOR, OMP_CLAUSE_DEFAULTMAP_SET_KIND):
Define.
* tree-inline.c (remap_gimple_stmt): Remap taskgroup clauses.
* tree-nested.c (convert_nonlocal_omp_clauses): Handle
OMP_CLAUSE__REDUCTEMP_, OMP_CLAUSE_NONTEMPORAL.
(convert_local_omp_clauses): Likewise.  Remove useless test.
* tree-parloops.c (create_call_for_reduction_1): Pass
OMP_MEMORY_ORDER_RELAXED as new argument to
dump_gimple_omp_atomic_load and dump_gimple_omp_atomic_store.
* tree-pretty-print.c (dump_omp_iterators): New function.
(dump_omp_clause): Handle OMP_CLAUSE__REDUCTEMP_,
OMP_CLAUSE_NONTEMPORAL, OMP_CLAUSE_{TASK,IN}_REDUCTION.  Print
reduction modifiers.  Handle OMP_CLAUSE_DEPEND_DEPOBJ and
OMP_CLAUSE_DEPEND_MUTEXINOUTSET.  Print iterators in depend clauses.
Print __internal__ for OMP_CLAUSE_DEPEND_LAST.  Handle cancel and
simd OMP_CLAUSE_IF_MODIFIERs.  Handle new kinds of
OMP_CLAUSE_DEFAULTMAP. Print conditional: for
OMP_CLAUSE_LASTPRIVATE_CONDITIONAL.
(dump_omp_atomic_memory_order): New function.
(dump_generic_node): Use it.  Print taskgroup clauses.  Print
taskwait with depend clauses.
* tree-pretty-print.h (dump_omp_atomic_memory_order): Declare.
* tree-streamer-in.c (unpack_ts_omp_clause_value_fields):
Handle OMP_CLAUSE_{TASK,IN}_REDUCTION.
* tree-streamer-out.c (pack_ts_omp_clause_value_fields,
write_ts_omp_clause_tree_pointers): Likewise.
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.
gcc/testsuite/
* c-c++-common/gomp/atomic-17.c: New test.
* c-c++-common/gomp/atomic-18.c: New test.
* c-c++-common/gomp/atomic-19.c: New test.
* c-c++-common/gomp/atomic-20.c: New test.
* c-c++-common/gomp/atomic-21.c: New test.
* c-c++-common/gomp/atomic-22.c: New test.
* c-c++-common/gomp/clauses-1.c (r2): New variable.
(foo): Add ntm argument and test if and nontemporal clauses on
constructs with simd.
(bar): Put taskloop simd inside of taskgroup with task_reduction,
use in_reduction clause instead of reduction.  Add another
taskloop simd without nogroup clause, but with reduction clause and
a new in_reduction.  Add ntm and i3 arguments.  Test if and
nontemporal clauses on constructs with simd.  Change if clauses on
some constructs from specific to the particular constituents to one
without a modifier.  Add new tests for combined host teams and for
new parallel master and {,parallel }master taskloop{, simd} combined
constructs.
(baz): New function with host teams tests.
* gcc.dg/gomp/combined-1.c: Moved to ...
* c-c++-common/gomp/combined-1.c: ... here.  Adjust expected library
call.
* c-c++-common/gomp/combined-2.c: New test.
* c-c++-common/gomp/combined-3.c: New test.
* c-c++-common/gomp/critical-1.c: New test.
* c-c++-common/gomp/critical-2.c: New test.
* c-c++-common/gomp/default-1.c: New test.
* c-c++-common/gomp/defaultmap-1.c: New test.
* c-c++-common/gomp/defaultmap-2.c: New test.
* c-c++-common/gomp/defaultmap-3.c: New test.
* c-c++-common/gomp/depend-5.c: New test.
* c-c++-common/gomp/depend-6.c: New test.
* c-c++-common/gomp/depend-iterator-1.c: New test.
* c-c++-common/gomp/depend-iterator-2.c: New test.
* c-c++-common/gomp/depobj-1.c: New test.
* c-c++-common/gomp/flush-1.c: New test.
* c-c++-common/gomp/flush-2.c: New test.
* c-c++-common/gomp/for-1.c: New test.
* c-c++-common/gomp/for-2.c: New test.
* c-c++-common/gomp/for-3.c: New test.
* c-c++-common/gomp/for-4.c: New test.
* c-c++-common/gomp/for-5.c: New test.
* c-c++-common/gomp/for-6.c: New test.
* c-c++-common/gomp/for-7.c: New test.
* c-c++-common/gomp/if-1.c (foo): Add some further tests.
* c-c++-common/gomp/if-2.c (foo): Likewise.  Expect slightly different
diagnostics wording in one case.
* c-c++-common/gomp/if-3.c: New test.
* c-c++-common/gomp/master-combined-1.c: New test.
* c-c++-common/gomp/master-combined-2.c: New test.
* c-c++-common/gomp/nontemporal-1.c: New test.
* c-c++-common/gomp/nontemporal-2.c: New test.
* c-c++-common/gomp/reduction-task-1.c: New test.
* c-c++-common/gomp/reduction-task-2.c: New test.
* c-c++-common/gomp/requires-1.c: New test.
* c-c++-common/gomp/requires-2.c: New test.
* c-c++-common/gomp/requires-3.c: New test.
* c-c++-common/gomp/requires-4.c: New test.
* c-c++-common/gomp/schedule-modifiers-1.c (bar): Don't expect
diagnostics for nonmonotonic modifier with static, runtime or auto
schedule kinds.
* c-c++-common/gomp/simd7.c: New test.
* c-c++-common/gomp/target-data-1.c: New test.
* c-c++-common/gomp/taskloop-reduction-1.c: New test.
* c-c++-common/gomp/taskwait-depend-1.c: New test.
* c-c++-common/gomp/teams-1.c: New test.
* c-c++-common/gomp/teams-2.c: New test.
* gcc.dg/gomp/appendix-a/a.24.1.c: Update from OpenMP examples.  Add
shared(c) clause.
* gcc.dg/gomp/atomic-5.c (f1): Add another expected error.
* gcc.dg/gomp/clause-1.c: Adjust expected diagnostics for const
qualified vars without mutable member no longer being predeterined
shared.
* gcc.dg/gomp/sharing-1.c: Likewise.
* g++.dg/gomp/clause-3.C: Likewise.
* g++.dg/gomp/member-2.C: Likewise.
* g++.dg/gomp/predetermined-1.C: Likewise.
* g++.dg/gomp/private-1.C: Likewise.
* g++.dg/gomp/sharing-1.C: Likewise.
* g++.dg/gomp/sharing-2.C: Likewise.  Add a few tests with aggregate
const static data member without mutable elements.
* gcc.dg/gomp/for-4.c: Expected nonmonotonic functions in the dumps.
* gcc.dg/gomp/for-5.c: Likewise.
* gcc.dg/gomp/for-6.c: Change expected library call.
* gcc.dg/gomp/pr39495-2.c (foo): Don't expect errors on !=.
* gcc.dg/gomp/reduction-2.c: New test.
* gcc.dg/gomp/simd-1.c: New test.
* gcc.dg/gomp/teams-1.c: Adjust expected diagnostic lines.
* g++.dg/gomp/atomic-18.C: New test.
* g++.dg/gomp/atomic-19.C: New test.
* g++.dg/gomp/atomic-5.C (f1): Adjust expected lines of read-only
variable messages.  Add another expected error.
* g++.dg/gomp/critical-3.C: New test.
* g++.dg/gomp/depend-iterator-1.C: New test.
* g++.dg/gomp/depend-iterator-2.C: New test.
* g++.dg/gomp/depobj-1.C: New test.
* g++.dg/gomp/doacross-1.C: New test.
* g++.dg/gomp/for-21.C: New test.
* g++.dg/gomp/for-4.C: Expected nonmonotonic functions in the dumps.
* g++.dg/gomp/for-5.C: Likewise.
* g++.dg/gomp/for-6.C: Change expected library call.
* g++.dg/gomp/loop-4.C: New test.
* g++.dg/gomp/pr33372-1.C: Adjust location of the expected
diagnostics.
* g++.dg/gomp/pr33372-3.C: Likewise.
* g++.dg/gomp/pr39495-2.C (foo): Don't expect errors on !=.
* g++.dg/gomp/simd-2.C: New test.
* g++.dg/gomp/tpl-atomic-2.C: Adjust expected diagnostic lines.
include/
* gomp-constants.h (GOMP_TASK_FLAG_REDUCTION,
GOMP_DEPEND_IN, GOMP_DEPEND_OUT, GOMP_DEPEND_INOUT,
GOMP_DEPEND_MUTEXINOUTSET): Define.
libgomp/
* affinity.c (gomp_display_affinity_place): New function.
* affinity-fmt.c: New file.
* alloc.c (gomp_aligned_alloc, gomp_aligned_free): New functions.
* config/linux/affinity.c (gomp_display_affinity_place): New function.
* config/nvptx/icv-device.c (omp_get_num_teams, omp_get_team_num):
Move these functions to ...
* config/nvptx/teams.c: ... here.  New file.
* config/nvptx/target.c (omp_pause_resource, omp_pause_resource_all):
New functions.
* config/nvptx/team.c (gomp_team_start, gomp_pause_host): New
functions.
* configure.ac: Check for aligned_alloc, posix_memalign, memalign
and _aligned_malloc.
(HAVE_UNAME, HAVE_GETHOSTNAME, HAVE_GETPID): Add new tests.
* configure.tgt: Add -DUSING_INITIAL_EXEC_TLS to XCFLAGS for Linux.
* env.c (gomp_display_affinity_var, gomp_affinity_format_var,
gomp_affinity_format_len): New variables.
(parse_schedule): Parse monotonic and nonmonotonic modifiers in
OMP_SCHEDULE variable.  Set GFS_MONOTONIC for monotonic schedules.
(handle_omp_display_env): Display monotonic/nonmonotonic schedule
modifiers.  Display (non-default) chunk sizes.  Print
OMP_DISPLAY_AFFINITY and OMP_AFFINITY_FORMAT.
(initialize_env): Don't call pthread_attr_setdetachstate.  Handle
OMP_DISPLAY_AFFINITY and OMP_AFFINITY_FORMAT env vars.
* fortran.c: Include stdio.h and string.h.
(omp_pause_resource, omp_pause_resource_all): Add ialias_redirect.
(omp_get_schedule_, omp_get_schedule_8_): Mask off GFS_MONOTONIC bit.
(omp_set_affinity_format_, omp_get_affinity_format_,
omp_display_affinity_, omp_capture_affinity_, omp_pause_resource_,
omp_pause_resource_all_): New functions.
* icv.c (omp_set_schedule): Mask off omp_sched_monotonic bit in
switch.
* icv-device.c (omp_get_num_teams, omp_get_team_num): Move these
functions to ...
* teams.c: ... here.  New file.
* libgomp_g.h: Include gstdint.h.
(GOMP_loop_nonmonotonic_runtime_start,
GOMP_loop_maybe_nonmonotonic_runtime_start, GOMP_loop_start,
GOMP_loop_ordered_start, GOMP_loop_nonmonotonic_runtime_next,
GOMP_loop_maybe_nonmonotonic_runtime_next, GOMP_loop_doacross_start,
GOMP_parallel_loop_nonmonotonic_runtime,
GOMP_parallel_loop_maybe_nonmonotonic_runtime,
GOMP_loop_ull_nonmonotonic_runtime_start,
GOMP_loop_ull_maybe_nonmonotonic_runtime_start, GOMP_loop_ull_start,
GOMP_loop_ull_ordered_start, GOMP_loop_ull_nonmonotonic_runtime_next,
GOMP_loop_ull_maybe_nonmonotonic_runtime_next,
GOMP_loop_ull_doacross_start, GOMP_parallel_reductions,
GOMP_taskwait_depend, GOMP_taskgroup_reduction_register,
GOMP_taskgroup_reduction_unregister, GOMP_task_reduction_remap,
GOMP_workshare_task_reduction_unregister, GOMP_sections2_start,
GOMP_teams_reg): Declare.
* libgomp.h (GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC): Define unless
gomp_aligned_alloc uses fallback implementation.
(gomp_aligned_alloc, gomp_aligned_free): Declare.
(enum gomp_schedule_type): Add GFS_MONOTONIC.
(struct gomp_doacross_work_share): Add extra field.
(struct gomp_work_share): Add task_reductions field.
(struct gomp_taskgroup): Add workshare and reductions fields.
(GOMP_NEEDS_THREAD_HANDLE): Define if needed.
(gomp_thread_handle): New typedef.
(gomp_display_affinity_place, gomp_set_affinity_format,
gomp_display_string, gomp_display_affinity,
gomp_display_affinity_thread): Declare.
(gomp_doacross_init, gomp_doacross_ull_init): Add size_t argument.
(gomp_parallel_reduction_register, gomp_workshare_taskgroup_start,
gomp_workshare_task_reduction_register): Declare.
(gomp_team_start): Add taskgroup argument.
(gomp_pause_host): Declare.
(gomp_init_work_share, gomp_work_share_start): Change bool argument
to size_t.
(gomp_thread_self, gomp_thread_to_pthread_t): New inline functions.
* libgomp.map (GOMP_5.0): Export GOMP_loop_start,
GOMP_loop_ordered_start, GOMP_loop_doacross_start,
GOMP_loop_ull_start, GOMP_loop_ull_ordered_start,
GOMP_loop_ull_doacross_start,
GOMP_workshare_task_reduction_unregister, GOMP_sections2_start,
GOMP_loop_maybe_nonmonotonic_runtime_next,
GOMP_loop_maybe_nonmonotonic_runtime_start,
GOMP_loop_nonmonotonic_runtime_next,
GOMP_loop_nonmonotonic_runtime_start,
GOMP_loop_ull_maybe_nonmonotonic_runtime_next,
GOMP_loop_ull_maybe_nonmonotonic_runtime_start,
GOMP_loop_ull_nonmonotonic_runtime_next,
GOMP_loop_ull_nonmonotonic_runtime_start,
GOMP_parallel_loop_maybe_nonmonotonic_runtime,
GOMP_parallel_loop_nonmonotonic_runtime, GOMP_parallel_reductions,
GOMP_taskgroup_reduction_register,
GOMP_taskgroup_reduction_unregister, GOMP_task_reduction_remap,
GOMP_teams_reg and GOMP_taskwait_depend.
(OMP_5.0): Export omp_pause_resource{,_all}{,_},
omp_{capture,display}_affinity{,_}, and
omp_[gs]et_affinity_format{,_}.
* loop.c: Include string.h.
(GOMP_loop_runtime_next): Add ialias.
(GOMP_taskgroup_reduction_register): Add ialias_redirect.
(gomp_loop_static_start, gomp_loop_dynamic_start,
gomp_loop_guided_start, gomp_loop_ordered_static_start,
gomp_loop_ordered_dynamic_start, gomp_loop_ordered_guided_start,
gomp_loop_doacross_static_start, gomp_loop_doacross_dynamic_start,
gomp_loop_doacross_guided_start): Adjust gomp_work_share_start
or gomp_doacross_init callers.
(gomp_adjust_sched, GOMP_loop_start, GOMP_loop_ordered_start,
GOMP_loop_doacross_start): New functions.
(GOMP_loop_runtime_start, GOMP_loop_ordered_runtime_start,
GOMP_loop_doacross_runtime_start, GOMP_parallel_loop_runtime_start):
Mask off GFS_MONOTONIC bit.
(GOMP_loop_maybe_nonmonotonic_runtime_next,
GOMP_loop_maybe_nonmonotonic_runtime_start,
GOMP_loop_nonmonotonic_runtime_next,
GOMP_loop_nonmonotonic_runtime_start,
GOMP_parallel_loop_maybe_nonmonotonic_runtime,
GOMP_parallel_loop_nonmonotonic_runtime): New aliases or wrapper
functions.
(gomp_parallel_loop_start): Pass NULL as taskgroup to
gomp_team_start.
* loop_ull.c: Include string.h.
(GOMP_loop_ull_runtime_next): Add ialias.
(GOMP_taskgroup_reduction_register): Add ialias_redirect.
(gomp_loop_ull_static_start, gomp_loop_ull_dynamic_start,
gomp_loop_ull_guided_start, gomp_loop_ull_ordered_static_start,
gomp_loop_ull_ordered_dynamic_start,
gomp_loop_ull_ordered_guided_start,
gomp_loop_ull_doacross_static_start,
gomp_loop_ull_doacross_dynamic_start,
gomp_loop_ull_doacross_guided_start): Adjust gomp_work_share_start
and gomp_doacross_ull_init callers.
(gomp_adjust_sched, GOMP_loop_ull_start, GOMP_loop_ull_ordered_start,
GOMP_loop_ull_doacross_start): New functions.
(GOMP_loop_ull_runtime_start,
GOMP_loop_ull_ordered_runtime_start,
GOMP_loop_ull_doacross_runtime_start): Mask off GFS_MONOTONIC bit.
(GOMP_loop_ull_maybe_nonmonotonic_runtime_next,
GOMP_loop_ull_maybe_nonmonotonic_runtime_start,
GOMP_loop_ull_nonmonotonic_runtime_next,
GOMP_loop_ull_nonmonotonic_runtime_start): Likewise.
* Makefile.am (libgomp_la_SOURCES): Add teams.c and affinity-fmt.c.
* omp.h.in (enum omp_sched_t): Add omp_sched_monotonic.
(omp_pause_resource_t, omp_depend_t): New typedefs.
(enum omp_lock_hint_t): Renamed to ...
(enum omp_sync_hint_t): ... this.  Define omp_sync_hint_*
enumerators using numbers and omp_lock_hint_* as their aliases.
(omp_lock_hint_t): New typedef.  Rename to ...
(omp_sync_hint_t): ... this.
(omp_init_lock_with_hint, omp_init_nest_lock_with_hint): Use
omp_sync_hint_t instead of omp_lock_hint_t.
(omp_pause_resource, omp_pause_resource_all, omp_set_affinity_format,
omp_get_affinity_format, omp_display_affinity, omp_capture_affinity):
Declare.
(omp_target_is_present, omp_target_disassociate_ptr):
Change first argument from void * to const void *.
(omp_target_memcpy, omp_target_memcpy_rect): Change second argument
from void * to const void *.
(omp_target_associate_ptr): Change first and second arguments from
void * to const void *.
* omp_lib.f90.in (omp_pause_resource_kind, omp_pause_soft,
omp_pause_hard): New parameters.
(omp_pause_resource, omp_pause_resource_all, omp_set_affinity_format,
omp_get_affinity_format, omp_display_affinity, omp_capture_affinity):
New interfaces.
* omp_lib.h.in (omp_pause_resource_kind, omp_pause_soft,
omp_pause_hard): New parameters.
(omp_pause_resource, omp_pause_resource_all, omp_set_affinity_format,
omp_get_affinity_format, omp_display_affinity, omp_capture_affinity):
New externals.
* ordered.c (gomp_doacross_init, gomp_doacross_ull_init): Add
EXTRA argument.  If not needed to prepare array, if extra is 0,
clear ws->doacross, otherwise allocate just doacross structure and
extra payload.  If array is needed, allocate also extra payload.
(GOMP_doacross_post, GOMP_doacross_wait, GOMP_doacross_ull_post,
GOMP_doacross_ull_wait): Handle doacross->array == NULL like
doacross == NULL.
* parallel.c (GOMP_parallel_start): Pass NULL as taskgroup to
gomp_team_start.
(GOMP_parallel): Likewise.  Formatting fix.
(GOMP_parallel_reductions): New function.
(GOMP_cancellation_point): If taskgroup has workshare
flag set, check cancelled of prev taskgroup if any.
(GOMP_cancel): If taskgroup has workshare flag set, set cancelled
on prev taskgroup if any.
* sections.c: Include string.h.
(GOMP_taskgroup_reduction_register): Add ialias_redirect.
(GOMP_sections_start): Adjust gomp_work_share_start caller.
(GOMP_sections2_start): New function.
(GOMP_parallel_sections_start, GOMP_parallel_sections):
Pass NULL as taskgroup to gomp_team_start.
* single.c (GOMP_single_start, GOMP_single_copy_start): Adjust
gomp_work_share_start callers.
* target.c (GOMP_target_update_ext, GOMP_target_enter_exit_data):
If taskgroup has workshare flag set, check cancelled on prev
taskgroup if any.  Guard all cancellation tests with
gomp_cancel_var test.
(omp_target_is_present, omp_target_disassociate_ptr):
Change ptr argument from void * to const void *.
(omp_target_memcpy): Change src argument from void * to const void *.
(omp_target_memcpy_rect): Likewise.
(omp_target_memcpy_rect_worker): Likewise.  Use const char * casts
instead of char * where needed.
(omp_target_associate_ptr): Change host_ptr and device_ptr arguments
from void * to const void *.
(omp_pause_resource, omp_pause_resource_all): New functions.
* task.c (gomp_task_handle_depend): Handle new depend array format
in addition to the old.  Handle mutexinoutset kinds the same as
inout for now, handle unspecified kinds.
(gomp_create_target_task): If taskgroup has workshare flag set, check
cancelled on prev taskgroup if any.  Guard all cancellation tests with
gomp_cancel_var test.  Handle new depend array format count in
addition to the old.
(GOMP_task): Likewise.  Adjust function comment.
(gomp_task_run_pre): If taskgroup has workshare flag set, check
cancelled on prev taskgroup if any.  Guard all cancellation tests with
gomp_cancel_var test.
(GOMP_taskwait_depend): New function.
(gomp_task_maybe_wait_for_dependencies): Handle new depend array
format in addition to the old.  Handle mutexinoutset kinds the same as
inout for now, handle unspecified kinds.  Fix a function comment typo.
(gomp_taskgroup_init): New function.
(GOMP_taskgroup_start): Use it.
(gomp_reduction_register, gomp_create_artificial_team,
GOMP_taskgroup_reduction_register,
GOMP_taskgroup_reduction_unregister, GOMP_task_reduction_remap,
gomp_parallel_reduction_register,
gomp_workshare_task_reduction_register,
gomp_workshare_taskgroup_start,
GOMP_workshare_task_reduction_unregister): New functions.
* taskloop.c (GOMP_taskloop): If taskgroup has workshare flag set,
check cancelled on prev taskgroup if any.  Guard all cancellation
tests with gomp_cancel_var test.  Handle GOMP_TASK_FLAG_REDUCTION flag
by calling GOMP_taskgroup_reduction_register.
* team.c (gomp_thread_attr): Remove comment.
(struct gomp_thread_start_data): Add handle field.
(gomp_thread_start): Call pthread_detach.
(gomp_new_team): Adjust gomp_init_work_share caller.
(gomp_free_pool_helper): Call pthread_detach.
(gomp_team_start): Add taskgroup argument, initialize implicit
tasks' taskgroup field to that.  Don't call
pthread_attr_setdetachstate.  Handle OMP_DISPLAY_AFFINITY env var.
(gomp_team_end): Determine nesting by thr->ts.level != 0
rather than thr->ts.team != NULL.
(gomp_pause_pool_helper, gomp_pause_host): New functions.
* work.c (alloc_work_share): Use gomp_aligned_alloc instead of
gomp_malloc if GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC is defined.
(gomp_init_work_share): Change ORDERED argument from bool to size_t,
if more than 1 allocate also extra payload at the end of array.  Never
keep ordered_team_ids NULL, set it to inline_ordered_team_ids instead.
(gomp_work_share_start): Change ORDERED argument from bool to size_t,
return true instead of ws.
* Makefile.in: Regenerated.
* configure: Regenerated.
* config.h.in: Regenerated.
* testsuite/libgomp.c/cancel-for-2.c (foo): Use cancel modifier
in some cases.
* testsuite/libgomp.c-c++-common/cancel-parallel-1.c: New test.
* testsuite/libgomp.c-c++-common/cancel-taskgroup-3.c: New test.
* testsuite/libgomp.c-c++-common/depend-iterator-1.c: New test.
* testsuite/libgomp.c-c++-common/depend-iterator-2.c: New test.
* testsuite/libgomp.c-c++-common/depend-mutexinout-1.c: New test.
* testsuite/libgomp.c-c++-common/depend-mutexinout-2.c: New test.
* testsuite/libgomp.c-c++-common/depobj-1.c: New test.
* testsuite/libgomp.c-c++-common/display-affinity-1.c: New test.
* testsuite/libgomp.c-c++-common/for-10.c: New test.
* testsuite/libgomp.c-c++-common/for-11.c: New test.
* testsuite/libgomp.c-c++-common/for-12.c: New test.
* testsuite/libgomp.c-c++-common/for-13.c: New test.
* testsuite/libgomp.c-c++-common/for-14.c: New test.
* testsuite/libgomp.c-c++-common/for-15.c: New test.
* testsuite/libgomp.c-c++-common/for-2.h: If CONDNE macro is defined,
define a different N(test), don't define N(f0) to N(f14), but instead
define N(f20) to N(f34) using != comparisons.
* testsuite/libgomp.c-c++-common/for-7.c: New test.
* testsuite/libgomp.c-c++-common/for-8.c: New test.
* testsuite/libgomp.c-c++-common/for-9.c: New test.
* testsuite/libgomp.c-c++-common/master-combined-1.c: New test.
* testsuite/libgomp.c-c++-common/pause-1.c: New test.
* testsuite/libgomp.c-c++-common/pause-2.c: New test.
* testsuite/libgomp.c-c++-common/pr66199-10.c: New test.
* testsuite/libgomp.c-c++-common/pr66199-11.c: New test.
* testsuite/libgomp.c-c++-common/pr66199-12.c: New test.
* testsuite/libgomp.c-c++-common/pr66199-13.c: New test.
* testsuite/libgomp.c-c++-common/pr66199-14.c: New test.
* testsuite/libgomp.c-c++-common/simd-1.c: New test.
* testsuite/libgomp.c-c++-common/taskloop-reduction-1.c: New test.
* testsuite/libgomp.c-c++-common/taskloop-reduction-2.c: New test.
* testsuite/libgomp.c-c++-common/taskloop-reduction-3.c: New test.
* testsuite/libgomp.c-c++-common/taskloop-reduction-4.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-11.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-12.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-1.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-2.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-3.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-4.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-5.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-6.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-7.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-8.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-9.c: New test.
* testsuite/libgomp.c-c++-common/taskwait-depend-1.c: New test.
* testsuite/libgomp.c++/depend-1.C: New test.
* testsuite/libgomp.c++/depend-iterator-1.C: New test.
* testsuite/libgomp.c++/depobj-1.C: New test.
* testsuite/libgomp.c++/for-16.C: New test.
* testsuite/libgomp.c++/for-21.C: New test.
* testsuite/libgomp.c++/for-22.C: New test.
* testsuite/libgomp.c++/for-23.C: New test.
* testsuite/libgomp.c++/for-24.C: New test.
* testsuite/libgomp.c++/for-25.C: New test.
* testsuite/libgomp.c++/for-26.C: New test.
* testsuite/libgomp.c++/taskloop-reduction-1.C: New test.
* testsuite/libgomp.c++/taskloop-reduction-2.C: New test.
* testsuite/libgomp.c++/taskloop-reduction-3.C: New test.
* testsuite/libgomp.c++/taskloop-reduction-4.C: New test.
* testsuite/libgomp.c++/task-reduction-10.C: New test.
* testsuite/libgomp.c++/task-reduction-11.C: New test.
* testsuite/libgomp.c++/task-reduction-12.C: New test.
* testsuite/libgomp.c++/task-reduction-13.C: New test.
* testsuite/libgomp.c++/task-reduction-14.C: New test.
* testsuite/libgomp.c++/task-reduction-15.C: New test.
* testsuite/libgomp.c++/task-reduction-16.C: New test.
* testsuite/libgomp.c++/task-reduction-17.C: New test.
* testsuite/libgomp.c++/task-reduction-18.C: New test.
* testsuite/libgomp.c++/task-reduction-19.C: New test.
* testsuite/libgomp.c/task-reduction-1.c: New test.
* testsuite/libgomp.c++/task-reduction-1.C: New test.
* testsuite/libgomp.c/task-reduction-2.c: New test.
* testsuite/libgomp.c++/task-reduction-2.C: New test.
* testsuite/libgomp.c++/task-reduction-3.C: New test.
* testsuite/libgomp.c++/task-reduction-4.C: New test.
* testsuite/libgomp.c++/task-reduction-5.C: New test.
* testsuite/libgomp.c++/task-reduction-6.C: New test.
* testsuite/libgomp.c++/task-reduction-7.C: New test.
* testsuite/libgomp.c++/task-reduction-8.C: New test.
* testsuite/libgomp.c++/task-reduction-9.C: New test.
* testsuite/libgomp.c/teams-1.c: New test.
* testsuite/libgomp.c/teams-2.c: New test.
* testsuite/libgomp.c/thread-limit-4.c: New test.
* testsuite/libgomp.c/thread-limit-5.c: New test.
* testsuite/libgomp.fortran/display-affinity-1.f90: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@265930 138bc75d-0d04-0410-961f-82ee72b054a4

260 files changed:
gcc/ChangeLog
gcc/Makefile.in
gcc/builtin-types.def
gcc/c-family/ChangeLog
gcc/c-family/c-common.h
gcc/c-family/c-omp.c
gcc/c-family/c-pragma.c
gcc/c-family/c-pragma.h
gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/c/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/cp/cp-gimplify.c
gcc/cp/cp-objcp-common.c
gcc/cp/cp-tree.def
gcc/cp/cp-tree.h
gcc/cp/cxx-pretty-print.c
gcc/cp/dump.c
gcc/cp/lex.c
gcc/cp/parser.c
gcc/cp/pt.c
gcc/cp/semantics.c
gcc/fortran/ChangeLog
gcc/fortran/trans-openmp.c
gcc/fortran/types.def
gcc/gengtype.c
gcc/gimple-pretty-print.c
gcc/gimple.c
gcc/gimple.def
gcc/gimple.h
gcc/gimplify.c
gcc/lto-streamer-out.c
gcc/omp-builtins.def
gcc/omp-expand.c
gcc/omp-general.c
gcc/omp-general.h
gcc/omp-grid.c
gcc/omp-low.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/gomp/atomic-17.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/atomic-18.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/atomic-19.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/atomic-20.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/atomic-21.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/atomic-22.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/clauses-1.c
gcc/testsuite/c-c++-common/gomp/combined-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/combined-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/combined-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/critical-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/critical-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/default-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/defaultmap-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/defaultmap-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/defaultmap-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/depend-5.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/depend-6.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/depend-iterator-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/depend-iterator-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/depobj-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/flush-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/flush-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/for-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/for-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/for-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/for-4.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/for-5.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/for-6.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/for-7.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/if-1.c
gcc/testsuite/c-c++-common/gomp/if-2.c
gcc/testsuite/c-c++-common/gomp/if-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/master-combined-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/master-combined-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/nontemporal-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/nontemporal-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/reduction-task-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/reduction-task-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/requires-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/requires-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/requires-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/requires-4.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/schedule-modifiers-1.c
gcc/testsuite/c-c++-common/gomp/simd7.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/target-data-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/taskloop-reduction-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/taskwait-depend-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/teams-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/teams-2.c [new file with mode: 0644]
gcc/testsuite/g++.dg/gomp/atomic-18.C [new file with mode: 0644]
gcc/testsuite/g++.dg/gomp/atomic-19.C [new file with mode: 0644]
gcc/testsuite/g++.dg/gomp/atomic-5.C
gcc/testsuite/g++.dg/gomp/clause-3.C
gcc/testsuite/g++.dg/gomp/critical-3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/gomp/depend-iterator-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/gomp/depend-iterator-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/gomp/depobj-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/gomp/doacross-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/gomp/for-21.C [new file with mode: 0644]
gcc/testsuite/g++.dg/gomp/for-4.C
gcc/testsuite/g++.dg/gomp/for-5.C
gcc/testsuite/g++.dg/gomp/for-6.C
gcc/testsuite/g++.dg/gomp/loop-4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/gomp/member-2.C
gcc/testsuite/g++.dg/gomp/pr33372-1.C
gcc/testsuite/g++.dg/gomp/pr33372-3.C
gcc/testsuite/g++.dg/gomp/pr39495-2.C
gcc/testsuite/g++.dg/gomp/predetermined-1.C
gcc/testsuite/g++.dg/gomp/private-1.C
gcc/testsuite/g++.dg/gomp/sharing-1.C
gcc/testsuite/g++.dg/gomp/sharing-2.C
gcc/testsuite/g++.dg/gomp/simd-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/gomp/tpl-atomic-2.C
gcc/testsuite/gcc.dg/gomp/appendix-a/a.24.1.c
gcc/testsuite/gcc.dg/gomp/atomic-5.c
gcc/testsuite/gcc.dg/gomp/clause-1.c
gcc/testsuite/gcc.dg/gomp/combined-1.c
gcc/testsuite/gcc.dg/gomp/for-4.c
gcc/testsuite/gcc.dg/gomp/for-5.c
gcc/testsuite/gcc.dg/gomp/for-6.c
gcc/testsuite/gcc.dg/gomp/pr39495-2.c
gcc/testsuite/gcc.dg/gomp/reduction-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/gomp/sharing-1.c
gcc/testsuite/gcc.dg/gomp/simd-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/gomp/teams-1.c
gcc/tree-core.h
gcc/tree-inline.c
gcc/tree-nested.c
gcc/tree-parloops.c
gcc/tree-pretty-print.c
gcc/tree-pretty-print.h
gcc/tree-streamer-in.c
gcc/tree-streamer-out.c
gcc/tree.c
gcc/tree.def
gcc/tree.h
include/ChangeLog
include/gomp-constants.h
libgomp/ChangeLog
libgomp/Makefile.am
libgomp/Makefile.in
libgomp/affinity-fmt.c [new file with mode: 0644]
libgomp/affinity.c
libgomp/alloc.c
libgomp/config.h.in
libgomp/config/linux/affinity.c
libgomp/config/nvptx/icv-device.c
libgomp/config/nvptx/target.c
libgomp/config/nvptx/team.c
libgomp/config/nvptx/teams.c [new file with mode: 0644]
libgomp/configure
libgomp/configure.ac
libgomp/configure.tgt
libgomp/env.c
libgomp/fortran.c
libgomp/icv-device.c
libgomp/icv.c
libgomp/libgomp.h
libgomp/libgomp.map
libgomp/libgomp_g.h
libgomp/loop.c
libgomp/loop_ull.c
libgomp/omp.h.in
libgomp/omp_lib.f90.in
libgomp/omp_lib.h.in
libgomp/ordered.c
libgomp/parallel.c
libgomp/sections.c
libgomp/single.c
libgomp/target.c
libgomp/task.c
libgomp/taskloop.c
libgomp/team.c
libgomp/teams.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/depend-1.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/depend-iterator-1.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/depobj-1.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/for-16.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/for-21.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/for-22.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/for-23.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/for-24.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/for-25.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/for-26.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-1.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-10.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-11.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-12.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-13.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-14.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-15.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-16.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-17.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-18.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-19.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-2.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-3.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-4.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-5.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-6.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-7.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-8.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/task-reduction-9.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/taskloop-reduction-1.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/taskloop-reduction-2.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/taskloop-reduction-3.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/taskloop-reduction-4.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/cancel-parallel-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/cancel-taskgroup-3.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/depend-iterator-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/depend-iterator-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/depend-mutexinout-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/depend-mutexinout-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/depobj-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/display-affinity-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/for-10.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/for-11.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/for-12.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/for-13.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/for-14.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/for-15.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/for-2.h
libgomp/testsuite/libgomp.c-c++-common/for-7.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/for-8.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/for-9.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/master-combined-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/pause-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/pause-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/pr66199-10.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/pr66199-11.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/pr66199-12.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/pr66199-13.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/pr66199-14.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/simd-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/task-reduction-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/task-reduction-11.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/task-reduction-12.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/task-reduction-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/task-reduction-3.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/task-reduction-4.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/task-reduction-5.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/task-reduction-6.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/task-reduction-7.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/task-reduction-8.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/task-reduction-9.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/taskloop-reduction-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/taskloop-reduction-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/taskloop-reduction-3.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/taskloop-reduction-4.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/taskwait-depend-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c/cancel-for-2.c
libgomp/testsuite/libgomp.c/task-reduction-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c/task-reduction-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c/teams-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c/teams-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c/thread-limit-4.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c/thread-limit-5.c [new file with mode: 0644]
libgomp/testsuite/libgomp.fortran/display-affinity-1.f90 [new file with mode: 0644]
libgomp/work.c

index c3e77f3e27e5ff657263e8d599a28ebf558a3eff..d4619601362bafa2762bc7af2a2e7465c1ca2617 100644 (file)
@@ -1,3 +1,307 @@
+2018-11-08  Jakub Jelinek  <jakub@redhat.com>
+
+       * builtin-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.
+       * gengtype.c (open_base_files): Add omp-general.h.
+       * gimple.c (gimple_build_omp_critical):
+       (gimple_build_omp_taskgroup): Add CLAUSES argument.  Call
+       gimple_omp_taskgroup_set_clauses.
+       (gimple_build_omp_atomic_load): Add mo argument, call
+       gimple_omp_atomic_set_memory_order.
+       (gimple_build_omp_atomic_store): Likewise.
+       (gimple_copy): Adjust handling of GIMPLE_OMP_TASKGROUP.
+       * gimple.def (GIMPLE_OMP_TASKGROUP): Use GSS_OMP_SINGLE_LAYOUT
+       instead of GSS_OMP.
+       (GIMPLE_OMP_TEAMS): Use GSS_OMP_PARALLEL_LAYOUT instead
+       of GSS_OMP_SINGLE_LAYOUT, adjust comments.
+       * gimple.h (enum gf_mask): Add GF_OMP_TEAMS_HOST, GF_OMP_TASK_TASKWAIT
+       and GF_OMP_ATOMIC_MEMORY_ORDER.  Remove GF_OMP_ATOMIC_SEQ_CST, use
+       different value for GF_OMP_ATOMIC_NEED_VALUE.
+       (struct gimple_statement_omp_taskreg): Add GIMPLE_OMP_TEAMS to
+       comments.
+       (struct gimple_statement_omp_single_layout): And remove here.
+       (struct gomp_teams): Inherit from gimple_statement_omp_taskreg rather
+       than gimple_statement_omp_single_layout.
+       (is_a_helper <gimple_statement_omp_taskreg *>::test): Allow
+       GIMPLE_OMP_TEAMS.
+       (is_a_helper <const gimple_statement_omp_taskreg *>::test): Likewise.
+       (gimple_omp_subcode): Formatting fix.
+       (gimple_omp_teams_child_fn, gimple_omp_teams_child_fn_ptr,
+       gimple_omp_teams_set_child_fn, gimple_omp_teams_data_arg,
+       gimple_omp_teams_data_arg_ptr, gimple_omp_teams_set_data_arg,
+       gimple_omp_teams_host, gimple_omp_teams_set_host,
+       gimple_omp_task_taskwait_p, gimple_omp_task_set_taskwait_p,
+       gimple_omp_taskgroup_clauses, gimple_omp_taskgroup_clauses_ptr,
+       gimple_omp_taskgroup_set_clauses): New inline functions.
+       (gimple_build_omp_atomic_load): Add enum omp_memory_order argument.
+       (gimple_build_omp_atomic_store): Likewise.
+       (gimple_omp_atomic_seq_cst_p): Remove.
+       (gimple_omp_atomic_memory_order): New function.
+       (gimple_omp_atomic_set_seq_cst): Remove.
+       (gimple_omp_atomic_set_memory_order): New function.
+       (gimple_build_omp_taskgroup): Add clauses argument.
+       * gimple-pretty-print.c (dump_gimple_omp_taskgroup): New function.
+       (dump_gimple_omp_task): Print taskwait with depend clauses.
+       (dump_gimple_omp_atomic_load, dump_gimple_omp_atomic_store): Use
+       dump_omp_atomic_memory_order.
+       (pp_gimple_stmt_1): Handle GIMPLE_OMP_TASKGROUP.
+       * gimplify.c (enum gimplify_omp_var_data): Add GOVD_MAP_ALLOC_ONLY,
+       GOVD_MAP_FROM_ONLY and GOVD_NONTEMPORAL.
+       (enum omp_region_type): Reserve bits 1 and 2 for auxiliary flags,
+       renumber values of most of ORT_* enumerators, add ORT_HOST_TEAMS,
+       ORT_COMBINED_HOST_TEAMS, ORT_TASKGROUP, ORT_TASKLOOP and
+       ORT_UNTIED_TASKLOOP enumerators.
+       (enum gimplify_defaultmap_kind): New.
+       (struct gimplify_omp_ctx): Remove target_map_scalars_firstprivate and
+       target_map_pointers_as_0len_arrays members, add defaultmap.
+       (new_omp_context): Initialize defaultmap member.
+       (gimple_add_tmp_var): Handle ORT_TASKGROUP like ORT_WORKSHARE.
+       (maybe_fold_stmt): Don't fold even in host teams regions.
+       (omp_firstprivatize_variable): Handle ORT_TASKGROUP like
+       ORT_WORKSHARE.  Test ctx->defaultmap[GDMK_SCALAR] instead of
+       ctx->omp_firstprivatize_variable.
+       (omp_add_variable): Don't add private/firstprivate for VLAs in
+       ORT_TASKGROUP.
+       (omp_default_clause): Print "taskloop" rather than "task" if
+       ORT_*TASKLOOP.
+       (omp_notice_variable): Handle ORT_TASKGROUP like ORT_WORKSHARE.
+       Handle new defaultmap clause kinds.
+       (omp_is_private): Handle ORT_TASKGROUP like ORT_WORKSHARE.  Allow simd
+       iterator to be lastprivate or private.  Fix up diagnostics if linear
+       is used on collapse>1 simd iterator.
+       (omp_check_private): Handle ORT_TASKGROUP like ORT_WORKSHARE.
+       (gimplify_omp_depend): New function.
+       (gimplify_scan_omp_clauses): Add shared clause on parallel for
+       combined parallel master taskloop{, simd} if taskloop has
+       firstprivate, lastprivate or reduction clause.  Handle
+       OMP_CLAUSE_REDUCTION_TASK diagnostics.  Adjust tests for
+       ORT_COMBINED_TEAMS.  Gimplify depend clauses with iterators.  Handle
+       cancel and simd OMP_CLAUSE_IF_MODIFIERs.  Handle
+       OMP_CLAUSE_NONTEMPORAL.  Handle new defaultmap clause kinds.  Handle
+       OMP_CLAUSE_{TASK,IN}_REDUCTION.  Diagnose invalid conditional
+       lastprivate.
+       (gimplify_adjust_omp_clauses_1): Ignore GOVD_NONTEMPORAL.  Handle
+       GOVD_MAP_ALLOC_ONLY and GOVD_MAP_FROM_ONLY.  
+       (gimplify_adjust_omp_clauses): Handle OMP_CLAUSE_NONTEMPORAL.  Handle
+       OMP_CLAUSE_{TASK,IN}_REDUCTION.
+       (gimplify_omp_task): Handle taskwait with depend clauses.
+       (gimplify_omp_for): Add shared clause on parallel for combined
+       parallel master taskloop{, simd} if taskloop has firstprivate,
+       lastprivate or reduction clause.  Use ORT_TASKLOOP or
+       ORT_UNTIED_TASKLOOP instead of ORT_TASK or ORT_UNTIED_TASK.  Adjust
+       tests for ORT_COMBINED_TEAMS.  Handle C++ range for loops with
+       NULL TREE_PURPOSE in OMP_FOR_ORIG_DECLS.  Firstprivatize
+       __for_end and __for_range temporaries on OMP_PARALLEL for
+       distribute parallel for{, simd}.  Move OMP_CLAUSE_REDUCTION
+       and OMP_CLAUSE_IN_REDUCTION from taskloop to the task construct
+       sandwiched in between two taskloops.
+       (computable_teams_clause): Test ctx->defaultmap[GDMK_SCALAR]
+       instead of ctx->omp_firstprivatize_variable.
+       (gimplify_omp_workshare): Set ort to ORT_HOST_TEAMS or
+       ORT_COMBINED_HOST_TEAMS if not inside of target construct.  If
+       host teams, use gimplify_and_return_first etc. for body like
+       for target or target data constructs, and at the end call
+       gimple_omp_teams_set_host on the GIMPLE_OMP_TEAMS object.
+       (gimplify_omp_atomic): Use OMP_ATOMIC_MEMORY_ORDER instead
+       of OMP_ATOMIC_SEQ_CST, pass it as new argument to
+       gimple_build_omp_atomic_load and gimple_build_omp_atomic_store, remove
+       gimple_omp_atomic_set_seq_cst calls.
+       (gimplify_expr) <case OMP_TASKGROUP>: Move handling into a separate
+       case, handle taskgroup clauses.
+       * lto-streamer-out.c (hash_tree): Handle
+       OMP_CLAUSE_{TASK,IN}_REDUCTION.
+       * Makefile.in (GTFILES): Add omp-general.h.
+       * omp-builtins.def (BUILT_IN_GOMP_TASKWAIT_DEPEND,
+       BUILT_IN_GOMP_LOOP_NONMONOTONIC_RUNTIME_START,
+       BUILT_IN_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_START,
+       BUILT_IN_GOMP_LOOP_START, BUILT_IN_GOMP_LOOP_ORDERED_START,
+       BUILT_IN_GOMP_LOOP_DOACROSS_START,
+       BUILT_IN_GOMP_LOOP_NONMONOTONIC_RUNTIME_NEXT,
+       BUILT_IN_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_NEXT,
+       BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_START,
+       BUILT_IN_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_START,
+       BUILT_IN_GOMP_LOOP_ULL_START, BUILT_IN_GOMP_LOOP_ULL_ORDERED_START,
+       BUILT_IN_GOMP_LOOP_ULL_DOACROSS_START,
+       BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_NEXT,
+       BUILT_IN_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_NEXT,
+       BUILT_IN_GOMP_PARALLEL_LOOP_NONMONOTONIC_RUNTIME,
+       BUILT_IN_GOMP_PARALLEL_LOOP_MAYBE_NONMONOTONIC_RUNTIME,
+       BUILT_IN_GOMP_PARALLEL_REDUCTIONS, BUILT_IN_GOMP_SECTIONS2_START,
+       BUILT_IN_GOMP_TEAMS_REG, BUILT_IN_GOMP_TASKGROUP_REDUCTION_REGISTER,
+       BUILT_IN_GOMP_TASKGROUP_REDUCTION_UNREGISTER,
+       BUILT_IN_GOMP_TASK_REDUCTION_REMAP,
+       BUILT_IN_GOMP_WORKSHARE_TASK_REDUCTION_UNREGISTER): New builtins.
+       * omp-expand.c (workshare_safe_to_combine_p): Return false for
+       non-worksharing loops.
+       (omp_adjust_chunk_size): Don't adjust anything if chunk_size is zero.
+       (determine_parallel_type): Don't combine parallel with worksharing
+       which has _reductemp_ clause.
+       (expand_parallel_call): Emit the GOMP_*nonmonotonic_runtime* or
+       GOMP_*maybe_nonmonotonic_runtime* builtins instead of GOMP_*runtime*
+       if there is nonmonotonic modifier or if there is no modifier and no
+       ordered clause.  For dynamic and guided schedule without monotonic
+       and nonmonotonic modifier, default to nonmonotonic.
+       (expand_omp_for): Likewise.  Adjust expand_omp_for_generic caller, use
+       GOMP_loop{,_ull}{,_ordered,_doacross}_start builtins if there are
+       task reductions.
+       (expand_task_call): Add GOMP_TASK_FLAG_REDUCTION flag to flags if
+       there are any reduction clauses.
+       (expand_taskwait_call): New function.
+       (expand_teams_call): New function.
+       (expand_omp_taskreg): Allow GIMPLE_OMP_TEAMS and call
+       expand_teams_call for it.  Formatting fix.  Handle taskwait with
+       depend clauses.
+       (expand_omp_for_generic): Add SCHED_ARG argument.  Handle expansion
+       of worksharing loops with task reductions.
+       (expand_omp_for_static_nochunk, expand_omp_for_static_chunk): Handle
+       expansion of worksharing loops with task reductions.
+       (expand_omp_sections): Handle expansion of sections with task
+       reductions.
+       (expand_omp_synch): For host teams call expand_omp_taskreg.
+       (omp_memory_order_to_memmodel): New function.
+       (expand_omp_atomic_load, expand_omp_atomic_store,
+       expand_omp_atomic_fetch_op): Use it and gimple_omp_atomic_memory_order
+       instead of gimple_omp_atomic_seq_cst_p.
+       (build_omp_regions_1, omp_make_gimple_edges): Treat taskwait with
+       depend clauses as a standalone directive.
+       * omp-general.c (enum omp_requires): New variable.
+       (omp_extract_for_data): Initialize have_reductemp member.  Allow
+       NE_EXPR even in OpenMP loops, transform them into LT_EXPR or
+       GT_EXPR loops depending on incr sign.  Formatting fixes.
+       * omp-general.h (struct omp_for_data): Add have_reductemp member.
+       (enum omp_requires): New enum.
+       (omp_requires_mask): Declare.
+       * omp-grid.c (grid_eliminate_combined_simd_part): Formatting fix.
+       Fix comment typos.
+       * omp-low.c (struct omp_context): Add task_reductions and
+       task_reduction_map fields.
+       (is_host_teams_ctx): New function.
+       (is_taskreg_ctx): Return true also if is_host_teams_ctx.
+       (use_pointer_for_field): Use is_global_var instead of
+       TREE_STATIC || DECL_EXTERNAL, and apply only if not privatized
+       in outer contexts.
+       (build_outer_var_ref): Ignore taskgroup outer contexts.
+       (delete_omp_context): Release task_reductions and task_reduction_map.
+       (scan_sharing_clauses): Don't add any fields for reduction clause on
+       taskloop.  Handle OMP_CLAUSE__REDUCTEMP_.  Handle
+       OMP_CLAUSE_{IN,TASK}_REDUCTION and OMP_CLAUSE_REDUCTION with task
+       modifier.  Don't ignore shared clauses in is_host_teams_ctx contexts.
+       Handle OMP_CLAUSE_NONTEMPORAL.
+       (add_taskreg_looptemp_clauses): Add OMP_CLAUSE__REDUCTEMP_ clause if
+       needed.
+       (scan_omp_parallel): Add _reductemp_ clause if there are any reduction
+       clauses with task modifier.
+       (scan_omp_task): Handle taskwait with depend clauses.
+       (finish_taskreg_scan): Move field corresponding to _reductemp_ clause
+       first.  Move also OMP_CLAUSE__REDUCTEMP_ clause in front if present.
+       Handle GIMPLE_OMP_TEAMS like GIMPLE_OMP_PARALLEL.
+       (scan_omp_for): Fix comment formatting.
+       (scan_omp_teams): Handle host teams constructs.
+       (check_omp_nesting_restrictions): Allow teams with no outer
+       OpenMP context.  Adjust diagnostics for teams strictly nested into
+       some explicit OpenMP construct other than target.  Allow OpenMP atomics
+       inside of simd regions.
+       (scan_omp_1_stmt): Call scan_sharing_clauses for taskgroups.
+       (scan_omp_1_stmt) <case GIMPLE_OMP_TEAMS>: Temporarily bump
+       taskreg_nesting_level while scanning host teams construct.
+       (task_reduction_read): New function.
+       (lower_rec_input_clauses): Handle OMP_CLAUSE_REDUCTION on taskloop
+       construct.  Handle OMP_CLAUSE_IN_REDUCTION and OMP_CLAUSE__REDUCTEMP_
+       clauses.  Handle OMP_CLAUSE_REDUCTION with task modifier.  Remove
+       second argument create_tmp_var if it is NULL.  Don't ignore shared
+       clauses in is_host_teams_ctx contexts.  Handle
+       OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE on OMP_CLAUSE_FIRSTPRIVATE
+       clauses.
+       (lower_reduction_clauses): Ignore reduction clauses with task
+       modifier.  Remove second argument create_tmp_var if it is NULL.
+       Initialize OMP_ATOMIC_MEMORY_ORDER to relaxed.
+       (lower_send_clauses): Ignore reduction clauses with task modifier.
+       Handle OMP_CLAUSE__REDUCTEMP_.  Don't send anything for
+       OMP_CLAUSE_REDUCTION on taskloop.  Handle OMP_CLAUSE_IN_REDUCTION.
+       (maybe_add_implicit_barrier_cancel): Add OMP_RETURN argument, don't
+       rely that it is the last stmt in body so far.  Ignore outer taskgroup
+       contexts.
+       (omp_task_reductions_find_first, omp_task_reduction_iterate,
+       lower_omp_task_reductions): New functions.
+       (lower_omp_sections): Handle reduction clauses with taskgroup
+       modifiers.  Adjust maybe_add_implicit_barrier_cancel caller.
+       (lower_omp_single): Adjust maybe_add_implicit_barrier_cancel caller.
+       (lower_omp_for): Likewise.  Handle reduction clauses with taskgroup
+       modifiers.
+       (lower_omp_taskgroup): Handle taskgroup reductions.
+       (create_task_copyfn): Copy over OMP_CLAUSE__REDUCTEMP_ pointer.
+       Handle OMP_CLAUSE_IN_REDUCTION and OMP_CLAUSE_REDUCTION clauses.
+       (lower_depend_clauses): If there are any
+       OMP_CLAUSE_DEPEND_DEPOBJ or OMP_CLAUSE_DEPEND_MUTEXINOUTSET
+       depend clauses, use a new array format.  If OMP_CLAUSE_DEPEND_LAST is
+       seen, assume lowering is done already and return early.  Set kind
+       on artificial depend clause to OMP_CLAUSE_DEPEND_LAST.
+       (lower_omp_taskreg): Handle reduction clauses with task modifier on
+       parallel construct.  Handle reduction clause on taskloop construct.
+       Handle taskwait with depend clauses.
+       (lower_omp_1): Use lower_omp_taskreg instead of lower_omp_teams
+       for host teams constructs.
+       * tree.c (omp_clause_num_ops): Add in_reduction, task_reduction,
+       nontemporal and _reductemp_ clause entries.
+       (omp_clause_code_name): Likewise.
+       (walk_tree_1): Handle OMP_CLAUSE_{IN,TASK}_REDUCTION,
+       OMP_CLAUSE_NONTEMPORAL and OMP_CLAUSE__REDUCTEMP_.
+       * tree-core.h (enum omp_clause_code): Add
+       OMP_CLAUSE_{{IN,TASK}_REDUCTION,NONTEMPORAL,_REDUCTEMP_}.
+       (enum omp_clause_defaultmap_kind, enum omp_memory_order): New.
+       (struct tree_base): Add omp_atomic_memory_order field into union.
+       Remove OMP_ATOMIC_SEQ_CST comment.
+       (enum omp_clause_depend_kind): Add OMP_CLAUSE_DEPEND_MUTEXINOUTSET
+       and OMP_CLAUSE_DEPEND_DEPOBJ.
+       (struct tree_omp_clause): Add subcode.defaultmap_kind.
+       * tree.def (OMP_TASKGROUP): Add another operand, move next to other
+       OpenMP constructs with body and clauses operands.
+       * tree.h (OMP_BODY): Use OMP_MASTER instead of OMP_TASKGROUP.
+       (OMP_CLAUSES): Use OMP_TASKGROUP instead of OMP_SINGLE.
+       (OMP_TASKGROUP_CLAUSES): Define.
+       (OMP_CLAUSE_DECL): Use OMP_CLAUSE__REDUCTEMP_ instead of
+       OMP_CLAUSE__LOOPTEMP_.
+       (OMP_ATOMIC_SEQ_CST): Remove.
+       (OMP_ATOMIC_MEMORY_ORDER, OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE,
+       OMP_CLAUSE_LASTPRIVATE_CONDITIONAL): Define.
+       (OMP_CLAUSE_REDUCTION_CODE, OMP_CLAUSE_REDUCTION_INIT,
+       OMP_CLAUSE_REDUCTION_MERGE, OMP_CLAUSE_REDUCTION_PLACEHOLDER,
+       OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER,
+       OMP_CLAUSE_REDUCTION_OMP_ORIG_REF): Handle
+       OMP_CLAUSE_{,IN_,TASK_}REDUCTION.
+       (OMP_CLAUSE_REDUCTION_TASK, OMP_CLAUSE_REDUCTION_INSCAN,
+       OMP_CLAUSE_DEFAULTMAP_KIND, OMP_CLAUSE_DEFAULTMAP_CATEGORY,
+       OMP_CLAUSE_DEFAULTMAP_BEHAVIOR, OMP_CLAUSE_DEFAULTMAP_SET_KIND):
+       Define.
+       * tree-inline.c (remap_gimple_stmt): Remap taskgroup clauses.
+       * tree-nested.c (convert_nonlocal_omp_clauses): Handle
+       OMP_CLAUSE__REDUCTEMP_, OMP_CLAUSE_NONTEMPORAL.
+       (convert_local_omp_clauses): Likewise.  Remove useless test.
+       * tree-parloops.c (create_call_for_reduction_1): Pass
+       OMP_MEMORY_ORDER_RELAXED as new argument to
+       dump_gimple_omp_atomic_load and dump_gimple_omp_atomic_store.
+       * tree-pretty-print.c (dump_omp_iterators): New function.
+       (dump_omp_clause): Handle OMP_CLAUSE__REDUCTEMP_,
+       OMP_CLAUSE_NONTEMPORAL, OMP_CLAUSE_{TASK,IN}_REDUCTION.  Print
+       reduction modifiers.  Handle OMP_CLAUSE_DEPEND_DEPOBJ and
+       OMP_CLAUSE_DEPEND_MUTEXINOUTSET.  Print iterators in depend clauses.
+       Print __internal__ for OMP_CLAUSE_DEPEND_LAST.  Handle cancel and
+       simd OMP_CLAUSE_IF_MODIFIERs.  Handle new kinds of
+       OMP_CLAUSE_DEFAULTMAP. Print conditional: for
+       OMP_CLAUSE_LASTPRIVATE_CONDITIONAL.
+       (dump_omp_atomic_memory_order): New function.
+       (dump_generic_node): Use it.  Print taskgroup clauses.  Print
+       taskwait with depend clauses.
+       * tree-pretty-print.h (dump_omp_atomic_memory_order): Declare.
+       * tree-streamer-in.c (unpack_ts_omp_clause_value_fields):
+       Handle OMP_CLAUSE_{TASK,IN}_REDUCTION.
+       * tree-streamer-out.c (pack_ts_omp_clause_value_fields,
+       write_ts_omp_clause_tree_pointers): Likewise.
+
 2018-11-08  David Malcolm  <dmalcolm@redhat.com>
 
        PR ipa/86395
index 6130554a0d30c5807ced951e33b9ee0b77f54a6e..16c9ed6c5fd741698e10c582de4d8c72a889036d 100644 (file)
@@ -2579,6 +2579,7 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h $(srcdir)/coretypes.h \
   $(srcdir)/internal-fn.h \
   $(srcdir)/hsa-common.c \
   $(srcdir)/calls.c \
+  $(srcdir)/omp-general.h \
   @all_gtfiles@
 
 # Compute the list of GT header files from the corresponding C sources,
index f13da6a188c9c3d4797bb8623b58a830cc928423..685b22f975a1c39a7580c7683107692b92714121 100644 (file)
@@ -251,6 +251,7 @@ DEF_FUNCTION_TYPE_1 (BT_FN_INT_CONST_STRING, BT_INT, BT_CONST_STRING)
 DEF_FUNCTION_TYPE_1 (BT_FN_PTR_PTR, BT_PTR, BT_PTR)
 DEF_FUNCTION_TYPE_1 (BT_FN_VOID_VALIST_REF, BT_VOID, BT_VALIST_REF)
 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_FLOAT_CONST_STRING, BT_FLOAT, BT_CONST_STRING)
 DEF_FUNCTION_TYPE_1 (BT_FN_DOUBLE_CONST_STRING, BT_DOUBLE, BT_CONST_STRING)
 DEF_FUNCTION_TYPE_1 (BT_FN_LONGDOUBLE_CONST_STRING,
@@ -621,6 +622,9 @@ DEF_FUNCTION_TYPE_3 (BT_FN_VOID_UINT32_UINT64_PTR,
                     BT_VOID, BT_UINT32, BT_UINT64, BT_PTR)
 DEF_FUNCTION_TYPE_3 (BT_FN_VOID_UINT32_UINT32_PTR,
                     BT_VOID, BT_UINT32, BT_UINT32, BT_PTR)
+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_SIZE_CONST_PTR_SIZE_SIZE_FILEPTR,
                     BT_SIZE, BT_CONST_PTR, BT_SIZE, BT_SIZE, BT_FILEPTR)
@@ -644,6 +648,8 @@ DEF_FUNCTION_TYPE_4 (BT_FN_INT_FILEPTR_INT_CONST_STRING_VALIST_ARG,
                     BT_INT, BT_FILEPTR, BT_INT, BT_CONST_STRING, BT_VALIST_ARG)
 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,
@@ -729,6 +735,12 @@ DEF_FUNCTION_TYPE_7 (BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_UINT_PTR,
 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,
@@ -737,6 +749,14 @@ DEF_FUNCTION_TYPE_9 (BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_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)
+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,
index ac2353978b111a6d719fbb67c5e289fc94f6880a..f1b9b27f8c003e1a70255893d671b46c4c2a224a 100644 (file)
@@ -1,3 +1,41 @@
+2018-11-08  Jakub Jelinek  <jakub@redhat.com>
+
+       * 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.
+
 2018-11-08  David Malcolm  <dmalcolm@redhat.com>
 
        * c-format.c (gcc_dump_printf_char_table): Add entry for %f.
index 641fe57d671d45fb2e8fdbd2737a13845810713a..a2184325a10f652896dad58ddff13cbb994aa665 100644 (file)
@@ -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);
index 89849379ca7691e91d9ac1ac8cfa2a4672bbea76..c7d44560da5081b6fc819f15fb724218bd3b6398 100644 (file)
@@ -28,8 +28,10 @@ along with GCC; see the file COPYING3.  If not see
 #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 parms, tree clauses)
 }
 
 /* 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, tree stmt)
   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, enum tree_code code,
     {
       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, enum tree_code code,
     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, enum tree_code code,
 }
 
 
+/* 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, tree exp, tree decl)
       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 (location_t loc, tree decl, tree incr)
 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 tree_code code, tree declv,
                {
                  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 tree_code code, tree declv,
                                            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 tree_code code, tree declv,
                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 tree_code code, tree declv,
                      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 *walk_subtrees, void *data)
       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, tree *not_loop_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, enum tree_code code,
       {
       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, enum tree_code code,
        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, enum tree_code code,
          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, enum tree_code code,
            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, enum tree_code code,
                  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, enum tree_code code,
          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, enum tree_code code,
              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, enum tree_code code,
                                    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, enum tree_code code,
                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, enum tree_code code,
              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, enum tree_code code,
          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, enum tree_code code,
            }
          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, enum tree_code code,
                    = 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, enum tree_code code,
              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 (tree fndecl, tree clauses)
 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.  */
index 84e4341ee5f0594515ff564d39a9073ed9f42466..fe21120df2f456e4ea8ff78e924c28355335ba8e 100644 (file)
@@ -1286,9 +1286,11 @@ static const struct omp_pragma_def omp_pragmas[] = {
   { "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 },
index b322547b11a752df47b0496ea329f0415cd0490d..b781f739f7f5d5c81a889fc0a88ff6d8ee25a15a 100644 (file)
@@ -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,
index 708ef5d7da2a361398e04b1f31088d79ad82b7fb..04f667ba15709d401867ebaaba5d0936356a42bd 100644 (file)
@@ -1,3 +1,90 @@
+2018-11-08  Jakub Jelinek  <jakub@redhat.com>
+
+       * 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.
+
 2018-10-29  David Malcolm  <dmalcolm@redhat.com>
 
        * c-decl.c (implicit_decl_warning): Update "is there a suggestion"
index b36fca9a330acdfc7bb1d9ab5f32c7974c5383bf..624d5a34c63bb8931bc1707cefaec6f127637eb7 100644 (file)
@@ -68,6 +68,7 @@ along with GCC; see the file COPYING3.  If not see
 #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_parser *);
 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_point (c_parser *, enum pragma_context);
 static bool c_parser_omp_target (c_parser *, enum pragma_context, bool *);
 static void c_parser_omp_end_declare_target (c_parser *);
 static void c_parser_omp_declare (c_parser *, enum pragma_context);
+static 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 pragma_context context, bool *if_p)
       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 pragma_context context, bool *if_p)
       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 *parser)
        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 *parser)
        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 *parser)
            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 *parser,
                            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 *parser,
              /* 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 *parser,
                          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 *parser,
 
                  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 *parser,
       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 *parser, tree list)
 
    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, tree list, bool is_omp)
     {
       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, tree list, bool is_omp)
            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, tree list, bool is_omp)
 }
 
 /* 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 *parser, tree list)
 
       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 *parser, tree list)
 }
 
 /* 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 *parser, tree list)
   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 *parser, tree list)
 
    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 *parser, tree list)
        {
          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 *parser, tree list)
              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 *parser, tree list)
   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_parser *parser, location_t clause_loc,
   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_parser *parser, location_t clause_loc,
    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 *parser, tree list)
       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 *parser, tree list)
   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 *parser, omp_clause_mask mask,
          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 *parser, omp_clause_mask mask,
          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 *parser, omp_clause_mask mask,
          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 *parser, omp_clause_mask mask,
          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 *parser, omp_clause_mask mask,
                                                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,61 +15751,156 @@ c_parser_omp_atomic (location_t loc, c_parser *parser)
   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"))
            {
-             seq_cst = true;
              c_parser_consume_token (parser);
+             clauses = c_parser_omp_clause_hint (parser, clauses);
+             continue;
+           }
+         else
+           {
+             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 ();
        }
     }
-  c_parser_skip_to_pragma_eol (parser);
+  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)
     {
@@ -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_parser *parser, bool *if_p)
       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_parser *parser, bool *if_p)
   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_parser *parser, enum tree_code code,
            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_parser *parser, enum tree_code code,
   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 tree_code code,
        | (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_parser *parser,
   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_parser *parser,
 */
 
 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_parser *parser,
       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_parser *parser,
          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_parser *parser, bool *if_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_parser *parser, bool *if_p)
 
 /* 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_parser *parser,
          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_parser *parser,
          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_parser *parser,
   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, c_parser *parser, bool *if_p)
            *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, c_parser *parser, bool *if_p)
       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, enum pragma_context context, bool *if_p)
       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, enum pragma_context context, bool *if_p)
          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, enum pragma_context context)
   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, enum pragma_context context)
        | (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_parser *parser,
 
   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_parser *parser,
          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_parser *parser,
          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_parser *parser,
       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, bool *if_p)
       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, bool *if_p)
       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");
index 9d09b8d65fd1d07d5bbeb8fa3fa5ec33b29b251f..144977e2f1b07253b9b3508ac5cc27238d32957a 100644 (file)
@@ -12525,6 +12525,11 @@ c_finish_omp_cancel (location_t loc, 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),
@@ -12717,7 +12722,9 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
       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, tree t, vec<tree> &types,
              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, tree t, vec<tree> &types,
          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, tree t, vec<tree> &types,
       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 c_omp_region_type ort)
   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 c_omp_region_type ort)
     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 c_omp_region_type ort)
       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 c_omp_region_type ort)
 
              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 c_omp_region_type ort)
                  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 c_omp_region_type ort)
        }
       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 *, void *data)
   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 c_omp_region_type ort)
   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 c_omp_region_type ort)
          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 c_omp_region_type ort)
                  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 c_omp_region_type ort)
              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 c_omp_region_type ort)
          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 c_omp_region_type ort)
            {
              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 c_omp_region_type ort)
                   && 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 c_omp_region_type ort)
          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 c_omp_region_type ort)
            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 c_omp_region_type ort)
                }
              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 c_omp_region_type ort)
                      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 c_omp_region_type ort)
              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 c_omp_region_type ort)
          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 c_omp_region_type ort)
        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 c_omp_region_type ort)
          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 c_omp_region_type ort)
                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 c_omp_region_type ort)
                            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 c_omp_region_type ort)
          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;
 }
index 79cc67326c4b267c157f574d832d4b84ba50ea29..1497dab500f0e67e5335f33646440462cc1de108 100644 (file)
@@ -1,3 +1,167 @@
+2018-11-08  Jakub Jelinek  <jakub@redhat.com>
+
+       * 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.
+
 2018-11-07  Nathan Sidwell  <nathan@acm.org>
 
        PR c++/87904
index 4fb1ba527e3207149e1703f1477d4060bf4bcc51..7b696da5834bb3dfddb0f94791371d380b75cf1d 100644 (file)
@@ -5917,6 +5917,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
     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:
index 90a8f9fef8f2398af46e7572c93480a97515e819..eb761b118a17632af0ff322f9a93926f2ee95a99 100644 (file)
@@ -1178,6 +1178,8 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data)
            *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 decl)
        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;
 }
index eef7ed60519db777dd69571f64ad4e30d50cfec3..584f4284b61f22d5ab305eb5be2f3002a1258e17 100644 (file)
@@ -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"
index c64225ded6f09de96d86694d4708a542c9372774..43d90eb1efb603301dab650b42a5836ad1ef1319 100644 (file)
@@ -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. */
index 91f5755a18700730bc0bdf6152d722b7a2fea212..6ca138d4ce65f72ec4b705bca8de74bae276b947 100644 (file)
@@ -4874,9 +4874,10 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter)
   (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_init_expr_arg_iterator *iter)
 #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, tree);
 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);
index c138c508c66e436e3e22183f575461cee45e11e3..b79ff5137aa19164cbe265a37ea594431c002bf4 100644 (file)
@@ -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;
index d9b868bfaef099a3760b37cfdef748b1a99b9cf3..16538864cbd7bf646c71536b70729cd39d089981 100644 (file)
@@ -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;
     }
index 26ec52f3498f82d7d10b7f7e0b03323774d8b58d..49bcf5157bbb887c26086d1022c2242100047002 100644 (file)
@@ -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));
index 30a47662f5561b6aa3231e85bcd4466d09c4ccdc..deaca5cc97496b4540ccfd60e8a26b1af066b69b 100644 (file)
@@ -44,6 +44,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gcc-rich-location.h"
 #include "tree-iterator.h"
 #include "cp-name-hint.h"
+#include "memmodel.h"
 
 \f
 /* 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 ivdep, unsigned short unroll)
   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 scope, tree init, bool ivdep,
 
 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, tree scope, tree init, tree range_decl,
       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 (cp_parser *parser)
 }
 
 \f
-/* 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 *parser)
        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 *parser)
        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 *parser)
            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_parser *parser, enum omp_clause_code kind,
     {
       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_parser *parser, enum omp_clause_code kind,
                                          /*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_parser *parser, enum omp_clause_code kind,
              /* 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_parser *parser, enum omp_clause_code kind,
                    {
                      /* 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_parser *parser, enum omp_clause_code kind,
                  /* 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_parser *parser, enum omp_clause_code kind,
              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 *parser, tree list, location_t location)
 
    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 *parser, tree list, location_t location,
       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 *parser, tree list, location_t location,
            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 *parser, tree list,
 }
 
 /* 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_parser *parser, tree list,
 {
   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))
+  if (cp_lexer_next_token_is_keyword (parser->lexer, RID_DEFAULT))
+    p = "default";
+  else if (!cp_lexer_next_token_is (parser->lexer, CPP_NAME))
     {
-      cp_parser_error (parser, "expected %<tofrom%>");
+    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 *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_parser *parser, tree list)
   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 *parser, tree list)
   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_parser *parser, location_t clause_loc,
   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_parser *parser, location_t clause_loc,
    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 *parser, tree list, location_t loc)
       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 *parser, omp_clause_mask mask,
          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 *parser, omp_clause_mask mask,
                                             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 *parser, omp_clause_mask mask,
          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 *parser, omp_clause_mask mask,
                                            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 *parser, omp_clause_mask mask,
                                                 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, cp_token *pragma_tok)
 {
   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"))
            {
-             seq_cst = true;
              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)
+           {
+             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 *parser, cp_token *pragma_tok, bool *if_p)
       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 *parser, cp_token *pragma_tok, bool *if_p)
   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 *parser, tree decl)
     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 *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 *parser, enum tree_code code, tree clauses,
                        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 *parser, enum tree_code code, tree clauses,
   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 *parser, enum tree_code code, tree clauses,
       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 *parser, enum tree_code code, tree clauses,
                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 *parser, enum tree_code code, tree clauses,
 
       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 *parser, enum tree_code code, tree clauses,
            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 *parser, enum tree_code code, tree clauses,
          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 *parser, enum tree_code code, tree clauses,
 
   /* 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, enum tree_code code,
        | (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, cp_token *pragma_tok,
        }
     }
 
+  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_token *pragma_tok,
       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 *parser, cp_token *pragma_tok,
       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 *parser, cp_token *pragma_tok,
          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, cp_token *pragma_tok, bool *if_p)
 {
   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, cp_token *pragma_tok, bool *if_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
 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, cp_token *pragma_tok, bool *if_p)
 }
 
 /* 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 *parser, cp_token *pragma_tok)
 
 /* 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 *parser, cp_token *pragma_tok,
       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, cp_token *pragma_tok,
          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, cp_token *pragma_tok,
   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 *parser, cp_token *pragma_tok, bool *if_p)
            *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 *parser, cp_token *pragma_tok, bool *if_p)
       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, cp_token *pragma_tok,
 {
   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, cp_token *pragma_tok,
   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, cp_token *pragma_tok,
        | (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 *parser, cp_token *pragma_tok,
 
   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 *parser, cp_token *pragma_tok,
       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 *parser, cp_token *pragma_tok,
                                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 *parser, cp_token *pragma_tok, bool *if_p)
                                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, enum pragma_context context, bool *if_p)
        }
       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, enum pragma_context context, bool *if_p)
       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;
index 80b4eec8fdbd7dee83e3fbddbfebd1a11c63d317..fe330cd29d5b3fe34b3064a8f5b6534ef1d63793 100644 (file)
@@ -16097,11 +16097,49 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 
 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 args, tsubst_flags_t complain,
       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_omp_region_type ort,
 {
   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_omp_region_type ort,
        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_omp_region_type ort,
                           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_region_type ort,
            }
          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_omp_region_type ort,
        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_omp_region_type ort,
          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_omp_region_type ort,
          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 args, tsubst_flags_t complain,
 
 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, tree declv, tree orig_declv,
 #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, tree declv, tree orig_declv,
     }
   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, tree declv, tree orig_declv,
          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, tree declv, tree orig_declv,
       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_flags_t complain, tree in_decl,
       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_flags_t complain, tree in_decl,
        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_flags_t complain, tree in_decl,
            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_flags_t complain, tree in_decl,
 
        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_flags_t complain, tree in_decl,
            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_flags_t complain, tree in_decl,
     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_flags_t complain, tree in_decl,
       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_flags_t complain, tree in_decl,
 
     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_flags_t complain, tree in_decl,
 
     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_flags_t complain, tree in_decl,
            }
          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_flags_t complain, tree in_decl,
              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 initv, tree condv, tree incrv)
       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 initv, tree condv, tree incrv)
              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;
+               }
            }
        }
     }
index b54ecb068be17792192ca4741f17c2fb3fe714ec..182d360a5622f7455e96a3a851c87d71345c429a 100644 (file)
@@ -44,6 +44,7 @@ along with GCC; see the file COPYING3.  If not see
 #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, tree t, vec<tree> &types,
     }
 
   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, tree t, vec<tree> &types,
       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, tree t, vec<tree> &types,
              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, tree t, vec<tree> &types,
          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, tree t, vec<tree> &types,
       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 c_omp_region_type ort)
   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 c_omp_region_type ort)
     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 c_omp_region_type ort)
        }
       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 c_omp_region_type ort)
 
              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 c_omp_region_type ort)
                  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 c_omp_region_type ort)
        {
          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, bool *need_default_ctor, bool *need_dtor)
                                  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, bool *need_default_ctor, bool *need_dtor)
       }
   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, bool *need_default_ctor, bool *need_dtor)
              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, bool *need_default_ctor, bool *need_dtor)
            {
              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, bool *need_default_ctor, bool *need_dtor)
     *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 sink_clause)
   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_omp_region_type ort)
   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_omp_region_type ort)
          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_region_type ort)
                   || 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_omp_region_type ort)
                  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_omp_region_type ort)
                       || !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_region_type ort)
                  || (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_omp_region_type ort)
              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_omp_region_type ort)
            {
              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_omp_region_type ort)
                   || 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_omp_region_type ort)
            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_omp_region_type ort)
              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_omp_region_type ort)
            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_omp_region_type ort)
              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_omp_region_type ort)
              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_omp_region_type ort)
          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_omp_region_type ort)
          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_omp_region_type ort)
          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_omp_region_type ort)
                  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_omp_region_type ort)
          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_omp_region_type ort)
          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_omp_region_type ort)
          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_omp_region_type ort)
          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_omp_region_type ort)
          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_omp_region_type ort)
              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_omp_region_type ort)
            }
          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_omp_region_type ort)
          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_omp_region_type ort)
                  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_omp_region_type ort)
                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_omp_region_type ort)
                      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_region_type ort)
                      || 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_omp_region_type ort)
                   && !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_omp_region_type ort)
              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_omp_region_type ort)
          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_omp_region_type ort)
              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_omp_region_type ort)
          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_omp_region_type ort)
          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_omp_region_type ort)
          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_omp_region_type ort)
                {
                  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_omp_region_type ort)
        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_omp_region_type ort)
          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_omp_region_type ort)
            }
          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_omp_region_type ort)
          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_omp_region_type ort)
        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_omp_region_type ort)
            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_omp_region_type ort)
            }
          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_omp_region_type ort)
       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, location_t locus, enum tree_code code,
     }
 
   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, location_t locus, enum tree_code code,
        = 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 tree_code code, tree declv,
       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 tree_code code, tree declv,
       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 tree_code code, tree declv,
       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 tree_code code, tree declv,
   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, enum tree_code opcode, tree lhs,
                     || (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, enum tree_code opcode, tree lhs,
                   "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, enum tree_code opcode, tree lhs,
     {
       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, enum tree_code opcode, tree lhs,
                                     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),
index 689c754e4ebfe93b4bc7a4cd6294e562cceab5bc..f5bcec3d69fa9e84ba1b4cf39b9d04bd2d796a46 100644 (file)
@@ -1,3 +1,19 @@
+2018-11-08  Jakub Jelinek  <jakub@redhat.com>
+
+       * 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.
+
 2018-11-02  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/46020
index f038f4c5bf8f632bb11e69b2bbc7b6ea8670b6f5..483ca663663c11dd239986d21d1be8ee426b4dc9 100644 (file)
@@ -2866,6 +2866,8 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses,
   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
index 78f3e20417ccbe3e7e385c534b600e42d384ef8e..0eabc3f4d993e39f5e9356e7603a2abb161b34be 100644 (file)
@@ -86,6 +86,7 @@ DEF_FUNCTION_TYPE_1 (BT_FN_INT_INT, BT_INT, BT_INT)
 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_INT, BT_VOID, BT_VOLATILE_PTR, BT_I2, BT
 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_PTR_PTR_PTR_UINT_PTR,
 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,
index 4339456e9c67ec053afac4209bf5ed032f7d5993..40406dfa88f53b5f236f9ce86bcb7d2fb6ddc805 100644 (file)
@@ -1724,7 +1724,8 @@ open_base_files (void)
       "tree-dfa.h", "tree-ssa.h", "reload.h", "cpplib.h", "tree-chrec.h",
       "except.h", "output.h",  "cfgloop.h", "target.h", "lto-streamer.h",
       "target-globals.h", "ipa-ref.h", "cgraph.h", "symbol-summary.h",
-      "ipa-prop.h", "ipa-fnsummary.h", "dwarf2out.h", "omp-offload.h", NULL
+      "ipa-prop.h", "ipa-fnsummary.h", "dwarf2out.h", "omp-general.h",
+      "omp-offload.h", NULL
     };
     const char *const *ifp;
     outf_p gtype_desc_c;
index 7dfec9120ab8ea020e49ed7bdcccc2eaa3b838b6..276e5798baced46fe2a112732abd4d6da139e092 100644 (file)
@@ -1554,6 +1554,35 @@ dump_gimple_omp_single (pretty_printer *buffer, gomp_single *gs,
     }
 }
 
+/* Dump a GIMPLE_OMP_TASKGROUP tuple on the pretty_printer BUFFER.  */
+
+static void
+dump_gimple_omp_taskgroup (pretty_printer *buffer, gimple *gs,
+                          int spc, dump_flags_t flags)
+{
+  if (flags & TDF_RAW)
+    {
+      dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
+                      gimple_omp_body (gs));
+      dump_omp_clauses (buffer, gimple_omp_taskgroup_clauses (gs), spc, flags);
+      dump_gimple_fmt (buffer, spc, flags, " >");
+    }
+  else
+    {
+      pp_string (buffer, "#pragma omp taskgroup");
+      dump_omp_clauses (buffer, gimple_omp_taskgroup_clauses (gs), spc, flags);
+      if (!gimple_seq_empty_p (gimple_omp_body (gs)))
+       {
+         newline_and_indent (buffer, spc + 2);
+         pp_left_brace (buffer);
+         pp_newline (buffer);
+         dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
+         newline_and_indent (buffer, spc + 2);
+         pp_right_brace (buffer);
+       }
+    }
+}
+
 /* Dump a GIMPLE_OMP_TARGET tuple on the pretty_printer BUFFER.  */
 
 static void
@@ -1712,7 +1741,7 @@ dump_gimple_omp_sections (pretty_printer *buffer, gomp_sections *gs,
     }
 }
 
-/* Dump a GIMPLE_OMP_{MASTER,TASKGROUP,ORDERED,SECTION} tuple on the
+/* Dump a GIMPLE_OMP_{MASTER,ORDERED,SECTION} tuple on the
    pretty_printer BUFFER.  */
 
 static void
@@ -2301,6 +2330,8 @@ dump_gimple_omp_task (pretty_printer *buffer, gomp_task *gs, int spc,
       gimple_seq body;
       if (gimple_omp_task_taskloop_p (gs))
        pp_string (buffer, "#pragma omp taskloop");
+      else if (gimple_omp_task_taskwait_p (gs))
+       pp_string (buffer, "#pragma omp taskwait");
       else
        pp_string (buffer, "#pragma omp task");
       dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
@@ -2353,8 +2384,8 @@ dump_gimple_omp_atomic_load (pretty_printer *buffer, gomp_atomic_load *gs,
   else
     {
       pp_string (buffer, "#pragma omp atomic_load");
-      if (gimple_omp_atomic_seq_cst_p (gs))
-       pp_string (buffer, " seq_cst");
+      dump_omp_atomic_memory_order (buffer,
+                                   gimple_omp_atomic_memory_order (gs));
       if (gimple_omp_atomic_need_value_p (gs))
        pp_string (buffer, " [needed]");
       newline_and_indent (buffer, spc + 2);
@@ -2385,9 +2416,10 @@ dump_gimple_omp_atomic_store (pretty_printer *buffer,
     }
   else
     {
-      pp_string (buffer, "#pragma omp atomic_store ");
-      if (gimple_omp_atomic_seq_cst_p (gs))
-       pp_string (buffer, "seq_cst ");
+      pp_string (buffer, "#pragma omp atomic_store");
+      dump_omp_atomic_memory_order (buffer,
+                                   gimple_omp_atomic_memory_order (gs));
+      pp_space (buffer);
       if (gimple_omp_atomic_need_value_p (gs))
        pp_string (buffer, "[needed] ");
       pp_left_paren (buffer);
@@ -2569,8 +2601,11 @@ pp_gimple_stmt_1 (pretty_printer *buffer, gimple *gs, int spc,
       pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
       break;
 
-    case GIMPLE_OMP_MASTER:
     case GIMPLE_OMP_TASKGROUP:
+      dump_gimple_omp_taskgroup (buffer, gs, spc, flags);
+      break;
+
+    case GIMPLE_OMP_MASTER:
     case GIMPLE_OMP_SECTION:
     case GIMPLE_OMP_GRID_BODY:
       dump_gimple_omp_block (buffer, gs, spc, flags);
index 579b750d913c8b9026f3aafd9296e640a32bf12a..41d9f677c4f755182dd5fcbf5ac842db2a531d11 100644 (file)
@@ -924,7 +924,7 @@ gimple_build_omp_critical (gimple_seq body, tree name, tree clauses)
 
    BODY is sequence of statements inside the for loop.
    KIND is the `for' variant.
-   CLAUSES, are any of the construct's clauses.
+   CLAUSES are any of the construct's clauses.
    COLLAPSE is the collapse count.
    PRE_BODY is the sequence of statements that are loop invariant.  */
 
@@ -950,7 +950,7 @@ gimple_build_omp_for (gimple_seq body, int kind, tree clauses, size_t collapse,
 /* Build a GIMPLE_OMP_PARALLEL statement.
 
    BODY is sequence of statements which are executed in parallel.
-   CLAUSES, are the OMP parallel construct's clauses.
+   CLAUSES are the OMP parallel construct's clauses.
    CHILD_FN is the function created for the parallel threads to execute.
    DATA_ARG are the shared data argument(s).  */
 
@@ -973,7 +973,7 @@ gimple_build_omp_parallel (gimple_seq body, tree clauses, tree child_fn,
 /* Build a GIMPLE_OMP_TASK statement.
 
    BODY is sequence of statements which are executed by the explicit task.
-   CLAUSES, are the OMP parallel construct's clauses.
+   CLAUSES are the OMP task construct's clauses.
    CHILD_FN is the function created for the parallel threads to execute.
    DATA_ARG are the shared data argument(s).
    COPY_FN is the optional function for firstprivate initialization.
@@ -1044,12 +1044,14 @@ gimple_build_omp_grid_body (gimple_seq body)
 /* Build a GIMPLE_OMP_TASKGROUP statement.
 
    BODY is the sequence of statements to be executed by the taskgroup
-   construct.  */
+   construct.
+   CLAUSES are any of the construct's clauses.  */
 
 gimple *
-gimple_build_omp_taskgroup (gimple_seq body)
+gimple_build_omp_taskgroup (gimple_seq body, tree clauses)
 {
   gimple *p = gimple_alloc (GIMPLE_OMP_TASKGROUP, 0);
+  gimple_omp_taskgroup_set_clauses (p, clauses);
   if (body)
     gimple_omp_set_body (p, body);
 
@@ -1192,12 +1194,13 @@ gimple_build_omp_teams (gimple_seq body, tree clauses)
 /* Build a GIMPLE_OMP_ATOMIC_LOAD statement.  */
 
 gomp_atomic_load *
-gimple_build_omp_atomic_load (tree lhs, tree rhs)
+gimple_build_omp_atomic_load (tree lhs, tree rhs, enum omp_memory_order mo)
 {
   gomp_atomic_load *p
     = as_a <gomp_atomic_load *> (gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD, 0));
   gimple_omp_atomic_load_set_lhs (p, lhs);
   gimple_omp_atomic_load_set_rhs (p, rhs);
+  gimple_omp_atomic_set_memory_order (p, mo);
   return p;
 }
 
@@ -1206,11 +1209,12 @@ gimple_build_omp_atomic_load (tree lhs, tree rhs)
    VAL is the value we are storing.  */
 
 gomp_atomic_store *
-gimple_build_omp_atomic_store (tree val)
+gimple_build_omp_atomic_store (tree val, enum omp_memory_order mo)
 {
   gomp_atomic_store *p
     = as_a <gomp_atomic_store *> (gimple_alloc (GIMPLE_OMP_ATOMIC_STORE, 0));
   gimple_omp_atomic_store_set_val (p, val);
+  gimple_omp_atomic_set_memory_order (p, mo);
   return p;
 }
 
@@ -1935,6 +1939,11 @@ gimple_copy (gimple *stmt)
          gimple_omp_ordered_set_clauses (as_a <gomp_ordered *> (copy), t);
          goto copy_omp_body;
 
+       case GIMPLE_OMP_TASKGROUP:
+         t = unshare_expr (gimple_omp_taskgroup_clauses (stmt));
+         gimple_omp_taskgroup_set_clauses (copy, t);
+         goto copy_omp_body;
+
        case GIMPLE_OMP_SECTIONS:
          t = unshare_expr (gimple_omp_sections_clauses (stmt));
          gimple_omp_sections_set_clauses (copy, t);
@@ -1971,7 +1980,6 @@ gimple_copy (gimple *stmt)
 
        case GIMPLE_OMP_SECTION:
        case GIMPLE_OMP_MASTER:
-       case GIMPLE_OMP_TASKGROUP:
        case GIMPLE_OMP_GRID_BODY:
        copy_omp_body:
          new_seq = gimple_seq_copy (gimple_omp_body (stmt));
index 513204ea49c42d8b83b49d875003dcd03d6c9c65..38206e9cd6402457ca48d7c516842cb05d1a98be 100644 (file)
@@ -279,9 +279,10 @@ DEFGSCODE(GIMPLE_OMP_FOR, "gimple_omp_for", GSS_OMP_FOR)
    BODY is the sequence of statements to execute in the master section.  */
 DEFGSCODE(GIMPLE_OMP_MASTER, "gimple_omp_master", GSS_OMP)
 
-/* GIMPLE_OMP_TASKGROUP <BODY> represents #pragma omp taskgroup.
-   BODY is the sequence of statements to execute in the taskgroup section.  */
-DEFGSCODE(GIMPLE_OMP_TASKGROUP, "gimple_omp_taskgroup", GSS_OMP)
+/* GIMPLE_OMP_TASKGROUP <BODY, CLAUSES> represents #pragma omp taskgroup.
+   BODY is the sequence of statements inside the taskgroup section.
+   CLAUSES is an OMP_CLAUSE chain holding the associated clauses.  */
+DEFGSCODE(GIMPLE_OMP_TASKGROUP, "gimple_omp_taskgroup", GSS_OMP_SINGLE_LAYOUT)
 
 /* GIMPLE_OMP_PARALLEL <BODY, CLAUSES, CHILD_FN, DATA_ARG> represents
 
@@ -366,10 +367,12 @@ DEFGSCODE(GIMPLE_OMP_SINGLE, "gimple_omp_single", GSS_OMP_SINGLE_LAYOUT)
    implement the MAP clauses.  */
 DEFGSCODE(GIMPLE_OMP_TARGET, "gimple_omp_target", GSS_OMP_PARALLEL_LAYOUT)
 
-/* GIMPLE_OMP_TEAMS <BODY, CLAUSES> represents #pragma omp teams
+/* GIMPLE_OMP_TEAMS <BODY, CLAUSES, CHILD_FN, DATA_ARG> represents
+   #pragma omp teams
    BODY is the sequence of statements inside the single section.
-   CLAUSES is an OMP_CLAUSE chain holding the associated clauses.  */
-DEFGSCODE(GIMPLE_OMP_TEAMS, "gimple_omp_teams", GSS_OMP_SINGLE_LAYOUT)
+   CLAUSES is an OMP_CLAUSE chain holding the associated clauses.
+   CHILD_FN and DATA_ARG like for GIMPLE_OMP_PARALLEL.  */
+DEFGSCODE(GIMPLE_OMP_TEAMS, "gimple_omp_teams", GSS_OMP_PARALLEL_LAYOUT)
 
 /* GIMPLE_OMP_ORDERED <BODY, CLAUSES> represents #pragma omp ordered.
    BODY is the sequence of statements to execute in the ordered section.
index cdd711dae5b5cd8d48009f3e9b6cc43e7b0586f5..145e9ad2fe3ca1e96a2a6afc775def0321320ac8 100644 (file)
@@ -151,6 +151,7 @@ enum gf_mask {
     GF_OMP_PARALLEL_COMBINED   = 1 << 0,
     GF_OMP_PARALLEL_GRID_PHONY = 1 << 1,
     GF_OMP_TASK_TASKLOOP       = 1 << 0,
+    GF_OMP_TASK_TASKWAIT       = 1 << 1,
     GF_OMP_FOR_KIND_MASK       = (1 << 4) - 1,
     GF_OMP_FOR_KIND_FOR                = 0,
     GF_OMP_FOR_KIND_DISTRIBUTE = 1,
@@ -183,6 +184,7 @@ enum gf_mask {
     GF_OMP_TARGET_KIND_OACC_DECLARE = 10,
     GF_OMP_TARGET_KIND_OACC_HOST_DATA = 11,
     GF_OMP_TEAMS_GRID_PHONY    = 1 << 0,
+    GF_OMP_TEAMS_HOST          = 1 << 1,
 
     /* True on an GIMPLE_OMP_RETURN statement if the return does not require
        a thread synchronization via some sort of barrier.  The exact barrier
@@ -191,8 +193,8 @@ enum gf_mask {
     GF_OMP_RETURN_NOWAIT       = 1 << 0,
 
     GF_OMP_SECTION_LAST                = 1 << 0,
-    GF_OMP_ATOMIC_NEED_VALUE   = 1 << 0,
-    GF_OMP_ATOMIC_SEQ_CST      = 1 << 1,
+    GF_OMP_ATOMIC_MEMORY_ORDER  = (1 << 3) - 1,
+    GF_OMP_ATOMIC_NEED_VALUE   = 1 << 3,
     GF_PREDICT_TAKEN           = 1 << 15
 };
 
@@ -637,7 +639,7 @@ struct GTY((tag("GSS_OMP_FOR")))
 };
 
 
-/* GIMPLE_OMP_PARALLEL, GIMPLE_OMP_TARGET, GIMPLE_OMP_TASK */
+/* GIMPLE_OMP_PARALLEL, GIMPLE_OMP_TARGET, GIMPLE_OMP_TASK, GIMPLE_OMP_TEAMS */
 
 struct GTY((tag("GSS_OMP_PARALLEL_LAYOUT")))
   gimple_statement_omp_parallel_layout : public gimple_statement_omp
@@ -663,7 +665,8 @@ struct GTY((tag("GSS_OMP_PARALLEL_LAYOUT")))
 {
     /* No extra fields; adds invariant:
          stmt->code == GIMPLE_OMP_PARALLEL
-        || stmt->code == GIMPLE_OMP_TASK.  */
+        || stmt->code == GIMPLE_OMP_TASK
+        || stmt->code == GIMPLE_OMP_TEAMS.  */
 };
 
 /* GIMPLE_OMP_PARALLEL */
@@ -737,7 +740,7 @@ struct GTY((tag("GSS_OMP_CONTINUE")))
   tree control_use;
 };
 
-/* GIMPLE_OMP_SINGLE, GIMPLE_OMP_TEAMS, GIMPLE_OMP_ORDERED */
+/* GIMPLE_OMP_SINGLE, GIMPLE_OMP_ORDERED, GIMPLE_OMP_TASKGROUP.  */
 
 struct GTY((tag("GSS_OMP_SINGLE_LAYOUT")))
   gimple_statement_omp_single_layout : public gimple_statement_omp
@@ -755,8 +758,8 @@ struct GTY((tag("GSS_OMP_SINGLE_LAYOUT")))
          stmt->code == GIMPLE_OMP_SINGLE.  */
 };
 
-struct GTY((tag("GSS_OMP_SINGLE_LAYOUT")))
-  gomp_teams : public gimple_statement_omp_single_layout
+struct GTY((tag("GSS_OMP_PARALLEL_LAYOUT")))
+  gomp_teams : public gimple_statement_omp_taskreg
 {
     /* No extra fields; adds invariant:
          stmt->code == GIMPLE_OMP_TEAMS.  */
@@ -1121,7 +1124,9 @@ template <>
 inline bool
 is_a_helper <gimple_statement_omp_taskreg *>::test (gimple *gs)
 {
-  return gs->code == GIMPLE_OMP_PARALLEL || gs->code == GIMPLE_OMP_TASK;
+  return (gs->code == GIMPLE_OMP_PARALLEL
+         || gs->code == GIMPLE_OMP_TASK
+         || gs->code == GIMPLE_OMP_TEAMS);
 }
 
 template <>
@@ -1337,7 +1342,9 @@ template <>
 inline bool
 is_a_helper <const gimple_statement_omp_taskreg *>::test (const gimple *gs)
 {
-  return gs->code == GIMPLE_OMP_PARALLEL || gs->code == GIMPLE_OMP_TASK;
+  return (gs->code == GIMPLE_OMP_PARALLEL
+         || gs->code == GIMPLE_OMP_TASK
+         || gs->code == GIMPLE_OMP_TEAMS);
 }
 
 template <>
@@ -1463,7 +1470,7 @@ gomp_task *gimple_build_omp_task (gimple_seq, tree, tree, tree, tree,
 gimple *gimple_build_omp_section (gimple_seq);
 gimple *gimple_build_omp_master (gimple_seq);
 gimple *gimple_build_omp_grid_body (gimple_seq);
-gimple *gimple_build_omp_taskgroup (gimple_seq);
+gimple *gimple_build_omp_taskgroup (gimple_seq, tree);
 gomp_continue *gimple_build_omp_continue (tree, tree);
 gomp_ordered *gimple_build_omp_ordered (gimple_seq, tree);
 gimple *gimple_build_omp_return (bool);
@@ -1472,8 +1479,9 @@ gimple *gimple_build_omp_sections_switch (void);
 gomp_single *gimple_build_omp_single (gimple_seq, tree);
 gomp_target *gimple_build_omp_target (gimple_seq, int, tree);
 gomp_teams *gimple_build_omp_teams (gimple_seq, tree);
-gomp_atomic_load *gimple_build_omp_atomic_load (tree, tree);
-gomp_atomic_store *gimple_build_omp_atomic_store (tree);
+gomp_atomic_load *gimple_build_omp_atomic_load (tree, tree,
+                                               enum omp_memory_order);
+gomp_atomic_store *gimple_build_omp_atomic_store (tree, enum omp_memory_order);
 gtransaction *gimple_build_transaction (gimple_seq);
 extern void gimple_seq_add_stmt (gimple_seq *, gimple *);
 extern void gimple_seq_add_stmt_without_update (gimple_seq *, gimple *);
@@ -2193,7 +2201,7 @@ static inline unsigned
 gimple_omp_subcode (const gimple *s)
 {
   gcc_gimple_checking_assert (gimple_code (s) >= GIMPLE_OMP_ATOMIC_LOAD
-             && gimple_code (s) <= GIMPLE_OMP_TEAMS);
+                             && gimple_code (s) <= GIMPLE_OMP_TEAMS);
   return s->subcode;
 }
 
@@ -2331,26 +2339,27 @@ gimple_omp_atomic_set_need_value (gimple *g)
 }
 
 
-/* Return true if OMP atomic load/store statement G has the
-   GF_OMP_ATOMIC_SEQ_CST flag set.  */
+/* Return the memory order of the OMP atomic load/store statement G.  */
 
-static inline bool
-gimple_omp_atomic_seq_cst_p (const gimple *g)
+static inline enum omp_memory_order
+gimple_omp_atomic_memory_order (const gimple *g)
 {
   if (gimple_code (g) != GIMPLE_OMP_ATOMIC_LOAD)
     GIMPLE_CHECK (g, GIMPLE_OMP_ATOMIC_STORE);
-  return (gimple_omp_subcode (g) & GF_OMP_ATOMIC_SEQ_CST) != 0;
+  return (enum omp_memory_order)
+        (gimple_omp_subcode (g) & GF_OMP_ATOMIC_MEMORY_ORDER);
 }
 
 
-/* Set the GF_OMP_ATOMIC_SEQ_CST flag on G.  */
+/* Set the memory order on G.  */
 
 static inline void
-gimple_omp_atomic_set_seq_cst (gimple *g)
+gimple_omp_atomic_set_memory_order (gimple *g, enum omp_memory_order mo)
 {
   if (gimple_code (g) != GIMPLE_OMP_ATOMIC_LOAD)
     GIMPLE_CHECK (g, GIMPLE_OMP_ATOMIC_STORE);
-  g->subcode |= GF_OMP_ATOMIC_SEQ_CST;
+  g->subcode = ((g->subcode & ~GF_OMP_ATOMIC_MEMORY_ORDER)
+               | (mo & GF_OMP_ATOMIC_MEMORY_ORDER));
 }
 
 
@@ -4915,6 +4924,40 @@ gimple_omp_ordered_set_clauses (gomp_ordered *ord_stmt, tree clauses)
 }
 
 
+/* Return the clauses associated with OMP_TASKGROUP statement GS.  */
+
+static inline tree
+gimple_omp_taskgroup_clauses (const gimple *gs)
+{
+  GIMPLE_CHECK (gs, GIMPLE_OMP_TASKGROUP);
+  return
+    static_cast <const gimple_statement_omp_single_layout *> (gs)->clauses;
+}
+
+
+/* Return a pointer to the clauses associated with OMP taskgroup statement
+   GS.  */
+
+static inline tree *
+gimple_omp_taskgroup_clauses_ptr (gimple *gs)
+{
+  GIMPLE_CHECK (gs, GIMPLE_OMP_TASKGROUP);
+  return &static_cast <gimple_statement_omp_single_layout *> (gs)->clauses;
+}
+
+
+/* Set CLAUSES to be the clauses associated with OMP taskgroup statement
+   GS.  */
+
+static inline void
+gimple_omp_taskgroup_set_clauses (gimple *gs, tree clauses)
+{
+  GIMPLE_CHECK (gs, GIMPLE_OMP_TASKGROUP);
+  static_cast <gimple_statement_omp_single_layout *> (gs)->clauses
+    = clauses;
+}
+
+
 /* Return the kind of the OMP_FOR statemement G.  */
 
 static inline int
@@ -5441,6 +5484,31 @@ gimple_omp_task_set_taskloop_p (gimple *g, bool taskloop_p)
 }
 
 
+/* Return true if OMP task statement G has the
+   GF_OMP_TASK_TASKWAIT flag set.  */
+
+static inline bool
+gimple_omp_task_taskwait_p (const gimple *g)
+{
+  GIMPLE_CHECK (g, GIMPLE_OMP_TASK);
+  return (gimple_omp_subcode (g) & GF_OMP_TASK_TASKWAIT) != 0;
+}
+
+
+/* Set the GF_OMP_TASK_TASKWAIT field in G depending on the boolean
+   value of TASKWAIT_P.  */
+
+static inline void
+gimple_omp_task_set_taskwait_p (gimple *g, bool taskwait_p)
+{
+  GIMPLE_CHECK (g, GIMPLE_OMP_TASK);
+  if (taskwait_p)
+    g->subcode |= GF_OMP_TASK_TASKWAIT;
+  else
+    g->subcode &= ~GF_OMP_TASK_TASKWAIT;
+}
+
+
 /* Return the child function used to hold the body of OMP_TASK GS.  */
 
 static inline tree
@@ -5857,6 +5925,60 @@ gimple_omp_teams_set_clauses (gomp_teams *omp_teams_stmt, tree clauses)
   omp_teams_stmt->clauses = clauses;
 }
 
+/* Return the child function used to hold the body of OMP_TEAMS_STMT.  */
+
+static inline tree
+gimple_omp_teams_child_fn (const gomp_teams *omp_teams_stmt)
+{
+  return omp_teams_stmt->child_fn;
+}
+
+/* Return a pointer to the child function used to hold the body of
+   OMP_TEAMS_STMT.  */
+
+static inline tree *
+gimple_omp_teams_child_fn_ptr (gomp_teams *omp_teams_stmt)
+{
+  return &omp_teams_stmt->child_fn;
+}
+
+
+/* Set CHILD_FN to be the child function for OMP_TEAMS_STMT.  */
+
+static inline void
+gimple_omp_teams_set_child_fn (gomp_teams *omp_teams_stmt, tree child_fn)
+{
+  omp_teams_stmt->child_fn = child_fn;
+}
+
+
+/* Return the artificial argument used to send variables and values
+   from the parent to the children threads in OMP_TEAMS_STMT.  */
+
+static inline tree
+gimple_omp_teams_data_arg (const gomp_teams *omp_teams_stmt)
+{
+  return omp_teams_stmt->data_arg;
+}
+
+
+/* Return a pointer to the data argument for OMP_TEAMS_STMT.  */
+
+static inline tree *
+gimple_omp_teams_data_arg_ptr (gomp_teams *omp_teams_stmt)
+{
+  return &omp_teams_stmt->data_arg;
+}
+
+
+/* Set DATA_ARG to be the data argument for OMP_TEAMS_STMT.  */
+
+static inline void
+gimple_omp_teams_set_data_arg (gomp_teams *omp_teams_stmt, tree data_arg)
+{
+  omp_teams_stmt->data_arg = data_arg;
+}
+
 /* Return the kernel_phony flag of an OMP_TEAMS_STMT.  */
 
 static inline bool
@@ -5876,6 +5998,25 @@ gimple_omp_teams_set_grid_phony (gomp_teams *omp_teams_stmt, bool value)
     omp_teams_stmt->subcode &= ~GF_OMP_TEAMS_GRID_PHONY;
 }
 
+/* Return the host flag of an OMP_TEAMS_STMT.  */
+
+static inline bool
+gimple_omp_teams_host (const gomp_teams *omp_teams_stmt)
+{
+  return (gimple_omp_subcode (omp_teams_stmt) & GF_OMP_TEAMS_HOST) != 0;
+}
+
+/* Set host flag of an OMP_TEAMS_STMT to VALUE.  */
+
+static inline void
+gimple_omp_teams_set_host (gomp_teams *omp_teams_stmt, bool value)
+{
+  if (value)
+    omp_teams_stmt->subcode |= GF_OMP_TEAMS_HOST;
+  else
+    omp_teams_stmt->subcode &= ~GF_OMP_TEAMS_HOST;
+}
+
 /* Return the clauses associated with OMP_SECTIONS GS.  */
 
 static inline tree
index 509fc2f3f5be20985558e8b4f2e94a7cbf814567..61dca240db6de51cfa7b78320c9e14cc22fa3f3c 100644 (file)
@@ -105,6 +105,14 @@ enum gimplify_omp_var_data
   /* Flag for GOVD_MAP: must be present already.  */
   GOVD_MAP_FORCE_PRESENT = 524288,
 
+  /* Flag for GOVD_MAP: only allocate.  */
+  GOVD_MAP_ALLOC_ONLY = 1048576,
+
+  /* Flag for GOVD_MAP: only copy back.  */
+  GOVD_MAP_FROM_ONLY = 2097152,
+
+  GOVD_NONTEMPORAL = 4194304,
+
   GOVD_DATA_SHARE_CLASS = (GOVD_SHARED | GOVD_PRIVATE | GOVD_FIRSTPRIVATE
                           | GOVD_LASTPRIVATE | GOVD_REDUCTION | GOVD_LINEAR
                           | GOVD_LOCAL)
@@ -114,34 +122,39 @@ enum gimplify_omp_var_data
 enum omp_region_type
 {
   ORT_WORKSHARE = 0x00,
-  ORT_SIMD     = 0x01,
+  ORT_TASKGROUP = 0x01,
+  ORT_SIMD     = 0x04,
 
-  ORT_PARALLEL = 0x02,
-  ORT_COMBINED_PARALLEL = 0x03,
+  ORT_PARALLEL = 0x08,
+  ORT_COMBINED_PARALLEL = ORT_PARALLEL | 1,
 
-  ORT_TASK     = 0x04,
-  ORT_UNTIED_TASK = 0x05,
+  ORT_TASK     = 0x10,
+  ORT_UNTIED_TASK = ORT_TASK | 1,
+  ORT_TASKLOOP  = ORT_TASK | 2,
+  ORT_UNTIED_TASKLOOP = ORT_UNTIED_TASK | 2,
 
-  ORT_TEAMS    = 0x08,
-  ORT_COMBINED_TEAMS = 0x09,
+  ORT_TEAMS    = 0x20,
+  ORT_COMBINED_TEAMS = ORT_TEAMS | 1,
+  ORT_HOST_TEAMS = ORT_TEAMS | 2,
+  ORT_COMBINED_HOST_TEAMS = ORT_COMBINED_TEAMS | 2,
 
   /* Data region.  */
-  ORT_TARGET_DATA = 0x10,
+  ORT_TARGET_DATA = 0x40,
 
   /* Data region with offloading.  */
-  ORT_TARGET   = 0x20,
-  ORT_COMBINED_TARGET = 0x21,
+  ORT_TARGET   = 0x80,
+  ORT_COMBINED_TARGET = ORT_TARGET | 1,
 
   /* OpenACC variants.  */
-  ORT_ACC      = 0x40,  /* A generic OpenACC region.  */
+  ORT_ACC      = 0x100,  /* A generic OpenACC region.  */
   ORT_ACC_DATA = ORT_ACC | ORT_TARGET_DATA, /* Data construct.  */
   ORT_ACC_PARALLEL = ORT_ACC | ORT_TARGET,  /* Parallel construct */
-  ORT_ACC_KERNELS  = ORT_ACC | ORT_TARGET | 0x80,  /* Kernels construct.  */
-  ORT_ACC_HOST_DATA = ORT_ACC | ORT_TARGET_DATA | 0x80,  /* Host data.  */
+  ORT_ACC_KERNELS  = ORT_ACC | ORT_TARGET | 2,  /* Kernels construct.  */
+  ORT_ACC_HOST_DATA = ORT_ACC | ORT_TARGET_DATA | 2,  /* Host data.  */
 
   /* Dummy OpenMP region, used to disable expansion of
      DECL_VALUE_EXPRs in taskloop pre body.  */
-  ORT_NONE     = 0x100
+  ORT_NONE     = 0x200
 };
 
 /* Gimplify hashtable helper.  */
@@ -176,6 +189,14 @@ struct gimplify_ctx
   unsigned in_switch_expr : 1;
 };
 
+enum gimplify_defaultmap_kind
+{
+  GDMK_SCALAR,
+  GDMK_AGGREGATE,
+  GDMK_ALLOCATABLE,
+  GDMK_POINTER
+};
+
 struct gimplify_omp_ctx
 {
   struct gimplify_omp_ctx *outer_context;
@@ -188,9 +209,8 @@ struct gimplify_omp_ctx
   enum omp_region_type region_type;
   bool combined_loop;
   bool distribute;
-  bool target_map_scalars_firstprivate;
-  bool target_map_pointers_as_0len_arrays;
   bool target_firstprivatize_array_bases;
+  int defaultmap[4];
 };
 
 static struct gimplify_ctx *gimplify_ctxp;
@@ -413,6 +433,10 @@ new_omp_context (enum omp_region_type region_type)
     c->default_kind = OMP_CLAUSE_DEFAULT_SHARED;
   else
     c->default_kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
+  c->defaultmap[GDMK_SCALAR] = GOVD_MAP;
+  c->defaultmap[GDMK_AGGREGATE] = GOVD_MAP;
+  c->defaultmap[GDMK_ALLOCATABLE] = GOVD_MAP;
+  c->defaultmap[GDMK_POINTER] = GOVD_MAP;
 
   return c;
 }
@@ -738,6 +762,7 @@ gimple_add_tmp_var (tree tmp)
          struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
          while (ctx
                 && (ctx->region_type == ORT_WORKSHARE
+                    || ctx->region_type == ORT_TASKGROUP
                     || ctx->region_type == ORT_SIMD
                     || ctx->region_type == ORT_ACC))
            ctx = ctx->outer_context;
@@ -3150,6 +3175,8 @@ maybe_fold_stmt (gimple_stmt_iterator *gsi)
   for (ctx = gimplify_omp_ctxp; ctx; ctx = ctx->outer_context)
     if ((ctx->region_type & (ORT_TARGET | ORT_PARALLEL | ORT_TASK)) != 0)
       return false;
+    else if ((ctx->region_type & ORT_HOST_TEAMS) == ORT_HOST_TEAMS)
+      return false;
   return fold_stmt (gsi);
 }
 
@@ -6641,12 +6668,13 @@ omp_firstprivatize_variable (struct gimplify_omp_ctx *ctx, tree decl)
        }
       else if ((ctx->region_type & ORT_TARGET) != 0)
        {
-         if (ctx->target_map_scalars_firstprivate)
+         if (ctx->defaultmap[GDMK_SCALAR] & GOVD_FIRSTPRIVATE)
            omp_add_variable (ctx, decl, GOVD_FIRSTPRIVATE);
          else
            omp_add_variable (ctx, decl, GOVD_MAP | GOVD_MAP_TO_ONLY);
        }
       else if (ctx->region_type != ORT_WORKSHARE
+              && ctx->region_type != ORT_TASKGROUP
               && ctx->region_type != ORT_SIMD
               && ctx->region_type != ORT_ACC
               && !(ctx->region_type & ORT_TARGET_DATA))
@@ -6760,7 +6788,7 @@ omp_add_variable (struct gimplify_omp_ctx *ctx, tree decl, unsigned int flags)
         replacement is private, else FIRSTPRIVATE since we'll need the
         address of the original variable either for SHARED, or for the
         copy into or out of the context.  */
-      if (!(flags & GOVD_LOCAL))
+      if (!(flags & GOVD_LOCAL) && ctx->region_type != ORT_TASKGROUP)
        {
          if (flags & GOVD_MAP)
            nflags = GOVD_MAP | GOVD_MAP_TO_ONLY | GOVD_EXPLICIT;
@@ -6962,6 +6990,8 @@ omp_default_clause (struct gimplify_omp_ctx *ctx, tree decl,
 
        if (ctx->region_type & ORT_PARALLEL)
          rtype = "parallel";
+       else if ((ctx->region_type & ORT_TASKLOOP) == ORT_TASKLOOP)
+         rtype = "taskloop";
        else if (ctx->region_type & ORT_TASK)
          rtype = "task";
        else if (ctx->region_type & ORT_TEAMS)
@@ -7173,11 +7203,9 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree decl, bool in_code)
       if (n == NULL)
        {
          unsigned nflags = flags;
-         if (ctx->target_map_pointers_as_0len_arrays
-             || ctx->target_map_scalars_firstprivate)
+         if ((ctx->region_type & ORT_ACC) == 0)
            {
              bool is_declare_target = false;
-             bool is_scalar = false;
              if (is_global_var (decl)
                  && varpool_node::get_create (decl)->offloadable)
                {
@@ -7194,18 +7222,34 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree decl, bool in_code)
                    }
                  is_declare_target = octx == NULL;
                }
-             if (!is_declare_target && ctx->target_map_scalars_firstprivate)
-               is_scalar = lang_hooks.decls.omp_scalar_p (decl);
-             if (is_declare_target)
-               ;
-             else if (ctx->target_map_pointers_as_0len_arrays
-                      && (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
-                          || (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE
-                              && TREE_CODE (TREE_TYPE (TREE_TYPE (decl)))
-                                 == POINTER_TYPE)))
-               nflags |= GOVD_MAP | GOVD_MAP_0LEN_ARRAY;
-             else if (is_scalar)
-               nflags |= GOVD_FIRSTPRIVATE;
+             if (!is_declare_target)
+               {
+                 int gdmk;
+                 if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
+                     || (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE
+                         && (TREE_CODE (TREE_TYPE (TREE_TYPE (decl)))
+                             == POINTER_TYPE)))
+                   gdmk = GDMK_POINTER;
+                 else if (lang_hooks.decls.omp_scalar_p (decl))
+                   gdmk = GDMK_SCALAR;
+                 else
+                   gdmk = GDMK_AGGREGATE;
+                 if (ctx->defaultmap[gdmk] == 0)
+                   {
+                     tree d = lang_hooks.decls.omp_report_decl (decl);
+                     error ("%qE not specified in enclosing %<target%>",
+                            DECL_NAME (d));
+                     error_at (ctx->location, "enclosing %<target%>");
+                   }
+                 else if (ctx->defaultmap[gdmk]
+                          & (GOVD_MAP_0LEN_ARRAY | GOVD_FIRSTPRIVATE))
+                   nflags |= ctx->defaultmap[gdmk];
+                 else
+                   {
+                     gcc_assert (ctx->defaultmap[gdmk] & GOVD_MAP);
+                     nflags |= ctx->defaultmap[gdmk] & ~GOVD_MAP;
+                   }
+               }
            }
 
          struct gimplify_omp_ctx *octx = ctx->outer_context;
@@ -7236,28 +7280,28 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree decl, bool in_code)
                }
            }
 
-         {
-           tree type = TREE_TYPE (decl);
-
-           if (nflags == flags
-               && gimplify_omp_ctxp->target_firstprivatize_array_bases
-               && lang_hooks.decls.omp_privatize_by_reference (decl))
-             type = TREE_TYPE (type);
-           if (nflags == flags
-               && !lang_hooks.types.omp_mappable_type (type))
-             {
-               error ("%qD referenced in target region does not have "
-                      "a mappable type", decl);
-               nflags |= GOVD_MAP | GOVD_EXPLICIT;
-             }
-           else if (nflags == flags)
-             {
-               if ((ctx->region_type & ORT_ACC) != 0)
-                 nflags = oacc_default_clause (ctx, decl, flags);
-               else
-                 nflags |= GOVD_MAP;
-             }
-         }
+         if ((nflags & ~(GOVD_MAP_TO_ONLY | GOVD_MAP_FROM_ONLY
+                         | GOVD_MAP_ALLOC_ONLY)) == flags)
+           {
+             tree type = TREE_TYPE (decl);
+
+             if (gimplify_omp_ctxp->target_firstprivatize_array_bases
+                 && lang_hooks.decls.omp_privatize_by_reference (decl))
+               type = TREE_TYPE (type);
+             if (!lang_hooks.types.omp_mappable_type (type))
+               {
+                 error ("%qD referenced in target region does not have "
+                        "a mappable type", decl);
+                 nflags |= GOVD_MAP | GOVD_EXPLICIT;
+               }
+             else
+               {
+                 if ((ctx->region_type & ORT_ACC) != 0)
+                   nflags = oacc_default_clause (ctx, decl, flags);
+                 else
+                   nflags |= GOVD_MAP;
+               }
+           }
        found_outer:
          omp_add_variable (ctx, decl, nflags);
        }
@@ -7275,6 +7319,7 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree decl, bool in_code)
   if (n == NULL)
     {
       if (ctx->region_type == ORT_WORKSHARE
+         || ctx->region_type == ORT_TASKGROUP
          || ctx->region_type == ORT_SIMD
          || ctx->region_type == ORT_ACC
          || (ctx->region_type & ORT_TARGET_DATA) != 0)
@@ -7386,18 +7431,9 @@ omp_is_private (struct gimplify_omp_ctx *ctx, tree decl, int simd)
          else if ((n->value & GOVD_REDUCTION) != 0)
            error ("iteration variable %qE should not be reduction",
                   DECL_NAME (decl));
-         else if (simd == 0 && (n->value & GOVD_LINEAR) != 0)
+         else if (simd != 1 && (n->value & GOVD_LINEAR) != 0)
            error ("iteration variable %qE should not be linear",
                   DECL_NAME (decl));
-         else if (simd == 1 && (n->value & GOVD_LASTPRIVATE) != 0)
-           error ("iteration variable %qE should not be lastprivate",
-                  DECL_NAME (decl));
-         else if (simd && (n->value & GOVD_PRIVATE) != 0)
-           error ("iteration variable %qE should not be private",
-                  DECL_NAME (decl));
-         else if (simd == 2 && (n->value & GOVD_LINEAR) != 0)
-           error ("iteration variable %qE is predetermined linear",
-                  DECL_NAME (decl));
        }
       return (ctx == gimplify_omp_ctxp
              || (ctx->region_type == ORT_COMBINED_PARALLEL
@@ -7405,6 +7441,7 @@ omp_is_private (struct gimplify_omp_ctx *ctx, tree decl, int simd)
     }
 
   if (ctx->region_type != ORT_WORKSHARE
+      && ctx->region_type != ORT_TASKGROUP
       && ctx->region_type != ORT_SIMD
       && ctx->region_type != ORT_ACC)
     return false;
@@ -7462,6 +7499,7 @@ omp_check_private (struct gimplify_omp_ctx *ctx, tree decl, bool copyprivate)
        }
     }
   while (ctx->region_type == ORT_WORKSHARE
+        || ctx->region_type == ORT_TASKGROUP
         || ctx->region_type == ORT_SIMD
         || ctx->region_type == ORT_ACC);
   return false;
@@ -7483,6 +7521,452 @@ find_decl_expr (tree *tp, int *walk_subtrees, void *data)
   return NULL_TREE;
 }
 
+/* If *LIST_P contains any OpenMP depend clauses with iterators,
+   lower all the depend clauses by populating corresponding depend
+   array.  Returns 0 if there are no such depend clauses, or
+   2 if all depend clauses should be removed, 1 otherwise.  */
+
+static int
+gimplify_omp_depend (tree *list_p, gimple_seq *pre_p)
+{
+  tree c;
+  gimple *g;
+  size_t n[4] = { 0, 0, 0, 0 };
+  bool unused[4];
+  tree counts[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
+  tree last_iter = NULL_TREE, last_count = NULL_TREE;
+  size_t i, j;
+  location_t first_loc = UNKNOWN_LOCATION;
+
+  for (c = *list_p; c; c = OMP_CLAUSE_CHAIN (c))
+    if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
+      {
+       switch (OMP_CLAUSE_DEPEND_KIND (c))
+         {
+         case OMP_CLAUSE_DEPEND_IN:
+           i = 2;
+           break;
+         case OMP_CLAUSE_DEPEND_OUT:
+         case OMP_CLAUSE_DEPEND_INOUT:
+           i = 0;
+           break;
+         case OMP_CLAUSE_DEPEND_MUTEXINOUTSET:
+           i = 1;
+           break;
+         case OMP_CLAUSE_DEPEND_DEPOBJ:
+           i = 3;
+           break;
+         case OMP_CLAUSE_DEPEND_SOURCE:
+         case OMP_CLAUSE_DEPEND_SINK:
+           continue;
+         default:
+           gcc_unreachable ();
+         }
+       tree t = OMP_CLAUSE_DECL (c);
+       if (first_loc == UNKNOWN_LOCATION)
+         first_loc = OMP_CLAUSE_LOCATION (c);
+       if (TREE_CODE (t) == TREE_LIST
+           && TREE_PURPOSE (t)
+           && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC)
+         {
+           if (TREE_PURPOSE (t) != last_iter)
+             {
+               tree tcnt = size_one_node;
+               for (tree it = TREE_PURPOSE (t); it; it = TREE_CHAIN (it))
+                 {
+                   if (gimplify_expr (&TREE_VEC_ELT (it, 1), pre_p, NULL,
+                                      is_gimple_val, fb_rvalue) == GS_ERROR
+                       || gimplify_expr (&TREE_VEC_ELT (it, 2), pre_p, NULL,
+                                         is_gimple_val, fb_rvalue) == GS_ERROR
+                       || gimplify_expr (&TREE_VEC_ELT (it, 3), pre_p, NULL,
+                                         is_gimple_val, fb_rvalue) == GS_ERROR
+                       || (gimplify_expr (&TREE_VEC_ELT (it, 4), pre_p, NULL,
+                                          is_gimple_val, fb_rvalue)
+                           == GS_ERROR))
+                     return 2;
+                   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_VEC_ELT (it, 4);
+                   tree type = TREE_TYPE (var);
+                   tree stype = TREE_TYPE (step);
+                   location_t loc = DECL_SOURCE_LOCATION (var);
+                   tree endmbegin;
+                   /* Compute count for this iterator as
+                      orig_step > 0
+                      ? (begin < end ? (end - begin + (step - 1)) / step : 0)
+                      : (begin > end ? (end - begin + (step + 1)) / step : 0)
+                      and compute product of those for the entire depend
+                      clause.  */
+                   if (POINTER_TYPE_P (type))
+                     endmbegin = fold_build2_loc (loc, POINTER_DIFF_EXPR,
+                                                  stype, end, begin);
+                   else
+                     endmbegin = fold_build2_loc (loc, MINUS_EXPR, type,
+                                                  end, begin);
+                   tree stepm1 = fold_build2_loc (loc, MINUS_EXPR, stype,
+                                                  step,
+                                                  build_int_cst (stype, 1));
+                   tree stepp1 = fold_build2_loc (loc, PLUS_EXPR, stype, step,
+                                                  build_int_cst (stype, 1));
+                   tree pos = fold_build2_loc (loc, PLUS_EXPR, stype,
+                                               unshare_expr (endmbegin),
+                                               stepm1);
+                   pos = fold_build2_loc (loc, TRUNC_DIV_EXPR, stype,
+                                          pos, step);
+                   tree neg = fold_build2_loc (loc, PLUS_EXPR, stype,
+                                               endmbegin, stepp1);
+                   if (TYPE_UNSIGNED (stype))
+                     {
+                       neg = fold_build1_loc (loc, NEGATE_EXPR, stype, neg);
+                       step = fold_build1_loc (loc, NEGATE_EXPR, stype, step);
+                     }
+                   neg = fold_build2_loc (loc, TRUNC_DIV_EXPR, stype,
+                                          neg, step);
+                   step = NULL_TREE;
+                   tree cond = fold_build2_loc (loc, LT_EXPR,
+                                                boolean_type_node,
+                                                begin, end);
+                   pos = fold_build3_loc (loc, COND_EXPR, stype, cond, pos,
+                                          build_int_cst (stype, 0));
+                   cond = fold_build2_loc (loc, LT_EXPR, boolean_type_node,
+                                           end, begin);
+                   neg = fold_build3_loc (loc, COND_EXPR, stype, cond, neg,
+                                          build_int_cst (stype, 0));
+                   tree osteptype = TREE_TYPE (orig_step);
+                   cond = fold_build2_loc (loc, GT_EXPR, boolean_type_node,
+                                           orig_step,
+                                           build_int_cst (osteptype, 0));
+                   tree cnt = fold_build3_loc (loc, COND_EXPR, stype,
+                                               cond, pos, neg);
+                   cnt = fold_convert_loc (loc, sizetype, cnt);
+                   if (gimplify_expr (&cnt, pre_p, NULL, is_gimple_val,
+                                      fb_rvalue) == GS_ERROR)
+                     return 2;
+                   tcnt = size_binop_loc (loc, MULT_EXPR, tcnt, cnt);
+                 }
+               if (gimplify_expr (&tcnt, pre_p, NULL, is_gimple_val,
+                                  fb_rvalue) == GS_ERROR)
+                 return 2;
+               last_iter = TREE_PURPOSE (t);
+               last_count = tcnt;
+             }
+           if (counts[i] == NULL_TREE)
+             counts[i] = last_count;
+           else
+             counts[i] = size_binop_loc (OMP_CLAUSE_LOCATION (c),
+                                         PLUS_EXPR, counts[i], last_count);
+         }
+       else
+         n[i]++;
+      }
+  for (i = 0; i < 4; i++)
+    if (counts[i])
+      break;
+  if (i == 4)
+    return 0;
+
+  tree total = size_zero_node;
+  for (i = 0; i < 4; i++)
+    {
+      unused[i] = counts[i] == NULL_TREE && n[i] == 0;
+      if (counts[i] == NULL_TREE)
+       counts[i] = size_zero_node;
+      if (n[i])
+       counts[i] = size_binop (PLUS_EXPR, counts[i], size_int (n[i]));
+      if (gimplify_expr (&counts[i], pre_p, NULL, is_gimple_val,
+                        fb_rvalue) == GS_ERROR)
+       return 2;
+      total = size_binop (PLUS_EXPR, total, counts[i]);
+    }
+
+  if (gimplify_expr (&total, pre_p, NULL, is_gimple_val, fb_rvalue)
+      == GS_ERROR)
+    return 2;
+  bool is_old = unused[1] && unused[3];
+  tree totalpx = size_binop (PLUS_EXPR, unshare_expr (total),
+                            size_int (is_old ? 1 : 4));
+  tree type = build_array_type (ptr_type_node, build_index_type (totalpx));
+  tree array = create_tmp_var_raw (type);
+  TREE_ADDRESSABLE (array) = 1;
+  if (TREE_CODE (totalpx) != INTEGER_CST)
+    {
+      if (!TYPE_SIZES_GIMPLIFIED (TREE_TYPE (array)))
+       gimplify_type_sizes (TREE_TYPE (array), pre_p);
+      if (gimplify_omp_ctxp)
+       {
+         struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
+         while (ctx
+                && (ctx->region_type == ORT_WORKSHARE
+                    || ctx->region_type == ORT_TASKGROUP
+                    || ctx->region_type == ORT_SIMD
+                    || ctx->region_type == ORT_ACC))
+           ctx = ctx->outer_context;
+         if (ctx)
+           omp_add_variable (ctx, array, GOVD_LOCAL | GOVD_SEEN);
+       }
+      gimplify_vla_decl (array, pre_p);
+    }
+  else
+    gimple_add_tmp_var (array);
+  tree r = build4 (ARRAY_REF, ptr_type_node, array, size_int (0), NULL_TREE,
+                  NULL_TREE);
+  tree tem;
+  if (!is_old)
+    {
+      tem = build2 (MODIFY_EXPR, void_type_node, r,
+                   build_int_cst (ptr_type_node, 0));
+      gimplify_and_add (tem, pre_p);
+      r = build4 (ARRAY_REF, ptr_type_node, array, size_int (1), NULL_TREE,
+                 NULL_TREE);
+    }
+  tem = build2 (MODIFY_EXPR, void_type_node, r,
+               fold_convert (ptr_type_node, total));
+  gimplify_and_add (tem, pre_p);
+  for (i = 1; i < (is_old ? 2 : 4); i++)
+    {
+      r = build4 (ARRAY_REF, ptr_type_node, array, size_int (i + !is_old),
+                 NULL_TREE, NULL_TREE);
+      tem = build2 (MODIFY_EXPR, void_type_node, r, counts[i - 1]);
+      gimplify_and_add (tem, pre_p);
+    }
+
+  tree cnts[4];
+  for (j = 4; j; j--)
+    if (!unused[j - 1])
+      break;
+  for (i = 0; i < 4; i++)
+    {
+      if (i && (i >= j || unused[i - 1]))
+       {
+         cnts[i] = cnts[i - 1];
+         continue;
+       }
+      cnts[i] = create_tmp_var (sizetype);
+      if (i == 0)
+       g = gimple_build_assign (cnts[i], size_int (is_old ? 2 : 5));
+      else
+       {
+         tree t;
+         if (is_old)
+           t = size_binop (PLUS_EXPR, counts[0], size_int (2));
+         else
+           t = size_binop (PLUS_EXPR, cnts[i - 1], counts[i - 1]);
+         if (gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue)
+             == GS_ERROR)
+           return 2;
+         g = gimple_build_assign (cnts[i], t);
+       }
+      gimple_seq_add_stmt (pre_p, g);
+    }
+
+  last_iter = NULL_TREE;
+  tree last_bind = NULL_TREE;
+  tree *last_body = NULL;
+  for (c = *list_p; c; c = OMP_CLAUSE_CHAIN (c))
+    if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
+      {
+       switch (OMP_CLAUSE_DEPEND_KIND (c))
+         {
+         case OMP_CLAUSE_DEPEND_IN:
+           i = 2;
+           break;
+         case OMP_CLAUSE_DEPEND_OUT:
+         case OMP_CLAUSE_DEPEND_INOUT:
+           i = 0;
+           break;
+         case OMP_CLAUSE_DEPEND_MUTEXINOUTSET:
+           i = 1;
+           break;
+         case OMP_CLAUSE_DEPEND_DEPOBJ:
+           i = 3;
+           break;
+         case OMP_CLAUSE_DEPEND_SOURCE:
+         case OMP_CLAUSE_DEPEND_SINK:
+           continue;
+         default:
+           gcc_unreachable ();
+         }
+       tree t = OMP_CLAUSE_DECL (c);
+       if (TREE_CODE (t) == TREE_LIST
+           && TREE_PURPOSE (t)
+           && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC)
+         {
+           if (TREE_PURPOSE (t) != last_iter)
+             {
+               if (last_bind)
+                 gimplify_and_add (last_bind, pre_p);
+               tree block = TREE_VEC_ELT (TREE_PURPOSE (t), 5);
+               last_bind = build3 (BIND_EXPR, void_type_node,
+                                   BLOCK_VARS (block), NULL, block);
+               TREE_SIDE_EFFECTS (last_bind) = 1;
+               SET_EXPR_LOCATION (last_bind, OMP_CLAUSE_LOCATION (c));
+               tree *p = &BIND_EXPR_BODY (last_bind);
+               for (tree it = TREE_PURPOSE (t); 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_VEC_ELT (it, 4);
+                   tree type = TREE_TYPE (var);
+                   location_t loc = DECL_SOURCE_LOCATION (var);
+                   /* Emit:
+                      var = begin;
+                      goto cond_label;
+                      beg_label:
+                      ...
+                      var = var + step;
+                      cond_label:
+                      if (orig_step > 0) {
+                        if (var < end) goto beg_label;
+                      } else {
+                        if (var > end) goto beg_label;
+                      }
+                      for each iterator, with inner iterators added to
+                      the ... above.  */
+                   tree beg_label = create_artificial_label (loc);
+                   tree cond_label = NULL_TREE;
+                   tem = build2_loc (loc, MODIFY_EXPR, void_type_node,
+                                     var, begin);
+                   append_to_statement_list_force (tem, p);
+                   tem = build_and_jump (&cond_label);
+                   append_to_statement_list_force (tem, p);
+                   tem = build1 (LABEL_EXPR, void_type_node, beg_label);
+                   append_to_statement_list (tem, p);
+                   tree bind = build3 (BIND_EXPR, void_type_node, NULL_TREE,
+                                       NULL_TREE, NULL_TREE);
+                   TREE_SIDE_EFFECTS (bind) = 1;
+                   SET_EXPR_LOCATION (bind, loc);
+                   append_to_statement_list_force (bind, p);
+                   if (POINTER_TYPE_P (type))
+                     tem = build2_loc (loc, POINTER_PLUS_EXPR, type,
+                                       var, fold_convert_loc (loc, sizetype,
+                                                              step));
+                   else
+                     tem = build2_loc (loc, PLUS_EXPR, type, var, step);
+                   tem = build2_loc (loc, MODIFY_EXPR, void_type_node,
+                                     var, tem);
+                   append_to_statement_list_force (tem, p);
+                   tem = build1 (LABEL_EXPR, void_type_node, cond_label);
+                   append_to_statement_list (tem, p);
+                   tree cond = fold_build2_loc (loc, LT_EXPR,
+                                                boolean_type_node,
+                                                var, end);
+                   tree pos
+                     = fold_build3_loc (loc, COND_EXPR, void_type_node,
+                                        cond, build_and_jump (&beg_label),
+                                        void_node);
+                   cond = fold_build2_loc (loc, GT_EXPR, boolean_type_node,
+                                           var, end);
+                   tree neg
+                     = fold_build3_loc (loc, COND_EXPR, void_type_node,
+                                        cond, build_and_jump (&beg_label),
+                                        void_node);
+                   tree osteptype = TREE_TYPE (orig_step);
+                   cond = fold_build2_loc (loc, GT_EXPR, boolean_type_node,
+                                           orig_step,
+                                           build_int_cst (osteptype, 0));
+                   tem = fold_build3_loc (loc, COND_EXPR, void_type_node,
+                                          cond, pos, neg);
+                   append_to_statement_list_force (tem, p);
+                   p = &BIND_EXPR_BODY (bind);
+                 }
+               last_body = p;
+             }
+           last_iter = TREE_PURPOSE (t);
+           if (TREE_CODE (TREE_VALUE (t)) == COMPOUND_EXPR)
+             {
+               append_to_statement_list (TREE_OPERAND (TREE_VALUE (t),
+                                         0), last_body);
+               TREE_VALUE (t) = TREE_OPERAND (TREE_VALUE (t), 1);
+             }
+           if (error_operand_p (TREE_VALUE (t)))
+             return 2;
+           TREE_VALUE (t) = build_fold_addr_expr (TREE_VALUE (t));
+           r = build4 (ARRAY_REF, ptr_type_node, array, cnts[i],
+                       NULL_TREE, NULL_TREE);
+           tem = build2_loc (OMP_CLAUSE_LOCATION (c), MODIFY_EXPR,
+                             void_type_node, r, TREE_VALUE (t));
+           append_to_statement_list_force (tem, last_body);
+           tem = build2_loc (OMP_CLAUSE_LOCATION (c), MODIFY_EXPR,
+                             void_type_node, cnts[i],
+                             size_binop (PLUS_EXPR, cnts[i], size_int (1)));
+           append_to_statement_list_force (tem, last_body);
+           TREE_VALUE (t) = null_pointer_node;
+         }
+       else
+         {
+           if (last_bind)
+             {
+               gimplify_and_add (last_bind, pre_p);
+               last_bind = NULL_TREE;
+             }
+           if (TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPOUND_EXPR)
+             {
+               gimplify_expr (&TREE_OPERAND (OMP_CLAUSE_DECL (c), 0), pre_p,
+                              NULL, is_gimple_val, fb_rvalue);
+               OMP_CLAUSE_DECL (c) = TREE_OPERAND (OMP_CLAUSE_DECL (c), 1);
+             }
+           if (error_operand_p (OMP_CLAUSE_DECL (c)))
+             return 2;
+           OMP_CLAUSE_DECL (c) = build_fold_addr_expr (OMP_CLAUSE_DECL (c));
+           if (gimplify_expr (&OMP_CLAUSE_DECL (c), pre_p, NULL,
+                              is_gimple_val, fb_rvalue) == GS_ERROR)
+             return 2;
+           r = build4 (ARRAY_REF, ptr_type_node, array, cnts[i],
+                       NULL_TREE, NULL_TREE);
+           tem = build2 (MODIFY_EXPR, void_type_node, r, OMP_CLAUSE_DECL (c));
+           gimplify_and_add (tem, pre_p);
+           g = gimple_build_assign (cnts[i], size_binop (PLUS_EXPR, cnts[i],
+                                                         size_int (1)));
+           gimple_seq_add_stmt (pre_p, g);
+         }
+      }
+  if (last_bind)
+    gimplify_and_add (last_bind, pre_p);
+  tree cond = boolean_false_node;
+  if (is_old)
+    {
+      if (!unused[0])
+       cond = build2_loc (first_loc, NE_EXPR, boolean_type_node, cnts[0],
+                          size_binop_loc (first_loc, PLUS_EXPR, counts[0],
+                                          size_int (2)));
+      if (!unused[2])
+       cond = build2_loc (first_loc, TRUTH_OR_EXPR, boolean_type_node, cond,
+                          build2_loc (first_loc, NE_EXPR, boolean_type_node,
+                                      cnts[2],
+                                      size_binop_loc (first_loc, PLUS_EXPR,
+                                                      totalpx,
+                                                      size_int (1))));
+    }
+  else
+    {
+      tree prev = size_int (5);
+      for (i = 0; i < 4; i++)
+       {
+         if (unused[i])
+           continue;
+         prev = size_binop_loc (first_loc, PLUS_EXPR, counts[i], prev);
+         cond = build2_loc (first_loc, TRUTH_OR_EXPR, boolean_type_node, cond,
+                            build2_loc (first_loc, NE_EXPR, boolean_type_node,
+                                        cnts[i], unshare_expr (prev)));
+       }
+    }
+  tem = build3_loc (first_loc, COND_EXPR, void_type_node, cond,
+                   build_call_expr_loc (first_loc,
+                                        builtin_decl_explicit (BUILT_IN_TRAP),
+                                        0), void_node);
+  gimplify_and_add (tem, pre_p);
+  c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_DEPEND);
+  OMP_CLAUSE_DEPEND_KIND (c) = OMP_CLAUSE_DEPEND_LAST;
+  OMP_CLAUSE_DECL (c) = build_fold_addr_expr (array);
+  OMP_CLAUSE_CHAIN (c) = *list_p;
+  *list_p = c;
+  return 1;
+}
+
 /* Scan the OMP clauses in *LIST_P, installing mappings into a new
    and previous omp contexts.  */
 
@@ -7495,14 +7979,16 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
   tree c;
   hash_map<tree, tree> *struct_map_to_clause = NULL;
   tree *prev_list_p = NULL;
+  int handled_depend_iterators = -1;
+  int nowait = -1;
 
   ctx = new_omp_context (region_type);
   outer_ctx = ctx->outer_context;
   if (code == OMP_TARGET)
     {
       if (!lang_GNU_Fortran ())
-       ctx->target_map_pointers_as_0len_arrays = true;
-      ctx->target_map_scalars_firstprivate = true;
+       ctx->defaultmap[GDMK_POINTER] = GOVD_MAP | GOVD_MAP_0LEN_ARRAY;
+      ctx->defaultmap[GDMK_SCALAR] = GOVD_FIRSTPRIVATE;
     }
   if (!lang_GNU_Fortran ())
     switch (code)
@@ -7548,16 +8034,43 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
          check_non_private = "firstprivate";
          goto do_add;
        case OMP_CLAUSE_LASTPRIVATE:
+         if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c))
+           switch (code)
+             {
+             case OMP_DISTRIBUTE:
+               error_at (OMP_CLAUSE_LOCATION (c),
+                         "conditional %<lastprivate%> clause on "
+                         "%<distribute%> construct");
+               OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) = 0;
+               break;
+             case OMP_TASKLOOP:
+               error_at (OMP_CLAUSE_LOCATION (c),
+                         "conditional %<lastprivate%> clause on "
+                         "%<taskloop%> construct");
+               OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) = 0;
+               break;
+             default:
+               break;
+             }
          flags = GOVD_LASTPRIVATE | GOVD_SEEN | GOVD_EXPLICIT;
          check_non_private = "lastprivate";
          decl = OMP_CLAUSE_DECL (c);
          if (error_operand_p (decl))
            goto do_add;
-         else if (outer_ctx
-                  && (outer_ctx->region_type == ORT_COMBINED_PARALLEL
-                      || outer_ctx->region_type == ORT_COMBINED_TEAMS)
-                  && splay_tree_lookup (outer_ctx->variables,
-                                        (splay_tree_key) decl) == NULL)
+         if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c)
+             && !lang_hooks.decls.omp_scalar_p (decl))
+           {
+             error_at (OMP_CLAUSE_LOCATION (c),
+                       "non-scalar variable %qD in conditional "
+                       "%<lastprivate%> clause", decl);
+             OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c) = 0;
+           }
+         if (outer_ctx
+             && (outer_ctx->region_type == ORT_COMBINED_PARALLEL
+                 || ((outer_ctx->region_type & ORT_COMBINED_TEAMS)
+                     == ORT_COMBINED_TEAMS))
+             && splay_tree_lookup (outer_ctx->variables,
+                                   (splay_tree_key) decl) == NULL)
            {
              omp_add_variable (outer_ctx, decl, GOVD_SHARED | GOVD_SEEN);
              if (outer_ctx->outer_context)
@@ -7603,7 +8116,8 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
                                            GOVD_LASTPRIVATE | GOVD_SEEN);
                          octx = octx->outer_context;
                          if (octx
-                             && octx->region_type == ORT_COMBINED_TEAMS
+                             && ((octx->region_type & ORT_COMBINED_TEAMS)
+                                 == ORT_COMBINED_TEAMS)
                              && (splay_tree_lookup (octx->variables,
                                                     (splay_tree_key) decl)
                                  == NULL))
@@ -7622,10 +8136,40 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
            }
          goto do_add;
        case OMP_CLAUSE_REDUCTION:
+         if (OMP_CLAUSE_REDUCTION_TASK (c))
+           {
+             if (region_type == ORT_WORKSHARE)
+               {
+                 if (nowait == -1)
+                   nowait = omp_find_clause (*list_p,
+                                             OMP_CLAUSE_NOWAIT) != NULL_TREE;
+                 if (nowait
+                     && (outer_ctx == NULL
+                         || outer_ctx->region_type != ORT_COMBINED_PARALLEL))
+                   {
+                     error_at (OMP_CLAUSE_LOCATION (c),
+                               "%<task%> reduction modifier on a construct "
+                               "with a %<nowait%> clause");
+                     OMP_CLAUSE_REDUCTION_TASK (c) = 0;
+                   }
+               }
+             else if ((region_type & ORT_PARALLEL) != ORT_PARALLEL)
+               {
+                 error_at (OMP_CLAUSE_LOCATION (c),
+                           "invalid %<task%> reduction modifier on construct "
+                           "other than %<parallel%>, %<for%> or %<sections%>");
+                 OMP_CLAUSE_REDUCTION_TASK (c) = 0;
+               }
+           }
+         /* FALLTHRU */
+       case OMP_CLAUSE_IN_REDUCTION:
+       case OMP_CLAUSE_TASK_REDUCTION:
          flags = GOVD_REDUCTION | GOVD_SEEN | GOVD_EXPLICIT;
          /* OpenACC permits reductions on private variables.  */
-         if (!(region_type & ORT_ACC))
-           check_non_private = "reduction";
+         if (!(region_type & ORT_ACC)
+             /* taskgroup is actually not a worksharing region.  */
+             && code != OMP_TASKGROUP)
+           check_non_private = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
          decl = OMP_CLAUSE_DECL (c);
          if (TREE_CODE (decl) == MEM_REF)
            {
@@ -7746,7 +8290,8 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
                           && octx == outer_ctx)
                    flags = GOVD_SEEN | GOVD_SHARED;
                  else if (octx
-                          && octx->region_type == ORT_COMBINED_TEAMS)
+                          && ((octx->region_type & ORT_COMBINED_TEAMS)
+                              == ORT_COMBINED_TEAMS))
                    flags = GOVD_SEEN | GOVD_SHARED;
                  else if (octx
                           && octx->region_type == ORT_COMBINED_TARGET)
@@ -8229,6 +8774,14 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
            }
          else if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SOURCE)
            break;
+         if (handled_depend_iterators == -1)
+           handled_depend_iterators = gimplify_omp_depend (list_p, pre_p);
+         if (handled_depend_iterators)
+           {
+             if (handled_depend_iterators == 2)
+               remove = true;
+             break;
+           }
          if (TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPOUND_EXPR)
            {
              gimplify_expr (&TREE_OPERAND (OMP_CLAUSE_DECL (c), 0), pre_p,
@@ -8311,7 +8864,9 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
              && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER)
            flags |= GOVD_MAP_0LEN_ARRAY;
          omp_add_variable (ctx, decl, flags);
-         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)
              && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
            {
              omp_add_variable (ctx, OMP_CLAUSE_REDUCTION_PLACEHOLDER (c),
@@ -8423,6 +8978,31 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
                          " or private in outer context", DECL_NAME (decl));
            }
        do_notice:
+         if ((region_type & ORT_TASKLOOP) == ORT_TASKLOOP
+             && outer_ctx
+             && outer_ctx->region_type == ORT_COMBINED_PARALLEL
+             && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+                 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
+                 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE))
+           {
+             splay_tree_node on
+               = splay_tree_lookup (outer_ctx->variables,
+                                    (splay_tree_key)decl);
+             if (on == NULL || (on->value & GOVD_DATA_SHARE_CLASS) == 0)
+               {
+                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+                     && TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF
+                     && (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
+                         || (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE
+                             && (TREE_CODE (TREE_TYPE (TREE_TYPE (decl)))
+                                 == POINTER_TYPE))))
+                   omp_firstprivatize_variable (outer_ctx, decl);
+                 else
+                   omp_add_variable (outer_ctx, decl,
+                                     GOVD_SEEN | GOVD_SHARED);
+                 omp_notice_variable (outer_ctx, decl, true);
+               }
+           }
          if (outer_ctx)
            omp_notice_variable (outer_ctx, decl, true);
          if (check_non_private
@@ -8453,7 +9033,9 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
              for (int i = 0; i < 2; i++)
                switch (i ? OMP_CLAUSE_IF_MODIFIER (c) : code)
                  {
+                 case VOID_CST: p[i] = "cancel"; break;
                  case OMP_PARALLEL: p[i] = "parallel"; break;
+                 case OMP_SIMD: p[i] = "simd"; break;
                  case OMP_TASK: p[i] = "task"; break;
                  case OMP_TASKLOOP: p[i] = "taskloop"; break;
                  case OMP_TARGET_DATA: p[i] = "target data"; break;
@@ -8508,6 +9090,9 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
          break;
 
        case OMP_CLAUSE_NOWAIT:
+         nowait = 1;
+         break;
+
        case OMP_CLAUSE_ORDERED:
        case OMP_CLAUSE_UNTIED:
        case OMP_CLAUSE_COLLAPSE:
@@ -8527,7 +9112,69 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
          break;
 
        case OMP_CLAUSE_DEFAULTMAP:
-         ctx->target_map_scalars_firstprivate = false;
+         enum gimplify_defaultmap_kind gdmkmin, gdmkmax;
+         switch (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c))
+           {
+           case OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED:
+             gdmkmin = GDMK_SCALAR;
+             gdmkmax = GDMK_POINTER;
+             break;
+           case OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR:
+             gdmkmin = gdmkmax = GDMK_SCALAR;
+             break;
+           case OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE:
+             gdmkmin = gdmkmax = GDMK_AGGREGATE;
+             break;
+           case OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALLOCATABLE:
+             gdmkmin = gdmkmax = GDMK_ALLOCATABLE;
+             break;
+           case OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER:
+             gdmkmin = gdmkmax = GDMK_POINTER;
+             break;
+           default:
+             gcc_unreachable ();
+           }
+         for (int gdmk = gdmkmin; gdmk <= gdmkmax; gdmk++)
+           switch (OMP_CLAUSE_DEFAULTMAP_BEHAVIOR (c))
+             {
+             case OMP_CLAUSE_DEFAULTMAP_ALLOC:
+               ctx->defaultmap[gdmk] = GOVD_MAP | GOVD_MAP_ALLOC_ONLY;
+               break;
+             case OMP_CLAUSE_DEFAULTMAP_TO:
+               ctx->defaultmap[gdmk] = GOVD_MAP | GOVD_MAP_TO_ONLY;
+               break;
+             case OMP_CLAUSE_DEFAULTMAP_FROM:
+               ctx->defaultmap[gdmk] = GOVD_MAP | GOVD_MAP_FROM_ONLY;
+               break;
+             case OMP_CLAUSE_DEFAULTMAP_TOFROM:
+               ctx->defaultmap[gdmk] = GOVD_MAP;
+               break;
+             case OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE:
+               ctx->defaultmap[gdmk] = GOVD_FIRSTPRIVATE;
+               break;
+             case OMP_CLAUSE_DEFAULTMAP_NONE:
+               ctx->defaultmap[gdmk] = 0;
+               break;
+             case OMP_CLAUSE_DEFAULTMAP_DEFAULT:
+               switch (gdmk)
+                 {
+                 case GDMK_SCALAR:
+                   ctx->defaultmap[gdmk] = GOVD_FIRSTPRIVATE;
+                   break;
+                 case GDMK_AGGREGATE:
+                 case GDMK_ALLOCATABLE:
+                   ctx->defaultmap[gdmk] = GOVD_MAP;
+                   break;
+                 case GDMK_POINTER:
+                   ctx->defaultmap[gdmk] = GOVD_MAP | GOVD_MAP_0LEN_ARRAY;
+                   break;
+                 default:
+                   gcc_unreachable ();
+                 }
+               break;
+             default:
+               gcc_unreachable ();
+             }
          break;
 
        case OMP_CLAUSE_ALIGNED:
@@ -8548,6 +9195,16 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
            omp_add_variable (ctx, decl, GOVD_ALIGNED);
          break;
 
+       case OMP_CLAUSE_NONTEMPORAL:
+         decl = OMP_CLAUSE_DECL (c);
+         if (error_operand_p (decl))
+           {
+             remove = true;
+             break;
+           }
+         omp_add_variable (ctx, decl, GOVD_NONTEMPORAL);
+         break;
+
        case OMP_CLAUSE_DEFAULT:
          ctx->default_kind = OMP_CLAUSE_DEFAULT_KIND (c);
          break;
@@ -8773,7 +9430,7 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data)
     }
   else if (flags & GOVD_LASTPRIVATE)
     code = OMP_CLAUSE_LASTPRIVATE;
-  else if (flags & GOVD_ALIGNED)
+  else if (flags & (GOVD_ALIGNED | GOVD_NONTEMPORAL))
     return 0;
   else
     gcc_unreachable ();
@@ -8827,7 +9484,9 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data)
       /* Not all combinations of these GOVD_MAP flags are actually valid.  */
       switch (flags & (GOVD_MAP_TO_ONLY
                       | GOVD_MAP_FORCE
-                      | GOVD_MAP_FORCE_PRESENT))
+                      | GOVD_MAP_FORCE_PRESENT
+                      | GOVD_MAP_ALLOC_ONLY
+                      | GOVD_MAP_FROM_ONLY))
        {
        case 0:
          kind = GOMP_MAP_TOFROM;
@@ -8838,6 +9497,12 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data)
        case GOVD_MAP_TO_ONLY:
          kind = GOMP_MAP_TO;
          break;
+       case GOVD_MAP_FROM_ONLY:
+         kind = GOMP_MAP_FROM;
+         break;
+       case GOVD_MAP_ALLOC_ONLY:
+         kind = GOMP_MAP_ALLOC;
+         break;
        case GOVD_MAP_TO_ONLY | GOVD_MAP_FORCE:
          kind = GOMP_MAP_TO | GOMP_MAP_FLAG_FORCE;
          break;
@@ -9062,6 +9727,12 @@ gimplify_adjust_omp_clauses (gimple_seq *pre_p, gimple_seq body, tree *list_p,
            }
          break;
 
+       case OMP_CLAUSE_NONTEMPORAL:
+         decl = OMP_CLAUSE_DECL (c);
+         n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
+         remove = n == NULL || !(n->value & GOVD_SEEN);
+         break;
+
        case OMP_CLAUSE_MAP:
          if (code == OMP_TARGET_EXIT_DATA
              && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER)
@@ -9229,6 +9900,8 @@ gimplify_adjust_omp_clauses (gimple_seq *pre_p, gimple_seq body, tree *list_p,
          break;
 
        case OMP_CLAUSE_REDUCTION:
+       case OMP_CLAUSE_IN_REDUCTION:
+       case OMP_CLAUSE_TASK_REDUCTION:
          decl = OMP_CLAUSE_DECL (c);
          /* OpenACC reductions need a present_or_copy data clause.
             Add one if necessary.  Emit error when the reduction is private.  */
@@ -9506,18 +10179,32 @@ gimplify_omp_task (tree *expr_p, gimple_seq *pre_p)
   gimple *g;
   gimple_seq body = NULL;
 
+  if (OMP_TASK_BODY (expr) == NULL_TREE)
+    for (tree c = OMP_TASK_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN (c))
+      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
+         && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_MUTEXINOUTSET)
+       {
+         error_at (OMP_CLAUSE_LOCATION (c),
+                   "%<mutexinoutset%> kind in %<depend%> clause on a "
+                   "%<taskwait%> construct");
+         break;
+       }
+
   gimplify_scan_omp_clauses (&OMP_TASK_CLAUSES (expr), pre_p,
                             omp_find_clause (OMP_TASK_CLAUSES (expr),
                                              OMP_CLAUSE_UNTIED)
                             ? ORT_UNTIED_TASK : ORT_TASK, OMP_TASK);
 
-  push_gimplify_context ();
+  if (OMP_TASK_BODY (expr))
+    {
+      push_gimplify_context ();
 
-  g = gimplify_and_return_first (OMP_TASK_BODY (expr), &body);
-  if (gimple_code (g) == GIMPLE_BIND)
-    pop_gimplify_context (g);
-  else
-    pop_gimplify_context (NULL);
+      g = gimplify_and_return_first (OMP_TASK_BODY (expr), &body);
+      if (gimple_code (g) == GIMPLE_BIND)
+       pop_gimplify_context (g);
+      else
+       pop_gimplify_context (NULL);
+    }
 
   gimplify_adjust_omp_clauses (pre_p, body, &OMP_TASK_CLAUSES (expr),
                               OMP_TASK);
@@ -9526,6 +10213,8 @@ gimplify_omp_task (tree *expr_p, gimple_seq *pre_p)
                             OMP_TASK_CLAUSES (expr),
                             NULL_TREE, NULL_TREE,
                             NULL_TREE, NULL_TREE, NULL_TREE);
+  if (OMP_TASK_BODY (expr) == NULL_TREE)
+    gimple_omp_task_set_taskwait_p (g, true);
   gimplify_seq_add_stmt (pre_p, g);
   *expr_p = NULL_TREE;
 }
@@ -9655,7 +10344,9 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
       for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (inner_for_stmt)); i++)
        if (OMP_FOR_ORIG_DECLS (inner_for_stmt)
            && TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt),
-                                       i)) == TREE_LIST)
+                                       i)) == TREE_LIST
+           && TREE_PURPOSE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt),
+                                          i)))
          {
            tree orig = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt), i);
            /* Class iterators aren't allowed on OMP_SIMD, so the only
@@ -9709,6 +10400,43 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
            OMP_CLAUSE_CHAIN (c) = OMP_PARALLEL_CLAUSES (*data[1]);
            OMP_PARALLEL_CLAUSES (*data[1]) = c;
          }
+      /* Similarly, take care of C++ range for temporaries, those should
+        be firstprivate on OMP_PARALLEL if any.  */
+      if (data[1])
+       for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (inner_for_stmt)); i++)
+         if (OMP_FOR_ORIG_DECLS (inner_for_stmt)
+             && TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt),
+                                         i)) == TREE_LIST
+             && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt),
+                                          i)))
+           {
+             tree orig
+               = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt), i);
+             tree v = TREE_CHAIN (orig);
+             tree c = build_omp_clause (UNKNOWN_LOCATION,
+                                        OMP_CLAUSE_FIRSTPRIVATE);
+             /* First add firstprivate clause for the __for_end artificial
+                decl.  */
+             OMP_CLAUSE_DECL (c) = TREE_VEC_ELT (v, 1);
+             if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c)))
+                 == REFERENCE_TYPE)
+               OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c) = 1;
+             OMP_CLAUSE_CHAIN (c) = OMP_PARALLEL_CLAUSES (*data[1]);
+             OMP_PARALLEL_CLAUSES (*data[1]) = c;
+             if (TREE_VEC_ELT (v, 0))
+               {
+                 /* And now the same for __for_range artificial decl if it
+                    exists.  */
+                 c = build_omp_clause (UNKNOWN_LOCATION,
+                                       OMP_CLAUSE_FIRSTPRIVATE);
+                 OMP_CLAUSE_DECL (c) = TREE_VEC_ELT (v, 0);
+                 if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c)))
+                     == REFERENCE_TYPE)
+                   OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c) = 1;
+                 OMP_CLAUSE_CHAIN (c) = OMP_PARALLEL_CLAUSES (*data[1]);
+                 OMP_PARALLEL_CLAUSES (*data[1]) = c;
+               }
+           }
     }
 
   switch (TREE_CODE (for_stmt))
@@ -9721,9 +10449,9 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
       break;
     case OMP_TASKLOOP:
       if (omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_UNTIED))
-       ort = ORT_UNTIED_TASK;
+       ort = ORT_UNTIED_TASKLOOP;
       else
-       ort = ORT_TASK;
+       ort = ORT_TASKLOOP;
       break;
     case OMP_SIMD:
       ort = ORT_SIMD;
@@ -9935,7 +10663,11 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
            {
              tree orig_decl = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt), i);
              if (TREE_CODE (orig_decl) == TREE_LIST)
-               orig_decl = TREE_PURPOSE (orig_decl);
+               {
+                 orig_decl = TREE_PURPOSE (orig_decl);
+                 if (!orig_decl)
+                   orig_decl = decl;
+               }
              gimplify_omp_ctxp->loop_iter_var.quick_push (orig_decl);
            }
          else
@@ -10027,7 +10759,8 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
                      else if (omp_check_private (outer, decl, false))
                        outer = NULL;
                    }
-                 else if (((outer->region_type & ORT_TASK) != 0)
+                 else if (((outer->region_type & ORT_TASKLOOP)
+                           == ORT_TASKLOOP)
                           && outer->combined_loop
                           && !omp_check_private (gimplify_omp_ctxp,
                                                  decl, false))
@@ -10066,8 +10799,12 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
                                outer = NULL;
                            }
                          if (outer && outer->outer_context
-                             && (outer->outer_context->region_type
-                                 == ORT_COMBINED_TEAMS))
+                             && ((outer->outer_context->region_type
+                                  & ORT_COMBINED_TEAMS) == ORT_COMBINED_TEAMS
+                                 || (((outer->region_type & ORT_TASKLOOP)
+                                      == ORT_TASKLOOP)
+                                     && (outer->outer_context->region_type
+                                         == ORT_COMBINED_PARALLEL))))
                            {
                              outer = outer->outer_context;
                              n = splay_tree_lookup (outer->variables,
@@ -10114,7 +10851,8 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
                      else if (omp_check_private (outer, decl, false))
                        outer = NULL;
                    }
-                 else if (((outer->region_type & ORT_TASK) != 0)
+                 else if (((outer->region_type & ORT_TASKLOOP)
+                           == ORT_TASKLOOP)
                           && outer->combined_loop
                           && !omp_check_private (gimplify_omp_ctxp,
                                                  decl, false))
@@ -10153,8 +10891,12 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
                                outer = NULL;
                            }
                          if (outer && outer->outer_context
-                             && (outer->outer_context->region_type
-                                 == ORT_COMBINED_TEAMS))
+                             && ((outer->outer_context->region_type
+                                  & ORT_COMBINED_TEAMS) == ORT_COMBINED_TEAMS
+                                 || (((outer->region_type & ORT_TASKLOOP)
+                                      == ORT_TASKLOOP)
+                                     && (outer->outer_context->region_type
+                                         == ORT_COMBINED_PARALLEL))))
                            {
                              outer = outer->outer_context;
                              n = splay_tree_lookup (outer->variables,
@@ -10496,6 +11238,8 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
          case OMP_CLAUSE_FINAL:
          case OMP_CLAUSE_MERGEABLE:
          case OMP_CLAUSE_PRIORITY:
+         case OMP_CLAUSE_REDUCTION:
+         case OMP_CLAUSE_IN_REDUCTION:
            *gtask_clauses_ptr = c;
            gtask_clauses_ptr = &OMP_CLAUSE_CHAIN (c);
            break;
@@ -10676,7 +11420,7 @@ computable_teams_clause (tree *tp, int *walk_subtrees, void *)
                             (splay_tree_key) *tp);
       if (n == NULL)
        {
-         if (gimplify_omp_ctxp->target_map_scalars_firstprivate)
+         if (gimplify_omp_ctxp->defaultmap[GDMK_SCALAR] & GOVD_FIRSTPRIVATE)
            return NULL_TREE;
          return *tp;
        }
@@ -10848,6 +11592,12 @@ gimplify_omp_workshare (tree *expr_p, gimple_seq *pre_p)
       break;
     case OMP_TEAMS:
       ort = OMP_TEAMS_COMBINED (expr) ? ORT_COMBINED_TEAMS : ORT_TEAMS;
+      if (gimplify_omp_ctxp == NULL
+         || (gimplify_omp_ctxp->region_type == ORT_TARGET
+             && gimplify_omp_ctxp->outer_context == NULL
+             && lookup_attribute ("omp declare target",
+                                  DECL_ATTRIBUTES (current_function_decl))))
+       ort = (enum omp_region_type) (ort | ORT_HOST_TEAMS);
       break;
     case OACC_HOST_DATA:
       ort = ORT_ACC_HOST_DATA;
@@ -10859,7 +11609,8 @@ gimplify_omp_workshare (tree *expr_p, gimple_seq *pre_p)
                             TREE_CODE (expr));
   if (TREE_CODE (expr) == OMP_TARGET)
     optimize_target_teams (expr, pre_p);
-  if ((ort & (ORT_TARGET | ORT_TARGET_DATA)) != 0)
+  if ((ort & (ORT_TARGET | ORT_TARGET_DATA)) != 0
+      || (ort & ORT_HOST_TEAMS) == ORT_HOST_TEAMS)
     {
       push_gimplify_context ();
       gimple *g = gimplify_and_return_first (OMP_BODY (expr), &body);
@@ -10930,6 +11681,8 @@ gimplify_omp_workshare (tree *expr_p, gimple_seq *pre_p)
       break;
     case OMP_TEAMS:
       stmt = gimple_build_omp_teams (body, OMP_CLAUSES (expr));
+      if ((ort & ORT_HOST_TEAMS) == ORT_HOST_TEAMS)
+       gimple_omp_teams_set_host (as_a <gomp_teams *> (stmt), true);
       break;
     default:
       gcc_unreachable ();
@@ -11165,7 +11918,8 @@ gimplify_omp_atomic (tree *expr_p, gimple_seq *pre_p)
       != GS_ALL_DONE)
     return GS_ERROR;
 
-  loadstmt = gimple_build_omp_atomic_load (tmp_load, addr);
+  loadstmt = gimple_build_omp_atomic_load (tmp_load, addr,
+                                          OMP_ATOMIC_MEMORY_ORDER (*expr_p));
   gimplify_seq_add_stmt (pre_p, loadstmt);
   if (rhs && gimplify_expr (&rhs, pre_p, NULL, is_gimple_val, fb_rvalue)
       != GS_ALL_DONE)
@@ -11173,13 +11927,9 @@ gimplify_omp_atomic (tree *expr_p, gimple_seq *pre_p)
 
   if (TREE_CODE (*expr_p) == OMP_ATOMIC_READ)
     rhs = tmp_load;
-  storestmt = gimple_build_omp_atomic_store (rhs);
+  storestmt
+    = gimple_build_omp_atomic_store (rhs, OMP_ATOMIC_MEMORY_ORDER (*expr_p));
   gimplify_seq_add_stmt (pre_p, storestmt);
-  if (OMP_ATOMIC_SEQ_CST (*expr_p))
-    {
-      gimple_omp_atomic_set_seq_cst (loadstmt);
-      gimple_omp_atomic_set_seq_cst (storestmt);
-    }
   switch (TREE_CODE (*expr_p))
     {
     case OMP_ATOMIC_READ:
@@ -12126,7 +12876,6 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
 
        case OMP_SECTION:
        case OMP_MASTER:
-       case OMP_TASKGROUP:
        case OMP_ORDERED:
        case OMP_CRITICAL:
          {
@@ -12142,19 +12891,6 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
              case OMP_MASTER:
                g = gimple_build_omp_master (body);
                break;
-             case OMP_TASKGROUP:
-               {
-                 gimple_seq cleanup = NULL;
-                 tree fn
-                   = builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_END);
-                 g = gimple_build_call (fn, 0);
-                 gimple_seq_add_stmt (&cleanup, g);
-                 g = gimple_build_try (body, cleanup, GIMPLE_TRY_FINALLY);
-                 body = NULL;
-                 gimple_seq_add_stmt (&body, g);
-                 g = gimple_build_omp_taskgroup (body);
-               }
-               break;
              case OMP_ORDERED:
                g = gimplify_omp_ordered (*expr_p, body);
                break;
@@ -12176,6 +12912,28 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
            break;
          }
 
+       case OMP_TASKGROUP:
+         {
+           gimple_seq body = NULL;
+
+           tree *pclauses = &OMP_TASKGROUP_CLAUSES (*expr_p);
+           gimplify_scan_omp_clauses (pclauses, pre_p, ORT_TASKGROUP,
+                                      OMP_TASKGROUP);
+           gimplify_adjust_omp_clauses (pre_p, NULL, pclauses, OMP_TASKGROUP);
+           gimplify_and_add (OMP_BODY (*expr_p), &body);
+           gimple_seq cleanup = NULL;
+           tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_END);
+           gimple *g = gimple_build_call (fn, 0);
+           gimple_seq_add_stmt (&cleanup, g);
+           g = gimple_build_try (body, cleanup, GIMPLE_TRY_FINALLY);
+           body = NULL;
+           gimple_seq_add_stmt (&body, g);
+           g = gimple_build_omp_taskgroup (body, *pclauses);
+           gimplify_seq_add_stmt (pre_p, g);
+           ret = GS_ALL_DONE;
+           break;
+         }
+
        case OMP_ATOMIC:
        case OMP_ATOMIC_READ:
        case OMP_ATOMIC_CAPTURE_OLD:
index e8f6a691301bccf7d1cc6851a060bc8950a6c40b..2cb04029862c898dcddb561464180dc81ed8cd8a 100644 (file)
@@ -1356,6 +1356,8 @@ hash_tree (struct streamer_tree_cache_d *cache, hash_map<tree, hashval_t> *map,
          val = OMP_CLAUSE_PROC_BIND_KIND (t);
          break;
        case OMP_CLAUSE_REDUCTION:
+       case OMP_CLAUSE_TASK_REDUCTION:
+       case OMP_CLAUSE_IN_REDUCTION:
          val = OMP_CLAUSE_REDUCTION_CODE (t);
          break;
        default:
index 55e56336ae976255e407eb5e1da2a07dc93c9f65..70051635fa0ac4b71af4ee659a976e3a5c337d88 100644 (file)
@@ -75,6 +75,8 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_BARRIER_CANCEL, "GOMP_barrier_cancel",
                  BT_FN_BOOL, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKWAIT, "GOMP_taskwait",
                  BT_FN_VOID, ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKWAIT_DEPEND, "GOMP_taskwait_depend",
+                 BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKYIELD, "GOMP_taskyield",
                  BT_FN_VOID, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKGROUP_START, "GOMP_taskgroup_start",
@@ -122,6 +124,14 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_NONMONOTONIC_GUIDED_START,
                  "GOMP_loop_nonmonotonic_guided_start",
                  BT_FN_BOOL_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR,
                  ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_NONMONOTONIC_RUNTIME_START,
+                 "GOMP_loop_nonmonotonic_runtime_start",
+                 BT_FN_BOOL_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR,
+                 ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_START,
+                 "GOMP_loop_maybe_nonmonotonic_runtime_start",
+                 BT_FN_BOOL_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR,
+                 ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ORDERED_STATIC_START,
                  "GOMP_loop_ordered_static_start",
                  BT_FN_BOOL_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR,
@@ -154,6 +164,18 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_DOACROSS_RUNTIME_START,
                  "GOMP_loop_doacross_runtime_start",
                  BT_FN_BOOL_UINT_LONGPTR_LONGPTR_LONGPTR,
                  ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_START,
+                 "GOMP_loop_start",
+                 BT_FN_BOOL_LONG_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR,
+                 ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ORDERED_START,
+                 "GOMP_loop_ordered_start",
+                 BT_FN_BOOL_LONG_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR,
+                 ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_DOACROSS_START,
+                 "GOMP_loop_doacross_start",
+                 BT_FN_BOOL_UINT_LONGPTR_LONG_LONG_LONGPTR_LONGPTR_PTR_PTR,
+                 ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_STATIC_NEXT, "GOMP_loop_static_next",
                  BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_DYNAMIC_NEXT, "GOMP_loop_dynamic_next",
@@ -168,6 +190,12 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_NONMONOTONIC_DYNAMIC_NEXT,
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_NONMONOTONIC_GUIDED_NEXT,
                  "GOMP_loop_nonmonotonic_guided_next",
                  BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_NONMONOTONIC_RUNTIME_NEXT,
+                 "GOMP_loop_nonmonotonic_runtime_next",
+                 BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_NEXT,
+                 "GOMP_loop_maybe_nonmonotonic_runtime_next",
+                 BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ORDERED_STATIC_NEXT,
                  "GOMP_loop_ordered_static_next",
                  BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LEAF_LIST)
@@ -204,6 +232,14 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_GUIDED_START,
                  "GOMP_loop_ull_nonmonotonic_guided_start",
                  BT_FN_BOOL_BOOL_ULL_ULL_ULL_ULL_ULLPTR_ULLPTR,
                  ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_START,
+                 "GOMP_loop_ull_nonmonotonic_runtime_start",
+                 BT_FN_BOOL_BOOL_ULL_ULL_ULL_ULL_ULLPTR_ULLPTR,
+                 ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_START,
+                 "GOMP_loop_ull_maybe_nonmonotonic_runtime_start",
+                 BT_FN_BOOL_BOOL_ULL_ULL_ULL_ULL_ULLPTR_ULLPTR,
+                 ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_ORDERED_STATIC_START,
                  "GOMP_loop_ull_ordered_static_start",
                  BT_FN_BOOL_BOOL_ULL_ULL_ULL_ULL_ULLPTR_ULLPTR,
@@ -236,6 +272,18 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_DOACROSS_RUNTIME_START,
                  "GOMP_loop_ull_doacross_runtime_start",
                  BT_FN_BOOL_UINT_ULLPTR_ULLPTR_ULLPTR,
                  ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_START,
+                 "GOMP_loop_ull_start",
+                 BT_FN_BOOL_BOOL_ULL_ULL_ULL_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR,
+                 ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_ORDERED_START,
+                 "GOMP_loop_ull_ordered_start",
+                 BT_FN_BOOL_BOOL_ULL_ULL_ULL_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR,
+                 ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_DOACROSS_START,
+                 "GOMP_loop_ull_doacross_start",
+                 BT_FN_BOOL_UINT_ULLPTR_LONG_ULL_ULLPTR_ULLPTR_PTR_PTR,
+                 ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_STATIC_NEXT,
                  "GOMP_loop_ull_static_next",
                  BT_FN_BOOL_ULONGLONGPTR_ULONGLONGPTR, ATTR_NOTHROW_LEAF_LIST)
@@ -254,6 +302,12 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_DYNAMIC_NEXT,
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_GUIDED_NEXT,
                  "GOMP_loop_ull_nonmonotonic_guided_next",
                  BT_FN_BOOL_ULONGLONGPTR_ULONGLONGPTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_NEXT,
+                 "GOMP_loop_ull_nonmonotonic_runtime_next",
+                 BT_FN_BOOL_ULONGLONGPTR_ULONGLONGPTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_NEXT,
+                 "GOMP_loop_ull_maybe_nonmonotonic_runtime_next",
+                 BT_FN_BOOL_ULONGLONGPTR_ULONGLONGPTR, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT,
                  "GOMP_loop_ull_ordered_static_next",
                  BT_FN_BOOL_ULONGLONGPTR_ULONGLONGPTR, ATTR_NOTHROW_LEAF_LIST)
@@ -293,6 +347,14 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_PARALLEL_LOOP_NONMONOTONIC_GUIDED,
                  "GOMP_parallel_loop_nonmonotonic_guided",
                  BT_FN_VOID_OMPFN_PTR_UINT_LONG_LONG_LONG_LONG_UINT,
                  ATTR_NOTHROW_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_PARALLEL_LOOP_NONMONOTONIC_RUNTIME,
+                 "GOMP_parallel_loop_nonmonotonic_runtime",
+                 BT_FN_VOID_OMPFN_PTR_UINT_LONG_LONG_LONG_LONG_UINT,
+                 ATTR_NOTHROW_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_PARALLEL_LOOP_MAYBE_NONMONOTONIC_RUNTIME,
+                 "GOMP_parallel_loop_maybe_nonmonotonic_runtime",
+                 BT_FN_VOID_OMPFN_PTR_UINT_LONG_LONG_LONG_LONG_UINT,
+                 ATTR_NOTHROW_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_END, "GOMP_loop_end",
                  BT_FN_VOID, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_END_CANCEL, "GOMP_loop_end_cancel",
@@ -313,6 +375,9 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_DOACROSS_ULL_WAIT, "GOMP_doacross_ull_wait",
                  BT_FN_VOID_ULL_VAR, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_PARALLEL, "GOMP_parallel",
                  BT_FN_VOID_OMPFN_PTR_UINT_UINT, ATTR_NOTHROW_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_PARALLEL_REDUCTIONS,
+                 "GOMP_parallel_reductions",
+                 BT_FN_UINT_OMPFN_PTR_UINT_UINT, ATTR_NOTHROW_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASK, "GOMP_task",
                  BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT,
                  ATTR_NOTHROW_LIST)
@@ -324,6 +389,8 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKLOOP_ULL, "GOMP_taskloop_ull",
                  ATTR_NOTHROW_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SECTIONS_START, "GOMP_sections_start",
                  BT_FN_UINT_UINT, ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SECTIONS2_START, "GOMP_sections2_start",
+                 BT_FN_UINT_UINT_PTR_PTR, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SECTIONS_NEXT, "GOMP_sections_next",
                  BT_FN_UINT, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_PARALLEL_SECTIONS,
@@ -363,5 +430,19 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TARGET_ENTER_EXIT_DATA,
                  BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_UINT_PTR, ATTR_NOTHROW_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TEAMS, "GOMP_teams",
                  BT_FN_VOID_UINT_UINT, ATTR_NOTHROW_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TEAMS_REG, "GOMP_teams_reg",
+                 BT_FN_VOID_OMPFN_PTR_UINT_UINT_UINT, ATTR_NOTHROW_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKGROUP_REDUCTION_REGISTER,
+                 "GOMP_taskgroup_reduction_register",
+                 BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKGROUP_REDUCTION_UNREGISTER,
+                 "GOMP_taskgroup_reduction_unregister",
+                 BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASK_REDUCTION_REMAP,
+                 "GOMP_task_reduction_remap",
+                 BT_FN_VOID_SIZE_SIZE_PTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_WORKSHARE_TASK_REDUCTION_UNREGISTER,
+                 "GOMP_workshare_task_reduction_unregister",
+                 BT_FN_VOID_BOOL, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOACC_BUILTIN (BUILT_IN_GOACC_DECLARE, "GOACC_declare",
                   BT_FN_VOID_INT_SIZE_PTR_PTR_PTR, ATTR_NOTHROW_LIST)
index 1185a26619ae46a46167b226423867af846618d9..95b89a6dd4572d96b3b318ef50e04a408ffd909e 100644 (file)
@@ -174,6 +174,8 @@ workshare_safe_to_combine_p (basic_block ws_entry_bb)
     return true;
 
   gcc_assert (gimple_code (ws_stmt) == GIMPLE_OMP_FOR);
+  if (gimple_omp_for_kind (ws_stmt) != GF_OMP_FOR_KIND_FOR)
+    return false;
 
   omp_extract_for_data (as_a <gomp_for *> (ws_stmt), &fd, NULL);
 
@@ -202,7 +204,7 @@ workshare_safe_to_combine_p (basic_block ws_entry_bb)
 static tree
 omp_adjust_chunk_size (tree chunk_size, bool simd_schedule)
 {
-  if (!simd_schedule)
+  if (!simd_schedule || integer_zerop (chunk_size))
     return chunk_size;
 
   poly_uint64 vf = omp_max_vf ();
@@ -310,6 +312,13 @@ determine_parallel_type (struct omp_region *region)
   ws_entry_bb = region->inner->entry;
   ws_exit_bb = region->inner->exit;
 
+  /* Give up for task reductions on the parallel, while it is implementable,
+     adding another big set of APIs or slowing down the normal paths is
+     not acceptable.  */
+  tree pclauses = gimple_omp_parallel_clauses (last_stmt (par_entry_bb));
+  if (omp_find_clause (pclauses, OMP_CLAUSE__REDUCTEMP_))
+    return;
+
   if (single_succ (par_entry_bb) == ws_entry_bb
       && single_succ (ws_exit_bb) == par_exit_bb
       && workshare_safe_to_combine_p (ws_entry_bb)
@@ -336,13 +345,14 @@ determine_parallel_type (struct omp_region *region)
          if (c == NULL
              || ((OMP_CLAUSE_SCHEDULE_KIND (c) & OMP_CLAUSE_SCHEDULE_MASK)
                  == OMP_CLAUSE_SCHEDULE_STATIC)
-             || omp_find_clause (clauses, OMP_CLAUSE_ORDERED))
-           {
-             region->is_combined_parallel = false;
-             region->inner->is_combined_parallel = false;
-             return;
-           }
+             || omp_find_clause (clauses, OMP_CLAUSE_ORDERED)
+             || omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_))
+           return;
        }
+      else if (region->inner->type == GIMPLE_OMP_SECTIONS
+              && omp_find_clause (gimple_omp_sections_clauses (ws_stmt),
+                                  OMP_CLAUSE__REDUCTEMP_))
+       return;
 
       region->is_combined_parallel = true;
       region->inner->is_combined_parallel = true;
@@ -534,7 +544,7 @@ adjust_context_and_scope (tree entry_block, tree child_fndecl)
     }
 }
 
-/* Build the function calls to GOMP_parallel_start etc to actually
+/* Build the function calls to GOMP_parallel etc to actually
    generate the parallel operation.  REGION is the parallel region
    being expanded.  BB is the block where to insert the code.  WS_ARGS
    will be set if this is a call to a combined parallel+workshare
@@ -559,7 +569,10 @@ expand_parallel_call (struct omp_region *region, basic_block bb,
   /* Determine what flavor of GOMP_parallel we will be
      emitting.  */
   start_ix = BUILT_IN_GOMP_PARALLEL;
-  if (is_combined_parallel (region))
+  tree rtmp = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_);
+  if (rtmp)
+    start_ix = BUILT_IN_GOMP_PARALLEL_REDUCTIONS;
+  else if (is_combined_parallel (region))
     {
       switch (region->inner->type)
        {
@@ -568,12 +581,19 @@ expand_parallel_call (struct omp_region *region, basic_block bb,
          switch (region->inner->sched_kind)
            {
            case OMP_CLAUSE_SCHEDULE_RUNTIME:
-             start_ix2 = 3;
+             if ((region->inner->sched_modifiers
+                  & OMP_CLAUSE_SCHEDULE_NONMONOTONIC) != 0)
+               start_ix2 = 6;
+             else if ((region->inner->sched_modifiers
+                       & OMP_CLAUSE_SCHEDULE_MONOTONIC) == 0)
+               start_ix2 = 7;
+             else
+               start_ix2 = 3;
              break;
            case OMP_CLAUSE_SCHEDULE_DYNAMIC:
            case OMP_CLAUSE_SCHEDULE_GUIDED:
-             if (region->inner->sched_modifiers
-                 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC)
+             if ((region->inner->sched_modifiers
+                  & OMP_CLAUSE_SCHEDULE_MONOTONIC) == 0)
                {
                  start_ix2 = 3 + region->inner->sched_kind;
                  break;
@@ -716,6 +736,13 @@ expand_parallel_call (struct omp_region *region, basic_block bb,
   t = build_call_expr_loc_vec (UNKNOWN_LOCATION,
                               builtin_decl_explicit (start_ix), args);
 
+  if (rtmp)
+    {
+      tree type = TREE_TYPE (OMP_CLAUSE_DECL (rtmp));
+      t = build2 (MODIFY_EXPR, type, OMP_CLAUSE_DECL (rtmp),
+                 fold_convert (type,
+                               fold_convert (pointer_sized_int_node, t)));
+    }
   force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
                            false, GSI_CONTINUE_LINKING);
 
@@ -792,6 +819,8 @@ expand_task_call (struct omp_region *region, basic_block bb,
       if (omp_find_clause (tclauses, OMP_CLAUSE_NOGROUP))
        iflags |= GOMP_TASK_FLAG_NOGROUP;
       ull = fd.iter_type == long_long_unsigned_type_node;
+      if (omp_find_clause (clauses, OMP_CLAUSE_REDUCTION))
+       iflags |= GOMP_TASK_FLAG_REDUCTION;
     }
   else if (priority)
     iflags |= GOMP_TASK_FLAG_PRIORITY;
@@ -866,6 +895,82 @@ expand_task_call (struct omp_region *region, basic_block bb,
                            false, GSI_CONTINUE_LINKING);
 }
 
+/* Build the function call to GOMP_taskwait_depend to actually
+   generate the taskwait operation.  BB is the block where to insert the
+   code.  */
+
+static void
+expand_taskwait_call (basic_block bb, gomp_task *entry_stmt)
+{
+  tree clauses = gimple_omp_task_clauses (entry_stmt);
+  tree depend = omp_find_clause (clauses, OMP_CLAUSE_DEPEND);
+  if (depend == NULL_TREE)
+    return;
+
+  depend = OMP_CLAUSE_DECL (depend);
+
+  gimple_stmt_iterator gsi = gsi_last_nondebug_bb (bb);
+  tree t
+    = build_call_expr (builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT_DEPEND),
+                      1, depend);
+
+  force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
+                           false, GSI_CONTINUE_LINKING);
+}
+
+/* Build the function call to GOMP_teams_reg to actually
+   generate the host teams operation.  REGION is the teams region
+   being expanded.  BB is the block where to insert the code.  */
+
+static void
+expand_teams_call (basic_block bb, gomp_teams *entry_stmt)
+{
+  tree clauses = gimple_omp_teams_clauses (entry_stmt);
+  tree num_teams = omp_find_clause (clauses, OMP_CLAUSE_NUM_TEAMS);
+  if (num_teams == NULL_TREE)
+    num_teams = build_int_cst (unsigned_type_node, 0);
+  else
+    {
+      num_teams = OMP_CLAUSE_NUM_TEAMS_EXPR (num_teams);
+      num_teams = fold_convert (unsigned_type_node, num_teams);
+    }
+  tree thread_limit = omp_find_clause (clauses, OMP_CLAUSE_THREAD_LIMIT);
+  if (thread_limit == NULL_TREE)
+    thread_limit = build_int_cst (unsigned_type_node, 0);
+  else
+    {
+      thread_limit = OMP_CLAUSE_THREAD_LIMIT_EXPR (thread_limit);
+      thread_limit = fold_convert (unsigned_type_node, thread_limit);
+    }
+
+  gimple_stmt_iterator gsi = gsi_last_nondebug_bb (bb);
+  tree t = gimple_omp_teams_data_arg (entry_stmt), t1;
+  if (t == NULL)
+    t1 = null_pointer_node;
+  else
+    t1 = build_fold_addr_expr (t);
+  tree child_fndecl = gimple_omp_teams_child_fn (entry_stmt);
+  tree t2 = build_fold_addr_expr (child_fndecl);
+
+  adjust_context_and_scope (gimple_block (entry_stmt), child_fndecl);
+
+  vec<tree, va_gc> *args;
+  vec_alloc (args, 5);
+  args->quick_push (t2);
+  args->quick_push (t1);
+  args->quick_push (num_teams);
+  args->quick_push (thread_limit);
+  /* For future extensibility.  */
+  args->quick_push (build_zero_cst (unsigned_type_node));
+
+  t = build_call_expr_loc_vec (UNKNOWN_LOCATION,
+                              builtin_decl_explicit (BUILT_IN_GOMP_TEAMS_REG),
+                              args);
+
+  force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
+                           false, GSI_CONTINUE_LINKING);
+}
+
 /* Chain all the DECLs in LIST by their TREE_CHAIN fields.  */
 
 static tree
@@ -1112,6 +1217,17 @@ expand_omp_taskreg (struct omp_region *region)
   vec<tree, va_gc> *ws_args;
 
   entry_stmt = last_stmt (region->entry);
+  if (gimple_code (entry_stmt) == GIMPLE_OMP_TASK
+      && gimple_omp_task_taskwait_p (entry_stmt))
+    {
+      new_bb = region->entry;
+      gsi = gsi_last_nondebug_bb (region->entry);
+      gcc_assert (gimple_code (gsi_stmt (gsi)) == GIMPLE_OMP_TASK);
+      gsi_remove (&gsi, true);
+      expand_taskwait_call (new_bb, as_a <gomp_task *> (entry_stmt));
+      return;
+    }
+
   child_fn = gimple_omp_taskreg_child_fn (entry_stmt);
   child_cfun = DECL_STRUCT_FUNCTION (child_fn);
 
@@ -1137,7 +1253,8 @@ expand_omp_taskreg (struct omp_region *region)
 
       gsi = gsi_last_nondebug_bb (entry_bb);
       gcc_assert (gimple_code (gsi_stmt (gsi)) == GIMPLE_OMP_PARALLEL
-                 || gimple_code (gsi_stmt (gsi)) == GIMPLE_OMP_TASK);
+                 || gimple_code (gsi_stmt (gsi)) == GIMPLE_OMP_TASK
+                 || gimple_code (gsi_stmt (gsi)) == GIMPLE_OMP_TEAMS);
       gsi_remove (&gsi, true);
 
       new_bb = entry_bb;
@@ -1190,8 +1307,8 @@ expand_omp_taskreg (struct omp_region *region)
                     effectively doing a STRIP_NOPS.  */
 
                  if (TREE_CODE (arg) == ADDR_EXPR
-                     && TREE_OPERAND (arg, 0)
-                       == gimple_omp_taskreg_data_arg (entry_stmt))
+                     && (TREE_OPERAND (arg, 0)
+                         == gimple_omp_taskreg_data_arg (entry_stmt)))
                    {
                      parcopy_stmt = stmt;
                      break;
@@ -1251,12 +1368,13 @@ expand_omp_taskreg (struct omp_region *region)
       gsi = gsi_last_nondebug_bb (entry_bb);
       stmt = gsi_stmt (gsi);
       gcc_assert (stmt && (gimple_code (stmt) == GIMPLE_OMP_PARALLEL
-                          || gimple_code (stmt) == GIMPLE_OMP_TASK));
+                          || gimple_code (stmt) == GIMPLE_OMP_TASK
+                          || gimple_code (stmt) == GIMPLE_OMP_TEAMS));
       e = split_block (entry_bb, stmt);
       gsi_remove (&gsi, true);
       entry_bb = e->dest;
       edge e2 = NULL;
-      if (gimple_code (entry_stmt) == GIMPLE_OMP_PARALLEL)
+      if (gimple_code (entry_stmt) != GIMPLE_OMP_TASK)
        single_succ_edge (entry_bb)->flags = EDGE_FALLTHRU;
       else
        {
@@ -1382,6 +1500,8 @@ expand_omp_taskreg (struct omp_region *region)
   if (gimple_code (entry_stmt) == GIMPLE_OMP_PARALLEL)
     expand_parallel_call (region, new_bb,
                          as_a <gomp_parallel *> (entry_stmt), ws_args);
+  else if (gimple_code (entry_stmt) == GIMPLE_OMP_TEAMS)
+    expand_teams_call (new_bb, as_a <gomp_teams *> (entry_stmt));
   else
     expand_task_call (region, new_bb, as_a <gomp_task *> (entry_stmt));
   if (gimple_in_ssa_p (cfun))
@@ -2499,6 +2619,7 @@ expand_omp_for_generic (struct omp_region *region,
                        struct omp_for_data *fd,
                        enum built_in_function start_fn,
                        enum built_in_function next_fn,
+                       tree sched_arg,
                        gimple *inner_stmt)
 {
   tree type, istart0, iend0, iend;
@@ -2546,6 +2667,30 @@ expand_omp_for_generic (struct omp_region *region,
       && omp_find_clause (gimple_omp_for_clauses (gsi_stmt (gsi)),
                          OMP_CLAUSE_LASTPRIVATE))
     ordered_lastprivate = false;
+  tree reductions = NULL_TREE;
+  tree mem = NULL_TREE;
+  if (sched_arg)
+    {
+      if (fd->have_reductemp)
+       {
+         tree c = omp_find_clause (gimple_omp_for_clauses (gsi_stmt (gsi)),
+                                   OMP_CLAUSE__REDUCTEMP_);
+         reductions = OMP_CLAUSE_DECL (c);
+         gcc_assert (TREE_CODE (reductions) == SSA_NAME);
+         gimple *g = SSA_NAME_DEF_STMT (reductions);
+         reductions = gimple_assign_rhs1 (g);
+         OMP_CLAUSE_DECL (c) = reductions;
+         entry_bb = gimple_bb (g);
+         edge e = split_block (entry_bb, g);
+         if (region->entry == entry_bb)
+           region->entry = e->dest;
+         gsi = gsi_last_bb (entry_bb);
+       }
+      else
+       reductions = null_pointer_node;
+      /* For now.  */
+      mem = null_pointer_node;
+    }
   if (fd->collapse > 1 || fd->ordered)
     {
       int first_zero_iter1 = -1, first_zero_iter2 = -1;
@@ -2732,7 +2877,18 @@ expand_omp_for_generic (struct omp_region *region,
            {
              t = fold_convert (fd->iter_type, fd->chunk_size);
              t = omp_adjust_chunk_size (t, fd->simd_schedule);
-             if (fd->ordered)
+             if (sched_arg)
+               {
+                 if (fd->ordered)
+                   t = build_call_expr (builtin_decl_explicit (start_fn),
+                                        8, t0, t1, sched_arg, t, t3, t4,
+                                        reductions, mem);
+                 else
+                   t = build_call_expr (builtin_decl_explicit (start_fn),
+                                        9, t0, t1, t2, sched_arg, t, t3, t4,
+                                        reductions, mem);
+               }
+             else if (fd->ordered)
                t = build_call_expr (builtin_decl_explicit (start_fn),
                                     5, t0, t1, t, t3, t4);
              else
@@ -2765,7 +2921,11 @@ expand_omp_for_generic (struct omp_region *region,
              tree bfn_decl = builtin_decl_explicit (start_fn);
              t = fold_convert (fd->iter_type, fd->chunk_size);
              t = omp_adjust_chunk_size (t, fd->simd_schedule);
-             t = build_call_expr (bfn_decl, 7, t5, t0, t1, t2, t, t3, t4);
+             if (sched_arg)
+               t = build_call_expr (bfn_decl, 10, t5, t0, t1, t2, sched_arg,
+                                    t, t3, t4, reductions, mem);
+             else
+               t = build_call_expr (bfn_decl, 7, t5, t0, t1, t2, t, t3, t4);
            }
          else
            t = build_call_expr (builtin_decl_explicit (start_fn),
@@ -2784,6 +2944,17 @@ expand_omp_for_generic (struct omp_region *region,
       gsi_insert_before (&gsi, gimple_build_assign (arr, clobber),
                         GSI_SAME_STMT);
     }
+  if (fd->have_reductemp)
+    {
+      gimple *g = gsi_stmt (gsi);
+      gsi_remove (&gsi, true);
+      release_ssa_name (gimple_assign_lhs (g));
+
+      entry_bb = region->entry;
+      gsi = gsi_last_nondebug_bb (entry_bb);
+
+      gcc_assert (gimple_code (gsi_stmt (gsi)) == GIMPLE_OMP_FOR);
+    }
   gsi_insert_after (&gsi, gimple_build_cond_empty (t), GSI_SAME_STMT);
 
   /* Remove the GIMPLE_OMP_FOR statement.  */
@@ -3082,9 +3253,6 @@ expand_omp_for_generic (struct omp_region *region,
   else
     t = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END);
   gcall *call_stmt = gimple_build_call (t, 0);
-  if (gimple_omp_return_lhs (gsi_stmt (gsi)))
-    gimple_call_set_lhs (call_stmt, gimple_omp_return_lhs (gsi_stmt (gsi)));
-  gsi_insert_after (&gsi, call_stmt, GSI_SAME_STMT);
   if (fd->ordered)
     {
       tree arr = counts[fd->ordered];
@@ -3093,6 +3261,17 @@ expand_omp_for_generic (struct omp_region *region,
       gsi_insert_after (&gsi, gimple_build_assign (arr, clobber),
                        GSI_SAME_STMT);
     }
+  if (gimple_omp_return_lhs (gsi_stmt (gsi)))
+    {
+      gimple_call_set_lhs (call_stmt, gimple_omp_return_lhs (gsi_stmt (gsi)));
+      if (fd->have_reductemp)
+       {
+         gimple *g = gimple_build_assign (reductions, NOP_EXPR,
+                                          gimple_call_lhs (call_stmt));
+         gsi_insert_after (&gsi, g, GSI_SAME_STMT);
+       }
+    }
+  gsi_insert_after (&gsi, call_stmt, GSI_SAME_STMT);
   gsi_remove (&gsi, true);
 
   /* Connect the new blocks.  */
@@ -3275,6 +3454,7 @@ expand_omp_for_static_nochunk (struct omp_region *region,
   bool broken_loop = region->cont == NULL;
   tree *counts = NULL;
   tree n1, n2, step;
+  tree reductions = NULL_TREE;
 
   itype = type = TREE_TYPE (fd->loop.v);
   if (POINTER_TYPE_P (type))
@@ -3358,6 +3538,29 @@ expand_omp_for_static_nochunk (struct omp_region *region,
       gsi = gsi_last_bb (entry_bb);
     }
 
+  if (fd->have_reductemp)
+    {
+      tree t1 = build_int_cst (long_integer_type_node, 0);
+      tree t2 = build_int_cst (long_integer_type_node, 1);
+      tree t3 = build_int_cstu (long_integer_type_node,
+                               (HOST_WIDE_INT_1U << 31) + 1);
+      tree clauses = gimple_omp_for_clauses (fd->for_stmt);
+      clauses = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_);
+      reductions = OMP_CLAUSE_DECL (clauses);
+      gcc_assert (TREE_CODE (reductions) == SSA_NAME);
+      gimple *g = SSA_NAME_DEF_STMT (reductions);
+      reductions = gimple_assign_rhs1 (g);
+      OMP_CLAUSE_DECL (clauses) = reductions;
+      gimple_stmt_iterator gsi2 = gsi_for_stmt (g);
+      tree t
+       = build_call_expr (builtin_decl_explicit (BUILT_IN_GOMP_LOOP_START),
+                          9, t1, t2, t2, t3, t1, null_pointer_node,
+                          null_pointer_node, reductions, null_pointer_node);
+      force_gimple_operand_gsi (&gsi2, t, true, NULL_TREE,
+                               true, GSI_SAME_STMT);
+      gsi_remove (&gsi2, true);
+      release_ssa_name (gimple_assign_lhs (g));
+    }
   switch (gimple_omp_for_kind (fd->for_stmt))
     {
     case GF_OMP_FOR_KIND_FOR:
@@ -3628,7 +3831,25 @@ expand_omp_for_static_nochunk (struct omp_region *region,
   if (!gimple_omp_return_nowait_p (gsi_stmt (gsi)))
     {
       t = gimple_omp_return_lhs (gsi_stmt (gsi));
-      gsi_insert_after (&gsi, omp_build_barrier (t), GSI_SAME_STMT);
+      if (fd->have_reductemp)
+       {
+         tree fn;
+         if (t)
+           fn = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END_CANCEL);
+         else
+           fn = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END);
+         gcall *g = gimple_build_call (fn, 0);
+         if (t)
+           {
+             gimple_call_set_lhs (g, t);
+             gsi_insert_after (&gsi, gimple_build_assign (reductions,
+                                                          NOP_EXPR, t),
+                               GSI_SAME_STMT);
+           }
+         gsi_insert_after (&gsi, g, GSI_SAME_STMT);
+       }
+      else
+       gsi_insert_after (&gsi, omp_build_barrier (t), GSI_SAME_STMT);
     }
   gsi_remove (&gsi, true);
 
@@ -3765,6 +3986,7 @@ expand_omp_for_static_chunk (struct omp_region *region,
   bool broken_loop = region->cont == NULL;
   tree *counts = NULL;
   tree n1, n2, step;
+  tree reductions = NULL_TREE;
 
   itype = type = TREE_TYPE (fd->loop.v);
   if (POINTER_TYPE_P (type))
@@ -3852,6 +4074,29 @@ expand_omp_for_static_chunk (struct omp_region *region,
       gsi = gsi_last_bb (entry_bb);
     }
 
+  if (fd->have_reductemp)
+    {
+      tree t1 = build_int_cst (long_integer_type_node, 0);
+      tree t2 = build_int_cst (long_integer_type_node, 1);
+      tree t3 = build_int_cstu (long_integer_type_node,
+                               (HOST_WIDE_INT_1U << 31) + 1);
+      tree clauses = gimple_omp_for_clauses (fd->for_stmt);
+      clauses = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_);
+      reductions = OMP_CLAUSE_DECL (clauses);
+      gcc_assert (TREE_CODE (reductions) == SSA_NAME);
+      gimple *g = SSA_NAME_DEF_STMT (reductions);
+      reductions = gimple_assign_rhs1 (g);
+      OMP_CLAUSE_DECL (clauses) = reductions;
+      gimple_stmt_iterator gsi2 = gsi_for_stmt (g);
+      tree t
+       = build_call_expr (builtin_decl_explicit (BUILT_IN_GOMP_LOOP_START),
+                          9, t1, t2, t2, t3, t1, null_pointer_node,
+                          null_pointer_node, reductions, null_pointer_node);
+      force_gimple_operand_gsi (&gsi2, t, true, NULL_TREE,
+                               true, GSI_SAME_STMT);
+      gsi_remove (&gsi2, true);
+      release_ssa_name (gimple_assign_lhs (g));
+    }
   switch (gimple_omp_for_kind (fd->for_stmt))
     {
     case GF_OMP_FOR_KIND_FOR:
@@ -4155,7 +4400,25 @@ expand_omp_for_static_chunk (struct omp_region *region,
   if (!gimple_omp_return_nowait_p (gsi_stmt (gsi)))
     {
       t = gimple_omp_return_lhs (gsi_stmt (gsi));
-      gsi_insert_after (&gsi, omp_build_barrier (t), GSI_SAME_STMT);
+      if (fd->have_reductemp)
+       {
+         tree fn;
+         if (t)
+           fn = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END_CANCEL);
+         else
+           fn = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END);
+         gcall *g = gimple_build_call (fn, 0);
+         if (t)
+           {
+             gimple_call_set_lhs (g, t);
+             gsi_insert_after (&gsi, gimple_build_assign (reductions,
+                                                          NOP_EXPR, t),
+                               GSI_SAME_STMT);
+           }
+         gsi_insert_after (&gsi, g, GSI_SAME_STMT);
+       }
+      else
+       gsi_insert_after (&gsi, omp_build_barrier (t), GSI_SAME_STMT);
     }
   gsi_remove (&gsi, true);
 
@@ -5690,39 +5953,72 @@ expand_omp_for (struct omp_region *region, gimple *inner_stmt)
   else
     {
       int fn_index, start_ix, next_ix;
+      unsigned HOST_WIDE_INT sched = 0;
+      tree sched_arg = NULL_TREE;
 
       gcc_assert (gimple_omp_for_kind (fd.for_stmt)
                  == GF_OMP_FOR_KIND_FOR);
       if (fd.chunk_size == NULL
          && fd.sched_kind == OMP_CLAUSE_SCHEDULE_STATIC)
        fd.chunk_size = integer_zero_node;
-      gcc_assert (fd.sched_kind != OMP_CLAUSE_SCHEDULE_AUTO);
       switch (fd.sched_kind)
        {
        case OMP_CLAUSE_SCHEDULE_RUNTIME:
-         fn_index = 3;
+         if ((fd.sched_modifiers & OMP_CLAUSE_SCHEDULE_NONMONOTONIC) != 0)
+           {
+             gcc_assert (!fd.have_ordered);
+             fn_index = 6;
+             sched = 4;
+           }
+         else if ((fd.sched_modifiers & OMP_CLAUSE_SCHEDULE_MONOTONIC) == 0
+                  && !fd.have_ordered)
+           fn_index = 7;
+         else
+           {
+             fn_index = 3;
+             sched = (HOST_WIDE_INT_1U << 31);
+           }
          break;
        case OMP_CLAUSE_SCHEDULE_DYNAMIC:
        case OMP_CLAUSE_SCHEDULE_GUIDED:
-         if ((fd.sched_modifiers & OMP_CLAUSE_SCHEDULE_NONMONOTONIC)
-             && !fd.ordered
+         if ((fd.sched_modifiers & OMP_CLAUSE_SCHEDULE_MONOTONIC) == 0
              && !fd.have_ordered)
            {
              fn_index = 3 + fd.sched_kind;
+             sched = (fd.sched_kind == OMP_CLAUSE_SCHEDULE_GUIDED) + 2;
              break;
            }
-         /* FALLTHRU */
-       default:
          fn_index = fd.sched_kind;
+         sched = (fd.sched_kind == OMP_CLAUSE_SCHEDULE_GUIDED) + 2;
+         sched += (HOST_WIDE_INT_1U << 31);
          break;
+       case OMP_CLAUSE_SCHEDULE_STATIC:
+         gcc_assert (fd.have_ordered);
+         fn_index = 0;
+         sched = (HOST_WIDE_INT_1U << 31) + 1;
+         break;
+       default:
+         gcc_unreachable ();
        }
       if (!fd.ordered)
-       fn_index += fd.have_ordered * 6;
+       fn_index += fd.have_ordered * 8;
       if (fd.ordered)
        start_ix = ((int)BUILT_IN_GOMP_LOOP_DOACROSS_STATIC_START) + fn_index;
       else
        start_ix = ((int)BUILT_IN_GOMP_LOOP_STATIC_START) + fn_index;
       next_ix = ((int)BUILT_IN_GOMP_LOOP_STATIC_NEXT) + fn_index;
+      if (fd.have_reductemp)
+       {
+         if (fd.ordered)
+           start_ix = (int)BUILT_IN_GOMP_LOOP_DOACROSS_START;
+         else if (fd.have_ordered)
+           start_ix = (int)BUILT_IN_GOMP_LOOP_ORDERED_START;
+         else
+           start_ix = (int)BUILT_IN_GOMP_LOOP_START;
+         sched_arg = build_int_cstu (long_integer_type_node, sched);
+         if (!fd.chunk_size)
+           fd.chunk_size = integer_zero_node;
+       }
       if (fd.iter_type == long_long_unsigned_type_node)
        {
          start_ix += ((int)BUILT_IN_GOMP_LOOP_ULL_STATIC_START
@@ -5731,7 +6027,8 @@ expand_omp_for (struct omp_region *region, gimple *inner_stmt)
                      - (int)BUILT_IN_GOMP_LOOP_STATIC_NEXT);
        }
       expand_omp_for_generic (region, &fd, (enum built_in_function) start_ix,
-                             (enum built_in_function) next_ix, inner_stmt);
+                             (enum built_in_function) next_ix, sched_arg,
+                             inner_stmt);
     }
 
   if (gimple_in_ssa_p (cfun))
@@ -5831,7 +6128,25 @@ expand_omp_sections (struct omp_region *region)
   sections_stmt = as_a <gomp_sections *> (gsi_stmt (si));
   gcc_assert (gimple_code (sections_stmt) == GIMPLE_OMP_SECTIONS);
   vin = gimple_omp_sections_control (sections_stmt);
-  if (!is_combined_parallel (region))
+  tree clauses = gimple_omp_sections_clauses (sections_stmt);
+  tree reductmp = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_);
+  if (reductmp)
+    {
+      tree reductions = OMP_CLAUSE_DECL (reductmp);
+      gcc_assert (TREE_CODE (reductions) == SSA_NAME);
+      gimple *g = SSA_NAME_DEF_STMT (reductions);
+      reductions = gimple_assign_rhs1 (g);
+      OMP_CLAUSE_DECL (reductmp) = reductions;
+      gimple_stmt_iterator gsi = gsi_for_stmt (g);
+      t = build_int_cst (unsigned_type_node, len - 1);
+      u = builtin_decl_explicit (BUILT_IN_GOMP_SECTIONS2_START);
+      stmt = gimple_build_call (u, 3, t, reductions, null_pointer_node);
+      gimple_call_set_lhs (stmt, vin);
+      gsi_insert_before (&gsi, stmt, GSI_SAME_STMT);
+      gsi_remove (&gsi, true);
+      release_ssa_name (gimple_assign_lhs (g));
+    }
+  else if (!is_combined_parallel (region))
     {
       /* If we are not inside a combined parallel+sections region,
         call GOMP_sections_start.  */
@@ -5845,8 +6160,11 @@ expand_omp_sections (struct omp_region *region)
       u = builtin_decl_explicit (BUILT_IN_GOMP_SECTIONS_NEXT);
       stmt = gimple_build_call (u, 0);
     }
-  gimple_call_set_lhs (stmt, vin);
-  gsi_insert_after (&si, stmt, GSI_SAME_STMT);
+  if (!reductmp)
+    {
+      gimple_call_set_lhs (stmt, vin);
+      gsi_insert_after (&si, stmt, GSI_SAME_STMT);
+    }
   gsi_remove (&si, true);
 
   /* The switch() statement replacing GIMPLE_OMP_SECTIONS_SWITCH goes in
@@ -6004,6 +6322,12 @@ expand_omp_synch (struct omp_region *region)
              || gimple_code (gsi_stmt (si)) == GIMPLE_OMP_ORDERED
              || gimple_code (gsi_stmt (si)) == GIMPLE_OMP_CRITICAL
              || gimple_code (gsi_stmt (si)) == GIMPLE_OMP_TEAMS);
+  if (gimple_code (gsi_stmt (si)) == GIMPLE_OMP_TEAMS
+      && gimple_omp_teams_host (as_a <gomp_teams *> (gsi_stmt (si))))
+    {
+      expand_omp_taskreg (region);
+      return;
+    }
   gsi_remove (&si, true);
   single_succ_edge (entry_bb)->flags = EDGE_FALLTHRU;
 
@@ -6016,6 +6340,24 @@ expand_omp_synch (struct omp_region *region)
     }
 }
 
+/* Translate enum omp_memory_order to enum memmodel.  The two enums
+   are using different numbers so that OMP_MEMORY_ORDER_UNSPECIFIED
+   is 0.  */
+
+static enum memmodel
+omp_memory_order_to_memmodel (enum omp_memory_order mo)
+{
+  switch (mo)
+    {
+    case OMP_MEMORY_ORDER_RELAXED: return MEMMODEL_RELAXED;
+    case OMP_MEMORY_ORDER_ACQUIRE: return MEMMODEL_ACQUIRE;
+    case OMP_MEMORY_ORDER_RELEASE: return MEMMODEL_RELEASE;
+    case OMP_MEMORY_ORDER_ACQ_REL: return MEMMODEL_ACQ_REL;
+    case OMP_MEMORY_ORDER_SEQ_CST: return MEMMODEL_SEQ_CST;
+    default: gcc_unreachable ();
+    }
+}
+
 /* A subroutine of expand_omp_atomic.  Attempt to implement the atomic
    operation as a normal volatile load.  */
 
@@ -6047,11 +6389,9 @@ expand_omp_atomic_load (basic_block load_bb, tree addr,
   type = TREE_TYPE (loaded_val);
   itype = TREE_TYPE (TREE_TYPE (decl));
 
-  call = build_call_expr_loc (loc, decl, 2, addr,
-                             build_int_cst (NULL,
-                                            gimple_omp_atomic_seq_cst_p (stmt)
-                                            ? MEMMODEL_SEQ_CST
-                                            : MEMMODEL_RELAXED));
+  enum omp_memory_order omo = gimple_omp_atomic_memory_order (stmt);
+  tree mo = build_int_cst (NULL, omp_memory_order_to_memmodel (omo));
+  call = build_call_expr_loc (loc, decl, 2, addr, mo);
   if (!useless_type_conversion_p (type, itype))
     call = fold_build1_loc (loc, VIEW_CONVERT_EXPR, type, call);
   call = build2_loc (loc, MODIFY_EXPR, void_type_node, loaded_val, call);
@@ -6122,11 +6462,9 @@ expand_omp_atomic_store (basic_block load_bb, tree addr,
 
   if (!useless_type_conversion_p (itype, type))
     stored_val = fold_build1_loc (loc, VIEW_CONVERT_EXPR, itype, stored_val);
-  call = build_call_expr_loc (loc, decl, 3, addr, stored_val,
-                             build_int_cst (NULL,
-                                            gimple_omp_atomic_seq_cst_p (stmt)
-                                            ? MEMMODEL_SEQ_CST
-                                            : MEMMODEL_RELAXED));
+  enum omp_memory_order omo = gimple_omp_atomic_memory_order (stmt);
+  tree mo = build_int_cst (NULL, omp_memory_order_to_memmodel (omo));
+  call = build_call_expr_loc (loc, decl, 3, addr, stored_val, mo);
   if (exchange)
     {
       if (!useless_type_conversion_p (type, itype))
@@ -6167,7 +6505,6 @@ expand_omp_atomic_fetch_op (basic_block load_bb,
   enum tree_code code;
   bool need_old, need_new;
   machine_mode imode;
-  bool seq_cst;
 
   /* We expect to find the following sequences:
 
@@ -6200,7 +6537,9 @@ expand_omp_atomic_fetch_op (basic_block load_bb,
     return false;
   need_new = gimple_omp_atomic_need_value_p (gsi_stmt (gsi));
   need_old = gimple_omp_atomic_need_value_p (last_stmt (load_bb));
-  seq_cst = gimple_omp_atomic_seq_cst_p (last_stmt (load_bb));
+  enum omp_memory_order omo
+    = gimple_omp_atomic_memory_order (last_stmt (load_bb));
+  enum memmodel mo = omp_memory_order_to_memmodel (omo);
   gcc_checking_assert (!need_old || !need_new);
 
   if (!operand_equal_p (gimple_assign_lhs (stmt), stored_val, 0))
@@ -6267,9 +6606,7 @@ expand_omp_atomic_fetch_op (basic_block load_bb,
      use the RELAXED memory model.  */
   call = build_call_expr_loc (loc, decl, 3, addr,
                              fold_convert_loc (loc, itype, rhs),
-                             build_int_cst (NULL,
-                                            seq_cst ? MEMMODEL_SEQ_CST
-                                                    : MEMMODEL_RELAXED));
+                             build_int_cst (NULL, mo));
 
   if (need_old || need_new)
     {
@@ -7921,6 +8258,10 @@ build_omp_regions_1 (basic_block bb, struct omp_region *parent,
            /* #pragma omp ordered depend is also just a stand-alone
               directive.  */
            region = NULL;
+         else if (code == GIMPLE_OMP_TASK
+                  && gimple_omp_task_taskwait_p (stmt))
+           /* #pragma omp taskwait depend(...) is a stand-alone directive.  */
+           region = NULL;
          /* ..., this directive becomes the parent for a new region.  */
          if (region)
            parent = region;
@@ -8111,7 +8452,6 @@ omp_make_gimple_edges (basic_block bb, struct omp_region **region,
   switch (code)
     {
     case GIMPLE_OMP_PARALLEL:
-    case GIMPLE_OMP_TASK:
     case GIMPLE_OMP_FOR:
     case GIMPLE_OMP_SINGLE:
     case GIMPLE_OMP_TEAMS:
@@ -8124,6 +8464,13 @@ omp_make_gimple_edges (basic_block bb, struct omp_region **region,
       fallthru = true;
       break;
 
+    case GIMPLE_OMP_TASK:
+      cur_region = new_omp_region (bb, code, cur_region);
+      fallthru = true;
+      if (gimple_omp_task_taskwait_p (last))
+       cur_region = cur_region->outer;
+      break;
+
     case GIMPLE_OMP_ORDERED:
       cur_region = new_omp_region (bb, code, cur_region);
       fallthru = true;
index cabbbbc6de2cd74a17d8e37cafb2470218d399bc..99d8226ef213d18cd3ffdbf092494d58c6fd2a51 100644 (file)
@@ -36,6 +36,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "stringpool.h"
 #include "attribs.h"
 
+enum omp_requires omp_requires_mask;
+
 tree
 omp_find_clause (tree clauses, enum omp_clause_code kind)
 {
@@ -136,6 +138,7 @@ omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd,
   fd->pre = NULL;
   fd->have_nowait = distribute || simd;
   fd->have_ordered = false;
+  fd->have_reductemp = false;
   fd->tiling = NULL_TREE;
   fd->collapse = 1;
   fd->ordered = 0;
@@ -186,6 +189,8 @@ omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd,
        collapse_iter = &OMP_CLAUSE_TILE_ITERVAR (t);
        collapse_count = &OMP_CLAUSE_TILE_COUNT (t);
        break;
+      case OMP_CLAUSE__REDUCTEMP_:
+       fd->have_reductemp = true;
       default:
        break;
       }
@@ -250,13 +255,45 @@ omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd,
 
       loop->cond_code = gimple_omp_for_cond (for_stmt, i);
       loop->n2 = gimple_omp_for_final (for_stmt, i);
-      gcc_assert (loop->cond_code != NE_EXPR);
+      gcc_assert (loop->cond_code != NE_EXPR
+                 || (gimple_omp_for_kind (for_stmt)
+                     != GF_OMP_FOR_KIND_OACC_LOOP));
       omp_adjust_for_condition (loc, &loop->cond_code, &loop->n2);
 
       t = gimple_omp_for_incr (for_stmt, i);
       gcc_assert (TREE_OPERAND (t, 0) == var);
       loop->step = omp_get_for_step_from_incr (loc, t);
 
+      if (loop->cond_code == NE_EXPR)
+       {
+         gcc_assert (TREE_CODE (loop->step) == INTEGER_CST);
+         if (TREE_CODE (TREE_TYPE (loop->v)) == INTEGER_TYPE)
+           {
+             if (integer_onep (loop->step))
+               loop->cond_code = LT_EXPR;
+             else
+               {
+                 gcc_assert (integer_minus_onep (loop->step));
+                 loop->cond_code = GT_EXPR;
+               }
+           }
+         else
+           {
+             tree unit = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (loop->v)));
+             gcc_assert (TREE_CODE (unit) == INTEGER_CST);
+             if (tree_int_cst_equal (unit, loop->step))
+               loop->cond_code = LT_EXPR;
+             else
+               {
+                 gcc_assert (wi::neg (wi::to_widest (unit))
+                             == wi::to_widest (loop->step));
+                 loop->cond_code = GT_EXPR;
+               }
+           }
+       }
+
+      omp_adjust_for_condition (loc, &loop->cond_code, &loop->n2);
+
       if (simd
          || (fd->sched_kind == OMP_CLAUSE_SCHEDULE_STATIC
              && !fd->have_ordered))
@@ -281,9 +318,8 @@ omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd,
              tree n;
 
              if (loop->cond_code == LT_EXPR)
-               n = fold_build2_loc (loc,
-                                PLUS_EXPR, TREE_TYPE (loop->v),
-                                loop->n2, loop->step);
+               n = fold_build2_loc (loc, PLUS_EXPR, TREE_TYPE (loop->v),
+                                    loop->n2, loop->step);
              else
                n = loop->n1;
              if (TREE_CODE (n) != INTEGER_CST
@@ -298,15 +334,13 @@ omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd,
              if (loop->cond_code == LT_EXPR)
                {
                  n1 = loop->n1;
-                 n2 = fold_build2_loc (loc,
-                                   PLUS_EXPR, TREE_TYPE (loop->v),
-                                   loop->n2, loop->step);
+                 n2 = fold_build2_loc (loc, PLUS_EXPR, TREE_TYPE (loop->v),
+                                       loop->n2, loop->step);
                }
              else
                {
-                 n1 = fold_build2_loc (loc,
-                                   MINUS_EXPR, TREE_TYPE (loop->v),
-                                   loop->n2, loop->step);
+                 n1 = fold_build2_loc (loc, MINUS_EXPR, TREE_TYPE (loop->v),
+                                       loop->n2, loop->step);
                  n2 = loop->n1;
                }
              if (TREE_CODE (n1) != INTEGER_CST
@@ -338,27 +372,31 @@ omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd,
              if (POINTER_TYPE_P (itype))
                itype = signed_type_for (itype);
              t = build_int_cst (itype, (loop->cond_code == LT_EXPR ? -1 : 1));
-             t = fold_build2_loc (loc,
-                              PLUS_EXPR, itype,
-                              fold_convert_loc (loc, itype, loop->step), t);
+             t = fold_build2_loc (loc, PLUS_EXPR, itype,
+                                  fold_convert_loc (loc, itype, loop->step),
+                                  t);
              t = fold_build2_loc (loc, PLUS_EXPR, itype, t,
-                              fold_convert_loc (loc, itype, loop->n2));
+                                  fold_convert_loc (loc, itype, loop->n2));
              t = fold_build2_loc (loc, MINUS_EXPR, itype, t,
-                              fold_convert_loc (loc, itype, loop->n1));
+                                  fold_convert_loc (loc, itype, loop->n1));
              if (TYPE_UNSIGNED (itype) && loop->cond_code == GT_EXPR)
-               t = fold_build2_loc (loc, TRUNC_DIV_EXPR, itype,
-                                fold_build1_loc (loc, NEGATE_EXPR, itype, t),
-                                fold_build1_loc (loc, NEGATE_EXPR, itype,
-                                             fold_convert_loc (loc, itype,
-                                                               loop->step)));
+               {
+                 tree step = fold_convert_loc (loc, itype, loop->step);
+                 t = fold_build2_loc (loc, TRUNC_DIV_EXPR, itype,
+                                      fold_build1_loc (loc, NEGATE_EXPR,
+                                                       itype, t),
+                                      fold_build1_loc (loc, NEGATE_EXPR,
+                                                       itype, step));
+               }
              else
                t = fold_build2_loc (loc, TRUNC_DIV_EXPR, itype, t,
-                                fold_convert_loc (loc, itype, loop->step));
+                                    fold_convert_loc (loc, itype,
+                                                      loop->step));
              t = fold_convert_loc (loc, long_long_unsigned_type_node, t);
              if (count != NULL_TREE)
-               count = fold_build2_loc (loc,
-                                    MULT_EXPR, long_long_unsigned_type_node,
-                                    count, t);
+               count = fold_build2_loc (loc, MULT_EXPR,
+                                        long_long_unsigned_type_node,
+                                        count, t);
              else
                count = t;
              if (TREE_CODE (count) != INTEGER_CST)
index 66f0a33c2e2fb75e8e5dab1753101c9ba7747275..b847506d45282092e64e55eca4709c61f52c42d7 100644 (file)
@@ -62,7 +62,7 @@ struct omp_for_data
   tree tiling;  /* Tiling values (if non null).  */
   int collapse;  /* Collapsed loops, 1 for a non-collapsed loop.  */
   int ordered;
-  bool have_nowait, have_ordered, simd_schedule;
+  bool have_nowait, have_ordered, simd_schedule, have_reductemp;
   unsigned char sched_modifiers;
   enum omp_clause_schedule_kind sched_kind;
   struct omp_for_data_loop *loops;
@@ -89,4 +89,16 @@ extern bool offloading_function_p (tree fn);
 extern int oacc_get_fn_dim_size (tree fn, int axis);
 extern int oacc_get_ifn_dim_arg (const gimple *stmt);
 
+enum omp_requires {
+  OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER = 0xf,
+  OMP_REQUIRES_UNIFIED_ADDRESS = 0x10,
+  OMP_REQUIRES_UNIFIED_SHARED_MEMORY = 0x20,
+  OMP_REQUIRES_DYNAMIC_ALLOCATORS = 0x40,
+  OMP_REQUIRES_REVERSE_OFFLOAD = 0x80,
+  OMP_REQUIRES_ATOMIC_DEFAULT_MEM_ORDER_USED = 0x100,
+  OMP_REQUIRES_TARGET_USED = 0x200
+};
+
+extern GTY(()) enum omp_requires omp_requires_mask;
+
 #endif /* GCC_OMP_GENERAL_H */
index 6edc92fd51980396482220d959324f25d73c396a..d443bce169b9f8b040e03d4d21fe4882272250c1 100644 (file)
@@ -1053,8 +1053,8 @@ grid_eliminate_combined_simd_part (gomp_for *parloop)
   while (*tgt)
     tgt = &OMP_CLAUSE_CHAIN (*tgt);
 
-  /* Copy over all clauses, except for linaer clauses, which are turned into
-     private clauses, and all other simd-specificl clauses, which are
+  /* Copy over all clauses, except for linear clauses, which are turned into
+     private clauses, and all other simd-specific clauses, which are
      ignored.  */
   tree *pc = gimple_omp_for_clauses_ptr (simd);
   while (*pc)
@@ -1083,7 +1083,7 @@ grid_eliminate_combined_simd_part (gomp_for *parloop)
          *pc = OMP_CLAUSE_CHAIN (c);
          OMP_CLAUSE_CHAIN (c) = NULL;
          *tgt = c;
-         tgt = &OMP_CLAUSE_CHAIN(c);
+         tgt = &OMP_CLAUSE_CHAIN (c);
          break;
        }
     }
index b06ddb385767283c64da3cb290dea1b0fe51b1fe..ca78d7abe26ba9dd14d635d3298dc023f2020e6a 100644 (file)
@@ -114,6 +114,15 @@ struct omp_context
      otherwise.  */
   gimple *simt_stmt;
 
+  /* For task reductions registered in this context, a vector containing
+     the length of the private copies block (if constant, otherwise NULL)
+     and then offsets (if constant, otherwise NULL) for each entry.  */
+  vec<tree> task_reductions;
+
+  /* And a hash map from the reduction clauses to the registered array
+     elts.  */
+  hash_map<tree, unsigned> *task_reduction_map;
+
   /* Nesting depth of this context.  Used to beautify error messages re
      invalid gotos.  The outermost ctx is depth 1, with depth 0 being
      reserved for the main body of the function.  */
@@ -280,12 +289,23 @@ is_taskloop_ctx (omp_context *ctx)
 }
 
 
-/* Return true if CTX is for an omp parallel or omp task.  */
+/* Return true if CTX is for a host omp teams.  */
+
+static inline bool
+is_host_teams_ctx (omp_context *ctx)
+{
+  return gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS
+        && gimple_omp_teams_host (as_a <gomp_teams *> (ctx->stmt));
+}
+
+/* Return true if CTX is for an omp parallel or omp task or host omp teams
+   (the last one is strictly not a task region in OpenMP speak, but we
+   need to treat it similarly).  */
 
 static inline bool
 is_taskreg_ctx (omp_context *ctx)
 {
-  return is_parallel_ctx (ctx) || is_task_ctx (ctx);
+  return is_parallel_ctx (ctx) || is_task_ctx (ctx) || is_host_teams_ctx (ctx);
 }
 
 /* Return true if EXPR is variable sized.  */
@@ -371,7 +391,7 @@ use_pointer_for_field (tree decl, omp_context *shared_ctx)
         be passing an address in this case?  Should we simply assert
         this to be false, or should we have a cleanup pass that removes
         these from the list of mappings?  */
-      if (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
+      if (is_global_var (maybe_lookup_decl_in_outer_ctx (decl, shared_ctx)))
        return true;
 
       /* For variables with DECL_HAS_VALUE_EXPR_P set, we cannot tell
@@ -522,6 +542,9 @@ build_outer_var_ref (tree var, omp_context *ctx,
                     enum omp_clause_code code = OMP_CLAUSE_ERROR)
 {
   tree x;
+  omp_context *outer = ctx->outer;
+  while (outer && gimple_code (outer->stmt) == GIMPLE_OMP_TASKGROUP)
+    outer = outer->outer;
 
   if (is_global_var (maybe_lookup_decl_in_outer_ctx (var, ctx)))
     x = var;
@@ -548,44 +571,43 @@ build_outer_var_ref (tree var, omp_context *ctx,
         Similarly for OMP_CLAUSE_PRIVATE with outer ref, that can refer
         to private vars in all worksharing constructs.  */
       x = NULL_TREE;
-      if (ctx->outer && is_taskreg_ctx (ctx))
-       x = lookup_decl (var, ctx->outer);
-      else if (ctx->outer)
+      if (outer && is_taskreg_ctx (outer))
+       x = lookup_decl (var, outer);
+      else if (outer)
        x = maybe_lookup_decl_in_outer_ctx (var, ctx);
       if (x == NULL_TREE)
        x = var;
     }
   else if (code == OMP_CLAUSE_LASTPRIVATE && is_taskloop_ctx (ctx))
     {
-      gcc_assert (ctx->outer);
+      gcc_assert (outer);
       splay_tree_node n
-       = splay_tree_lookup (ctx->outer->field_map,
+       = splay_tree_lookup (outer->field_map,
                             (splay_tree_key) &DECL_UID (var));
       if (n == NULL)
        {
-         if (is_global_var (maybe_lookup_decl_in_outer_ctx (var, ctx->outer)))
+         if (is_global_var (maybe_lookup_decl_in_outer_ctx (var, outer)))
            x = var;
          else
-           x = lookup_decl (var, ctx->outer);
+           x = lookup_decl (var, outer);
        }
       else
        {
          tree field = (tree) n->value;
          /* If the receiver record type was remapped in the child function,
             remap the field into the new record type.  */
-         x = maybe_lookup_field (field, ctx->outer);
+         x = maybe_lookup_field (field, outer);
          if (x != NULL)
            field = x;
 
-         x = build_simple_mem_ref (ctx->outer->receiver_decl);
+         x = build_simple_mem_ref (outer->receiver_decl);
          x = omp_build_component_ref (x, field);
-         if (use_pointer_for_field (var, ctx->outer))
+         if (use_pointer_for_field (var, outer))
            x = build_simple_mem_ref (x);
        }
     }
-  else if (ctx->outer)
+  else if (outer)
     {
-      omp_context *outer = ctx->outer;
       if (gimple_code (outer->stmt) == GIMPLE_OMP_GRID_BODY)
        {
          outer = outer->outer;
@@ -925,6 +947,12 @@ delete_omp_context (splay_tree_value value)
   if (is_task_ctx (ctx))
     finalize_task_copyfn (as_a <gomp_task *> (ctx->stmt));
 
+  if (ctx->task_reduction_map)
+    {
+      ctx->task_reductions.release ();
+      delete ctx->task_reduction_map;
+    }
+
   XDELETE (ctx);
 }
 
@@ -1011,8 +1039,10 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
 
        case OMP_CLAUSE_SHARED:
          decl = OMP_CLAUSE_DECL (c);
-         /* Ignore shared directives in teams construct.  */
-         if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS)
+         /* Ignore shared directives in teams construct inside of
+            target construct.  */
+         if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS
+             && !is_host_teams_ctx (ctx))
            {
              /* Global variables don't need to be copied,
                 the receiver side will use them directly.  */
@@ -1050,9 +1080,9 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
          goto do_private;
 
        case OMP_CLAUSE_REDUCTION:
+       case OMP_CLAUSE_IN_REDUCTION:
          decl = OMP_CLAUSE_DECL (c);
-         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
-             && TREE_CODE (decl) == MEM_REF)
+         if (TREE_CODE (decl) == MEM_REF)
            {
              tree t = TREE_OPERAND (decl, 0);
              if (TREE_CODE (t) == POINTER_PLUS_EXPR)
@@ -1062,14 +1092,52 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
                t = TREE_OPERAND (t, 0);
              install_var_local (t, ctx);
              if (is_taskreg_ctx (ctx)
-                 && !is_global_var (maybe_lookup_decl_in_outer_ctx (t, ctx))
-                 && !is_variable_sized (t))
+                 && (!is_global_var (maybe_lookup_decl_in_outer_ctx (t, ctx))
+                     || (is_task_ctx (ctx)
+                         && (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE
+                             || (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE
+                                 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
+                                     == POINTER_TYPE)))))
+                 && !is_variable_sized (t)
+                 && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
+                     || (!OMP_CLAUSE_REDUCTION_TASK (c)
+                         && !is_task_ctx (ctx))))
                {
-                 by_ref = use_pointer_for_field (t, ctx);
-                 install_var_field (t, by_ref, 3, ctx);
+                 by_ref = use_pointer_for_field (t, NULL);
+                 if (is_task_ctx (ctx)
+                     && TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE
+                     && TREE_CODE (TREE_TYPE (TREE_TYPE (t))) == POINTER_TYPE)
+                   {
+                     install_var_field (t, false, 1, ctx);
+                     install_var_field (t, by_ref, 2, ctx);
+                   }
+                 else
+                   install_var_field (t, by_ref, 3, ctx);
                }
              break;
            }
+         if (is_task_ctx (ctx)
+             || (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+                 && OMP_CLAUSE_REDUCTION_TASK (c)
+                 && is_parallel_ctx (ctx)))
+           {
+             /* Global variables don't need to be copied,
+                the receiver side will use them directly.  */
+             if (!is_global_var (maybe_lookup_decl_in_outer_ctx (decl, ctx)))
+               {
+                 by_ref = use_pointer_for_field (decl, ctx);
+                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
+                   install_var_field (decl, by_ref, 3, ctx);
+               }
+             install_var_local (decl, ctx);
+             break;
+           }
+         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+             && OMP_CLAUSE_REDUCTION_TASK (c))
+           {
+             install_var_local (decl, ctx);
+             break;
+           }
          goto do_private;
 
        case OMP_CLAUSE_LASTPRIVATE:
@@ -1142,6 +1210,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
          goto do_private;
 
        case OMP_CLAUSE__LOOPTEMP_:
+       case OMP_CLAUSE__REDUCTEMP_:
          gcc_assert (is_taskreg_ctx (ctx));
          decl = OMP_CLAUSE_DECL (c);
          install_var_field (decl, false, 3, ctx);
@@ -1323,8 +1392,10 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
        case OMP_CLAUSE_TILE:
        case OMP_CLAUSE__SIMT_:
        case OMP_CLAUSE_DEFAULT:
+       case OMP_CLAUSE_NONTEMPORAL:
        case OMP_CLAUSE_IF_PRESENT:
        case OMP_CLAUSE_FINALIZE:
+       case OMP_CLAUSE_TASK_REDUCTION:
          break;
 
        case OMP_CLAUSE_ALIGNED:
@@ -1382,6 +1453,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
          break;
 
        case OMP_CLAUSE_REDUCTION:
+       case OMP_CLAUSE_IN_REDUCTION:
          decl = OMP_CLAUSE_DECL (c);
          if (TREE_CODE (decl) != MEM_REF)
            {
@@ -1393,9 +1465,16 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
            scan_array_reductions = true;
          break;
 
+       case OMP_CLAUSE_TASK_REDUCTION:
+         if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
+           scan_array_reductions = true;
+         break;
+
        case OMP_CLAUSE_SHARED:
-         /* Ignore shared directives in teams construct.  */
-         if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS)
+         /* Ignore shared directives in teams construct inside of
+            target construct.  */
+         if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS
+             && !is_host_teams_ctx (ctx))
            break;
          decl = OMP_CLAUSE_DECL (c);
          if (is_global_var (maybe_lookup_decl_in_outer_ctx (decl, ctx)))
@@ -1472,6 +1551,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
        case OMP_CLAUSE_ALIGNED:
        case OMP_CLAUSE_DEPEND:
        case OMP_CLAUSE__LOOPTEMP_:
+       case OMP_CLAUSE__REDUCTEMP_:
        case OMP_CLAUSE_TO:
        case OMP_CLAUSE_FROM:
        case OMP_CLAUSE_PRIORITY:
@@ -1482,6 +1562,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
        case OMP_CLAUSE_NOGROUP:
        case OMP_CLAUSE_DEFAULTMAP:
        case OMP_CLAUSE_USE_DEVICE_PTR:
+       case OMP_CLAUSE_NONTEMPORAL:
        case OMP_CLAUSE_ASYNC:
        case OMP_CLAUSE_WAIT:
        case OMP_CLAUSE_NUM_GANGS:
@@ -1511,7 +1592,9 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
   if (scan_array_reductions)
     {
       for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
-       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)
            && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
          {
            scan_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c), ctx);
@@ -1700,7 +1783,7 @@ omp_find_combined_for (gimple_stmt_iterator *gsi_p,
   return NULL;
 }
 
-/* Add _LOOPTEMP_ clauses on OpenMP parallel or task.  */
+/* Add _LOOPTEMP_/_REDUCTEMP_ clauses on OpenMP parallel or task.  */
 
 static void
 add_taskreg_looptemp_clauses (enum gf_mask msk, gimple *stmt,
@@ -1747,6 +1830,18 @@ add_taskreg_looptemp_clauses (enum gf_mask msk, gimple *stmt,
          gimple_omp_taskreg_set_clauses (stmt, c);
        }
     }
+  if (msk == GF_OMP_FOR_KIND_TASKLOOP
+      && omp_find_clause (gimple_omp_task_clauses (stmt),
+                         OMP_CLAUSE_REDUCTION))
+    {
+      tree type = build_pointer_type (pointer_sized_int_node);
+      tree temp = create_tmp_var (type);
+      tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__REDUCTEMP_);
+      insert_decl_map (&outer_ctx->cb, temp, temp);
+      OMP_CLAUSE_DECL (c) = temp;
+      OMP_CLAUSE_CHAIN (c) = gimple_omp_task_clauses (stmt);
+      gimple_omp_task_set_clauses (stmt, c);
+    }
 }
 
 /* Scan an OpenMP parallel directive.  */
@@ -1771,6 +1866,23 @@ scan_omp_parallel (gimple_stmt_iterator *gsi, omp_context *outer_ctx)
 
   if (gimple_omp_parallel_combined_p (stmt))
     add_taskreg_looptemp_clauses (GF_OMP_FOR_KIND_FOR, stmt, outer_ctx);
+  for (tree c = omp_find_clause (gimple_omp_parallel_clauses (stmt),
+                                OMP_CLAUSE_REDUCTION);
+       c; c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_REDUCTION))
+    if (OMP_CLAUSE_REDUCTION_TASK (c))
+      {
+       tree type = build_pointer_type (pointer_sized_int_node);
+       tree temp = create_tmp_var (type);
+       tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__REDUCTEMP_);
+       if (outer_ctx)
+         insert_decl_map (&outer_ctx->cb, temp, temp);
+       OMP_CLAUSE_DECL (c) = temp;
+       OMP_CLAUSE_CHAIN (c) = gimple_omp_parallel_clauses (stmt);
+       gimple_omp_parallel_set_clauses (stmt, c);
+       break;
+      }
+    else if (OMP_CLAUSE_CHAIN (c) == NULL_TREE)
+      break;
 
   ctx = new_omp_context (stmt, outer_ctx);
   taskreg_contexts.safe_push (ctx);
@@ -1810,6 +1922,7 @@ scan_omp_task (gimple_stmt_iterator *gsi, omp_context *outer_ctx)
   /* Ignore task directives with empty bodies, unless they have depend
      clause.  */
   if (optimize > 0
+      && gimple_omp_body (stmt)
       && empty_body_p (gimple_omp_body (stmt))
       && !omp_find_clause (gimple_omp_task_clauses (stmt), OMP_CLAUSE_DEPEND))
     {
@@ -1821,6 +1934,13 @@ scan_omp_task (gimple_stmt_iterator *gsi, omp_context *outer_ctx)
     add_taskreg_looptemp_clauses (GF_OMP_FOR_KIND_TASKLOOP, stmt, outer_ctx);
 
   ctx = new_omp_context (stmt, outer_ctx);
+
+  if (gimple_omp_task_taskwait_p (stmt))
+    {
+      scan_sharing_clauses (gimple_omp_task_clauses (stmt), ctx);
+      return;
+    }
+
   taskreg_contexts.safe_push (ctx);
   if (taskreg_nesting_level > 1)
     ctx->is_nested = true;
@@ -1897,7 +2017,7 @@ finish_taskreg_scan (omp_context *ctx)
     return;
 
   /* If any task_shared_vars were needed, verify all
-     OMP_CLAUSE_SHARED clauses on GIMPLE_OMP_{PARALLEL,TASK}
+     OMP_CLAUSE_SHARED clauses on GIMPLE_OMP_{PARALLEL,TASK,TEAMS}
      statements if use_pointer_for_field hasn't changed
      because of that.  If it did, update field types now.  */
   if (task_shared_vars)
@@ -1942,6 +2062,30 @@ finish_taskreg_scan (omp_context *ctx)
     }
 
   if (gimple_code (ctx->stmt) == GIMPLE_OMP_PARALLEL)
+    {
+      tree clauses = gimple_omp_parallel_clauses (ctx->stmt);
+      tree c = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_);
+      if (c)
+       {
+         /* Move the _reductemp_ clause first.  GOMP_parallel_reductions
+            expects to find it at the start of data.  */
+         tree f = lookup_field (OMP_CLAUSE_DECL (c), ctx);
+         tree *p = &TYPE_FIELDS (ctx->record_type);
+         while (*p)
+           if (*p == f)
+             {
+               *p = DECL_CHAIN (*p);
+               break;
+             }
+           else
+             p = &DECL_CHAIN (*p);
+         DECL_CHAIN (f) = TYPE_FIELDS (ctx->record_type);
+         TYPE_FIELDS (ctx->record_type) = f;
+       }
+      layout_type (ctx->record_type);
+      fixup_child_record_type (ctx);
+    }
+  else if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS)
     {
       layout_type (ctx->record_type);
       fixup_child_record_type (ctx);
@@ -1969,33 +2113,50 @@ finish_taskreg_scan (omp_context *ctx)
          /* Move fields corresponding to first and second _looptemp_
             clause first.  There are filled by GOMP_taskloop
             and thus need to be in specific positions.  */
-         tree c1 = gimple_omp_task_clauses (ctx->stmt);
-         c1 = omp_find_clause (c1, OMP_CLAUSE__LOOPTEMP_);
+         tree clauses = gimple_omp_task_clauses (ctx->stmt);
+         tree c1 = omp_find_clause (clauses, OMP_CLAUSE__LOOPTEMP_);
          tree c2 = omp_find_clause (OMP_CLAUSE_CHAIN (c1),
                                     OMP_CLAUSE__LOOPTEMP_);
+         tree c3 = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_);
          tree f1 = lookup_field (OMP_CLAUSE_DECL (c1), ctx);
          tree f2 = lookup_field (OMP_CLAUSE_DECL (c2), ctx);
+         tree f3 = c3 ? lookup_field (OMP_CLAUSE_DECL (c3), ctx) : NULL_TREE;
          p = &TYPE_FIELDS (ctx->record_type);
          while (*p)
-           if (*p == f1 || *p == f2)
+           if (*p == f1 || *p == f2 || *p == f3)
              *p = DECL_CHAIN (*p);
            else
              p = &DECL_CHAIN (*p);
          DECL_CHAIN (f1) = f2;
-         DECL_CHAIN (f2) = TYPE_FIELDS (ctx->record_type);
+         if (c3)
+           {
+             DECL_CHAIN (f2) = f3;
+             DECL_CHAIN (f3) = TYPE_FIELDS (ctx->record_type);
+           }
+         else
+           DECL_CHAIN (f2) = TYPE_FIELDS (ctx->record_type);
          TYPE_FIELDS (ctx->record_type) = f1;
          if (ctx->srecord_type)
            {
              f1 = lookup_sfield (OMP_CLAUSE_DECL (c1), ctx);
              f2 = lookup_sfield (OMP_CLAUSE_DECL (c2), ctx);
+             if (c3)
+               f3 = lookup_sfield (OMP_CLAUSE_DECL (c3), ctx);
              p = &TYPE_FIELDS (ctx->srecord_type);
              while (*p)
-               if (*p == f1 || *p == f2)
+               if (*p == f1 || *p == f2 || *p == f3)
                  *p = DECL_CHAIN (*p);
                else
                  p = &DECL_CHAIN (*p);
              DECL_CHAIN (f1) = f2;
              DECL_CHAIN (f2) = TYPE_FIELDS (ctx->srecord_type);
+             if (c3)
+               {
+                 DECL_CHAIN (f2) = f3;
+                 DECL_CHAIN (f3) = TYPE_FIELDS (ctx->srecord_type);
+               }
+             else
+               DECL_CHAIN (f2) = TYPE_FIELDS (ctx->srecord_type);
              TYPE_FIELDS (ctx->srecord_type) = f1;
            }
        }
@@ -2154,7 +2315,7 @@ scan_omp_for (gomp_for *stmt, omp_context *outer_ctx)
 
       if (tgt && is_oacc_kernels (tgt))
        {
-         /* Strip out reductions, as they are not  handled yet.  */
+         /* Strip out reductions, as they are not handled yet.  */
          tree *prev_ptr = &clauses;
 
          while (tree probe = *prev_ptr)
@@ -2321,8 +2482,32 @@ static void
 scan_omp_teams (gomp_teams *stmt, omp_context *outer_ctx)
 {
   omp_context *ctx = new_omp_context (stmt, outer_ctx);
+
+  if (!gimple_omp_teams_host (stmt))
+    {
+      scan_sharing_clauses (gimple_omp_teams_clauses (stmt), ctx);
+      scan_omp (gimple_omp_body_ptr (stmt), ctx);
+      return;
+    }
+  taskreg_contexts.safe_push (ctx);
+  gcc_assert (taskreg_nesting_level == 1);
+  ctx->field_map = splay_tree_new (splay_tree_compare_pointers, 0, 0);
+  ctx->record_type = lang_hooks.types.make_type (RECORD_TYPE);
+  tree name = create_tmp_var_name (".omp_data_s");
+  name = build_decl (gimple_location (stmt),
+                    TYPE_DECL, name, ctx->record_type);
+  DECL_ARTIFICIAL (name) = 1;
+  DECL_NAMELESS (name) = 1;
+  TYPE_NAME (ctx->record_type) = name;
+  TYPE_ARTIFICIAL (ctx->record_type) = 1;
+  create_omp_child_function (ctx, false);
+  gimple_omp_teams_set_child_fn (stmt, ctx->cb.dst_fn);
+
   scan_sharing_clauses (gimple_omp_teams_clauses (stmt), ctx);
   scan_omp (gimple_omp_body_ptr (stmt), ctx);
+
+  if (TYPE_FIELDS (ctx->record_type) == NULL)
+    ctx->record_type = ctx->receiver_decl = NULL;
 }
 
 /* Check nesting restrictions.  */
@@ -2388,9 +2573,13 @@ check_omp_nesting_restrictions (gimple *stmt, omp_context *ctx)
                  return true;
                }
            }
+         else if (gimple_code (stmt) == GIMPLE_OMP_ATOMIC_LOAD
+                  || gimple_code (stmt) == GIMPLE_OMP_ATOMIC_STORE)
+           return true;
          error_at (gimple_location (stmt),
                    "OpenMP constructs other than %<#pragma omp ordered simd%>"
-                   " may not be nested inside %<simd%> region");
+                   " or %<#pragma omp atomic%> may not be nested inside"
+                   " %<simd%> region");
          return false;
        }
       else if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS)
@@ -2814,13 +3003,20 @@ check_omp_nesting_restrictions (gimple *stmt, omp_context *ctx)
       }
       break;
     case GIMPLE_OMP_TEAMS:
-      if (ctx == NULL
-         || gimple_code (ctx->stmt) != GIMPLE_OMP_TARGET
-         || gimple_omp_target_kind (ctx->stmt) != GF_OMP_TARGET_KIND_REGION)
+      if (ctx == NULL)
+       break;
+      else if (gimple_code (ctx->stmt) != GIMPLE_OMP_TARGET
+              || (gimple_omp_target_kind (ctx->stmt)
+                  != GF_OMP_TARGET_KIND_REGION))
        {
+         /* Teams construct can appear either strictly nested inside of
+            target construct with no intervening stmts, or can be encountered
+            only by initial task (so must not appear inside any OpenMP
+            construct.  */
          error_at (gimple_location (stmt),
-                   "%<teams%> construct not closely nested inside of "
-                   "%<target%> construct");
+                   "%<teams%> construct must be closely nested inside of "
+                   "%<target%> construct or not nested in any OpenMP "
+                   "construct");
          return false;
        }
       break;
@@ -3090,7 +3286,6 @@ scan_omp_1_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
 
     case GIMPLE_OMP_SECTION:
     case GIMPLE_OMP_MASTER:
-    case GIMPLE_OMP_TASKGROUP:
     case GIMPLE_OMP_ORDERED:
     case GIMPLE_OMP_CRITICAL:
     case GIMPLE_OMP_GRID_BODY:
@@ -3098,12 +3293,25 @@ scan_omp_1_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
       scan_omp (gimple_omp_body_ptr (stmt), ctx);
       break;
 
+    case GIMPLE_OMP_TASKGROUP:
+      ctx = new_omp_context (stmt, ctx);
+      scan_sharing_clauses (gimple_omp_taskgroup_clauses (stmt), ctx);
+      scan_omp (gimple_omp_body_ptr (stmt), ctx);
+      break;
+
     case GIMPLE_OMP_TARGET:
       scan_omp_target (as_a <gomp_target *> (stmt), ctx);
       break;
 
     case GIMPLE_OMP_TEAMS:
-      scan_omp_teams (as_a <gomp_teams *> (stmt), ctx);
+      if (gimple_omp_teams_host (as_a <gomp_teams *> (stmt)))
+       {
+         taskreg_nesting_level++;
+         scan_omp_teams (as_a <gomp_teams *> (stmt), ctx);
+         taskreg_nesting_level--;
+       }
+      else
+       scan_omp_teams (as_a <gomp_teams *> (stmt), ctx);
       break;
 
     case GIMPLE_BIND:
@@ -3515,6 +3723,30 @@ handle_simd_reference (location_t loc, tree new_vard, gimple_seq *ilist)
     }
 }
 
+/* Helper function for lower_rec_input_clauses.  Emit into ilist sequence
+   code to emit (type) (tskred_temp[idx]).  */
+
+static tree
+task_reduction_read (gimple_seq *ilist, tree tskred_temp, tree type,
+                    unsigned idx)
+{
+  unsigned HOST_WIDE_INT sz
+    = tree_to_uhwi (TYPE_SIZE_UNIT (pointer_sized_int_node));
+  tree r = build2 (MEM_REF, pointer_sized_int_node,
+                  tskred_temp, build_int_cst (TREE_TYPE (tskred_temp),
+                                              idx * sz));
+  tree v = create_tmp_var (pointer_sized_int_node);
+  gimple *g = gimple_build_assign (v, r);
+  gimple_seq_add_stmt (ilist, g);
+  if (!useless_type_conversion_p (type, pointer_sized_int_node))
+    {
+      v = create_tmp_var (type);
+      g = gimple_build_assign (v, NOP_EXPR, gimple_assign_lhs (g));
+      gimple_seq_add_stmt (ilist, g);
+    }
+  return v;
+}
+
 /* Generate code to implement the input clauses, FIRSTPRIVATE and COPYIN,
    from the receiver (aka child) side and initializers for REFERENCE_TYPE
    private variables.  Initialization statements go in ILIST, while calls
@@ -3558,6 +3790,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
            sctx.max_vf = 1;
          break;
        case OMP_CLAUSE_REDUCTION:
+       case OMP_CLAUSE_IN_REDUCTION:
          if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF
              || is_variable_sized (OMP_CLAUSE_DECL (c)))
            sctx.max_vf = 1;
@@ -3570,18 +3803,87 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
   if (sctx.is_simt && maybe_ne (sctx.max_vf, 1U))
     sctx.simt_eargs.safe_push (NULL_TREE);
 
+  unsigned task_reduction_cnt = 0;
+  unsigned task_reduction_cntorig = 0;
+  unsigned task_reduction_cnt_full = 0;
+  unsigned task_reduction_cntorig_full = 0;
+  unsigned task_reduction_other_cnt = 0;
+  tree tskred_atype = NULL_TREE, tskred_avar = NULL_TREE;
+  tree tskred_base = NULL_TREE, tskred_temp = NULL_TREE;
   /* Do all the fixed sized types in the first pass, and the variable sized
      types in the second pass.  This makes sure that the scalar arguments to
      the variable sized types are processed before we use them in the
-     variable sized operations.  */
-  for (pass = 0; pass < 2; ++pass)
-    {
+     variable sized operations.  For task reductions we use 4 passes, in the
+     first two we ignore them, in the third one gather arguments for
+     GOMP_task_reduction_remap call and in the last pass actually handle
+     the task reductions.  */
+  for (pass = 0; pass < ((task_reduction_cnt || task_reduction_other_cnt)
+                        ? 4 : 2); ++pass)
+    {
+      if (pass == 2 && task_reduction_cnt)
+       {
+         tskred_atype
+           = build_array_type_nelts (ptr_type_node, task_reduction_cnt
+                                                    + task_reduction_cntorig);
+         tskred_avar = create_tmp_var_raw (tskred_atype);
+         gimple_add_tmp_var (tskred_avar);
+         TREE_ADDRESSABLE (tskred_avar) = 1;
+         task_reduction_cnt_full = task_reduction_cnt;
+         task_reduction_cntorig_full = task_reduction_cntorig;
+       }
+      else if (pass == 3 && task_reduction_cnt)
+       {
+         x = builtin_decl_explicit (BUILT_IN_GOMP_TASK_REDUCTION_REMAP);
+         gimple *g
+           = gimple_build_call (x, 3, size_int (task_reduction_cnt),
+                                size_int (task_reduction_cntorig),
+                                build_fold_addr_expr (tskred_avar));
+         gimple_seq_add_stmt (ilist, g);
+       }
+      if (pass == 3 && task_reduction_other_cnt)
+       {
+         /* For reduction clauses, build
+            tskred_base = (void *) tskred_temp[2]
+                          + omp_get_thread_num () * tskred_temp[1]
+            or if tskred_temp[1] is known to be constant, that constant
+            directly.  This is the start of the private reduction copy block
+            for the current thread.  */
+         tree v = create_tmp_var (integer_type_node);
+         x = builtin_decl_explicit (BUILT_IN_OMP_GET_THREAD_NUM);
+         gimple *g = gimple_build_call (x, 0);
+         gimple_call_set_lhs (g, v);
+         gimple_seq_add_stmt (ilist, g);
+         c = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_);
+         tskred_temp = OMP_CLAUSE_DECL (c);
+         if (is_taskreg_ctx (ctx))
+           tskred_temp = lookup_decl (tskred_temp, ctx);
+         tree v2 = create_tmp_var (sizetype);
+         g = gimple_build_assign (v2, NOP_EXPR, v);
+         gimple_seq_add_stmt (ilist, g);
+         if (ctx->task_reductions[0])
+           v = fold_convert (sizetype, ctx->task_reductions[0]);
+         else
+           v = task_reduction_read (ilist, tskred_temp, sizetype, 1);
+         tree v3 = create_tmp_var (sizetype);
+         g = gimple_build_assign (v3, MULT_EXPR, v2, v);
+         gimple_seq_add_stmt (ilist, g);
+         v = task_reduction_read (ilist, tskred_temp, ptr_type_node, 2);
+         tskred_base = create_tmp_var (ptr_type_node);
+         g = gimple_build_assign (tskred_base, POINTER_PLUS_EXPR, v, v3);
+         gimple_seq_add_stmt (ilist, g);
+       }
+      task_reduction_cnt = 0;
+      task_reduction_cntorig = 0;
+      task_reduction_other_cnt = 0;
       for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
        {
          enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
          tree var, new_var;
          bool by_ref;
          location_t clause_loc = OMP_CLAUSE_LOCATION (c);
+         bool task_reduction_p = false;
+         bool task_reduction_needs_orig_p = false;
+         tree cond = NULL_TREE;
 
          switch (c_kind)
            {
@@ -3590,8 +3892,10 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
                continue;
              break;
            case OMP_CLAUSE_SHARED:
-             /* Ignore shared directives in teams construct.  */
-             if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS)
+             /* Ignore shared directives in teams construct inside
+                of target construct.  */
+             if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS
+                 && !is_host_teams_ctx (ctx))
                continue;
              if (maybe_lookup_decl (OMP_CLAUSE_DECL (c), ctx) == NULL)
                {
@@ -3608,11 +3912,46 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
                lastprivate_firstprivate = true;
              break;
            case OMP_CLAUSE_REDUCTION:
-             if (OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c))
+           case OMP_CLAUSE_IN_REDUCTION:
+             if (is_task_ctx (ctx) || OMP_CLAUSE_REDUCTION_TASK (c))
+               {
+                 task_reduction_p = true;
+                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
+                   {
+                     task_reduction_other_cnt++;
+                     if (pass == 2)
+                       continue;
+                   }
+                 else
+                   task_reduction_cnt++;
+                 if (OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c))
+                   {
+                     var = OMP_CLAUSE_DECL (c);
+                     /* If var is a global variable that isn't privatized
+                        in outer contexts, we don't need to look up the
+                        original address, it is always the address of the
+                        global variable itself.  */
+                     if (!DECL_P (var)
+                         || omp_is_reference (var)
+                         || !is_global_var
+                               (maybe_lookup_decl_in_outer_ctx (var, ctx)))
+                       {
+                         task_reduction_needs_orig_p = true;
+                         if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
+                           task_reduction_cntorig++;
+                       }
+                   }
+               }
+             else if (OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c))
                reduction_omp_orig_ref = true;
              break;
+           case OMP_CLAUSE__REDUCTEMP_:
+             if (!is_taskreg_ctx (ctx))
+               continue;
+             /* FALLTHRU */
            case OMP_CLAUSE__LOOPTEMP_:
-             /* Handle _looptemp_ clauses only on parallel/task.  */
+             /* Handle _looptemp_/_reductemp_ clauses only on
+                parallel/task.  */
              if (fd)
                continue;
              break;
@@ -3632,7 +3971,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
                lastprivate_firstprivate = true;
              break;
            case OMP_CLAUSE_ALIGNED:
-             if (pass == 0)
+             if (pass != 1)
                continue;
              var = OMP_CLAUSE_DECL (c);
              if (TREE_CODE (TREE_TYPE (var)) == POINTER_TYPE
@@ -3673,8 +4012,13 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
              continue;
            }
 
+         if (task_reduction_p != (pass >= 2))
+           continue;
+
          new_var = var = OMP_CLAUSE_DECL (c);
-         if (c_kind == OMP_CLAUSE_REDUCTION && TREE_CODE (var) == MEM_REF)
+         if ((c_kind == OMP_CLAUSE_REDUCTION
+              || c_kind == OMP_CLAUSE_IN_REDUCTION)
+             && TREE_CODE (var) == MEM_REF)
            {
              var = TREE_OPERAND (var, 0);
              if (TREE_CODE (var) == POINTER_PLUS_EXPR)
@@ -3701,7 +4045,8 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
                continue;
            }
          /* C/C++ array section reductions.  */
-         else if (c_kind == OMP_CLAUSE_REDUCTION
+         else if ((c_kind == OMP_CLAUSE_REDUCTION
+                   || c_kind == OMP_CLAUSE_IN_REDUCTION)
                   && var != OMP_CLAUSE_DECL (c))
            {
              if (pass == 0)
@@ -3709,6 +4054,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
 
              tree bias = TREE_OPERAND (OMP_CLAUSE_DECL (c), 1);
              tree orig_var = TREE_OPERAND (OMP_CLAUSE_DECL (c), 0);
+
              if (TREE_CODE (orig_var) == POINTER_PLUS_EXPR)
                {
                  tree b = TREE_OPERAND (orig_var, 1);
@@ -3729,6 +4075,47 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
                    }
                  orig_var = TREE_OPERAND (orig_var, 0);
                }
+             if (pass == 2)
+               {
+                 tree out = maybe_lookup_decl_in_outer_ctx (var, ctx);
+                 if (is_global_var (out)
+                     && TREE_CODE (TREE_TYPE (out)) != POINTER_TYPE
+                     && (TREE_CODE (TREE_TYPE (out)) != REFERENCE_TYPE
+                         || (TREE_CODE (TREE_TYPE (TREE_TYPE (out)))
+                             != POINTER_TYPE)))
+                   x = var;
+                 else
+                   {
+                     bool by_ref = use_pointer_for_field (var, NULL);
+                     x = build_receiver_ref (var, by_ref, ctx);
+                     if (TREE_CODE (TREE_TYPE (var)) == REFERENCE_TYPE
+                         && (TREE_CODE (TREE_TYPE (TREE_TYPE (var)))
+                             == POINTER_TYPE))
+                       x = build_fold_addr_expr (x);
+                   }
+                 if (TREE_CODE (orig_var) == INDIRECT_REF)
+                   x = build_simple_mem_ref (x);
+                 else if (TREE_CODE (orig_var) == ADDR_EXPR)
+                   {
+                     if (var == TREE_OPERAND (orig_var, 0))
+                       x = build_fold_addr_expr (x);
+                   }
+                 bias = fold_convert (sizetype, bias);
+                 x = fold_convert (ptr_type_node, x);
+                 x = fold_build2_loc (clause_loc, POINTER_PLUS_EXPR,
+                                      TREE_TYPE (x), x, bias);
+                 unsigned cnt = task_reduction_cnt - 1;
+                 if (!task_reduction_needs_orig_p)
+                   cnt += (task_reduction_cntorig_full
+                           - task_reduction_cntorig);
+                 else
+                   cnt = task_reduction_cntorig - 1;
+                 tree r = build4 (ARRAY_REF, ptr_type_node, tskred_avar,
+                                  size_int (cnt), NULL_TREE, NULL_TREE);
+                 gimplify_assign (r, x, ilist);
+                 continue;
+               }
+
              if (TREE_CODE (orig_var) == INDIRECT_REF
                  || TREE_CODE (orig_var) == ADDR_EXPR)
                orig_var = TREE_OPERAND (orig_var, 0);
@@ -3737,7 +4124,64 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
              gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
              tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
              const char *name = get_name (orig_var);
-             if (TREE_CONSTANT (v))
+             if (pass == 3)
+               {
+                 tree xv = create_tmp_var (ptr_type_node);
+                 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
+                   {
+                     unsigned cnt = task_reduction_cnt - 1;
+                     if (!task_reduction_needs_orig_p)
+                       cnt += (task_reduction_cntorig_full
+                               - task_reduction_cntorig);
+                     else
+                       cnt = task_reduction_cntorig - 1;
+                     x = build4 (ARRAY_REF, ptr_type_node, tskred_avar,
+                                 size_int (cnt), NULL_TREE, NULL_TREE);
+
+                     gimple *g = gimple_build_assign (xv, x);
+                     gimple_seq_add_stmt (ilist, g);
+                   }
+                 else
+                   {
+                     unsigned int idx = *ctx->task_reduction_map->get (c);
+                     tree off;
+                     if (ctx->task_reductions[1 + idx])
+                       off = fold_convert (sizetype,
+                                           ctx->task_reductions[1 + idx]);
+                     else
+                       off = task_reduction_read (ilist, tskred_temp, sizetype,
+                                                  7 + 3 * idx + 1);
+                     gimple *g = gimple_build_assign (xv, POINTER_PLUS_EXPR,
+                                                      tskred_base, off);
+                     gimple_seq_add_stmt (ilist, g);
+                   }
+                 x = fold_convert (build_pointer_type (boolean_type_node),
+                                   xv);
+                 if (TREE_CONSTANT (v))
+                   x = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (x), x,
+                                    TYPE_SIZE_UNIT (type));
+                 else
+                   {
+                     tree t = maybe_lookup_decl (v, ctx);
+                     if (t)
+                       v = t;
+                     else
+                       v = maybe_lookup_decl_in_outer_ctx (v, ctx);
+                     gimplify_expr (&v, ilist, NULL, is_gimple_val,
+                                    fb_rvalue);
+                     t = fold_build2_loc (clause_loc, PLUS_EXPR,
+                                          TREE_TYPE (v), v,
+                                          build_int_cst (TREE_TYPE (v), 1));
+                     t = fold_build2_loc (clause_loc, MULT_EXPR,
+                                          TREE_TYPE (v), t,
+                                          TYPE_SIZE_UNIT (TREE_TYPE (type)));
+                     x = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (x), x, t);
+                   }
+                 cond = create_tmp_var (TREE_TYPE (x));
+                 gimplify_assign (cond, x, ilist);
+                 x = xv;
+               }
+             else if (TREE_CONSTANT (v))
                {
                  x = create_tmp_var_raw (type, name);
                  gimple_add_tmp_var (x);
@@ -3799,7 +4243,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
                      tree new_orig_var = lookup_decl (orig_var, ctx);
                      tree t = build_fold_indirect_ref (new_var);
                      DECL_IGNORED_P (new_var) = 0;
-                     TREE_THIS_NOTRAP (t);
+                     TREE_THIS_NOTRAP (t) = 1;
                      SET_DECL_VALUE_EXPR (new_orig_var, t);
                      DECL_HAS_VALUE_EXPR_P (new_orig_var) = 1;
                    }
@@ -3824,44 +4268,101 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
                  x = fold_convert_loc (clause_loc, TREE_TYPE (new_var), x);
                  gimplify_assign (new_var, x, ilist);
                }
-             tree y1 = create_tmp_var (ptype, NULL);
+             /* GOMP_taskgroup_reduction_register memsets the whole
+                array to zero.  If the initializer is zero, we don't
+                need to initialize it again, just mark it as ever
+                used unconditionally, i.e. cond = true.  */
+             if (cond
+                 && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE
+                 && initializer_zerop (omp_reduction_init (c,
+                                                           TREE_TYPE (type))))
+               {
+                 gimple *g = gimple_build_assign (build_simple_mem_ref (cond),
+                                                  boolean_true_node);
+                 gimple_seq_add_stmt (ilist, g);
+                 continue;
+               }
+             tree end = create_artificial_label (UNKNOWN_LOCATION);
+             if (cond)
+               {
+                 gimple *g;
+                 if (!is_parallel_ctx (ctx))
+                   {
+                     tree condv = create_tmp_var (boolean_type_node);
+                     g = gimple_build_assign (condv,
+                                              build_simple_mem_ref (cond));
+                     gimple_seq_add_stmt (ilist, g);
+                     tree lab1 = create_artificial_label (UNKNOWN_LOCATION);
+                     g = gimple_build_cond (NE_EXPR, condv,
+                                            boolean_false_node, end, lab1);
+                     gimple_seq_add_stmt (ilist, g);
+                     gimple_seq_add_stmt (ilist, gimple_build_label (lab1));
+                   }
+                 g = gimple_build_assign (build_simple_mem_ref (cond),
+                                          boolean_true_node);
+                 gimple_seq_add_stmt (ilist, g);
+               }
+
+             tree y1 = create_tmp_var (ptype);
              gimplify_assign (y1, y, ilist);
              tree i2 = NULL_TREE, y2 = NULL_TREE;
              tree body2 = NULL_TREE, end2 = NULL_TREE;
              tree y3 = NULL_TREE, y4 = NULL_TREE;
-             if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) || is_simd)
+             if (task_reduction_needs_orig_p)
                {
-                 y2 = create_tmp_var (ptype, NULL);
-                 gimplify_assign (y2, y, ilist);
-                 tree ref = build_outer_var_ref (var, ctx);
-                 /* For ref build_outer_var_ref already performs this.  */
-                 if (TREE_CODE (d) == INDIRECT_REF)
-                   gcc_assert (omp_is_reference (var));
-                 else if (TREE_CODE (d) == ADDR_EXPR)
-                   ref = build_fold_addr_expr (ref);
-                 else if (omp_is_reference (var))
-                   ref = build_fold_addr_expr (ref);
-                 ref = fold_convert_loc (clause_loc, ptype, ref);
-                 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
-                     && OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c))
+                 y3 = create_tmp_var (ptype);
+                 tree ref;
+                 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
+                   ref = build4 (ARRAY_REF, ptr_type_node, tskred_avar,
+                                 size_int (task_reduction_cnt_full
+                                           + task_reduction_cntorig - 1),
+                                 NULL_TREE, NULL_TREE);
+                 else
                    {
-                     y3 = create_tmp_var (ptype, NULL);
-                     gimplify_assign (y3, unshare_expr (ref), ilist);
+                     unsigned int idx = *ctx->task_reduction_map->get (c);
+                     ref = task_reduction_read (ilist, tskred_temp, ptype,
+                                                7 + 3 * idx);
                    }
-                 if (is_simd)
+                 gimplify_assign (y3, ref, ilist);
+               }
+             else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) || is_simd)
+               {
+                 if (pass != 3)
                    {
-                     y4 = create_tmp_var (ptype, NULL);
-                     gimplify_assign (y4, ref, dlist);
+                     y2 = create_tmp_var (ptype);
+                     gimplify_assign (y2, y, ilist);
+                   }
+                 if (is_simd || OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c))
+                   {
+                     tree ref = build_outer_var_ref (var, ctx);
+                     /* For ref build_outer_var_ref already performs this.  */
+                     if (TREE_CODE (d) == INDIRECT_REF)
+                       gcc_assert (omp_is_reference (var));
+                     else if (TREE_CODE (d) == ADDR_EXPR)
+                       ref = build_fold_addr_expr (ref);
+                     else if (omp_is_reference (var))
+                       ref = build_fold_addr_expr (ref);
+                     ref = fold_convert_loc (clause_loc, ptype, ref);
+                     if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
+                         && OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c))
+                       {
+                         y3 = create_tmp_var (ptype);
+                         gimplify_assign (y3, unshare_expr (ref), ilist);
+                       }
+                     if (is_simd)
+                       {
+                         y4 = create_tmp_var (ptype);
+                         gimplify_assign (y4, ref, dlist);
+                       }
                    }
                }
-             tree i = create_tmp_var (TREE_TYPE (v), NULL);
+             tree i = create_tmp_var (TREE_TYPE (v));
              gimplify_assign (i, build_int_cst (TREE_TYPE (v), 0), ilist);
              tree body = create_artificial_label (UNKNOWN_LOCATION);
-             tree end = create_artificial_label (UNKNOWN_LOCATION);
              gimple_seq_add_stmt (ilist, gimple_build_label (body));
              if (y2)
                {
-                 i2 = create_tmp_var (TREE_TYPE (v), NULL);
+                 i2 = create_tmp_var (TREE_TYPE (v));
                  gimplify_assign (i2, build_int_cst (TREE_TYPE (v), 0), dlist);
                  body2 = create_artificial_label (UNKNOWN_LOCATION);
                  end2 = create_artificial_label (UNKNOWN_LOCATION);
@@ -3904,14 +4405,17 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
                    }
                  DECL_HAS_VALUE_EXPR_P (placeholder) = 0;
                  DECL_HAS_VALUE_EXPR_P (decl_placeholder) = 0;
-                 x = lang_hooks.decls.omp_clause_dtor
-                                       (c, build_simple_mem_ref (y2));
-                 if (x)
+                 if (y2)
                    {
-                     gimple_seq tseq = NULL;
-                     dtor = x;
-                     gimplify_stmt (&dtor, &tseq);
-                     gimple_seq_add_seq (dlist, tseq);
+                     x = lang_hooks.decls.omp_clause_dtor
+                                               (c, build_simple_mem_ref (y2));
+                     if (x)
+                       {
+                         gimple_seq tseq = NULL;
+                         dtor = x;
+                         gimplify_stmt (&dtor, &tseq);
+                         gimple_seq_add_seq (dlist, tseq);
+                       }
                    }
                }
              else
@@ -3970,6 +4474,78 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
                }
              continue;
            }
+         else if (pass == 2)
+           {
+             if (is_global_var (maybe_lookup_decl_in_outer_ctx (var, ctx)))
+               x = var;
+             else
+               {
+                 bool by_ref = use_pointer_for_field (var, ctx);
+                 x = build_receiver_ref (var, by_ref, ctx);
+               }
+             if (!omp_is_reference (var))
+               x = build_fold_addr_expr (x);
+             x = fold_convert (ptr_type_node, x);
+             unsigned cnt = task_reduction_cnt - 1;
+             if (!task_reduction_needs_orig_p)
+               cnt += task_reduction_cntorig_full - task_reduction_cntorig;
+             else
+               cnt = task_reduction_cntorig - 1;
+             tree r = build4 (ARRAY_REF, ptr_type_node, tskred_avar,
+                              size_int (cnt), NULL_TREE, NULL_TREE);
+             gimplify_assign (r, x, ilist);
+             continue;
+           }
+         else if (pass == 3)
+           {
+             tree type = TREE_TYPE (new_var);
+             if (!omp_is_reference (var))
+               type = build_pointer_type (type);
+             if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
+               {
+                 unsigned cnt = task_reduction_cnt - 1;
+                 if (!task_reduction_needs_orig_p)
+                   cnt += (task_reduction_cntorig_full
+                           - task_reduction_cntorig);
+                 else
+                   cnt = task_reduction_cntorig - 1;
+                 x = build4 (ARRAY_REF, ptr_type_node, tskred_avar,
+                             size_int (cnt), NULL_TREE, NULL_TREE);
+               }
+             else
+               {
+                 unsigned int idx = *ctx->task_reduction_map->get (c);
+                 tree off;
+                 if (ctx->task_reductions[1 + idx])
+                   off = fold_convert (sizetype,
+                                       ctx->task_reductions[1 + idx]);
+                 else
+                   off = task_reduction_read (ilist, tskred_temp, sizetype,
+                                              7 + 3 * idx + 1);
+                 x = fold_build2 (POINTER_PLUS_EXPR, ptr_type_node,
+                                  tskred_base, off);
+               }
+             x = fold_convert (type, x);
+             tree t;
+             if (omp_is_reference (var))
+               {
+                 gimplify_assign (new_var, x, ilist);
+                 t = new_var;
+                 new_var = build_simple_mem_ref (new_var);
+               }
+             else
+               {
+                 t = create_tmp_var (type);
+                 gimplify_assign (t, x, ilist);
+                 SET_DECL_VALUE_EXPR (new_var, build_simple_mem_ref (t));
+                 DECL_HAS_VALUE_EXPR_P (new_var) = 1;
+               }
+             t = fold_convert (build_pointer_type (boolean_type_node), t);
+             t = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t,
+                              TYPE_SIZE_UNIT (TREE_TYPE (type)));
+             cond = create_tmp_var (TREE_TYPE (t));
+             gimplify_assign (cond, t, ilist);
+           }
          else if (is_variable_sized (var))
            {
              /* For variable sized types, we need to allocate the
@@ -4003,7 +4579,9 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
                  gimplify_assign (ptr, x, ilist);
                }
            }
-         else if (omp_is_reference (var))
+         else if (omp_is_reference (var)
+                  && (c_kind != OMP_CLAUSE_FIRSTPRIVATE
+                      || !OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c)))
            {
              /* For references that are being privatized for Fortran,
                 allocate new backing storage for the new pointer
@@ -4053,7 +4631,8 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
 
              new_var = build_simple_mem_ref_loc (clause_loc, new_var);
            }
-         else if (c_kind == OMP_CLAUSE_REDUCTION
+         else if ((c_kind == OMP_CLAUSE_REDUCTION
+                   || c_kind == OMP_CLAUSE_IN_REDUCTION)
                   && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
            {
              if (pass == 0)
@@ -4065,8 +4644,10 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
          switch (OMP_CLAUSE_CODE (c))
            {
            case OMP_CLAUSE_SHARED:
-             /* Ignore shared directives in teams construct.  */
-             if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS)
+             /* Ignore shared directives in teams construct inside
+                target construct.  */
+             if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS
+                 && !is_host_teams_ctx (ctx))
                continue;
              /* Shared global vars are just accessed directly.  */
              if (is_global_var (new_var))
@@ -4170,7 +4751,9 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
            case OMP_CLAUSE_FIRSTPRIVATE:
              if (is_task_ctx (ctx))
                {
-                 if (omp_is_reference (var) || is_variable_sized (var))
+                 if ((omp_is_reference (var)
+                      && !OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c))
+                     || is_variable_sized (var))
                    goto do_dtor;
                  else if (is_global_var (maybe_lookup_decl_in_outer_ctx (var,
                                                                          ctx))
@@ -4182,6 +4765,18 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
                      goto do_dtor;
                    }
                }
+             if (OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c)
+                 && omp_is_reference (var))
+               {
+                 x = build_outer_var_ref (var, ctx);
+                 gcc_assert (TREE_CODE (x) == MEM_REF
+                             && integer_zerop (TREE_OPERAND (x, 1)));
+                 x = TREE_OPERAND (x, 0);
+                 x = lang_hooks.decls.omp_clause_copy_ctor
+                                               (c, unshare_expr (new_var), x);
+                 gimplify_and_add (x, ilist);
+                 goto do_dtor;
+               }
            do_firstprivate:
              x = build_outer_var_ref (var, ctx);
              if (is_simd)
@@ -4273,6 +4868,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
              goto do_dtor;
 
            case OMP_CLAUSE__LOOPTEMP_:
+           case OMP_CLAUSE__REDUCTEMP_:
              gcc_assert (is_taskreg_ctx (ctx));
              x = build_outer_var_ref (var, ctx);
              x = build2 (MODIFY_EXPR, TREE_TYPE (new_var), new_var, x);
@@ -4288,6 +4884,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
              break;
 
            case OMP_CLAUSE_REDUCTION:
+           case OMP_CLAUSE_IN_REDUCTION:
              /* OpenACC reductions are initialized using the
                 GOACC_REDUCTION internal function.  */
              if (is_gimple_omp_oacc (ctx->stmt))
@@ -4296,12 +4893,40 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
                {
                  tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
                  gimple *tseq;
-                 x = build_outer_var_ref (var, ctx);
+                 tree ptype = TREE_TYPE (placeholder);
+                 if (cond)
+                   {
+                     x = error_mark_node;
+                     if (OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c)
+                         && !task_reduction_needs_orig_p)
+                       x = var;
+                     else if (OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c))
+                       {
+                         tree pptype = build_pointer_type (ptype);
+                         if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
+                           x = build4 (ARRAY_REF, ptr_type_node, tskred_avar,
+                                       size_int (task_reduction_cnt_full
+                                                 + task_reduction_cntorig - 1),
+                                       NULL_TREE, NULL_TREE);
+                         else
+                           {
+                             unsigned int idx
+                               = *ctx->task_reduction_map->get (c);
+                             x = task_reduction_read (ilist, tskred_temp,
+                                                      pptype, 7 + 3 * idx);
+                           }
+                         x = fold_convert (pptype, x);
+                         x = build_simple_mem_ref (x);
+                       }
+                   }
+                 else
+                   {
+                     x = build_outer_var_ref (var, ctx);
 
-                 if (omp_is_reference (var)
-                     && !useless_type_conversion_p (TREE_TYPE (placeholder),
-                                                    TREE_TYPE (x)))
-                   x = build_fold_addr_expr_loc (clause_loc, x);
+                     if (omp_is_reference (var)
+                         && !useless_type_conversion_p (ptype, TREE_TYPE (x)))
+                       x = build_fold_addr_expr_loc (clause_loc, x);
+                   }
                  SET_DECL_VALUE_EXPR (placeholder, x);
                  DECL_HAS_VALUE_EXPR_P (placeholder) = 1;
                  tree new_vard = new_var;
@@ -4365,9 +4990,35 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
                     initialization now.  */
                  else if (omp_is_reference (var) && is_simd)
                    handle_simd_reference (clause_loc, new_vard, ilist);
+
+                 tree lab2 = NULL_TREE;
+                 if (cond)
+                   {
+                     gimple *g;
+                     if (!is_parallel_ctx (ctx))
+                       {
+                         tree condv = create_tmp_var (boolean_type_node);
+                         tree m = build_simple_mem_ref (cond);
+                         g = gimple_build_assign (condv, m);
+                         gimple_seq_add_stmt (ilist, g);
+                         tree lab1
+                           = create_artificial_label (UNKNOWN_LOCATION);
+                         lab2 = create_artificial_label (UNKNOWN_LOCATION);
+                         g = gimple_build_cond (NE_EXPR, condv,
+                                                boolean_false_node,
+                                                lab2, lab1);
+                         gimple_seq_add_stmt (ilist, g);
+                         gimple_seq_add_stmt (ilist,
+                                              gimple_build_label (lab1));
+                       }
+                     g = gimple_build_assign (build_simple_mem_ref (cond),
+                                              boolean_true_node);
+                     gimple_seq_add_stmt (ilist, g);
+                   }
                  x = lang_hooks.decls.omp_clause_default_ctor
                                (c, unshare_expr (new_var),
-                                build_outer_var_ref (var, ctx));
+                                cond ? NULL_TREE
+                                : build_outer_var_ref (var, ctx));
                  if (x)
                    gimplify_and_add (x, ilist);
                  if (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c))
@@ -4385,6 +5036,12 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
                      OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL;
                    }
                  DECL_HAS_VALUE_EXPR_P (placeholder) = 0;
+                 if (cond)
+                   {
+                     if (lab2)
+                       gimple_seq_add_stmt (ilist, gimple_build_label (lab2));
+                     break;
+                   }
                  goto do_dtor;
                }
              else
@@ -4393,6 +5050,49 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
                  gcc_assert (TREE_CODE (TREE_TYPE (new_var)) != ARRAY_TYPE);
                  enum tree_code code = OMP_CLAUSE_REDUCTION_CODE (c);
 
+                 if (cond)
+                   {
+                     gimple *g;
+                     tree lab2 = NULL_TREE;
+                     /* GOMP_taskgroup_reduction_register memsets the whole
+                        array to zero.  If the initializer is zero, we don't
+                        need to initialize it again, just mark it as ever
+                        used unconditionally, i.e. cond = true.  */
+                     if (initializer_zerop (x))
+                       {
+                         g = gimple_build_assign (build_simple_mem_ref (cond),
+                                                  boolean_true_node);
+                         gimple_seq_add_stmt (ilist, g);
+                         break;
+                       }
+
+                     /* Otherwise, emit
+                        if (!cond) { cond = true; new_var = x; }  */
+                     if (!is_parallel_ctx (ctx))
+                       {
+                         tree condv = create_tmp_var (boolean_type_node);
+                         tree m = build_simple_mem_ref (cond);
+                         g = gimple_build_assign (condv, m);
+                         gimple_seq_add_stmt (ilist, g);
+                         tree lab1
+                           = create_artificial_label (UNKNOWN_LOCATION);
+                         lab2 = create_artificial_label (UNKNOWN_LOCATION);
+                         g = gimple_build_cond (NE_EXPR, condv,
+                                                boolean_false_node,
+                                                lab2, lab1);
+                         gimple_seq_add_stmt (ilist, g);
+                         gimple_seq_add_stmt (ilist,
+                                              gimple_build_label (lab1));
+                       }
+                     g = gimple_build_assign (build_simple_mem_ref (cond),
+                                              boolean_true_node);
+                     gimple_seq_add_stmt (ilist, g);
+                     gimplify_assign (new_var, x, ilist);
+                     if (lab2)
+                       gimple_seq_add_stmt (ilist, gimple_build_label (lab2));
+                     break;
+                   }
+
                  /* reduction(-:var) sums up the partial results, so it
                     acts identically to reduction(+:var).  */
                  if (code == MINUS_EXPR)
@@ -4456,6 +5156,12 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
            }
        }
     }
+  if (tskred_avar)
+    {
+      tree clobber = build_constructor (TREE_TYPE (tskred_avar), NULL);
+      TREE_THIS_VOLATILE (clobber) = 1;
+      gimple_seq_add_stmt (ilist, gimple_build_assign (tskred_avar, clobber));
+    }
 
   if (known_eq (sctx.max_vf, 1U))
     sctx.is_simt = false;
@@ -4587,8 +5293,9 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
     {
       /* Don't add any barrier for #pragma omp simd or
         #pragma omp distribute.  */
-      if (gimple_code (ctx->stmt) != GIMPLE_OMP_FOR
-         || gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_FOR)
+      if (!is_task_ctx (ctx)
+         && (gimple_code (ctx->stmt) != GIMPLE_OMP_FOR
+             || gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_FOR))
        gimple_seq_add_stmt (ilist, omp_build_barrier (NULL_TREE));
     }
 
@@ -5078,7 +5785,8 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx)
   /* First see if there is exactly one reduction clause.  Use OMP_ATOMIC
      update in that case, otherwise use a lock.  */
   for (c = clauses; c && count < 2; c = OMP_CLAUSE_CHAIN (c))
-    if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
+    if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+       && !OMP_CLAUSE_REDUCTION_TASK (c))
       {
        if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
            || TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
@@ -5099,7 +5807,8 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx)
       enum tree_code code;
       location_t clause_loc = OMP_CLAUSE_LOCATION (c);
 
-      if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
+      if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
+         || OMP_CLAUSE_REDUCTION_TASK (c))
        continue;
 
       enum omp_clause_code ccode = OMP_CLAUSE_REDUCTION;
@@ -5150,6 +5859,7 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx)
          ref = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (addr)), addr);
          x = fold_build2_loc (clause_loc, code, TREE_TYPE (ref), ref, new_var);
          x = build2 (OMP_ATOMIC, void_type_node, addr, x);
+         OMP_ATOMIC_MEMORY_ORDER (x) = OMP_MEMORY_ORDER_RELAXED;
          gimplify_and_add (x, stmt_seqp);
          return;
        }
@@ -5158,7 +5868,7 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx)
          tree d = OMP_CLAUSE_DECL (c);
          tree type = TREE_TYPE (d);
          tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
-         tree i = create_tmp_var (TREE_TYPE (v), NULL);
+         tree i = create_tmp_var (TREE_TYPE (v));
          tree ptype = build_pointer_type (TREE_TYPE (type));
          tree bias = TREE_OPERAND (d, 1);
          d = TREE_OPERAND (d, 0);
@@ -5222,10 +5932,10 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx)
            }
          new_var = fold_convert_loc (clause_loc, ptype, new_var);
          ref = fold_convert_loc (clause_loc, ptype, ref);
-         tree m = create_tmp_var (ptype, NULL);
+         tree m = create_tmp_var (ptype);
          gimplify_assign (m, new_var, stmt_seqp);
          new_var = m;
-         m = create_tmp_var (ptype, NULL);
+         m = create_tmp_var (ptype);
          gimplify_assign (m, ref, stmt_seqp);
          ref = m;
          gimplify_assign (i, build_int_cst (TREE_TYPE (v), 0), stmt_seqp);
@@ -5387,7 +6097,12 @@ lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist,
        case OMP_CLAUSE_FIRSTPRIVATE:
        case OMP_CLAUSE_COPYIN:
        case OMP_CLAUSE_LASTPRIVATE:
+       case OMP_CLAUSE_IN_REDUCTION:
+       case OMP_CLAUSE__REDUCTEMP_:
+         break;
        case OMP_CLAUSE_REDUCTION:
+         if (is_task_ctx (ctx) || OMP_CLAUSE_REDUCTION_TASK (c))
+           continue;
          break;
        case OMP_CLAUSE_SHARED:
          if (OMP_CLAUSE_SHARED_FIRSTPRIVATE (c))
@@ -5405,7 +6120,8 @@ lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist,
        }
 
       val = OMP_CLAUSE_DECL (c);
-      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+      if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
+          || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
          && TREE_CODE (val) == MEM_REF)
        {
          val = TREE_OPERAND (val, 0);
@@ -5429,7 +6145,13 @@ lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist,
       var = lookup_decl_in_outer_ctx (val, ctx_for_o);
 
       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_COPYIN
-         && is_global_var (var))
+         && is_global_var (var)
+         && (val == OMP_CLAUSE_DECL (c)
+             || !is_task_ctx (ctx)
+             || (TREE_CODE (TREE_TYPE (val)) != POINTER_TYPE
+                 && (TREE_CODE (TREE_TYPE (val)) != REFERENCE_TYPE
+                     || (TREE_CODE (TREE_TYPE (TREE_TYPE (val)))
+                         != POINTER_TYPE)))))
        continue;
 
       t = omp_member_access_dummy_var (var);
@@ -5457,7 +6179,8 @@ lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist,
          continue;
        }
 
-      if ((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
+      if (((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
+           && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION)
           || val == OMP_CLAUSE_DECL (c))
          && is_variable_sized (val))
        continue;
@@ -5476,6 +6199,7 @@ lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist,
        case OMP_CLAUSE_PRIVATE:
        case OMP_CLAUSE_COPYIN:
        case OMP_CLAUSE__LOOPTEMP_:
+       case OMP_CLAUSE__REDUCTEMP_:
          do_in = true;
          break;
 
@@ -5495,9 +6219,15 @@ lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist,
          break;
 
        case OMP_CLAUSE_REDUCTION:
+       case OMP_CLAUSE_IN_REDUCTION:
          do_in = true;
          if (val == OMP_CLAUSE_DECL (c))
-           do_out = !(by_ref || omp_is_reference (val));
+           {
+             if (is_task_ctx (ctx))
+               by_ref = use_pointer_for_field (val, ctx);
+             else
+               do_out = !(by_ref || omp_is_reference (val));
+           }
          else
            by_ref = TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE;
          break;
@@ -5802,30 +6532,55 @@ maybe_catch_exception (gimple_seq body)
    cancellation in the implicit barrier.  */
 
 static void
-maybe_add_implicit_barrier_cancel (omp_context *ctx, gimple_seq *body)
+maybe_add_implicit_barrier_cancel (omp_context *ctx, gimple *omp_return,
+                                  gimple_seq *body)
 {
-  gimple *omp_return = gimple_seq_last_stmt (*body);
   gcc_assert (gimple_code (omp_return) == GIMPLE_OMP_RETURN);
   if (gimple_omp_return_nowait_p (omp_return))
     return;
-  if (ctx->outer
-      && gimple_code (ctx->outer->stmt) == GIMPLE_OMP_PARALLEL
-      && ctx->outer->cancellable)
-    {
-      tree fndecl = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
-      tree c_bool_type = TREE_TYPE (TREE_TYPE (fndecl));
-      tree lhs = create_tmp_var (c_bool_type);
-      gimple_omp_return_set_lhs (omp_return, lhs);
-      tree fallthru_label = create_artificial_label (UNKNOWN_LOCATION);
-      gimple *g = gimple_build_cond (NE_EXPR, lhs,
-                                   fold_convert (c_bool_type,
-                                                 boolean_false_node),
-                                   ctx->outer->cancel_label, fallthru_label);
-      gimple_seq_add_stmt (body, g);
-      gimple_seq_add_stmt (body, gimple_build_label (fallthru_label));
+  for (omp_context *outer = ctx->outer; outer; outer = outer->outer)
+    if (gimple_code (outer->stmt) == GIMPLE_OMP_PARALLEL
+       && outer->cancellable)
+      {
+       tree fndecl = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
+       tree c_bool_type = TREE_TYPE (TREE_TYPE (fndecl));
+       tree lhs = create_tmp_var (c_bool_type);
+       gimple_omp_return_set_lhs (omp_return, lhs);
+       tree fallthru_label = create_artificial_label (UNKNOWN_LOCATION);
+       gimple *g = gimple_build_cond (NE_EXPR, lhs,
+                                      fold_convert (c_bool_type,
+                                                    boolean_false_node),
+                                      outer->cancel_label, fallthru_label);
+       gimple_seq_add_stmt (body, g);
+       gimple_seq_add_stmt (body, gimple_build_label (fallthru_label));
+      }
+    else if (gimple_code (outer->stmt) != GIMPLE_OMP_TASKGROUP)
+      return;
+}
+
+/* Find the first task_reduction or reduction clause or return NULL
+   if there are none.  */
+
+static inline tree
+omp_task_reductions_find_first (tree clauses, enum tree_code code,
+                               enum omp_clause_code ccode)
+{
+  while (1)
+    {
+      clauses = omp_find_clause (clauses, ccode);
+      if (clauses == NULL_TREE)
+       return NULL_TREE;
+      if (ccode != OMP_CLAUSE_REDUCTION
+         || code == OMP_TASKLOOP
+         || OMP_CLAUSE_REDUCTION_TASK (clauses))
+       return clauses;
+      clauses = OMP_CLAUSE_CHAIN (clauses);
     }
 }
 
+static void lower_omp_task_reductions (omp_context *, enum tree_code, tree,
+                                      gimple_seq *, gimple_seq *);
+
 /* Lower the OpenMP sections directive in the current statement in GSI_P.
    CTX is the enclosing OMP context for the current statement.  */
 
@@ -5837,7 +6592,7 @@ lower_omp_sections (gimple_stmt_iterator *gsi_p, omp_context *ctx)
   gomp_sections *stmt;
   gimple *t;
   gbind *new_stmt, *bind;
-  gimple_seq ilist, dlist, olist, new_body;
+  gimple_seq ilist, dlist, olist, tred_dlist = NULL, new_body;
 
   stmt = as_a <gomp_sections *> (gsi_stmt (*gsi_p));
 
@@ -5845,6 +6600,27 @@ lower_omp_sections (gimple_stmt_iterator *gsi_p, omp_context *ctx)
 
   dlist = NULL;
   ilist = NULL;
+
+  tree rclauses
+    = omp_task_reductions_find_first (gimple_omp_sections_clauses (stmt),
+                                     OMP_SECTIONS, OMP_CLAUSE_REDUCTION);
+  tree rtmp = NULL_TREE;
+  if (rclauses)
+    {
+      tree type = build_pointer_type (pointer_sized_int_node);
+      tree temp = create_tmp_var (type);
+      tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__REDUCTEMP_);
+      OMP_CLAUSE_DECL (c) = temp;
+      OMP_CLAUSE_CHAIN (c) = gimple_omp_sections_clauses (stmt);
+      gimple_omp_sections_set_clauses (stmt, c);
+      lower_omp_task_reductions (ctx, OMP_SECTIONS,
+                                gimple_omp_sections_clauses (stmt),
+                                &ilist, &tred_dlist);
+      rclauses = c;
+      rtmp = make_ssa_name (type);
+      gimple_seq_add_stmt (&ilist, gimple_build_assign (rtmp, temp));
+    }
+
   lower_rec_input_clauses (gimple_omp_sections_clauses (stmt),
                           &ilist, &dlist, ctx, NULL);
 
@@ -5916,7 +6692,11 @@ lower_omp_sections (gimple_stmt_iterator *gsi_p, omp_context *ctx)
                                 OMP_CLAUSE_NOWAIT) != NULL_TREE;
   t = gimple_build_omp_return (nowait);
   gimple_seq_add_stmt (&new_body, t);
-  maybe_add_implicit_barrier_cancel (ctx, &new_body);
+  gimple_seq_add_seq (&new_body, tred_dlist);
+  maybe_add_implicit_barrier_cancel (ctx, t, &new_body);
+
+  if (rclauses)
+    OMP_CLAUSE_DECL (rclauses) = rtmp;
 
   gimple_bind_set_body (new_stmt, new_body);
 }
@@ -6078,7 +6858,7 @@ lower_omp_single (gimple_stmt_iterator *gsi_p, omp_context *ctx)
                                 OMP_CLAUSE_NOWAIT) != NULL_TREE;
   gimple *g = gimple_build_omp_return (nowait);
   gimple_seq_add_stmt (&bind_body_tail, g);
-  maybe_add_implicit_barrier_cancel (ctx, &bind_body_tail);
+  maybe_add_implicit_barrier_cancel (ctx, g, &bind_body_tail);
   if (ctx->record_type)
     {
       gimple_stmt_iterator gsi = gsi_start (bind_body_tail);
@@ -6140,6 +6920,604 @@ lower_omp_master (gimple_stmt_iterator *gsi_p, omp_context *ctx)
   BLOCK_VARS (block) = ctx->block_vars;
 }
 
+/* Helper function for lower_omp_task_reductions.  For a specific PASS
+   find out the current clause it should be processed, or return false
+   if all have been processed already.  */
+
+static inline bool
+omp_task_reduction_iterate (int pass, enum tree_code code,
+                           enum omp_clause_code ccode, tree *c, tree *decl,
+                           tree *type, tree *next)
+{
+  for (; *c; *c = omp_find_clause (OMP_CLAUSE_CHAIN (*c), ccode))
+    {
+      if (ccode == OMP_CLAUSE_REDUCTION
+         && code != OMP_TASKLOOP
+         && !OMP_CLAUSE_REDUCTION_TASK (*c))
+       continue;
+      *decl = OMP_CLAUSE_DECL (*c);
+      *type = TREE_TYPE (*decl);
+      if (TREE_CODE (*decl) == MEM_REF)
+       {
+         if (pass != 1)
+           continue;
+       }
+      else
+       {
+         if (omp_is_reference (*decl))
+           *type = TREE_TYPE (*type);
+         if (pass != (!TREE_CONSTANT (TYPE_SIZE_UNIT (*type))))
+           continue;
+       }
+      *next = omp_find_clause (OMP_CLAUSE_CHAIN (*c), ccode);
+      return true;
+    }
+  *decl = NULL_TREE;
+  *type = NULL_TREE;
+  *next = NULL_TREE;
+  return false;
+}
+
+/* Lower task_reduction and reduction clauses (the latter unless CODE is
+   OMP_TASKGROUP only with task modifier).  Register mapping of those in
+   START sequence and reducing them and unregister them in the END sequence.  */
+
+static void
+lower_omp_task_reductions (omp_context *ctx, enum tree_code code, tree clauses,
+                          gimple_seq *start, gimple_seq *end)
+{
+  enum omp_clause_code ccode
+    = (code == OMP_TASKGROUP
+       ? OMP_CLAUSE_TASK_REDUCTION : OMP_CLAUSE_REDUCTION);
+  tree cancellable = NULL_TREE;
+  clauses = omp_task_reductions_find_first (clauses, code, ccode);
+  if (clauses == NULL_TREE)
+    return;
+  if (code == OMP_FOR || code == OMP_SECTIONS)
+    {
+      for (omp_context *outer = ctx->outer; outer; outer = outer->outer)
+       if (gimple_code (outer->stmt) == GIMPLE_OMP_PARALLEL
+           && outer->cancellable)
+         {
+           cancellable = error_mark_node;
+           break;
+         }
+       else if (gimple_code (outer->stmt) != GIMPLE_OMP_TASKGROUP)
+         break;
+    }
+  tree record_type = lang_hooks.types.make_type (RECORD_TYPE);
+  tree *last = &TYPE_FIELDS (record_type);
+  unsigned cnt = 0;
+  if (cancellable)
+    {
+      tree field = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE,
+                              ptr_type_node);
+      tree ifield = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE,
+                               integer_type_node);
+      *last = field;
+      DECL_CHAIN (field) = ifield;
+      last = &DECL_CHAIN (ifield);
+    }
+  for (int pass = 0; pass < 2; pass++)
+    {
+      tree decl, type, next;
+      for (tree c = clauses;
+          omp_task_reduction_iterate (pass, code, ccode,
+                                      &c, &decl, &type, &next); c = next)
+       {
+         ++cnt;
+         tree new_type = type;
+         if (ctx->outer)
+           new_type = remap_type (type, &ctx->outer->cb);
+         tree field
+           = build_decl (OMP_CLAUSE_LOCATION (c), FIELD_DECL,
+                         DECL_P (decl) ? DECL_NAME (decl) : NULL_TREE,
+                         new_type);
+         if (DECL_P (decl) && type == TREE_TYPE (decl))
+           {
+             SET_DECL_ALIGN (field, DECL_ALIGN (decl));
+             DECL_USER_ALIGN (field) = DECL_USER_ALIGN (decl);
+             TREE_THIS_VOLATILE (field) = TREE_THIS_VOLATILE (decl);
+           }
+         else
+           SET_DECL_ALIGN (field, TYPE_ALIGN (type));
+         DECL_CONTEXT (field) = record_type;
+         *last = field;
+         last = &DECL_CHAIN (field);
+         tree bfield
+           = build_decl (OMP_CLAUSE_LOCATION (c), FIELD_DECL, NULL_TREE,
+                         boolean_type_node);
+         DECL_CONTEXT (bfield) = record_type;
+         *last = bfield;
+         last = &DECL_CHAIN (bfield);
+       }
+    }
+  *last = NULL_TREE;
+  layout_type (record_type);
+
+  /* Build up an array which registers with the runtime all the reductions
+     and deregisters them at the end.  Format documented in libgomp/task.c.  */
+  tree atype = build_array_type_nelts (pointer_sized_int_node, 7 + cnt * 3);
+  tree avar = create_tmp_var_raw (atype);
+  gimple_add_tmp_var (avar);
+  TREE_ADDRESSABLE (avar) = 1;
+  tree r = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_zero_node,
+                  NULL_TREE, NULL_TREE);
+  tree t = build_int_cst (pointer_sized_int_node, cnt);
+  gimple_seq_add_stmt (start, gimple_build_assign (r, t));
+  gimple_seq seq = NULL;
+  tree sz = fold_convert (pointer_sized_int_node,
+                         TYPE_SIZE_UNIT (record_type));
+  int cachesz = 64;
+  sz = fold_build2 (PLUS_EXPR, pointer_sized_int_node, sz,
+                   build_int_cst (pointer_sized_int_node, cachesz - 1));
+  sz = fold_build2 (BIT_AND_EXPR, pointer_sized_int_node, sz,
+                   build_int_cst (pointer_sized_int_node, ~(cachesz - 1)));
+  ctx->task_reductions.create (1 + cnt);
+  ctx->task_reduction_map = new hash_map<tree, unsigned>;
+  ctx->task_reductions.quick_push (TREE_CODE (sz) == INTEGER_CST
+                                  ? sz : NULL_TREE);
+  sz = force_gimple_operand (sz, &seq, true, NULL_TREE);
+  gimple_seq_add_seq (start, seq);
+  r = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_one_node,
+             NULL_TREE, NULL_TREE);
+  gimple_seq_add_stmt (start, gimple_build_assign (r, sz));
+  r = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_int (2),
+             NULL_TREE, NULL_TREE);
+  t = build_int_cst (pointer_sized_int_node,
+                    MAX (TYPE_ALIGN_UNIT (record_type), (unsigned) cachesz));
+  gimple_seq_add_stmt (start, gimple_build_assign (r, t));
+  r = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_int (3),
+             NULL_TREE, NULL_TREE);
+  t = build_int_cst (pointer_sized_int_node, -1);
+  gimple_seq_add_stmt (start, gimple_build_assign (r, t));
+  r = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_int (4),
+             NULL_TREE, NULL_TREE);
+  t = build_int_cst (pointer_sized_int_node, 0);
+  gimple_seq_add_stmt (start, gimple_build_assign (r, t));
+
+  /* In end, build a loop that iterates from 0 to < omp_get_num_threads ()
+     and for each task reduction checks a bool right after the private variable
+     within that thread's chunk; if the bool is clear, it hasn't been
+     initialized and thus isn't going to be reduced nor destructed, otherwise
+     reduce and destruct it.  */
+  tree idx = create_tmp_var (size_type_node);
+  gimple_seq_add_stmt (end, gimple_build_assign (idx, size_zero_node));
+  tree num_thr_sz = create_tmp_var (size_type_node);
+  tree lab1 = create_artificial_label (UNKNOWN_LOCATION);
+  tree lab2 = create_artificial_label (UNKNOWN_LOCATION);
+  tree lab3 = NULL_TREE;
+  gimple *g;
+  if (code == OMP_FOR || code == OMP_SECTIONS)
+    {
+      /* For worksharing constructs, only perform it in the master thread,
+        with the exception of cancelled implicit barriers - then only handle
+        the current thread.  */
+      tree lab4 = create_artificial_label (UNKNOWN_LOCATION);
+      t = builtin_decl_explicit (BUILT_IN_OMP_GET_THREAD_NUM);
+      tree thr_num = create_tmp_var (integer_type_node);
+      g = gimple_build_call (t, 0);
+      gimple_call_set_lhs (g, thr_num);
+      gimple_seq_add_stmt (end, g);
+      if (cancellable)
+       {
+         tree c;
+         tree lab5 = create_artificial_label (UNKNOWN_LOCATION);
+         tree lab6 = create_artificial_label (UNKNOWN_LOCATION);
+         lab3 = create_artificial_label (UNKNOWN_LOCATION);
+         if (code == OMP_FOR)
+           c = gimple_omp_for_clauses (ctx->stmt);
+         else if (code == OMP_SECTIONS)
+           c = gimple_omp_sections_clauses (ctx->stmt);
+         c = OMP_CLAUSE_DECL (omp_find_clause (c, OMP_CLAUSE__REDUCTEMP_));
+         cancellable = c;
+         g = gimple_build_cond (NE_EXPR, c, build_zero_cst (TREE_TYPE (c)),
+                                lab5, lab6);
+         gimple_seq_add_stmt (end, g);
+         gimple_seq_add_stmt (end, gimple_build_label (lab5));
+         g = gimple_build_assign (idx, NOP_EXPR, thr_num);
+         gimple_seq_add_stmt (end, g);
+         g = gimple_build_assign (num_thr_sz, PLUS_EXPR, idx,
+                                  build_one_cst (TREE_TYPE (idx)));
+         gimple_seq_add_stmt (end, g);
+         gimple_seq_add_stmt (end, gimple_build_goto (lab3));
+         gimple_seq_add_stmt (end, gimple_build_label (lab6));
+       }
+      g = gimple_build_cond (NE_EXPR, thr_num, integer_zero_node, lab2, lab4);
+      gimple_seq_add_stmt (end, g);
+      gimple_seq_add_stmt (end, gimple_build_label (lab4));
+    }
+  if (code != OMP_PARALLEL)
+    {
+      t = builtin_decl_explicit (BUILT_IN_OMP_GET_NUM_THREADS);
+      tree num_thr = create_tmp_var (integer_type_node);
+      g = gimple_build_call (t, 0);
+      gimple_call_set_lhs (g, num_thr);
+      gimple_seq_add_stmt (end, g);
+      g = gimple_build_assign (num_thr_sz, NOP_EXPR, num_thr);
+      gimple_seq_add_stmt (end, g);
+      if (cancellable)
+       gimple_seq_add_stmt (end, gimple_build_label (lab3));
+    }
+  else
+    {
+      tree c = omp_find_clause (gimple_omp_parallel_clauses (ctx->stmt),
+                               OMP_CLAUSE__REDUCTEMP_);
+      t = fold_convert (pointer_sized_int_node, OMP_CLAUSE_DECL (c));
+      t = fold_convert (size_type_node, t);
+      gimplify_assign (num_thr_sz, t, end);
+    }
+  t = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_int (2),
+             NULL_TREE, NULL_TREE);
+  tree data = create_tmp_var (pointer_sized_int_node);
+  gimple_seq_add_stmt (end, gimple_build_assign (data, t));
+  gimple_seq_add_stmt (end, gimple_build_label (lab1));
+  tree ptr;
+  if (TREE_CODE (TYPE_SIZE_UNIT (record_type)) == INTEGER_CST)
+    ptr = create_tmp_var (build_pointer_type (record_type));
+  else
+    ptr = create_tmp_var (ptr_type_node);
+  gimple_seq_add_stmt (end, gimple_build_assign (ptr, NOP_EXPR, data));
+
+  tree field = TYPE_FIELDS (record_type);
+  cnt = 0;
+  if (cancellable)
+    field = DECL_CHAIN (DECL_CHAIN (field));
+  for (int pass = 0; pass < 2; pass++)
+    {
+      tree decl, type, next;
+      for (tree c = clauses;
+          omp_task_reduction_iterate (pass, code, ccode,
+                                      &c, &decl, &type, &next); c = next)
+       {
+         tree var = decl, ref;
+         if (TREE_CODE (decl) == MEM_REF)
+           {
+             var = TREE_OPERAND (var, 0);
+             if (TREE_CODE (var) == POINTER_PLUS_EXPR)
+               var = TREE_OPERAND (var, 0);
+             tree v = var;
+             if (TREE_CODE (var) == ADDR_EXPR)
+               var = TREE_OPERAND (var, 0);
+             else if (TREE_CODE (var) == INDIRECT_REF)
+               var = TREE_OPERAND (var, 0);
+             tree orig_var = var;
+             if (is_variable_sized (var))
+               {
+                 gcc_assert (DECL_HAS_VALUE_EXPR_P (var));
+                 var = DECL_VALUE_EXPR (var);
+                 gcc_assert (TREE_CODE (var) == INDIRECT_REF);
+                 var = TREE_OPERAND (var, 0);
+                 gcc_assert (DECL_P (var));
+               }
+             t = ref = maybe_lookup_decl_in_outer_ctx (var, ctx);
+             if (orig_var != var)
+               gcc_assert (TREE_CODE (v) == ADDR_EXPR);
+             else if (TREE_CODE (v) == ADDR_EXPR)
+               t = build_fold_addr_expr (t);
+             else if (TREE_CODE (v) == INDIRECT_REF)
+               t = build_fold_indirect_ref (t);
+             if (TREE_CODE (TREE_OPERAND (decl, 0)) == POINTER_PLUS_EXPR)
+               {
+                 tree b = TREE_OPERAND (TREE_OPERAND (decl, 0), 1);
+                 b = maybe_lookup_decl_in_outer_ctx (b, ctx);
+                 t = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t, b);
+               }
+             if (!integer_zerop (TREE_OPERAND (decl, 1)))
+               t = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t,
+                                fold_convert (size_type_node,
+                                              TREE_OPERAND (decl, 1)));
+           }
+         else
+           {
+             t = ref = maybe_lookup_decl_in_outer_ctx (var, ctx);
+             if (!omp_is_reference (decl))
+               t = build_fold_addr_expr (t);
+           }
+         t = fold_convert (pointer_sized_int_node, t);
+         seq = NULL;
+         t = force_gimple_operand (t, &seq, true, NULL_TREE);
+         gimple_seq_add_seq (start, seq);
+         r = build4 (ARRAY_REF, pointer_sized_int_node, avar,
+                     size_int (7 + cnt * 3), NULL_TREE, NULL_TREE);
+         gimple_seq_add_stmt (start, gimple_build_assign (r, t));
+         t = unshare_expr (byte_position (field));
+         t = fold_convert (pointer_sized_int_node, t);
+         ctx->task_reduction_map->put (c, cnt);
+         ctx->task_reductions.quick_push (TREE_CODE (t) == INTEGER_CST
+                                          ? t : NULL_TREE);
+         seq = NULL;
+         t = force_gimple_operand (t, &seq, true, NULL_TREE);
+         gimple_seq_add_seq (start, seq);
+         r = build4 (ARRAY_REF, pointer_sized_int_node, avar,
+                     size_int (7 + cnt * 3 + 1), NULL_TREE, NULL_TREE);
+         gimple_seq_add_stmt (start, gimple_build_assign (r, t));
+
+         tree bfield = DECL_CHAIN (field);
+         tree cond;
+         if (code == OMP_PARALLEL || code == OMP_FOR || code == OMP_SECTIONS)
+           /* In parallel or worksharing all threads unconditionally
+              initialize all their task reduction private variables.  */
+           cond = boolean_true_node;
+         else if (TREE_TYPE (ptr) == ptr_type_node)
+           {
+             cond = build2 (POINTER_PLUS_EXPR, ptr_type_node, ptr,
+                            unshare_expr (byte_position (bfield)));
+             seq = NULL;
+             cond = force_gimple_operand (cond, &seq, true, NULL_TREE);
+             gimple_seq_add_seq (end, seq);
+             tree pbool = build_pointer_type (TREE_TYPE (bfield));
+             cond = build2 (MEM_REF, TREE_TYPE (bfield), cond,
+                            build_int_cst (pbool, 0));
+           }
+         else
+           cond = build3 (COMPONENT_REF, TREE_TYPE (bfield),
+                          build_simple_mem_ref (ptr), bfield, NULL_TREE);
+         tree lab3 = create_artificial_label (UNKNOWN_LOCATION);
+         tree lab4 = create_artificial_label (UNKNOWN_LOCATION);
+         tree condv = create_tmp_var (boolean_type_node);
+         gimple_seq_add_stmt (end, gimple_build_assign (condv, cond));
+         g = gimple_build_cond (NE_EXPR, condv, boolean_false_node,
+                                lab3, lab4);
+         gimple_seq_add_stmt (end, g);
+         gimple_seq_add_stmt (end, gimple_build_label (lab3));
+         if (cancellable && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE)
+           {
+             /* If this reduction doesn't need destruction and parallel
+                has been cancelled, there is nothing to do for this
+                reduction, so jump around the merge operation.  */
+             tree lab5 = create_artificial_label (UNKNOWN_LOCATION);
+             g = gimple_build_cond (NE_EXPR, cancellable,
+                                    build_zero_cst (TREE_TYPE (cancellable)),
+                                    lab4, lab5);
+             gimple_seq_add_stmt (end, g);
+             gimple_seq_add_stmt (end, gimple_build_label (lab5));
+           }
+
+         tree new_var;
+         if (TREE_TYPE (ptr) == ptr_type_node)
+           {
+             new_var = build2 (POINTER_PLUS_EXPR, ptr_type_node, ptr,
+                               unshare_expr (byte_position (field)));
+             seq = NULL;
+             new_var = force_gimple_operand (new_var, &seq, true, NULL_TREE);
+             gimple_seq_add_seq (end, seq);
+             tree pbool = build_pointer_type (TREE_TYPE (field));
+             new_var = build2 (MEM_REF, TREE_TYPE (field), new_var,
+                               build_int_cst (pbool, 0));
+           }
+         else
+           new_var = build3 (COMPONENT_REF, TREE_TYPE (field),
+                             build_simple_mem_ref (ptr), field, NULL_TREE);
+
+         enum tree_code rcode = OMP_CLAUSE_REDUCTION_CODE (c);
+         if (TREE_CODE (decl) != MEM_REF && omp_is_reference (decl))
+           ref = build_simple_mem_ref (ref);
+         /* reduction(-:var) sums up the partial results, so it acts
+            identically to reduction(+:var).  */
+         if (rcode == MINUS_EXPR)
+           rcode = PLUS_EXPR;
+         if (TREE_CODE (decl) == MEM_REF)
+           {
+             tree type = TREE_TYPE (new_var);
+             tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
+             tree i = create_tmp_var (TREE_TYPE (v));
+             tree ptype = build_pointer_type (TREE_TYPE (type));
+             if (DECL_P (v))
+               {
+                 v = maybe_lookup_decl_in_outer_ctx (v, ctx);
+                 tree vv = create_tmp_var (TREE_TYPE (v));
+                 gimplify_assign (vv, v, start);
+                 v = vv;
+               }
+             ref = build4 (ARRAY_REF, pointer_sized_int_node, avar,
+                           size_int (7 + cnt * 3), NULL_TREE, NULL_TREE);
+             new_var = build_fold_addr_expr (new_var);
+             new_var = fold_convert (ptype, new_var);
+             ref = fold_convert (ptype, ref);
+             tree m = create_tmp_var (ptype);
+             gimplify_assign (m, new_var, end);
+             new_var = m;
+             m = create_tmp_var (ptype);
+             gimplify_assign (m, ref, end);
+             ref = m;
+             gimplify_assign (i, build_int_cst (TREE_TYPE (v), 0), end);
+             tree body = create_artificial_label (UNKNOWN_LOCATION);
+             tree endl = create_artificial_label (UNKNOWN_LOCATION);
+             gimple_seq_add_stmt (end, gimple_build_label (body));
+             tree priv = build_simple_mem_ref (new_var);
+             tree out = build_simple_mem_ref (ref);
+             if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
+               {
+                 tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
+                 tree decl_placeholder
+                   = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c);
+                 tree lab6 = NULL_TREE;
+                 if (cancellable)
+                   {
+                     /* If this reduction needs destruction and parallel
+                        has been cancelled, jump around the merge operation
+                        to the destruction.  */
+                     tree lab5 = create_artificial_label (UNKNOWN_LOCATION);
+                     lab6 = create_artificial_label (UNKNOWN_LOCATION);
+                     tree zero = build_zero_cst (TREE_TYPE (cancellable));
+                     g = gimple_build_cond (NE_EXPR, cancellable, zero,
+                                            lab6, lab5);
+                     gimple_seq_add_stmt (end, g);
+                     gimple_seq_add_stmt (end, gimple_build_label (lab5));
+                   }
+                 SET_DECL_VALUE_EXPR (placeholder, out);
+                 DECL_HAS_VALUE_EXPR_P (placeholder) = 1;
+                 SET_DECL_VALUE_EXPR (decl_placeholder, priv);
+                 DECL_HAS_VALUE_EXPR_P (decl_placeholder) = 1;
+                 lower_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c), ctx);
+                 gimple_seq_add_seq (end,
+                                     OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c));
+                 OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL;
+                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
+                   {
+                     OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL;
+                     OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = NULL;
+                   }
+                 if (cancellable)
+                   gimple_seq_add_stmt (end, gimple_build_label (lab6));
+                 tree x = lang_hooks.decls.omp_clause_dtor (c, priv);
+                 if (x)
+                   {
+                     gimple_seq tseq = NULL;
+                     gimplify_stmt (&x, &tseq);
+                     gimple_seq_add_seq (end, tseq);
+                   }
+               }
+             else
+               {
+                 tree x = build2 (rcode, TREE_TYPE (out), out, priv);
+                 out = unshare_expr (out);
+                 gimplify_assign (out, x, end);
+               }
+             gimple *g
+               = gimple_build_assign (new_var, POINTER_PLUS_EXPR, new_var,
+                                      TYPE_SIZE_UNIT (TREE_TYPE (type)));
+             gimple_seq_add_stmt (end, g);
+             g = gimple_build_assign (ref, POINTER_PLUS_EXPR, ref,
+                                      TYPE_SIZE_UNIT (TREE_TYPE (type)));
+             gimple_seq_add_stmt (end, g);
+             g = gimple_build_assign (i, PLUS_EXPR, i,
+                                      build_int_cst (TREE_TYPE (i), 1));
+             gimple_seq_add_stmt (end, g);
+             g = gimple_build_cond (LE_EXPR, i, v, body, endl);
+             gimple_seq_add_stmt (end, g);
+             gimple_seq_add_stmt (end, gimple_build_label (endl));
+           }
+         else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
+           {
+             tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
+             tree oldv = NULL_TREE;
+             tree lab6 = NULL_TREE;
+             if (cancellable)
+               {
+                 /* If this reduction needs destruction and parallel
+                    has been cancelled, jump around the merge operation
+                    to the destruction.  */
+                 tree lab5 = create_artificial_label (UNKNOWN_LOCATION);
+                 lab6 = create_artificial_label (UNKNOWN_LOCATION);
+                 tree zero = build_zero_cst (TREE_TYPE (cancellable));
+                 g = gimple_build_cond (NE_EXPR, cancellable, zero,
+                                        lab6, lab5);
+                 gimple_seq_add_stmt (end, g);
+                 gimple_seq_add_stmt (end, gimple_build_label (lab5));
+               }
+             if (omp_is_reference (decl)
+                 && !useless_type_conversion_p (TREE_TYPE (placeholder),
+                                                TREE_TYPE (ref)))
+               ref = build_fold_addr_expr_loc (OMP_CLAUSE_LOCATION (c), ref);
+             ref = build_fold_addr_expr_loc (OMP_CLAUSE_LOCATION (c), ref);
+             tree refv = create_tmp_var (TREE_TYPE (ref));
+             gimplify_assign (refv, ref, end);
+             ref = build_simple_mem_ref_loc (OMP_CLAUSE_LOCATION (c), refv);
+             SET_DECL_VALUE_EXPR (placeholder, ref);
+             DECL_HAS_VALUE_EXPR_P (placeholder) = 1;
+             tree d = maybe_lookup_decl (decl, ctx);
+             gcc_assert (d);
+             if (DECL_HAS_VALUE_EXPR_P (d))
+               oldv = DECL_VALUE_EXPR (d);
+             if (omp_is_reference (var))
+               {
+                 tree v = fold_convert (TREE_TYPE (d),
+                                        build_fold_addr_expr (new_var));
+                 SET_DECL_VALUE_EXPR (d, v);
+               }
+             else
+               SET_DECL_VALUE_EXPR (d, new_var);
+             DECL_HAS_VALUE_EXPR_P (d) = 1;
+             lower_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c), ctx);
+             if (oldv)
+               SET_DECL_VALUE_EXPR (d, oldv);
+             else
+               {
+                 SET_DECL_VALUE_EXPR (d, NULL_TREE);
+                 DECL_HAS_VALUE_EXPR_P (d) = 0;
+               }
+             gimple_seq_add_seq (end, OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c));
+             OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL;
+             if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
+               OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL;
+             if (cancellable)
+               gimple_seq_add_stmt (end, gimple_build_label (lab6));
+             tree x = lang_hooks.decls.omp_clause_dtor (c, new_var);
+             if (x)
+               {
+                 gimple_seq tseq = NULL;
+                 gimplify_stmt (&x, &tseq);
+                 gimple_seq_add_seq (end, tseq);
+               }
+           }
+         else
+           {
+             tree x = build2 (rcode, TREE_TYPE (ref), ref, new_var);
+             ref = unshare_expr (ref);
+             gimplify_assign (ref, x, end);
+           }
+         gimple_seq_add_stmt (end, gimple_build_label (lab4));
+         ++cnt;
+         field = DECL_CHAIN (bfield);
+       }
+    }
+
+  if (code == OMP_TASKGROUP)
+    {
+      t = builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_REDUCTION_REGISTER);
+      g = gimple_build_call (t, 1, build_fold_addr_expr (avar));
+      gimple_seq_add_stmt (start, g);
+    }
+  else
+    {
+      tree c;
+      if (code == OMP_FOR)
+       c = gimple_omp_for_clauses (ctx->stmt);
+      else if (code == OMP_SECTIONS)
+       c = gimple_omp_sections_clauses (ctx->stmt);
+      else
+       c = gimple_omp_taskreg_clauses (ctx->stmt);
+      c = omp_find_clause (c, OMP_CLAUSE__REDUCTEMP_);
+      t = fold_convert (TREE_TYPE (OMP_CLAUSE_DECL (c)),
+                       build_fold_addr_expr (avar));
+      gimplify_assign (OMP_CLAUSE_DECL (c), t, start);
+    }
+
+  gimple_seq_add_stmt (end, gimple_build_assign (data, PLUS_EXPR, data, sz));
+  gimple_seq_add_stmt (end, gimple_build_assign (idx, PLUS_EXPR, idx,
+                                                size_one_node));
+  g = gimple_build_cond (NE_EXPR, idx, num_thr_sz, lab1, lab2);
+  gimple_seq_add_stmt (end, g);
+  gimple_seq_add_stmt (end, gimple_build_label (lab2));
+  if (code == OMP_FOR || code == OMP_SECTIONS)
+    {
+      enum built_in_function bfn
+       = BUILT_IN_GOMP_WORKSHARE_TASK_REDUCTION_UNREGISTER;
+      t = builtin_decl_explicit (bfn);
+      tree c_bool_type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (t)));
+      tree arg;
+      if (cancellable)
+       {
+         arg = create_tmp_var (c_bool_type);
+         gimple_seq_add_stmt (end, gimple_build_assign (arg, NOP_EXPR,
+                                                        cancellable));
+       }
+      else
+       arg = build_int_cst (c_bool_type, 0);
+      g = gimple_build_call (t, 1, arg);
+    }
+  else
+    {
+      t = builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_REDUCTION_UNREGISTER);
+      g = gimple_build_call (t, 1, build_fold_addr_expr (avar));
+    }
+  gimple_seq_add_stmt (end, g);
+  t = build_constructor (atype, NULL);
+  TREE_THIS_VOLATILE (t) = 1;
+  gimple_seq_add_stmt (end, gimple_build_assign (avar, t));
+}
 
 /* Expand code for an OpenMP taskgroup directive.  */
 
@@ -6149,21 +7527,31 @@ lower_omp_taskgroup (gimple_stmt_iterator *gsi_p, omp_context *ctx)
   gimple *stmt = gsi_stmt (*gsi_p);
   gcall *x;
   gbind *bind;
+  gimple_seq dseq = NULL;
   tree block = make_node (BLOCK);
 
   bind = gimple_build_bind (NULL, NULL, block);
   gsi_replace (gsi_p, bind, true);
   gimple_bind_add_stmt (bind, stmt);
 
+  push_gimplify_context ();
+
   x = gimple_build_call (builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_START),
                         0);
   gimple_bind_add_stmt (bind, x);
 
+  lower_omp_task_reductions (ctx, OMP_TASKGROUP,
+                            gimple_omp_taskgroup_clauses (stmt),
+                            gimple_bind_body_ptr (bind), &dseq);
+
   lower_omp (gimple_omp_body_ptr (stmt), ctx);
   gimple_bind_add_seq (bind, gimple_omp_body (stmt));
   gimple_omp_set_body (stmt, NULL);
 
   gimple_bind_add_stmt (bind, gimple_build_omp_return (true));
+  gimple_bind_add_seq (bind, dseq);
+
+  pop_gimplify_context (bind);
 
   gimple_bind_append_vars (bind, ctx->block_vars);
   BLOCK_VARS (block) = ctx->block_vars;
@@ -6752,7 +8140,8 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx)
   struct omp_for_data fd, *fdp = NULL;
   gomp_for *stmt = as_a <gomp_for *> (gsi_stmt (*gsi_p));
   gbind *new_stmt;
-  gimple_seq omp_for_body, body, dlist;
+  gimple_seq omp_for_body, body, dlist, tred_ilist = NULL, tred_dlist = NULL;
+  gimple_seq cnt_list = NULL;
   gimple_seq oacc_head = NULL, oacc_tail = NULL;
   size_t i;
 
@@ -6845,9 +8234,30 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx)
   /* The pre-body and input clauses go before the lowered GIMPLE_OMP_FOR.  */
   dlist = NULL;
   body = NULL;
+  tree rclauses
+    = omp_task_reductions_find_first (gimple_omp_for_clauses (stmt), OMP_FOR,
+                                     OMP_CLAUSE_REDUCTION);
+  tree rtmp = NULL_TREE;
+  if (rclauses)
+    {
+      tree type = build_pointer_type (pointer_sized_int_node);
+      tree temp = create_tmp_var (type);
+      tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__REDUCTEMP_);
+      OMP_CLAUSE_DECL (c) = temp;
+      OMP_CLAUSE_CHAIN (c) = gimple_omp_for_clauses (stmt);
+      gimple_omp_for_set_clauses (stmt, c);
+      lower_omp_task_reductions (ctx, OMP_FOR,
+                                gimple_omp_for_clauses (stmt),
+                                &tred_ilist, &tred_dlist);
+      rclauses = c;
+      rtmp = make_ssa_name (type);
+      gimple_seq_add_stmt (&body, gimple_build_assign (rtmp, temp));
+    }
+
   lower_rec_input_clauses (gimple_omp_for_clauses (stmt), &body, &dlist, ctx,
                           fdp);
-  gimple_seq_add_seq (&body, gimple_omp_for_pre_body (stmt));
+  gimple_seq_add_seq (rclauses ? &tred_ilist : &body,
+                     gimple_omp_for_pre_body (stmt));
 
   lower_omp (gimple_omp_body_ptr (stmt), ctx);
 
@@ -6862,20 +8272,24 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx)
     {
       rhs_p = gimple_omp_for_initial_ptr (stmt, i);
       if (!is_gimple_min_invariant (*rhs_p))
-       *rhs_p = get_formal_tmp_var (*rhs_p, &body);
+       *rhs_p = get_formal_tmp_var (*rhs_p, &cnt_list);
       else if (TREE_CODE (*rhs_p) == ADDR_EXPR)
        recompute_tree_invariant_for_addr_expr (*rhs_p);
 
       rhs_p = gimple_omp_for_final_ptr (stmt, i);
       if (!is_gimple_min_invariant (*rhs_p))
-       *rhs_p = get_formal_tmp_var (*rhs_p, &body);
+       *rhs_p = get_formal_tmp_var (*rhs_p, &cnt_list);
       else if (TREE_CODE (*rhs_p) == ADDR_EXPR)
        recompute_tree_invariant_for_addr_expr (*rhs_p);
 
       rhs_p = &TREE_OPERAND (gimple_omp_for_incr (stmt, i), 1);
       if (!is_gimple_min_invariant (*rhs_p))
-       *rhs_p = get_formal_tmp_var (*rhs_p, &body);
+       *rhs_p = get_formal_tmp_var (*rhs_p, &cnt_list);
     }
+  if (rclauses)
+    gimple_seq_add_seq (&tred_ilist, cnt_list);
+  else
+    gimple_seq_add_seq (&body, cnt_list);
 
   /* Once lowered, extract the bounds and clauses.  */
   omp_extract_for_data (stmt, &fd, NULL);
@@ -6922,13 +8336,26 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx)
 
   gimple_seq_add_seq (&body, dlist);
 
+  if (rclauses)
+    {
+      gimple_seq_add_seq (&tred_ilist, body);
+      body = tred_ilist;
+    }
+
   body = maybe_catch_exception (body);
 
   if (!phony_loop)
     {
       /* Region exit marker goes at the end of the loop body.  */
-      gimple_seq_add_stmt (&body, gimple_build_omp_return (fd.have_nowait));
-      maybe_add_implicit_barrier_cancel (ctx, &body);
+      gimple *g = gimple_build_omp_return (fd.have_nowait);
+      gimple_seq_add_stmt (&body, g);
+
+      gimple_seq_add_seq (&body, tred_dlist);
+
+      maybe_add_implicit_barrier_cancel (ctx, g, &body);
+
+      if (rclauses)
+       OMP_CLAUSE_DECL (rclauses) = rtmp;
     }
 
   /* Add OpenACC joining and reduction markers just after the loop.  */
@@ -7153,6 +8580,40 @@ create_task_copyfn (gomp_task *task_stmt, omp_context *ctx)
        t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
        append_to_statement_list (t, &list);
        break;
+      case OMP_CLAUSE_REDUCTION:
+      case OMP_CLAUSE_IN_REDUCTION:
+       decl = OMP_CLAUSE_DECL (c);
+       if (TREE_CODE (decl) == MEM_REF)
+         {
+           decl = TREE_OPERAND (decl, 0);
+           if (TREE_CODE (decl) == POINTER_PLUS_EXPR)
+             decl = TREE_OPERAND (decl, 0);
+           if (TREE_CODE (decl) == INDIRECT_REF
+               || TREE_CODE (decl) == ADDR_EXPR)
+             decl = TREE_OPERAND (decl, 0);
+         }
+       key = (splay_tree_key) decl;
+       n = splay_tree_lookup (ctx->field_map, key);
+       if (n == NULL)
+         break;
+       f = (tree) n->value;
+       if (tcctx.cb.decl_map)
+         f = *tcctx.cb.decl_map->get (f);
+       n = splay_tree_lookup (ctx->sfield_map, key);
+       sf = (tree) n->value;
+       if (tcctx.cb.decl_map)
+         sf = *tcctx.cb.decl_map->get (sf);
+       src = build_simple_mem_ref_loc (loc, sarg);
+       src = omp_build_component_ref (src, sf);
+       if (decl != OMP_CLAUSE_DECL (c)
+           && TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE
+           && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == POINTER_TYPE)
+         src = build_simple_mem_ref_loc (loc, src);
+       dst = build_simple_mem_ref_loc (loc, arg);
+       dst = omp_build_component_ref (dst, f);
+       t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
+       append_to_statement_list (t, &list);
+       break;
       case OMP_CLAUSE__LOOPTEMP_:
        /* Fields for first two _looptemp_ clauses are initialized by
           GOMP_taskloop*, the rest are handled like firstprivate.  */
@@ -7162,6 +8623,7 @@ create_task_copyfn (gomp_task *task_stmt, omp_context *ctx)
            break;
          }
        /* FALLTHRU */
+      case OMP_CLAUSE__REDUCTEMP_:
       case OMP_CLAUSE_FIRSTPRIVATE:
        decl = OMP_CLAUSE_DECL (c);
        if (is_variable_sized (decl))
@@ -7187,7 +8649,7 @@ create_task_copyfn (gomp_task *task_stmt, omp_context *ctx)
          src = decl;
        dst = build_simple_mem_ref_loc (loc, arg);
        dst = omp_build_component_ref (dst, f);
-       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE__LOOPTEMP_)
+       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE)
          t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
        else
          t = lang_hooks.decls.omp_clause_copy_ctor (c, dst, src);
@@ -7279,7 +8741,7 @@ lower_depend_clauses (tree *pclauses, gimple_seq *iseq, gimple_seq *oseq)
 {
   tree c, clauses;
   gimple *g;
-  size_t n_in = 0, n_out = 0, idx = 2, i;
+  size_t cnt[4] = { 0, 0, 0, 0 }, idx = 2, i;
 
   clauses = omp_find_clause (*pclauses, OMP_CLAUSE_DEPEND);
   gcc_assert (clauses);
@@ -7287,12 +8749,21 @@ lower_depend_clauses (tree *pclauses, gimple_seq *iseq, gimple_seq *oseq)
     if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
       switch (OMP_CLAUSE_DEPEND_KIND (c))
        {
+       case OMP_CLAUSE_DEPEND_LAST:
+         /* Lowering already done at gimplification.  */
+         return;
        case OMP_CLAUSE_DEPEND_IN:
-         n_in++;
+         cnt[2]++;
          break;
        case OMP_CLAUSE_DEPEND_OUT:
        case OMP_CLAUSE_DEPEND_INOUT:
-         n_out++;
+         cnt[0]++;
+         break;
+       case OMP_CLAUSE_DEPEND_MUTEXINOUTSET:
+         cnt[1]++;
+         break;
+       case OMP_CLAUSE_DEPEND_DEPOBJ:
+         cnt[3]++;
          break;
        case OMP_CLAUSE_DEPEND_SOURCE:
        case OMP_CLAUSE_DEPEND_SINK:
@@ -7300,25 +8771,61 @@ lower_depend_clauses (tree *pclauses, gimple_seq *iseq, gimple_seq *oseq)
        default:
          gcc_unreachable ();
        }
-  tree type = build_array_type_nelts (ptr_type_node, n_in + n_out + 2);
+  if (cnt[1] || cnt[3])
+    idx = 5;
+  size_t total = cnt[0] + cnt[1] + cnt[2] + cnt[3];
+  tree type = build_array_type_nelts (ptr_type_node, total + idx);
   tree array = create_tmp_var (type);
   TREE_ADDRESSABLE (array) = 1;
   tree r = build4 (ARRAY_REF, ptr_type_node, array, size_int (0), NULL_TREE,
                   NULL_TREE);
-  g = gimple_build_assign (r, build_int_cst (ptr_type_node, n_in + n_out));
-  gimple_seq_add_stmt (iseq, g);
-  r = build4 (ARRAY_REF, ptr_type_node, array, size_int (1), NULL_TREE,
-             NULL_TREE);
-  g = gimple_build_assign (r, build_int_cst (ptr_type_node, n_out));
+  if (idx == 5)
+    {
+      g = gimple_build_assign (r, build_int_cst (ptr_type_node, 0));
+      gimple_seq_add_stmt (iseq, g);
+      r = build4 (ARRAY_REF, ptr_type_node, array, size_int (1), NULL_TREE,
+                 NULL_TREE);
+    }
+  g = gimple_build_assign (r, build_int_cst (ptr_type_node, total));
   gimple_seq_add_stmt (iseq, g);
-  for (i = 0; i < 2; i++)
+  for (i = 0; i < (idx == 5 ? 3 : 1); i++)
+    {
+      r = build4 (ARRAY_REF, ptr_type_node, array,
+                 size_int (i + 1 + (idx == 5)), NULL_TREE, NULL_TREE);
+      g = gimple_build_assign (r, build_int_cst (ptr_type_node, cnt[i]));
+      gimple_seq_add_stmt (iseq, g);
+    }
+  for (i = 0; i < 4; i++)
     {
-      if ((i ? n_in : n_out) == 0)
+      if (cnt[i] == 0)
        continue;
       for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
-       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
-           && ((OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_IN) ^ i))
+       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
+         continue;
+       else
          {
+           switch (OMP_CLAUSE_DEPEND_KIND (c))
+             {
+             case OMP_CLAUSE_DEPEND_IN:
+               if (i != 2)
+                 continue;
+               break;
+             case OMP_CLAUSE_DEPEND_OUT:
+             case OMP_CLAUSE_DEPEND_INOUT:
+               if (i != 0)
+                 continue;
+               break;
+             case OMP_CLAUSE_DEPEND_MUTEXINOUTSET:
+               if (i != 1)
+                 continue;
+               break;
+             case OMP_CLAUSE_DEPEND_DEPOBJ:
+               if (i != 3)
+                 continue;
+               break;
+             default:
+               gcc_unreachable ();
+             }
            tree t = OMP_CLAUSE_DECL (c);
            t = fold_convert (ptr_type_node, t);
            gimplify_expr (&t, iseq, NULL, is_gimple_val, fb_rvalue);
@@ -7329,6 +8836,7 @@ lower_depend_clauses (tree *pclauses, gimple_seq *iseq, gimple_seq *oseq)
          }
     }
   c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_DEPEND);
+  OMP_CLAUSE_DEPEND_KIND (c) = OMP_CLAUSE_DEPEND_LAST;
   OMP_CLAUSE_DECL (c) = build_fold_addr_expr (array);
   OMP_CLAUSE_CHAIN (c) = *pclauses;
   *pclauses = c;
@@ -7348,13 +8856,22 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx)
   tree child_fn, t;
   gimple *stmt = gsi_stmt (*gsi_p);
   gbind *par_bind, *bind, *dep_bind = NULL;
-  gimple_seq par_body, olist, ilist, par_olist, par_rlist, par_ilist, new_body;
+  gimple_seq par_body;
   location_t loc = gimple_location (stmt);
 
   clauses = gimple_omp_taskreg_clauses (stmt);
-  par_bind
-    = as_a <gbind *> (gimple_seq_first_stmt (gimple_omp_body (stmt)));
-  par_body = gimple_bind_body (par_bind);
+  if (gimple_code (stmt) == GIMPLE_OMP_TASK
+      && gimple_omp_task_taskwait_p (stmt))
+    {
+      par_bind = NULL;
+      par_body = NULL;
+    }
+  else
+    {
+      par_bind
+       = as_a <gbind *> (gimple_seq_first_stmt (gimple_omp_body (stmt)));
+      par_body = gimple_bind_body (par_bind);
+    }
   child_fn = ctx->cb.dst_fn;
   if (gimple_code (stmt) == GIMPLE_OMP_PARALLEL
       && !gimple_omp_parallel_combined_p (stmt))
@@ -7380,14 +8897,49 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx)
                            &dep_ilist, &dep_olist);
     }
 
+  if (gimple_code (stmt) == GIMPLE_OMP_TASK
+      && gimple_omp_task_taskwait_p (stmt))
+    {
+      if (dep_bind)
+       {
+         gsi_replace (gsi_p, dep_bind, true);
+         gimple_bind_add_seq (dep_bind, dep_ilist);
+         gimple_bind_add_stmt (dep_bind, stmt);
+         gimple_bind_add_seq (dep_bind, dep_olist);
+         pop_gimplify_context (dep_bind);
+       }
+      return;
+    }
+
   if (ctx->srecord_type)
     create_task_copyfn (as_a <gomp_task *> (stmt), ctx);
 
+  gimple_seq tskred_ilist = NULL;
+  gimple_seq tskred_olist = NULL;
+  if ((is_task_ctx (ctx)
+       && gimple_omp_task_taskloop_p (ctx->stmt)
+       && omp_find_clause (gimple_omp_task_clauses (ctx->stmt),
+                          OMP_CLAUSE_REDUCTION))
+      || (is_parallel_ctx (ctx)
+         && omp_find_clause (gimple_omp_parallel_clauses (stmt),
+                             OMP_CLAUSE__REDUCTEMP_)))
+    {
+      if (dep_bind == NULL)
+       {
+         push_gimplify_context ();
+         dep_bind = gimple_build_bind (NULL, NULL, make_node (BLOCK));
+       }
+      lower_omp_task_reductions (ctx, is_task_ctx (ctx) ? OMP_TASKLOOP
+                                                       : OMP_PARALLEL,
+                                gimple_omp_taskreg_clauses (ctx->stmt),
+                                &tskred_ilist, &tskred_olist);
+    }
+
   push_gimplify_context ();
 
-  par_olist = NULL;
-  par_ilist = NULL;
-  par_rlist = NULL;
+  gimple_seq par_olist = NULL;
+  gimple_seq par_ilist = NULL;
+  gimple_seq par_rlist = NULL;
   bool phony_construct = gimple_code (stmt) == GIMPLE_OMP_PARALLEL
     && gimple_omp_parallel_grid_phony (as_a <gomp_parallel *> (stmt));
   if (phony_construct && ctx->record_type)
@@ -7417,8 +8969,8 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx)
       gimple_omp_taskreg_set_data_arg (stmt, ctx->sender_decl);
     }
 
-  olist = NULL;
-  ilist = NULL;
+  gimple_seq olist = NULL;
+  gimple_seq ilist = NULL;
   lower_send_clauses (clauses, &ilist, &olist, ctx);
   lower_send_shared_vars (&ilist, &olist, ctx);
 
@@ -7433,7 +8985,7 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx)
   /* Once all the expansions are done, sequence all the different
      fragments inside gimple_omp_body.  */
 
-  new_body = NULL;
+  gimple_seq new_body = NULL;
 
   if (ctx->record_type)
     {
@@ -7461,7 +9013,10 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx)
       gimple_omp_set_body (stmt, new_body);
     }
 
-  bind = gimple_build_bind (NULL, NULL, gimple_bind_block (par_bind));
+  if (dep_bind && gimple_bind_block (par_bind) == NULL_TREE)
+    bind = gimple_build_bind (NULL, NULL, make_node (BLOCK));
+  else
+    bind = gimple_build_bind (NULL, NULL, gimple_bind_block (par_bind));
   gsi_replace (gsi_p, dep_bind ? dep_bind : bind, true);
   gimple_bind_add_seq (bind, ilist);
   if (!phony_construct)
@@ -7475,7 +9030,9 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx)
   if (dep_bind)
     {
       gimple_bind_add_seq (dep_bind, dep_ilist);
+      gimple_bind_add_seq (dep_bind, tskred_ilist);
       gimple_bind_add_stmt (dep_bind, bind);
+      gimple_bind_add_seq (dep_bind, tskred_olist);
       gimple_bind_add_seq (dep_bind, dep_olist);
       pop_gimplify_context (dep_bind);
     }
@@ -8830,7 +10387,10 @@ lower_omp_1 (gimple_stmt_iterator *gsi_p, omp_context *ctx)
     case GIMPLE_OMP_TEAMS:
       ctx = maybe_lookup_ctx (stmt);
       gcc_assert (ctx);
-      lower_omp_teams (gsi_p, ctx);
+      if (gimple_omp_teams_host (as_a <gomp_teams *> (stmt)))
+       lower_omp_taskreg (gsi_p, ctx);
+      else
+       lower_omp_teams (gsi_p, ctx);
       break;
     case GIMPLE_OMP_GRID_BODY:
       ctx = maybe_lookup_ctx (stmt);
index 5d24473159532cdec51d4fdbd38a9b646bf5273d..c227dc95ca10265f1e2b269ee117e93e0435067a 100644 (file)
@@ -1,3 +1,114 @@
+2018-11-08  Jakub Jelinek  <jakub@redhat.com>
+
+       * c-c++-common/gomp/atomic-17.c: New test.
+       * c-c++-common/gomp/atomic-18.c: New test.
+       * c-c++-common/gomp/atomic-19.c: New test.
+       * c-c++-common/gomp/atomic-20.c: New test.
+       * c-c++-common/gomp/atomic-21.c: New test.
+       * c-c++-common/gomp/atomic-22.c: New test.
+       * c-c++-common/gomp/clauses-1.c (r2): New variable.
+       (foo): Add ntm argument and test if and nontemporal clauses on
+       constructs with simd.
+       (bar): Put taskloop simd inside of taskgroup with task_reduction,
+       use in_reduction clause instead of reduction.  Add another
+       taskloop simd without nogroup clause, but with reduction clause and
+       a new in_reduction.  Add ntm and i3 arguments.  Test if and
+       nontemporal clauses on constructs with simd.  Change if clauses on
+       some constructs from specific to the particular constituents to one
+       without a modifier.  Add new tests for combined host teams and for
+       new parallel master and {,parallel }master taskloop{, simd} combined
+       constructs.
+       (baz): New function with host teams tests.
+       * gcc.dg/gomp/combined-1.c: Moved to ...
+       * c-c++-common/gomp/combined-1.c: ... here.  Adjust expected library
+       call.
+       * c-c++-common/gomp/combined-2.c: New test.
+       * c-c++-common/gomp/combined-3.c: New test.
+       * c-c++-common/gomp/critical-1.c: New test.
+       * c-c++-common/gomp/critical-2.c: New test.
+       * c-c++-common/gomp/default-1.c: New test.
+       * c-c++-common/gomp/defaultmap-1.c: New test.
+       * c-c++-common/gomp/defaultmap-2.c: New test.
+       * c-c++-common/gomp/defaultmap-3.c: New test.
+       * c-c++-common/gomp/depend-5.c: New test.
+       * c-c++-common/gomp/depend-6.c: New test.
+       * c-c++-common/gomp/depend-iterator-1.c: New test.
+       * c-c++-common/gomp/depend-iterator-2.c: New test.
+       * c-c++-common/gomp/depobj-1.c: New test.
+       * c-c++-common/gomp/flush-1.c: New test.
+       * c-c++-common/gomp/flush-2.c: New test.
+       * c-c++-common/gomp/for-1.c: New test.
+       * c-c++-common/gomp/for-2.c: New test.
+       * c-c++-common/gomp/for-3.c: New test.
+       * c-c++-common/gomp/for-4.c: New test.
+       * c-c++-common/gomp/for-5.c: New test.
+       * c-c++-common/gomp/for-6.c: New test.
+       * c-c++-common/gomp/for-7.c: New test.
+       * c-c++-common/gomp/if-1.c (foo): Add some further tests.
+       * c-c++-common/gomp/if-2.c (foo): Likewise.  Expect slightly different
+       diagnostics wording in one case.
+       * c-c++-common/gomp/if-3.c: New test.
+       * c-c++-common/gomp/master-combined-1.c: New test.
+       * c-c++-common/gomp/master-combined-2.c: New test.
+       * c-c++-common/gomp/nontemporal-1.c: New test.
+       * c-c++-common/gomp/nontemporal-2.c: New test.
+       * c-c++-common/gomp/reduction-task-1.c: New test.
+       * c-c++-common/gomp/reduction-task-2.c: New test.
+       * c-c++-common/gomp/requires-1.c: New test.
+       * c-c++-common/gomp/requires-2.c: New test.
+       * c-c++-common/gomp/requires-3.c: New test.
+       * c-c++-common/gomp/requires-4.c: New test.
+       * c-c++-common/gomp/schedule-modifiers-1.c (bar): Don't expect
+       diagnostics for nonmonotonic modifier with static, runtime or auto
+       schedule kinds.
+       * c-c++-common/gomp/simd7.c: New test.
+       * c-c++-common/gomp/target-data-1.c: New test.
+       * c-c++-common/gomp/taskloop-reduction-1.c: New test.
+       * c-c++-common/gomp/taskwait-depend-1.c: New test.
+       * c-c++-common/gomp/teams-1.c: New test.
+       * c-c++-common/gomp/teams-2.c: New test.
+       * gcc.dg/gomp/appendix-a/a.24.1.c: Update from OpenMP examples.  Add
+       shared(c) clause.
+       * gcc.dg/gomp/atomic-5.c (f1): Add another expected error.
+       * gcc.dg/gomp/clause-1.c: Adjust expected diagnostics for const
+       qualified vars without mutable member no longer being predeterined
+       shared.
+       * gcc.dg/gomp/sharing-1.c: Likewise.
+       * g++.dg/gomp/clause-3.C: Likewise.
+       * g++.dg/gomp/member-2.C: Likewise.
+       * g++.dg/gomp/predetermined-1.C: Likewise.
+       * g++.dg/gomp/private-1.C: Likewise.
+       * g++.dg/gomp/sharing-1.C: Likewise.
+       * g++.dg/gomp/sharing-2.C: Likewise.  Add a few tests with aggregate
+       const static data member without mutable elements.
+       * gcc.dg/gomp/for-4.c: Expected nonmonotonic functions in the dumps.
+       * gcc.dg/gomp/for-5.c: Likewise.
+       * gcc.dg/gomp/for-6.c: Change expected library call.
+       * gcc.dg/gomp/pr39495-2.c (foo): Don't expect errors on !=.
+       * gcc.dg/gomp/reduction-2.c: New test.
+       * gcc.dg/gomp/simd-1.c: New test.
+       * gcc.dg/gomp/teams-1.c: Adjust expected diagnostic lines.
+       * g++.dg/gomp/atomic-18.C: New test.
+       * g++.dg/gomp/atomic-19.C: New test.
+       * g++.dg/gomp/atomic-5.C (f1): Adjust expected lines of read-only
+       variable messages.  Add another expected error.
+       * g++.dg/gomp/critical-3.C: New test.
+       * g++.dg/gomp/depend-iterator-1.C: New test.
+       * g++.dg/gomp/depend-iterator-2.C: New test.
+       * g++.dg/gomp/depobj-1.C: New test.
+       * g++.dg/gomp/doacross-1.C: New test.
+       * g++.dg/gomp/for-21.C: New test.
+       * g++.dg/gomp/for-4.C: Expected nonmonotonic functions in the dumps.
+       * g++.dg/gomp/for-5.C: Likewise.
+       * g++.dg/gomp/for-6.C: Change expected library call.
+       * g++.dg/gomp/loop-4.C: New test.
+       * g++.dg/gomp/pr33372-1.C: Adjust location of the expected
+       diagnostics.
+       * g++.dg/gomp/pr33372-3.C: Likewise.
+       * g++.dg/gomp/pr39495-2.C (foo): Don't expect errors on !=.
+       * g++.dg/gomp/simd-2.C: New test.
+       * g++.dg/gomp/tpl-atomic-2.C: Adjust expected diagnostic lines.
+
 2018-11-08  Uros Bizjak  <ubizjak@gmail.com>
 
        * gcc.dg/pr87874.c (em): Declare uint64_max as
diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-17.c b/gcc/testsuite/c-c++-common/gomp/atomic-17.c
new file mode 100644 (file)
index 0000000..d313b29
--- /dev/null
@@ -0,0 +1,29 @@
+int i, v;
+float f;
+
+void
+foo ()
+{
+  #pragma omp atomic release, hint (0), update
+  i = i + 1;
+  #pragma omp atomic hint(0)seq_cst
+  i = i + 1;
+  #pragma omp atomic relaxed,update,hint (0)
+  i = i + 1;
+  #pragma omp atomic release
+  i = i + 1;
+  #pragma omp atomic relaxed
+  i = i + 1;
+  #pragma omp atomic acq_rel capture
+  v = i = i + 1;
+  #pragma omp atomic capture,acq_rel , hint (1)
+  v = i = i + 1;
+  #pragma omp atomic hint(0),acquire capture
+  v = i = i + 1;
+  #pragma omp atomic read acquire
+  v = i;
+  #pragma omp atomic release,write
+  i = v;
+  #pragma omp atomic hint(1),update,release
+  f = f + 2.0;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-18.c b/gcc/testsuite/c-c++-common/gomp/atomic-18.c
new file mode 100644 (file)
index 0000000..95fbcd1
--- /dev/null
@@ -0,0 +1,35 @@
+int i, v;
+float f;
+
+void
+foo (int j)
+{
+  #pragma omp atomic update,update     /* { dg-error "too many atomic clauses" } */
+  i = i + 1;
+  #pragma omp atomic seq_cst release   /* { dg-error "too many memory order clauses" } */
+  i = i + 1;
+  #pragma omp atomic read,release      /* { dg-error "incompatible with 'acq_rel' or 'release' clauses" } */
+  v = i;
+  #pragma omp atomic acq_rel read      /* { dg-error "incompatible with 'acq_rel' or 'release' clauses" } */
+  v = i;
+  #pragma omp atomic write acq_rel     /* { dg-error "incompatible with 'acq_rel' or 'acquire' clauses" } */
+  i = v;
+  #pragma omp atomic acquire , write   /* { dg-error "incompatible with 'acq_rel' or 'acquire' clauses" } */
+  i = v;
+  #pragma omp atomic update ,acquire   /* { dg-error "incompatible with 'acq_rel' or 'acquire' clauses" } */
+  i = i + 1;
+  #pragma omp atomic acq_rel update    /* { dg-error "incompatible with 'acq_rel' or 'acquire' clauses" } */
+  i = i + 1;
+  #pragma omp atomic acq_rel,hint(0)   /* { dg-error "incompatible with 'acq_rel' or 'acquire' clauses" } */
+  i = i + 1;
+  #pragma omp atomic acquire           /* { dg-error "incompatible with 'acq_rel' or 'acquire' clauses" } */
+  i = i + 1;
+  #pragma omp atomic capture hint (0) capture  /* { dg-error "too many atomic clauses" } */
+  v = i = i + 1;
+  #pragma omp atomic hint(j + 2)       /* { dg-error "constant integer expression" } */
+  i = i + 1;
+  #pragma omp atomic hint(f)           /* { dg-error "integ" } */
+  i = i + 1;
+  #pragma omp atomic foobar            /* { dg-error "expected 'read', 'write', 'update', 'capture', 'seq_cst', 'acq_rel', 'release', 'relaxed' or 'hint' clause" } */
+  i = i + 1;                           /* { dg-error "expected end of line before" "" { target *-*-* } .-1 } */
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-19.c b/gcc/testsuite/c-c++-common/gomp/atomic-19.c
new file mode 100644 (file)
index 0000000..b15761e
--- /dev/null
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-original" } */
+/* { dg-final { scan-tree-dump-times "omp atomic release" 1 "original" } } */
+/* { dg-final { scan-tree-dump-times "omp atomic relaxed" 3 "original" } } */
+/* { dg-final { scan-tree-dump-times "omp atomic read relaxed" 1 "original" } } */
+/* { dg-final { scan-tree-dump-times "omp atomic capture relaxed" 1 "original" } } */
+
+int i, j, k, l, m, n;
+
+void
+foo ()
+{
+  int v;
+  #pragma omp atomic release
+  i = i + 1;
+  #pragma omp requires atomic_default_mem_order (relaxed)
+  #pragma omp atomic
+  j = j + 1;
+  #pragma omp atomic update
+  k = k + 1;
+  #pragma omp atomic read
+  v = l;
+  #pragma omp atomic write
+  m = v;
+  #pragma omp atomic capture
+  v = n = n + 1;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-20.c b/gcc/testsuite/c-c++-common/gomp/atomic-20.c
new file mode 100644 (file)
index 0000000..3343d5e
--- /dev/null
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-original" } */
+/* { dg-final { scan-tree-dump-times "omp atomic release" 1 "original" } } */
+/* { dg-final { scan-tree-dump-times "omp atomic seq_cst" 3 "original" } } */
+/* { dg-final { scan-tree-dump-times "omp atomic read seq_cst" 1 "original" } } */
+/* { dg-final { scan-tree-dump-times "omp atomic capture seq_cst" 1 "original" } } */
+
+int i, j, k, l, m, n;
+
+void
+foo ()
+{
+  int v;
+  #pragma omp atomic release
+  i = i + 1;
+  #pragma omp requires atomic_default_mem_order (seq_cst)
+  #pragma omp atomic
+  j = j + 1;
+  #pragma omp atomic update
+  k = k + 1;
+  #pragma omp atomic read
+  v = l;
+  #pragma omp atomic write
+  m = v;
+  #pragma omp atomic capture
+  v = n = n + 1;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-21.c b/gcc/testsuite/c-c++-common/gomp/atomic-21.c
new file mode 100644 (file)
index 0000000..8fa97b1
--- /dev/null
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-original" } */
+/* { dg-final { scan-tree-dump-times "omp atomic release" 4 "original" } } */
+/* { dg-final { scan-tree-dump-times "omp atomic read acquire" 1 "original" } } */
+/* { dg-final { scan-tree-dump-times "omp atomic capture acq_rel" 1 "original" } } */
+
+int i, j, k, l, m, n;
+
+void
+foo ()
+{
+  int v;
+  #pragma omp atomic release
+  i = i + 1;
+  #pragma omp requires atomic_default_mem_order (acq_rel)
+  #pragma omp atomic
+  j = j + 1;
+  #pragma omp atomic update
+  k = k + 1;
+  #pragma omp atomic read
+  v = l;
+  #pragma omp atomic write
+  m = v;
+  #pragma omp atomic capture
+  v = n = n + 1;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-22.c b/gcc/testsuite/c-c++-common/gomp/atomic-22.c
new file mode 100644 (file)
index 0000000..57b0dcb
--- /dev/null
@@ -0,0 +1,12 @@
+int i, j;
+
+void
+foo ()
+{
+  int v;
+  #pragma omp atomic release
+  i = i + 1;
+  #pragma omp atomic read
+  v = j;
+  #pragma omp requires atomic_default_mem_order (acq_rel)      /* { dg-error "'atomic_default_mem_order' clause used lexically after first 'atomic' construct without memory order clause" } */
+}
index fe90c2428e0447d8bf482cefdd6def52fee197c8..652270cc0bdd381a9e1f5348138928cfe5cdbd34 100644 (file)
@@ -5,11 +5,11 @@ int t;
 #pragma omp threadprivate (t)
 
 #pragma omp declare target
-int f, l, ll, r;
+int f, l, ll, r, r2;
 
 void
 foo (int d, int m, int i1, int i2, int p, int *idp, int s,
-     int nte, int tl, int nth, int g, int nta, int fi, int pp, int *q)
+     int nte, int tl, int nth, int g, int nta, int fi, int pp, int *q, int ntm)
 {
   #pragma omp distribute parallel for \
     private (p) firstprivate (f) collapse(1) dist_schedule(static, 16) \
@@ -19,26 +19,50 @@ foo (int d, int m, int i1, int i2, int p, int *idp, int s,
     ll++;
   #pragma omp distribute parallel for simd \
     private (p) firstprivate (f) collapse(1) dist_schedule(static, 16) \
-    if (parallel: i2) default(shared) shared(s) reduction(+:r) num_threads (nth) proc_bind(spread) \
-    lastprivate (l) schedule(static, 4) \
+    if (parallel: i2) if(simd: i1) default(shared) shared(s) reduction(+:r) num_threads (nth) proc_bind(spread) \
+    lastprivate (l) schedule(static, 4) nontemporal(ntm) \
     safelen(8) simdlen(4) aligned(q: 32)
   for (int i = 0; i < 64; i++)
     ll++;
   #pragma omp distribute simd \
     private (p) firstprivate (f) collapse(1) dist_schedule(static, 16) \
-    safelen(8) simdlen(4) aligned(q: 32) reduction(+:r)
+    safelen(8) simdlen(4) aligned(q: 32) reduction(+:r) if(i1) nontemporal(ntm)
   for (int i = 0; i < 64; i++)
     ll++;
 }
 #pragma omp end declare target
 
 void
-bar (int d, int m, int i1, int i2, int p, int *idp, int s,
-     int nte, int tl, int nth, int g, int nta, int fi, int pp, int *q, int *dd)
+baz (int d, int m, int i1, int i2, int p, int *idp, int s,
+     int nte, int tl, int nth, int g, int nta, int fi, int pp, int *q, int ntm)
+{
+  #pragma omp distribute parallel for \
+    private (p) firstprivate (f) collapse(1) dist_schedule(static, 16) \
+    if (parallel: i2) default(shared) shared(s) reduction(+:r) num_threads (nth) proc_bind(spread) \
+    lastprivate (l) schedule(static, 4) copyin(t)
+  for (int i = 0; i < 64; i++)
+    ll++;
+  #pragma omp distribute parallel for simd \
+    private (p) firstprivate (f) collapse(1) dist_schedule(static, 16) \
+    if (parallel: i2) if(simd: i1) default(shared) shared(s) reduction(+:r) num_threads (nth) proc_bind(spread) \
+    lastprivate (l) schedule(static, 4) nontemporal(ntm) \
+    safelen(8) simdlen(4) aligned(q: 32) copyin(t)
+  for (int i = 0; i < 64; i++)
+    ll++;
+  #pragma omp distribute simd \
+    private (p) firstprivate (f) collapse(1) dist_schedule(static, 16) \
+    safelen(8) simdlen(4) aligned(q: 32) reduction(+:r) if(i1) nontemporal(ntm)
+  for (int i = 0; i < 64; i++)
+    ll++;
+}
+
+void
+bar (int d, int m, int i1, int i2, int i3, int p, int *idp, int s,
+     int nte, int tl, int nth, int g, int nta, int fi, int pp, int *q, int *dd, int ntm)
 {
   #pragma omp for simd \
     private (p) firstprivate (f) lastprivate (l) linear (ll:1) reduction(+:r) schedule(static, 4) collapse(1) nowait \
-    safelen(8) simdlen(4) aligned(q: 32)
+    safelen(8) simdlen(4) aligned(q: 32) nontemporal(ntm) if(i1)
   for (int i = 0; i < 64; i++)
     ll++;
   #pragma omp parallel for \
@@ -47,9 +71,9 @@ bar (int d, int m, int i1, int i2, int p, int *idp, int s,
   for (int i = 0; i < 64; i++)
     ll++;
   #pragma omp parallel for simd \
-    private (p) firstprivate (f) if (parallel: i2) default(shared) shared(s) copyin(t) reduction(+:r) num_threads (nth) proc_bind(spread) \
+    private (p) firstprivate (f) if (i2) default(shared) shared(s) copyin(t) reduction(+:r) num_threads (nth) proc_bind(spread) \
     lastprivate (l) linear (ll:1) schedule(static, 4) collapse(1) \
-    safelen(8) simdlen(4) aligned(q: 32)
+    safelen(8) simdlen(4) aligned(q: 32) nontemporal(ntm)
   for (int i = 0; i < 64; i++)
     ll++;
   #pragma omp parallel sections \
@@ -76,7 +100,7 @@ bar (int d, int m, int i1, int i2, int p, int *idp, int s,
     device(d) map (tofrom: m) if (target: i1) private (p) firstprivate (f) defaultmap(tofrom: scalar) is_device_ptr (idp) \
     if (parallel: i2) default(shared) shared(s) reduction(+:r) num_threads (nth) proc_bind(spread) \
     lastprivate (l) linear (ll:1) schedule(static, 4) collapse(1) \
-    safelen(8) simdlen(4) aligned(q: 32) nowait depend(inout: dd[0])
+    safelen(8) simdlen(4) aligned(q: 32) nowait depend(inout: dd[0]) nontemporal(ntm) if (simd: i3)
   for (int i = 0; i < 64; i++)
     ll++;
   #pragma omp target teams \
@@ -103,31 +127,38 @@ bar (int d, int m, int i1, int i2, int p, int *idp, int s,
     collapse(1) dist_schedule(static, 16) \
     if (parallel: i2) num_threads (nth) proc_bind(spread) \
     lastprivate (l) schedule(static, 4) \
-    safelen(8) simdlen(4) aligned(q: 32) nowait depend(inout: dd[0])
+    safelen(8) simdlen(4) aligned(q: 32) nowait depend(inout: dd[0]) nontemporal(ntm) if (simd: i3)
   for (int i = 0; i < 64; i++)
     ll++;
   #pragma omp target teams distribute simd \
-    device(d) map (tofrom: m) if (target: i1) private (p) firstprivate (f) defaultmap(tofrom: scalar) is_device_ptr (idp) \
+    device(d) map (tofrom: m) if (i1) private (p) firstprivate (f) defaultmap(tofrom: scalar) is_device_ptr (idp) \
     shared(s) default(shared) reduction(+:r) num_teams(nte) thread_limit(tl) \
     collapse(1) dist_schedule(static, 16) \
-    safelen(8) simdlen(4) aligned(q: 32) nowait depend(inout: dd[0])
+    safelen(8) simdlen(4) aligned(q: 32) nowait depend(inout: dd[0]) nontemporal(ntm)
   for (int i = 0; i < 64; i++)
     ll++;
   #pragma omp target simd \
     device(d) map (tofrom: m) if (target: i1) private (p) firstprivate (f) defaultmap(tofrom: scalar) is_device_ptr (idp) \
     safelen(8) simdlen(4) lastprivate (l) linear(ll: 1) aligned(q: 32) reduction(+:r) \
-     nowait depend(inout: dd[0])
+     nowait depend(inout: dd[0]) nontemporal(ntm) if(simd:i3)
+  for (int i = 0; i < 64; i++)
+    ll++;
+  #pragma omp taskgroup task_reduction(+:r2)
+  #pragma omp taskloop simd \
+    private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) grainsize (g) collapse(1) untied if(taskloop: i1) if(simd: i2) final(fi) mergeable priority (pp) \
+    safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(default, +:r) in_reduction(+:r2) nontemporal(ntm)
   for (int i = 0; i < 64; i++)
     ll++;
+  #pragma omp taskgroup task_reduction(+:r)
   #pragma omp taskloop simd \
-    private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) grainsize (g) collapse(1) untied if(taskloop: i1) final(fi) mergeable nogroup priority (pp) \
-    safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(+:r)
+    private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) grainsize (g) collapse(1) untied if(i1) final(fi) mergeable nogroup priority (pp) \
+    safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) in_reduction(+:r) nontemporal(ntm)
   for (int i = 0; i < 64; i++)
     ll++;
   #pragma omp taskwait
   #pragma omp taskloop simd \
     private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) num_tasks (nta) collapse(1) if(taskloop: i1) final(fi) priority (pp) \
-    safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(+:r)
+    safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(+:r) if (simd: i3) nontemporal(ntm)
   for (int i = 0; i < 64; i++)
     ll++;
   #pragma omp target nowait depend(inout: dd[0])
@@ -150,14 +181,83 @@ bar (int d, int m, int i1, int i2, int p, int *idp, int s,
     collapse(1) dist_schedule(static, 16) \
     if (parallel: i2) num_threads (nth) proc_bind(spread) \
     lastprivate (l) schedule(static, 4) \
-    safelen(8) simdlen(4) aligned(q: 32)
+    safelen(8) simdlen(4) aligned(q: 32) if (simd: i3) nontemporal(ntm)
   for (int i = 0; i < 64; i++)
     ll++;
   #pragma omp target
   #pragma omp teams distribute simd \
     private(p) firstprivate (f) shared(s) default(shared) reduction(+:r) num_teams(nte) thread_limit(tl) \
     collapse(1) dist_schedule(static, 16) \
-    safelen(8) simdlen(4) aligned(q: 32)
+    safelen(8) simdlen(4) aligned(q: 32) if(i3) nontemporal(ntm)
+  for (int i = 0; i < 64; i++)
+    ll++;
+  #pragma omp teams distribute parallel for \
+    private(p) firstprivate (f) shared(s) default(shared) reduction(+:r) num_teams(nte) thread_limit(tl) \
+    collapse(1) dist_schedule(static, 16) \
+    if (parallel: i2) num_threads (nth) proc_bind(spread) \
+    lastprivate (l) schedule(static, 4) copyin(t)
+  for (int i = 0; i < 64; i++)
+    ll++;
+  #pragma omp teams distribute parallel for simd \
+    private(p) firstprivate (f) shared(s) default(shared) reduction(+:r) num_teams(nte) thread_limit(tl) \
+    collapse(1) dist_schedule(static, 16) \
+    if (parallel: i2) num_threads (nth) proc_bind(spread) \
+    lastprivate (l) schedule(static, 4) \
+    safelen(8) simdlen(4) aligned(q: 32) if (simd: i3) nontemporal(ntm) copyin(t)
+  for (int i = 0; i < 64; i++)
+    ll++;
+  #pragma omp teams distribute simd \
+    private(p) firstprivate (f) shared(s) default(shared) reduction(+:r) num_teams(nte) thread_limit(tl) \
+    collapse(1) dist_schedule(static, 16) \
+    safelen(8) simdlen(4) aligned(q: 32) if(i3) nontemporal(ntm)
+  for (int i = 0; i < 64; i++)
+    ll++;
+  #pragma omp parallel master \
+    private (p) firstprivate (f) if (parallel: i2) default(shared) shared(s) reduction(+:r) \
+    num_threads (nth) proc_bind(spread) copyin(t)
+    ;
+  #pragma omp taskgroup task_reduction (+:r2)
+  #pragma omp master taskloop \
+    private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) grainsize (g) collapse(1) untied if(taskloop: i1) final(fi) mergeable priority (pp) \
+    reduction(default, +:r) in_reduction(+:r2)
+  for (int i = 0; i < 64; i++)
+    ll++;
+  #pragma omp taskgroup task_reduction (+:r2)
+  #pragma omp master taskloop simd \
+    private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) grainsize (g) collapse(1) untied if(taskloop: i1) if(simd: i2) final(fi) mergeable priority (pp) \
+    safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(default, +:r) in_reduction(+:r2) nontemporal(ntm)
+  for (int i = 0; i < 64; i++)
+    ll++;
+  #pragma omp parallel master taskloop \
+    private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) grainsize (g) collapse(1) untied if(taskloop: i1) final(fi) mergeable priority (pp) \
+    reduction(default, +:r) if (parallel: i2) num_threads (nth) proc_bind(spread) copyin(t)
+  for (int i = 0; i < 64; i++)
+    ll++;
+  #pragma omp parallel master taskloop simd \
+    private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) grainsize (g) collapse(1) untied if(taskloop: i1) if(simd: i2) final(fi) mergeable priority (pp) \
+    safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(default, +:r) nontemporal(ntm) if (parallel: i2) num_threads (nth) proc_bind(spread) copyin(t)
+  for (int i = 0; i < 64; i++)
+    ll++;
+  #pragma omp taskgroup task_reduction (+:r2)
+  #pragma omp master taskloop \
+    private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) num_tasks (nta) collapse(1) untied if(i1) final(fi) mergeable priority (pp) \
+    reduction(default, +:r) in_reduction(+:r2)
+  for (int i = 0; i < 64; i++)
+    ll++;
+  #pragma omp taskgroup task_reduction (+:r2)
+  #pragma omp master taskloop simd \
+    private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) num_tasks (nta) collapse(1) untied if(i1) final(fi) mergeable priority (pp) \
+    safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(default, +:r) in_reduction(+:r2) nontemporal(ntm)
+  for (int i = 0; i < 64; i++)
+    ll++;
+  #pragma omp parallel master taskloop \
+    private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) num_tasks (nta) collapse(1) untied if(i1) final(fi) mergeable priority (pp) \
+    reduction(default, +:r) num_threads (nth) proc_bind(spread) copyin(t)
+  for (int i = 0; i < 64; i++)
+    ll++;
+  #pragma omp parallel master taskloop simd \
+    private (p) firstprivate (f) lastprivate (l) shared (s) default(shared) num_tasks (nta) collapse(1) untied if(i1) final(fi) mergeable priority (pp) \
+    safelen(8) simdlen(4) linear(ll: 1) aligned(q: 32) reduction(default, +:r) nontemporal(ntm) num_threads (nth) proc_bind(spread) copyin(t)
   for (int i = 0; i < 64; i++)
     ll++;
 }
diff --git a/gcc/testsuite/c-c++-common/gomp/combined-1.c b/gcc/testsuite/c-c++-common/gomp/combined-1.c
new file mode 100644 (file)
index 0000000..4d62844
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fopenmp -fdump-tree-optimized" } */
+
+int a[10];
+void foo (void)
+{
+    int i;
+#pragma omp parallel for schedule(runtime)
+    for (i = 0; i < 10; i++)
+      a[i] = i;
+#pragma omp parallel
+#pragma omp for schedule(runtime)
+    for (i = 0; i < 10; i++)
+      a[i] = 10 - i;
+#pragma omp parallel
+      {
+#pragma omp for schedule(runtime)
+       for (i = 0; i < 10; i++)
+         a[i] = i;
+      }
+}
+
+/* { dg-final { scan-tree-dump-times "GOMP_parallel_loop_maybe_nonmonotonic_runtime" 3 "optimized" } } */
diff --git a/gcc/testsuite/c-c++-common/gomp/combined-2.c b/gcc/testsuite/c-c++-common/gomp/combined-2.c
new file mode 100644 (file)
index 0000000..82bc4df
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fopenmp -fdump-tree-optimized" } */
+
+int a[10];
+void foo (void)
+{
+    int i;
+#pragma omp parallel for schedule(monotonic:runtime)
+    for (i = 0; i < 10; i++)
+      a[i] = i;
+#pragma omp parallel
+#pragma omp for schedule(monotonic :runtime)
+    for (i = 0; i < 10; i++)
+      a[i] = 10 - i;
+#pragma omp parallel
+      {
+#pragma omp for schedule(monotonic: runtime)
+       for (i = 0; i < 10; i++)
+         a[i] = i;
+      }
+}
+
+/* { dg-final { scan-tree-dump-times "GOMP_parallel_loop_runtime" 3 "optimized" } } */
diff --git a/gcc/testsuite/c-c++-common/gomp/combined-3.c b/gcc/testsuite/c-c++-common/gomp/combined-3.c
new file mode 100644 (file)
index 0000000..33c9884
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fopenmp -fdump-tree-optimized" } */
+
+int a[10];
+void foo (void)
+{
+    int i;
+#pragma omp parallel for schedule(nonmonotonic:runtime)
+    for (i = 0; i < 10; i++)
+      a[i] = i;
+#pragma omp parallel
+#pragma omp for schedule(nonmonotonic :runtime)
+    for (i = 0; i < 10; i++)
+      a[i] = 10 - i;
+#pragma omp parallel
+      {
+#pragma omp for schedule(nonmonotonic: runtime)
+       for (i = 0; i < 10; i++)
+         a[i] = i;
+      }
+}
+
+/* { dg-final { scan-tree-dump-times "GOMP_parallel_loop_nonmonotonic_runtime" 3 "optimized" } } */
diff --git a/gcc/testsuite/c-c++-common/gomp/critical-1.c b/gcc/testsuite/c-c++-common/gomp/critical-1.c
new file mode 100644 (file)
index 0000000..8d607e4
--- /dev/null
@@ -0,0 +1,14 @@
+int i;
+
+void
+foo (void)
+{
+  #pragma omp critical
+  i = i + 1;
+  #pragma omp critical (foo)
+  i = i + 1;
+  #pragma omp critical (foo) hint (0)
+  i = i + 1;
+  #pragma omp critical (foo),hint(1)
+  i = i + 1;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/critical-2.c b/gcc/testsuite/c-c++-common/gomp/critical-2.c
new file mode 100644 (file)
index 0000000..f501cc1
--- /dev/null
@@ -0,0 +1,10 @@
+int i;
+
+void
+foo (int j)
+{
+  #pragma omp critical (foo) hint (j + 1)      /* { dg-error "constant integer expression" } */
+  i = i + 1;
+  #pragma omp critical (foo),hint(j)           /* { dg-error "constant integer expression" } */
+  i = i + 1;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/default-1.c b/gcc/testsuite/c-c++-common/gomp/default-1.c
new file mode 100644 (file)
index 0000000..6525483
--- /dev/null
@@ -0,0 +1,22 @@
+void
+foo (void)
+{
+  int x = 0, i;
+  #pragma omp task default(none)       /* { dg-error "enclosing 'task'" } */
+  {
+    x++;       /* { dg-error "'x' not specified in enclosing 'task'" } */
+  }
+  #pragma omp taskloop default(none)   /* { dg-error "enclosing 'taskloop'" } */
+  for (i = 0; i < 64; i++)
+    {
+      x++;     /* { dg-error "'x' not specified in enclosing 'taskloop'" } */
+    }
+  #pragma omp teams default(none)      /* { dg-error "enclosing 'teams'" } */
+  {
+    x++;       /* { dg-error "'x' not specified in enclosing 'teams'" } */
+  }
+  #pragma omp parallel default(none)   /* { dg-error "enclosing 'parallel'" } */
+  {
+    x++;       /* { dg-error "'x' not specified in enclosing 'parallel'" } */
+  }
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/defaultmap-1.c b/gcc/testsuite/c-c++-common/gomp/defaultmap-1.c
new file mode 100644 (file)
index 0000000..80a111c
--- /dev/null
@@ -0,0 +1,30 @@
+void
+foo (void)
+{
+  #pragma omp target defaultmap(alloc) defaultmap(alloc)       /* { dg-error "too many 'defaultmap' clauses with unspecified category" } */
+  ;
+  #pragma omp target defaultmap(to) defaultmap(from)           /* { dg-error "too many 'defaultmap' clauses with unspecified category" } */
+  ;
+  #pragma omp target defaultmap(tofrom) defaultmap(firstprivate:scalar)        /* { dg-error "too many 'defaultmap' clauses with 'scalar' category" } */
+  ;
+  #pragma omp target defaultmap(none:aggregate) defaultmap(alloc:scalar) defaultmap(none:scalar) /* { dg-error "too many 'defaultmap' clauses with 'scalar' category" } */
+  ;
+  #pragma omp target defaultmap(none : pointer) defaultmap ( none ) /* { dg-error "too many 'defaultmap' clauses with 'pointer' category" } */
+  ;
+  #pragma omp target defaultmap()                              /* { dg-error "expected" } */
+  ;
+  #pragma omp target defaultmap(for)                           /* { dg-error "expected" } */
+  ;
+  #pragma omp target defaultmap(blah)                          /* { dg-error "expected" } */
+  ;
+  #pragma omp target defaultmap(tofrom:)                       /* { dg-error "expected" } */
+  ;
+  #pragma omp target defaultmap(tofrom scalar)                 /* { dg-error "expected" } */
+  ;
+  #pragma omp target defaultmap(tofrom,scalar)                 /* { dg-error "expected" } */
+  ;
+  #pragma omp target defaultmap(default ;)                     /* { dg-error "expected" } */
+  ;
+  #pragma omp target defaultmap(default : qux)                 /* { dg-error "expected" } */
+  ;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/defaultmap-2.c b/gcc/testsuite/c-c++-common/gomp/defaultmap-2.c
new file mode 100644 (file)
index 0000000..75dca23
--- /dev/null
@@ -0,0 +1,131 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-gimple" } */
+
+struct S { int s; };
+void foo (char *);
+void bar (int, char *, struct S, int *);
+#pragma omp declare target to (bar)
+#define N 16
+
+void
+f1 (int sc1, struct S ag1, int *pt1)
+{
+  char ar1[N];
+  foo (ar1);
+  #pragma omp target
+  bar (sc1, ar1, ag1, pt1);
+/* { dg-final { scan-tree-dump "firstprivate\\(sc1\\)" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(tofrom:ar1" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(tofrom:ag1" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(firstprivate:pt1 .pointer assign" "gimple" } } */
+}
+
+void
+f2 (int sc2, struct S ag2, int *pt2)
+{
+  char ar2[N];
+  foo (ar2);
+  #pragma omp target firstprivate (sc2, ar2, ag2, pt2) defaultmap (none)
+  bar (sc2, ar2, ag2, pt2);
+/* { dg-final { scan-tree-dump "firstprivate\\(sc2\\)" "gimple" } } */
+/* { dg-final { scan-tree-dump "firstprivate\\(ar2\\)" "gimple" } } */
+/* { dg-final { scan-tree-dump "firstprivate\\(ag2\\)" "gimple" } } */
+/* { dg-final { scan-tree-dump "firstprivate\\(pt2\\)" "gimple" } } */
+}
+
+void
+f3 (int sc3, struct S ag3, int *pt3)
+{
+  char ar3[N];
+  foo (ar3);
+  #pragma omp target defaultmap(none:scalar) defaultmap(none:aggregate) \
+                    map (sc3, ar3, ag3, pt3) defaultmap(none:pointer)
+  bar (sc3, ar3, ag3, pt3);
+/* { dg-final { scan-tree-dump "map\\(tofrom:sc3" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(tofrom:ar3" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(tofrom:ag3" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(tofrom:pt3" "gimple" } } */
+}
+
+void
+f4 (int sc4, struct S ag4, int *pt4)
+{
+  char ar4[N];
+  foo (ar4);
+  #pragma omp target defaultmap(tofrom:scalar)
+  bar (sc4, ar4, ag4, pt4);
+/* { dg-final { scan-tree-dump "map\\(tofrom:sc4" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(tofrom:ar4" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(tofrom:ag4" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(firstprivate:pt4 .pointer assign" "gimple" } } */
+}
+
+void
+f5 (int sc5, struct S ag5, int *pt5)
+{
+  char ar5[N];
+  foo (ar5);
+  #pragma omp target defaultmap(to)
+  bar (sc5, ar5, ag5, pt5);
+/* { dg-final { scan-tree-dump "map\\(to:sc5" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(to:ar5" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(to:ag5" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(to:pt5" "gimple" } } */
+}
+
+void
+f6 (int sc6, struct S ag6, int *pt6)
+{
+  char ar6[N];
+  foo (ar6);
+  #pragma omp target defaultmap(firstprivate)
+  bar (sc6, ar6, ag6, pt6);
+/* { dg-final { scan-tree-dump "firstprivate\\(sc6\\)" "gimple" } } */
+/* { dg-final { scan-tree-dump "firstprivate\\(ar6\\)" "gimple" } } */
+/* { dg-final { scan-tree-dump "firstprivate\\(ag6\\)" "gimple" } } */
+/* { dg-final { scan-tree-dump "firstprivate\\(pt6\\)" "gimple" } } */
+}
+
+void
+f7 (int sc7, struct S ag7, int *pt7)
+{
+  char ar7[N];
+  foo (ar7);
+  #pragma omp target defaultmap(alloc: scalar) defaultmap(from: aggregate) defaultmap(default: pointer)
+  {
+    int *q = &sc7;
+    *q = 6;
+    ag7.s = 5;
+    int i;
+    for (i = 0; i < N; ++i)
+      ar7[i] = 7;
+    bar (sc7, ar7, ag7, pt7);
+  }
+/* { dg-final { scan-tree-dump "map\\(alloc:sc7" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(from:ar7" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(from:ag7" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(firstprivate:pt7 .pointer assign" "gimple" } } */
+}
+
+void
+f8 (int sc8, struct S ag8, int *pt8)
+{
+  char ar8[N];
+  foo (ar8);
+  #pragma omp target defaultmap(firstprivate:aggregate) defaultmap(none:scalar) \
+                    defaultmap(tofrom:pointer) map(to: sc8)
+  bar (sc8, ar8, ag8, pt8);
+/* { dg-final { scan-tree-dump "map\\(to:sc8" "gimple" } } */
+/* { dg-final { scan-tree-dump "firstprivate\\(ar8\\)" "gimple" } } */
+/* { dg-final { scan-tree-dump "firstprivate\\(ag8\\)" "gimple" } } */
+/* { dg-final { scan-tree-dump "map\\(tofrom:pt8" "gimple" } } */
+}
+
+void
+f9 (int sc9, struct S ag9)
+{
+  char ar9[sc9 + 2];
+  foo (ar9);
+  #pragma omp target defaultmap(none) map(to: ar9, ag9) firstprivate (sc9)
+  bar (sc9, ar9, ag9, &sc9);
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/defaultmap-3.c b/gcc/testsuite/c-c++-common/gomp/defaultmap-3.c
new file mode 100644 (file)
index 0000000..2f5b303
--- /dev/null
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+
+struct S { int s; };
+void foo (char *);
+void bar (int, char *, struct S, int *);
+#pragma omp declare target to (bar)
+#define N 16
+
+void
+f1 (int sc1, struct S ag1, int *pt1)
+{
+  char ar1[N];
+  foo (ar1);
+  #pragma omp target defaultmap(default:scalar) defaultmap(to:aggregate) defaultmap(none:pointer)      /* { dg-error "enclosing 'target'" } */
+  bar (sc1, ar1, ag1, pt1);    /* { dg-error "'pt1' not specified in enclosing 'target'" } */
+}
+
+void
+f2 (int sc2, struct S ag2, int *pt2)
+{
+  char ar2[N];
+  foo (ar2);
+  #pragma omp target defaultmap(none:scalar) defaultmap(from:aggregate) defaultmap(default:pointer)    /* { dg-error "enclosing 'target'" } */
+  bar (sc2, ar2, ag2, pt2);    /* { dg-error "'sc2' not specified in enclosing 'target'" } */
+}
+
+void
+f3 (int sc3, struct S ag3, int *pt3)
+{
+  char ar3[N];
+  foo (ar3);
+  #pragma omp target defaultmap(firstprivate:scalar) defaultmap(none:aggregate) defaultmap(to:pointer) /* { dg-error "enclosing 'target'" } */
+  bar (sc3, ar3, ag3, pt3);    /* { dg-error "'ar3' not specified in enclosing 'target'" } */
+}                              /* { dg-error "'ag3' not specified in enclosing 'target'" "" { target *-*-* } .-1 } */
diff --git a/gcc/testsuite/c-c++-common/gomp/depend-5.c b/gcc/testsuite/c-c++-common/gomp/depend-5.c
new file mode 100644 (file)
index 0000000..993987f
--- /dev/null
@@ -0,0 +1,48 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+struct T { int c[3]; };
+struct S { int a; struct T *b; struct T g; };
+struct S d[10];
+struct S *e[10];
+struct S *f;
+struct S h;
+
+void
+foo (void)
+{
+  #pragma omp task depend(inout: d)
+  ;
+  #pragma omp task depend(out: d[2])
+  ;
+  #pragma omp task depend(in: d[:])
+  ;
+  #pragma omp task depend(in: d[2:2])
+  ;
+  #pragma omp task depend(in: d[:2])
+  ;
+  #pragma omp task depend(inout: d[1].b->c[2])
+  ;
+  #pragma omp task depend(out: d[0].a)
+  ;
+  #pragma omp task depend(in: e[3]->a)
+  ;
+  #pragma omp task depend(inout: e[2]->b->c)
+  ;
+  #pragma omp task depend(in: e[1]->b->c[2])
+  ;
+  #pragma omp task depend(out: (*f).a)
+  ;
+  #pragma omp task depend(inout: f->b->c[0])
+  ;
+  #pragma omp task depend(in: f)
+  ;
+  #pragma omp task depend(out: *f)
+  ;
+  #pragma omp task depend(inout: f[0])
+  ;
+  #pragma omp task depend(in: f[0].a)
+  ;
+  #pragma omp task depend(inout: h.g.c[2])
+  ;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/depend-6.c b/gcc/testsuite/c-c++-common/gomp/depend-6.c
new file mode 100644 (file)
index 0000000..4684653
--- /dev/null
@@ -0,0 +1,36 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+struct T { int c[3]; };
+struct S { int a; struct T *b; struct T g; };
+struct U { int a : 5; };
+struct S d[10];
+struct S *e[10];
+struct S *f;
+struct S h;
+struct U i;
+
+void
+foo (void)
+{
+  #pragma omp task depend(in: d[:2].b->c[2])   /* { dg-error "expected" } */
+  ;
+  #pragma omp task depend(inout: d[1:].b->c[2])        /* { dg-error "expected" } */
+  ;
+  #pragma omp task depend(out: d[0:1].a)       /* { dg-error "expected" } */
+  ;
+  #pragma omp task depend(in: e[3:2]->a)       /* { dg-error "expected" } */
+  ;
+  #pragma omp task depend(inout: e[2:2]->b->c) /* { dg-error "expected" } */
+  ;
+  #pragma omp task depend(in: e[1]->b->c[2:1]) /* { dg-error "expected" } */
+  ;
+  #pragma omp task depend(out: f + 0)          /* { dg-error "not lvalue expression" } */
+  ;
+  #pragma omp task depend(inout: f[0:1].a)     /* { dg-error "expected" } */
+  ;
+  #pragma omp task depend(inout: h.g.c[2:1])   /* { dg-error "expected" } */
+  ;
+  #pragma omp task depend(in: i.a)             /* { dg-error "bit-field '\[^\n\r]*' in 'depend' clause" } */
+  ;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/depend-iterator-1.c b/gcc/testsuite/c-c++-common/gomp/depend-iterator-1.c
new file mode 100644 (file)
index 0000000..4fb01c1
--- /dev/null
@@ -0,0 +1,75 @@
+int arr[64], arr2[64];
+struct S { int a[4]; } k;
+short arr4[4];
+volatile int v;
+#define TEST_EQ(x,y) ({ int o[x == y ? 1 : -1]; 0; })
+
+void
+foo (unsigned char i, signed char j)
+{
+  #pragma omp task depend (iterator (j=6:2:-2) , out : \
+       arr[TEST_EQ (sizeof (j), sizeof (int)), \
+           TEST_EQ (sizeof (i), sizeof (unsigned char)), \
+           TEST_EQ (sizeof (k), sizeof (struct S)), j], \
+       arr2[TEST_EQ (((__typeof (j)) -1) < 0, 1), \
+            TEST_EQ (((__typeof (i)) -1) < 0, 0), \
+            TEST_EQ (((__typeof (k.a[0])) -1) < 0, 1), j]) \
+       depend(out: arr[0]) \
+       depend (iterator (long long i=__LONG_LONG_MAX__ - 4:__LONG_LONG_MAX__ - 2:2, \
+                         unsigned short j=~0U-16:~0U-8:3, \
+                         short *k=&arr4[1]:&arr4[2]:1) , in : \
+       arr[TEST_EQ (sizeof (i), sizeof (long long)), \
+           TEST_EQ (sizeof (j), sizeof (unsigned short)), \
+           TEST_EQ (sizeof (k), sizeof (short *)), \
+           TEST_EQ (sizeof (*k), sizeof (short)), i - __LONG_LONG_MAX__ + 4], \
+       arr2[TEST_EQ (((__typeof (i)) -1) < 0, 1), \
+            TEST_EQ (((__typeof (j)) -1) < 0, 0), \
+            TEST_EQ (((__typeof (*k)) -1) < 0, 1), j - (~0U-16)], \
+       arr2[k - &arr4[0]]) \
+       depend(in : k)
+    v++;
+}
+
+void
+bar (unsigned char i, signed char j)
+{
+  int m = j;
+  int n = j + 2;
+  #pragma omp task depend (iterator (j=6:2:m) , out : \
+       arr[TEST_EQ (sizeof (j), sizeof (int)), \
+           TEST_EQ (sizeof (i), sizeof (unsigned char)), \
+           TEST_EQ (sizeof (k), sizeof (struct S)), j], \
+       arr2[TEST_EQ (((__typeof (j)) -1) < 0, 1), \
+            TEST_EQ (((__typeof (i)) -1) < 0, 0), \
+            TEST_EQ (((__typeof (k.a[0])) -1) < 0, 1), j]) \
+       depend(out: arr[0]) \
+       depend (iterator (long long i=__LONG_LONG_MAX__ - 4 - n:__LONG_LONG_MAX__ - 2:2, \
+                         unsigned short j=~0U-16:~0U-8-n:3, \
+                         short *k=&arr4[1]:&arr4[n + 2]:1) , in : \
+       arr[TEST_EQ (sizeof (i), sizeof (long long)), \
+           TEST_EQ (sizeof (j), sizeof (unsigned short)), \
+           TEST_EQ (sizeof (k), sizeof (short *)), \
+           TEST_EQ (sizeof (*k), sizeof (short)), i - __LONG_LONG_MAX__ + 4], \
+       arr2[TEST_EQ (((__typeof (i)) -1) < 0, 1), \
+            TEST_EQ (((__typeof (j)) -1) < 0, 0), \
+            TEST_EQ (((__typeof (*k)) -1) < 0, 1), j - (~0U-16)], \
+       arr2[k - &arr4[0]:10]) \
+       depend(in : k)
+    v++;
+}
+
+void
+baz (void)
+{
+  #pragma omp parallel
+  #pragma omp master
+  {
+    #pragma omp task depend(iterator(unsigned long int k = 0 : 2) , inout : \
+       arr[TEST_EQ (sizeof (k), sizeof (unsigned long)), \
+           TEST_EQ (((__typeof (k)) -1) < 0, 0), k]) \
+       depend(iterator(signed char s = -3 : -12 : -1) , out : \
+       arr[TEST_EQ (sizeof (s), sizeof (signed char)), \
+           TEST_EQ (((__typeof (s)) -1) < 0, 1), s + 12])
+      v++;
+  }
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/depend-iterator-2.c b/gcc/testsuite/c-c++-common/gomp/depend-iterator-2.c
new file mode 100644 (file)
index 0000000..1275282
--- /dev/null
@@ -0,0 +1,97 @@
+int a, b[64];
+struct S { int c; } *d, *e;
+struct T;
+struct T *f, *g;
+int *h;
+
+void
+f1 (void)
+{
+  #pragma omp task depend (iterator , in : a)  /* { dg-error "expected" } */
+  ;
+  #pragma omp task depend (iterator (for = 0 : 2) , in : a)    /* { dg-error "expected" } */
+  ;
+  #pragma omp task depend (iterator (5 = 0 : 2) , in : a)      /* { dg-error "expected" } */
+  ;
+  #pragma omp task depend (iterator (i : 0 : 2) , in : a)      /* { dg-error "expected '='|name a type|expected" } */
+  ;
+  #pragma omp task depend (iterator (i = 0, 1 : 2) , in : a)   /* { dg-error "expected" } */
+  ;
+  #pragma omp task depend (iterator (i = (0, 1) : 2) , in : a)
+  ;
+  #pragma omp task depend (iterator (i = 0 : 1 : 2 : 3) , in : a)      /* { dg-error "expected '.'" } */
+  ;
+  #pragma omp task depend (iterator (i = 0 : 2, 3) , in : a)   /* { dg-error "expected" } */
+  ;
+  #pragma omp task depend (iterator (i = 0 : 10 : 2, 3) , in : a)      /* { dg-error "expected" } */
+  ;
+  #pragma omp task depend (iterator (i = 0:1), iterator (j = 0:1) , in : a)    /* { dg-error "invalid depend kind" } */
+  ;
+  #pragma omp task depend (iterator (i = 0:32) , in : b[i*2:2])
+  ;
+  #pragma omp task depend (iterator (struct S i = 0:1), in : a)                /* { dg-error "iterator 'i' has neither integral nor pointer type" } */
+  ;
+  #pragma omp task depend (iterator (void i = 0:1) , in : a)           /* { dg-error "iterator 'i' has neither integral nor pointer type" } */
+  ;
+  #pragma omp task depend (iterator (float f = 0.2:0.4) , in : a)      /* { dg-error "iterator 'f' has neither integral nor pointer type" } */
+  ;
+  #pragma omp task depend (iterator (struct S *p = d:e:2) , in : a)
+  ;
+  #pragma omp task depend (iterator (struct T *p = f:g) , in : a)      /* { dg-error "invalid use of" } */
+  ;
+  #pragma omp task depend (iterator (int i = 0:4, \
+                                    struct U { int (*p)[i + 2]; } *p = 0:2) , in : a)  /* { dg-error "type of iterator 'p' refers to outer iterator 'i'" "" { target c } } */
+  ;                                                                    /* { dg-error "types may not be defined in iterator type|not an integer constant" "" { target c++ } .-1 } */
+  #pragma omp task depend (iterator (i = 0:4, j = i:16) , in : a)      /* { dg-error "begin expression refers to outer iterator 'i'" } */
+  ;
+  #pragma omp task depend (iterator (i = 0:4, j = 2:i:1) , in : a)     /* { dg-error "end expression refers to outer iterator 'i'" } */
+  ;
+  #pragma omp task depend (iterator (i = 0:4, j = 2:8:i) , in : a)     /* { dg-error "step expression refers to outer iterator 'i'" } */
+  ;
+  #pragma omp task depend (iterator (i = *d:2) , in : a)       /* { dg-error "aggregate value used where an integer was expected" "" { target c } } */
+  ;                                                            /* { dg-error "invalid cast from type 'S' to type 'int'" "" { target c++ } .-1 } */
+  #pragma omp task depend (iterator (i = 2:*d:2) , in : a)     /* { dg-error "aggregate value used where an integer was expected" "" { target c } } */
+  ;                                                            /* { dg-error "invalid cast from type 'S' to type 'int'" "" { target c++ } .-1 } */
+  #pragma omp task depend (iterator (i = 2:4:*d) , in : a)     /* { dg-error "iterator step with non-integral type" } */
+  ;
+  #pragma omp task depend (iterator (i = 1.25:2.5:3) , in : a)
+  ;
+  #pragma omp task depend (iterator (i = 1:2:3.5) , in : a)    /* { dg-error "iterator step with non-integral type" } */
+  ;
+  #pragma omp task depend (iterator (int *p = 23 : h) , in : a)
+  ;
+  #pragma omp task depend (iterator (short i=1:3:0) , in : a)  /* { dg-error "iterator 'i' has zero step" } */
+  ;
+  #pragma omp task depend (iterator (i = 1 : 3 : 3 - 3) , in : a)      /* { dg-error "iterator 'i' has zero step" } */
+  ;
+  #pragma omp task depend (iterator (int *p = &b[6]:&b[9]:4 - 4) , in : a)     /* { dg-error "iterator 'p' has zero step" } */
+  ;
+  #pragma omp task depend (iterator (const int i = 0 : 2) , in : a)    /* { dg-error "const qualified" } */
+  ;
+  #pragma omp task depend (iterator (const long long unsigned i = 0 : 2) , in : a)     /* { dg-error "const qualified" } */
+  ;
+#if !defined (__cplusplus) && __STDC_VERSION__ >= 201112L
+  #pragma omp task depend (iterator (_Atomic unsigned i = 0 : 2) , in : a)     /* { dg-error "_Atomic" "" { target c } } */
+  ;
+#endif
+}
+
+void
+f2 (void)
+{
+  int i, j;
+  #pragma omp for ordered(2)
+  for (i = 0; i < 64; i++)
+    for (j = 0; j < 64; j++)
+      {
+      #pragma omp ordered depend (iterator (k=0:1) , sink: i - 1, j - 1)       /* { dg-error "'iterator' modifier incompatible with 'sink'" } */
+      #pragma omp ordered depend (iterator (int l = 0:2:3) , source)           /* { dg-error "'iterator' modifier incompatible with 'source'" } */
+      }
+}
+
+void
+f3 (void)
+{
+  #pragma omp task depend (iterator (i = 0:1), iterator (j = 0:1) , in : a)    /* { dg-error "invalid depend kind" } */
+  ;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/depobj-1.c b/gcc/testsuite/c-c++-common/gomp/depobj-1.c
new file mode 100644 (file)
index 0000000..688371b
--- /dev/null
@@ -0,0 +1,63 @@
+typedef struct __attribute__((__aligned__ (sizeof (void *)))) omp_depend_t {
+  char __omp_depend_t__[2 * sizeof (void *)];
+} omp_depend_t;
+
+omp_depend_t bar (void);
+extern const omp_depend_t cdepobj;
+extern omp_depend_t depobj;
+extern omp_depend_t depobja[4];
+extern omp_depend_t *pdepobj;
+int a, b, i, j;
+
+void
+f1 (void)
+{
+  #pragma omp depobj(depobj) depend(in : a)
+  #pragma omp depobj(depobj) update(inout)
+  #pragma omp task depend (depobj: depobj)
+  ;
+  #pragma omp depobj(depobj) destroy
+  #pragma omp task depend (iterator (i=1:3) , depobj: *(depobja + i))
+  ;
+  #pragma omp depobj(pdepobj[0]) depend(mutexinoutset:a)
+  #pragma omp depobj(*pdepobj) destroy
+}
+
+void
+f2 (void)
+{
+  omp_depend_t depobjb[4];
+  #pragma omp depobj                                   /* { dg-error "expected" } */
+  #pragma omp depobj destroy                           /* { dg-error "expected" } */
+  #pragma omp depobj (depobj)                          /* { dg-error "expected 'depend', 'destroy' or 'update' clause" } */
+  #pragma omp depobj (depobj) foobar                   /* { dg-error "expected 'depend', 'destroy' or 'update' clause" } */
+  #pragma omp depobj(bar ()) update(inout)             /* { dg-error "'depobj' expression is not lvalue expression" } */
+  #pragma omp depobj (cdepobj) update(in)              /* { dg-error "'const' qualified 'depobj' expression" } */
+  #pragma omp depobj (depobjb) depend(in: a)           /* { dg-error "type of 'depobj' expression is not 'omp_depend_t'" } */
+  #pragma omp depobj (pdepobj) depend(in: a)           /* { dg-error "type of 'depobj' expression is not 'omp_depend_t'" } */
+  #pragma omp depobj (a) destroy                       /* { dg-error "type of 'depobj' expression is not 'omp_depend_t'" } */
+  #pragma omp depobj (depobj) depend(depobj:a)         /* { dg-error "does not have 'omp_depend_t' type in 'depend' clause with 'depobj' dependence type" } */
+  #pragma omp depobj (depobj) depend(depobj:*depobjb)  /* { dg-error "'depobj' dependence type specified in 'depend' clause on 'depobj' construct" } */
+  #pragma omp depobj (depobj) update(foobar)           /* { dg-error "expected 'in', 'out', 'inout' or 'mutexinoutset'" } */
+  #pragma omp depobj (depobj) depend(in: *depobja)     /* { dg-error "should not have 'omp_depend_t' type in 'depend' clause with dependence type" } */
+  #pragma omp depobj (depobj) depend(in: a) depend(in: b)      /* { dg-error "expected" } */
+  #pragma omp depobj (depobj) depend(in: a) update(out)        /* { dg-error "expected" } */
+  #pragma omp depobj (depobj) depend(in: a, b)         /* { dg-error "more than one locator in 'depend' clause on 'depobj' construct" } */
+  #pragma omp depobj (depobj) depend(source)           /* { dg-error "'depend\\(source\\)' is only allowed in 'omp ordered'" } */
+  #pragma omp depobj (depobj) depend(sink: i + 1, j - 1)       /* { dg-error "'depend\\(sink\\)' is only allowed in 'omp ordered'" } */
+  #pragma omp depobj (depobj) depend(iterator (i = 0:2) , in : a)      /* { dg-error "'iterator' modifier may not be specified on 'depobj' construct" } */
+  if (0)
+    #pragma omp depobj (depobj) destroy                        /* { dg-error "'#pragma omp depobj' may only be used in compound statements" } */
+    ;
+}
+
+void
+f3 (void)
+{
+  #pragma omp task depend (depobj: depobja[1:2])       /* { dg-error "'depend' clause with 'depobj' dependence type on array section" } */
+  ;
+  #pragma omp task depend (depobj: a)                  /* { dg-error "'a' does not have 'omp_depend_t' type in 'depend' clause with 'depobj' dependence type" } */
+  ;
+  #pragma omp task depend (in: depobj)                 /* { dg-error "'depobj' should not have 'omp_depend_t' type in 'depend' clause with dependence type" } */
+  ;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/flush-1.c b/gcc/testsuite/c-c++-common/gomp/flush-1.c
new file mode 100644 (file)
index 0000000..7c3e529
--- /dev/null
@@ -0,0 +1,39 @@
+/* { dg-additional-options "-fdump-tree-gimple" } */
+/* { dg-final { scan-tree-dump "foo \\(4\\);\[\n\r]*  __atomic_thread_fence \\(4\\);\[\n\r]*  foo \\(4\\);" "gimple" } } */
+/* { dg-final { scan-tree-dump "foo \\(3\\);\[\n\r]*  __atomic_thread_fence \\(3\\);\[\n\r]*  foo \\(3\\);" "gimple" } } */
+/* { dg-final { scan-tree-dump "foo \\(2\\);\[\n\r]*  __atomic_thread_fence \\(2\\);\[\n\r]*  foo \\(2\\);" "gimple" } } */
+/* { dg-final { scan-tree-dump "foo \\(5\\);\[\n\r]*  __sync_synchronize \\(\\);\[\n\r]*  foo \\(5\\);" "gimple" } } */
+
+void foo (int);
+
+void
+f1 (void)
+{
+  foo (4);
+  #pragma omp flush acq_rel
+  foo (4);
+}
+
+void
+f2 (void)
+{
+  foo (3);
+  #pragma omp flush release
+  foo (3);
+}
+
+void
+f3 (void)
+{
+  foo (2);
+  #pragma omp flush acquire
+  foo (2);
+}
+
+void
+f4 (void)
+{
+  foo (5);
+  #pragma omp flush
+  foo (5);
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/flush-2.c b/gcc/testsuite/c-c++-common/gomp/flush-2.c
new file mode 100644 (file)
index 0000000..00baa8a
--- /dev/null
@@ -0,0 +1,17 @@
+int a, b;
+
+void
+foo (void)
+{
+  #pragma omp flush
+  #pragma omp flush (a, b)
+  #pragma omp flush acquire
+  #pragma omp flush release
+  #pragma omp flush acq_rel
+  #pragma omp flush relaxed            /* { dg-error "expected 'acq_rel', 'release' or 'acquire'" } */
+  #pragma omp flush seq_cst            /* { dg-error "expected 'acq_rel', 'release' or 'acquire'" } */
+  #pragma omp flush foobar             /* { dg-error "expected 'acq_rel', 'release' or 'acquire'" } */
+  #pragma omp flush acquire (a, b)     /* { dg-error "'flush' list specified together with memory order clause" } */
+  #pragma omp flush release (a, b)     /* { dg-error "'flush' list specified together with memory order clause" } */
+  #pragma omp flush acq_rel (a, b)     /* { dg-error "'flush' list specified together with memory order clause" } */
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/for-1.c b/gcc/testsuite/c-c++-common/gomp/for-1.c
new file mode 100644 (file)
index 0000000..a0e498b
--- /dev/null
@@ -0,0 +1,60 @@
+void bar (int);
+
+int a[256];
+
+void
+foo (void)
+{
+  int i;
+  #pragma omp for
+  for (i = 0; i != 64; i++)
+    bar (i);
+  #pragma omp for
+  for (i = 128; i != 64; i--)
+    bar (i);
+  #pragma omp for
+  for (i = 0; i != 64; i = i + 1)
+    bar (i);
+  #pragma omp for
+  for (i = 128; i != 64; i = i - 1)
+    bar (i);
+  #pragma omp for
+  for (i = 0; i != 64; i = 1 + i)
+    bar (i);
+  #pragma omp for
+  for (i = 128; i != 64; i = -1 + i)
+    bar (i);
+  #pragma omp for
+  for (i = 0; i != 64; i += 1)
+    bar (i);
+  #pragma omp for
+  for (i = 128; i != 64; i -= 1)
+    bar (i);
+  #pragma omp single
+  {
+    #pragma omp simd
+    for (i = 0; i != 64; i++)
+      a[i] = a[i] + 1;
+    #pragma omp simd
+    for (i = 128; i != 64; i--)
+      a[i] = a[i] + 1;
+    #pragma omp simd
+    for (i = 0; i != 64; i = i + 1)
+      a[i] = a[i] + 1;
+    #pragma omp simd
+    for (i = 128; i != 64; i = i - 1)
+      a[i] = a[i] + 1;
+    #pragma omp simd
+    for (i = 0; i != 64; i = 1 + i)
+      a[i] = a[i] + 1;
+    #pragma omp simd
+    for (i = 128; i != 64; i = -1 + i)
+      a[i] = a[i] + 1;
+    #pragma omp simd
+    for (i = 0; i != 64; i += 1)
+      a[i] = a[i] + 1;
+    #pragma omp simd
+    for (i = 128; i != 64; i -= 1)
+      a[i] = a[i] + 1;
+  }
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/for-2.c b/gcc/testsuite/c-c++-common/gomp/for-2.c
new file mode 100644 (file)
index 0000000..98dfe21
--- /dev/null
@@ -0,0 +1,31 @@
+void bar (short *);
+
+void
+foo (short *q, short *r, short *s)
+{
+  short *p;
+  #pragma omp for
+  for (p = q; p != r; p++)
+    bar (p);
+  #pragma omp for
+  for (p = s; p != r; p--)
+    bar (p);
+  #pragma omp for
+  for (p = q; p != r; p = p + 1)
+    bar (p);
+  #pragma omp for
+  for (p = s; p != r; p = p - 1)
+    bar (p);
+  #pragma omp for
+  for (p = q; p != r; p = 1 + p)
+    bar (p);
+  #pragma omp for
+  for (p = s; p != r; p = -1 + p)
+    bar (p);
+  #pragma omp for
+  for (p = q; p != r; p += 1)
+    bar (p);
+  #pragma omp for
+  for (p = s; p != r; p -= 1)
+    bar (p);
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/for-3.c b/gcc/testsuite/c-c++-common/gomp/for-3.c
new file mode 100644 (file)
index 0000000..c3c57e4
--- /dev/null
@@ -0,0 +1,48 @@
+void bar (int);
+
+int a[256];
+
+void
+foo (int j)
+{
+  int i;
+  #pragma omp for
+  for (i = 0; i != 64; i = i + 4)      /* { dg-error "increment is not constant 1 or -1" } */
+    bar (i);
+  #pragma omp for
+  for (i = 128; i != 64; i = i - 4)    /* { dg-error "increment is not constant 1 or -1" } */
+    bar (i);
+  #pragma omp for
+  for (i = 0; i != 64; i = j + i)      /* { dg-error "increment is not constant 1 or -1" } */
+    bar (i);
+  #pragma omp for
+  for (i = 128; i != 64; i = -16 + i)  /* { dg-error "increment is not constant 1 or -1" } */
+    bar (i);
+  #pragma omp for
+  for (i = 0; i != 64; i += j)         /* { dg-error "increment is not constant 1 or -1" } */
+    bar (i);
+  #pragma omp for
+  for (i = 128; i != 64; i -= 8)       /* { dg-error "increment is not constant 1 or -1" } */
+    bar (i);
+  #pragma omp single
+  {
+    #pragma omp simd
+    for (i = 0; i != 64; i = i + 16)   /* { dg-error "increment is not constant 1 or -1" } */
+      a[i] = a[i] + 1;
+    #pragma omp simd
+    for (i = 128; i != 64; i = i - 2)  /* { dg-error "increment is not constant 1 or -1" } */
+      a[i] = a[i] + 1;
+    #pragma omp simd
+    for (i = 0; i != 64; i = j + i)    /* { dg-error "increment is not constant 1 or -1" } */
+      a[i] = a[i] + 1;
+    #pragma omp simd
+    for (i = 128; i != 64; i = -j + i) /* { dg-error "increment is not constant 1 or -1" } */
+      a[i] = a[i] + 1;
+    #pragma omp simd
+    for (i = 0; i != 64; i += 8)       /* { dg-error "increment is not constant 1 or -1" } */
+      a[i] = a[i] + 1;
+    #pragma omp simd
+    for (i = 128; i != 64; i -= j)     /* { dg-error "increment is not constant 1 or -1" } */
+      a[i] = a[i] + 1;
+  }
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/for-4.c b/gcc/testsuite/c-c++-common/gomp/for-4.c
new file mode 100644 (file)
index 0000000..53d5260
--- /dev/null
@@ -0,0 +1,25 @@
+void bar (short *);
+
+void
+foo (short *q, short *r, short *s, long t)
+{
+  short *p;
+  #pragma omp for
+  for (p = q; p != r; p = p + 5)       /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = s; p != r; p = p - 2)       /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = q; p != r; p = t + p)       /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = s; p != r; p = -t + p)      /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = q; p != r; p += t)          /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = s; p != r; p -= 7)          /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/for-5.c b/gcc/testsuite/c-c++-common/gomp/for-5.c
new file mode 100644 (file)
index 0000000..6a1d1db
--- /dev/null
@@ -0,0 +1,50 @@
+// { dg-options "-fopenmp" }
+
+void bar (void *);
+
+__attribute__((noinline, noclone)) void
+foo (void *qx, void *rx, void *sx, int n)
+{
+  unsigned short (*q)[n], (*r)[n], (*s)[n], (*p)[n];
+  q = (typeof (q)) qx;
+  r = (typeof (r)) rx;
+  s = (typeof (s)) sx;
+  int t = 1;
+  int o = -1;
+  #pragma omp for
+  for (p = q; p != r; p += t)          /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = s; p != r; p += o)          /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = q; p != r; p = p + t)       /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = s; p != r; p = p + o)       /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = q; p != r; p = t + p)       /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = s; p != r; p = o + p)       /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = q; p != r; p += 2)          /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = s; p != r; p -= 2)          /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = q; p != r; p = p + 3)       /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = s; p != r; p = p - 3)       /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = q; p != r; p = 4 + p)       /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+  #pragma omp for
+  for (p = s; p != r; p = -5 + p)      /* { dg-error "increment is not constant 1 or -1" } */
+    bar (p);
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/for-6.c b/gcc/testsuite/c-c++-common/gomp/for-6.c
new file mode 100644 (file)
index 0000000..274e189
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -fdump-tree-ompexp" } */
+
+extern void bar(int);
+
+void foo (int n)
+{
+  int i;
+
+  #pragma omp for schedule(monotonic:runtime)
+  for (i = 0; i < n; ++i)
+    bar(i);
+}
+
+/* { dg-final { scan-tree-dump-times "GOMP_loop_runtime_start" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_runtime_next" 1 "ompexp" } } */
diff --git a/gcc/testsuite/c-c++-common/gomp/for-7.c b/gcc/testsuite/c-c++-common/gomp/for-7.c
new file mode 100644 (file)
index 0000000..5cd0a91
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -fdump-tree-ompexp" } */
+
+extern void bar(int);
+
+void foo (int n)
+{
+  int i;
+
+  #pragma omp for schedule(nonmonotonic:runtime)
+  for (i = 0; i < n; ++i)
+    bar(i);
+}
+
+/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_runtime_start" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_runtime_next" 1 "ompexp" } } */
index 3a9b53870c6e7d8d028a0472656d31e2d9b25f07..1ae39e6684a0e562ba20a5908e7278fc25755b3e 100644 (file)
@@ -12,6 +12,12 @@ foo (int a, int b, int *p, int *q)
   for (i = 0; i < 16; i++)
     ;
   #pragma omp parallel for simd if (parallel : a)
+  for (i = 0; i < 16; i++)
+    ;
+  #pragma omp parallel for simd if (simd : a)
+  for (i = 0; i < 16; i++)
+    ;
+  #pragma omp parallel for simd if (simd : a) if (parallel:b)
   for (i = 0; i < 16; i++)
     ;
   #pragma omp task if (a)
@@ -22,16 +28,37 @@ foo (int a, int b, int *p, int *q)
   for (i = 0; i < 16; i++)
     ;
   #pragma omp taskloop if (taskloop : a)
+  for (i = 0; i < 16; i++)
+    ;
+  #pragma omp taskloop simd if (a)
+  for (i = 0; i < 16; i++)
+    ;
+  #pragma omp taskloop simd if (taskloop : a)
+  for (i = 0; i < 16; i++)
+    ;
+  #pragma omp taskloop simd if (simd : a)
+  for (i = 0; i < 16; i++)
+    ;
+  #pragma omp taskloop simd if (taskloop:b) if (simd : a)
   for (i = 0; i < 16; i++)
     ;
   #pragma omp target if (a)
     ;
   #pragma omp target if (target: a)
     ;
+  #pragma omp target simd if (a)
+  for (i = 0; i < 16; i++)
+    ;
+  #pragma omp target simd if (simd : a) if (target: b)
+  for (i = 0; i < 16; i++)
+    ;
   #pragma omp target teams distribute parallel for simd if (a)
   for (i = 0; i < 16; i++)
     ;
   #pragma omp target teams distribute parallel for simd if (parallel : a) if (target: b)
+  for (i = 0; i < 16; i++)
+    ;
+  #pragma omp target teams distribute parallel for simd if (simd : a) if (target: b)
   for (i = 0; i < 16; i++)
     ;
   #pragma omp target data if (a) map (p[0:2])
@@ -44,4 +71,47 @@ foo (int a, int b, int *p, int *q)
   #pragma omp target exit data if (target exit data: a) map (from: p[0:2])
   #pragma omp target update if (a) to (q[0:3])
   #pragma omp target update if (target update:a) to (q[0:3])
+  #pragma omp parallel
+  {
+    #pragma omp cancel parallel if (a)
+  }
+ #pragma omp parallel
+  {
+    #pragma omp cancel parallel if (cancel:a)
+  }
+  #pragma omp for
+  for (i = 0; i < 16; i++)
+    {
+      #pragma omp cancel for if (a)
+    }
+  #pragma omp for
+  for (i = 0; i < 16; i++)
+    {
+      #pragma omp cancel for if (cancel: a)
+    }
+  #pragma omp sections
+    {
+    #pragma omp section
+      {
+       #pragma omp cancel sections if (a)
+      }
+    }
+  #pragma omp sections
+    {
+    #pragma omp section
+      {
+       #pragma omp cancel sections if (cancel: a)
+      }
+    }
+  #pragma omp taskgroup
+  {
+    #pragma omp task
+    {
+      #pragma omp cancel taskgroup if (a)
+    }
+    #pragma omp task
+    {
+      #pragma omp cancel taskgroup if (cancel: a)
+    }
+  }
 }
index f1f417ed23571cbe15393de63944d1e8c22e0b5d..0e9daf24b1265e7542d572545e7a029f4a3048f4 100644 (file)
@@ -18,6 +18,8 @@ foo (int a, int b, int *p, int *q, int task)
     ;
   #pragma omp parallel if (target update:a) /* { dg-error "expected .parallel. .if. clause modifier rather than .target update." } */
     ;
+  #pragma omp parallel if (cancel:a) /* { dg-error "expected .parallel. .if. clause modifier rather than .cancel." } */
+    ;
   #pragma omp parallel for simd if (target update: a) /* { dg-error "expected .parallel. .if. clause modifier rather than .target update." } */
   for (i = 0; i < 16; i++)
     ;
@@ -27,12 +29,15 @@ foo (int a, int b, int *p, int *q, int task)
     ;
   #pragma omp task if (parallel: a) /* { dg-error "expected .task. .if. clause modifier rather than .parallel." } */
     ;
+  #pragma omp simd if (cancel: a) /* { dg-error "expected .simd. .if. clause modifier rather than .cancel." } */
+  for (i = 0; i < 16; i++)
+    ;
   #pragma omp taskloop if (task : a) /* { dg-error "expected .taskloop. .if. clause modifier rather than .task." } */
   for (i = 0; i < 16; i++)
     ;
   #pragma omp target if (taskloop: a) /* { dg-error "expected .target. .if. clause modifier rather than .taskloop." } */
     ;
-  #pragma omp target teams distribute parallel for simd if (target exit data : a) /* { dg-error "expected .parallel. or .target. .if. clause modifier" } */
+  #pragma omp target teams distribute parallel for simd if (target exit data : a) /* { dg-error "expected .target. .if. clause modifier" } */
   for (i = 0; i < 16; i++)
     ;
   #pragma omp target data if (target: a) map (p[0:2]) /* { dg-error "expected .target data. .if. clause modifier rather than .target." } */
@@ -40,4 +45,9 @@ foo (int a, int b, int *p, int *q, int task)
   #pragma omp target enter data if (target data: a) map (to: p[0:2]) /* { dg-error "expected .target enter data. .if. clause modifier rather than .target data." } */
   #pragma omp target exit data if (target enter data: a) map (from: p[0:2]) /* { dg-error "expected .target exit data. .if. clause modifier rather than .target enter data." } */
   #pragma omp target update if (target exit data:a) to (q[0:3]) /* { dg-error "expected .target update. .if. clause modifier rather than .target exit data." } */
+  #pragma omp for
+  for (i = 0; i < 16; i++)
+    {
+      #pragma omp cancel for if (target exit data:a) /* { dg-error "expected .cancel. .if. clause modifier" } */
+    }
 }
diff --git a/gcc/testsuite/c-c++-common/gomp/if-3.c b/gcc/testsuite/c-c++-common/gomp/if-3.c
new file mode 100644 (file)
index 0000000..12c342b
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O2" } */
+
+#define N 1024
+
+void
+foo (int *x, int *y, int *z, int a)
+{
+  int i;
+  #pragma omp simd if (simd: a > 2) aligned (x, y, z : 16)
+  for (i = 0; i < N; i++)
+    x[i] = y[i] + z[i];
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/master-combined-1.c b/gcc/testsuite/c-c++-common/gomp/master-combined-1.c
new file mode 100644 (file)
index 0000000..b11f5db
--- /dev/null
@@ -0,0 +1,32 @@
+void bar (int *);
+
+void
+foo (int *a)
+{
+  int i, j, k, u = 0, v = 0, w = 0, x = 0, y = 0, z = 0;
+  #pragma omp parallel master default(none) private (k)
+  bar (&k);
+  #pragma omp parallel default(none) firstprivate(a) shared(x, y, z)
+  {
+    #pragma omp master taskloop reduction (+:x) default(none) firstprivate(a)
+    for (i = 0; i < 64; i++)
+      x += a[i];
+    #pragma omp master taskloop simd reduction (+:y) default(none) firstprivate(a) private (i)
+    for (i = 0; i < 64; i++)
+      y += a[i];
+    #pragma omp master taskloop simd collapse(2) reduction (+:z) default(none) firstprivate(a) private (i, j)
+    for (j = 0; j < 1; j++)
+      for (i = 0; i < 64; ++i)
+       z += a[i];
+  }
+  #pragma omp parallel master taskloop reduction (+:u) default(none) firstprivate(a)
+  for (i = 0; i < 64; i++)
+    u += a[i];
+  #pragma omp parallel master taskloop simd reduction (+:v) default(none) firstprivate(a)
+  for (i = 0; i < 64; i++)
+    v += a[i];
+  #pragma omp parallel master taskloop simd collapse(2) reduction (+:w) default(none) firstprivate(a)
+  for (j = 0; j < 1; j++)
+    for (i = 0; i < 64; ++i)
+      w += a[i];
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/master-combined-2.c b/gcc/testsuite/c-c++-common/gomp/master-combined-2.c
new file mode 100644 (file)
index 0000000..4f7b574
--- /dev/null
@@ -0,0 +1,13 @@
+void
+foo (int *a)
+{
+  int i, r = 0, s = 0;
+  #pragma omp taskgroup task_reduction(+:r)
+  #pragma omp parallel master taskloop in_reduction(+:r)       /* { dg-error "'in_reduction' is not valid for '#pragma omp parallel master taskloop'" } */
+  for (i = 0; i < 64; i++)
+    r += a[i];
+  #pragma omp taskgroup task_reduction(+:s)
+  #pragma omp parallel master taskloop simd in_reduction(+:s)  /* { dg-error "'in_reduction' is not valid for '#pragma omp parallel master taskloop simd'" } */
+  for (i = 0; i < 64; i++)
+    s += a[i];
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/nontemporal-1.c b/gcc/testsuite/c-c++-common/gomp/nontemporal-1.c
new file mode 100644 (file)
index 0000000..7f1f182
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O2" } */
+
+#define N 1024
+int a[N], b[N], c[N], d[N];
+
+void
+foo (void)
+{
+  int i;
+  #pragma omp simd nontemporal (a, b)
+  for (i = 0; i < N; ++i)
+    a[i] = b[i] + c[i];
+  #pragma omp simd nontemporal (d)
+  for (i = 0; i < N; ++i)
+    d[i] = 2 * c[i];
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/nontemporal-2.c b/gcc/testsuite/c-c++-common/gomp/nontemporal-2.c
new file mode 100644 (file)
index 0000000..950a87d
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+
+#define N 1024
+extern int a[N], b[N], c[N], d[N];
+
+void
+foo (void)
+{
+  int i;
+  #pragma omp simd nontemporal (a, b) aligned (a, b, c)
+  for (i = 0; i < N; ++i)
+    a[i] = b[i] + c[i];
+  #pragma omp simd nontemporal (d) nontemporal (d)     /* { dg-error "'d' appears more than once in 'nontemporal' clauses" } */
+  for (i = 0; i < N; ++i)
+    d[i] = 2 * c[i];
+  #pragma omp simd nontemporal (a, b, b)               /* { dg-error "'b' appears more than once in 'nontemporal' clauses" } */
+  for (i = 0; i < N; ++i)
+    a[i] += b[i] + c[i];
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/reduction-task-1.c b/gcc/testsuite/c-c++-common/gomp/reduction-task-1.c
new file mode 100644 (file)
index 0000000..3c509d6
--- /dev/null
@@ -0,0 +1,86 @@
+int v;
+extern void foo (int);
+
+void
+bar (void)
+{
+  int i;
+  #pragma omp for reduction (task, +: v)
+  for (i = 0; i < 64; i++)
+    foo (i);
+  #pragma omp sections reduction (task, +: v)
+  {
+    foo (-2);
+    #pragma omp section
+    foo (-3);
+  }
+  #pragma omp parallel reduction (task, +: v)
+  foo (-1);
+  #pragma omp parallel for reduction (task, +: v)
+  for (i = 0; i < 64; i++)
+    foo (i);
+  #pragma omp parallel sections reduction (task, +: v)
+  {
+    foo (-2);
+    #pragma omp section
+    foo (-3);
+  }
+  #pragma omp teams distribute parallel for reduction (task, +: v)
+  for (i = 0; i < 64; i++)
+    foo (i);
+  #pragma omp for reduction (default, +: v)
+  for (i = 0; i < 64; i++)
+    foo (i);
+  #pragma omp sections reduction (default, +: v)
+  {
+    foo (-2);
+    #pragma omp section
+    foo (-3);
+  }
+  #pragma omp parallel reduction (default, +: v)
+  foo (-1);
+  #pragma omp parallel for reduction (default, +: v)
+  for (i = 0; i < 64; i++)
+    foo (i);
+  #pragma omp parallel sections reduction (default, +: v)
+  {
+    foo (-2);
+    #pragma omp section
+    foo (-3);
+  }
+  #pragma omp teams distribute parallel for reduction (default, +: v)
+  for (i = 0; i < 64; i++)
+    foo (i);
+  #pragma omp for reduction (default, +: v) nowait
+  for (i = 0; i < 64; i++)
+    foo (i);
+  #pragma omp sections nowait reduction (default, +: v)
+  {
+    foo (-2);
+    #pragma omp section
+    foo (-3);
+  }
+  #pragma omp simd reduction (default, +: v)
+  for (i = 0; i < 64; i++)
+    v++;
+  #pragma omp for simd reduction (default, +: v)
+  for (i = 0; i < 64; i++)
+    v++;
+  #pragma omp parallel for simd reduction (default, +: v)
+  for (i = 0; i < 64; i++)
+    v++;
+  #pragma omp teams distribute parallel for simd reduction (default, +: v)
+  for (i = 0; i < 64; i++)
+    v++;
+  #pragma omp taskloop reduction (default, +: v)
+  for (i = 0; i < 64; i++)
+    foo (i);
+  #pragma omp taskloop simd reduction (default, +: v)
+  for (i = 0; i < 64; i++)
+    v++;
+  #pragma omp teams reduction (default, +: v)
+  foo (i);
+  #pragma omp teams distribute reduction (default, +: v)
+  for (i = 0; i < 64; i++)
+    foo (i);
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/reduction-task-2.c b/gcc/testsuite/c-c++-common/gomp/reduction-task-2.c
new file mode 100644 (file)
index 0000000..1e262d3
--- /dev/null
@@ -0,0 +1,40 @@
+int v;
+extern void foo (int);
+
+void
+bar (void)
+{
+  int i;
+  #pragma omp for reduction (task, +: v) nowait        /* { dg-error "'task' reduction modifier on a construct with a 'nowait' clause" } */
+  for (i = 0; i < 64; i++)
+    foo (i);
+  #pragma omp sections nowait reduction (task, +: v)   /* { dg-error "'task' reduction modifier on a construct with a 'nowait' clause" } */
+  {
+    foo (-2);
+    #pragma omp section
+    foo (-3);
+  }
+  #pragma omp simd reduction (task, +: v)      /* { dg-error "invalid 'task' reduction modifier on construct other than 'parallel', 'for' or 'sections'" } */
+  for (i = 0; i < 64; i++)
+    v++;
+  #pragma omp for simd reduction (task, +: v)  /* { dg-error "invalid 'task' reduction modifier on construct combined with 'simd'" } */
+  for (i = 0; i < 64; i++)
+    v++;
+  #pragma omp parallel for simd reduction (task, +: v) /* { dg-error "invalid 'task' reduction modifier on construct combined with 'simd'" } */
+  for (i = 0; i < 64; i++)
+    v++;
+  #pragma omp teams distribute parallel for simd reduction (task, +: v)        /* { dg-error "invalid 'task' reduction modifier on construct combined with 'simd'" } */
+  for (i = 0; i < 64; i++)
+    v++;
+  #pragma omp taskloop reduction (task, +: v)  /* { dg-error "invalid 'task' reduction modifier on construct other than 'parallel', 'for' or 'sections'" } */
+  for (i = 0; i < 64; i++)
+    foo (i);
+  #pragma omp taskloop simd reduction (task, +: v)     /* { dg-error "invalid 'task' reduction modifier on construct combined with 'simd'" } */
+  for (i = 0; i < 64; i++)
+    v++;
+  #pragma omp teams reduction (task, +: v)     /* { dg-error "invalid 'task' reduction modifier on construct other than 'parallel', 'for' or 'sections'" } */
+  foo (i);
+  #pragma omp teams distribute reduction (task, +: v)  /* { dg-error "invalid 'task' reduction modifier on construct not combined with 'parallel', 'for' or 'sections'" } */
+  for (i = 0; i < 64; i++)
+    foo (i);
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/requires-1.c b/gcc/testsuite/c-c++-common/gomp/requires-1.c
new file mode 100644 (file)
index 0000000..7be6c38
--- /dev/null
@@ -0,0 +1,15 @@
+#pragma omp requires unified_address
+#pragma omp requires unified_shared_memory
+#pragma omp requires unified_shared_memory unified_address
+#pragma omp requires dynamic_allocators,reverse_offload
+
+int i;
+
+void
+foo ()
+{
+  if (0)
+    #pragma omp requires unified_shared_memory unified_address
+    i++;
+  #pragma omp requries atomic_default_mem_order(seq_cst)
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/requires-2.c b/gcc/testsuite/c-c++-common/gomp/requires-2.c
new file mode 100644 (file)
index 0000000..d242a32
--- /dev/null
@@ -0,0 +1,18 @@
+#pragma omp requires   /* { dg-error "requires at least one clause" } */
+#pragma omp requires unified_shared_memory,unified_shared_memory       /* { dg-error "too many 'unified_shared_memory' clauses" } */
+#pragma omp requires unified_address   unified_address /* { dg-error "too many 'unified_address' clauses" } */
+#pragma omp requires reverse_offload reverse_offload   /* { dg-error "too many 'reverse_offload' clauses" } */
+#pragma omp requires foobarbaz /* { dg-error "expected 'unified_address', 'unified_shared_memory', 'dynamic_allocators', 'reverse_offload' or 'atomic_default_mem_order' clause" } */
+
+int i;
+
+void
+foo ()
+{
+  #pragma omp requires dynamic_allocators , dynamic_allocators /* { dg-error "too many 'dynamic_allocators' clauses" } */
+  if (0)
+    #pragma omp requires atomic_default_mem_order(seq_cst) atomic_default_mem_order(seq_cst)   /* { dg-error "too many 'atomic_default_mem_order' clauses" } */
+    i++;
+}
+
+#pragma omp requires atomic_default_mem_order (seq_cst)        /* { dg-error "more than one 'atomic_default_mem_order' clause in a single compilation unit" } */
diff --git a/gcc/testsuite/c-c++-common/gomp/requires-3.c b/gcc/testsuite/c-c++-common/gomp/requires-3.c
new file mode 100644 (file)
index 0000000..e5a6cbb
--- /dev/null
@@ -0,0 +1,3 @@
+#pragma omp requires atomic_default_mem_order(acquire) /* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */
+#pragma omp requires atomic_default_mem_order(release) /* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */
+#pragma omp requires atomic_default_mem_order(foobar)  /* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */
diff --git a/gcc/testsuite/c-c++-common/gomp/requires-4.c b/gcc/testsuite/c-c++-common/gomp/requires-4.c
new file mode 100644 (file)
index 0000000..a3497b1
--- /dev/null
@@ -0,0 +1,11 @@
+#pragma omp requires unified_shared_memory,unified_address,reverse_offload
+void
+foo (void)
+{
+  #pragma omp target
+  ;
+  #pragma omp requires unified_shared_memory   /* { dg-error "'unified_shared_memory' clause used lexically after first target construct or offloading API" } */
+}
+
+#pragma omp requires unified_address   /* { dg-error "'unified_address' clause used lexically after first target construct or offloading API" } */
+#pragma omp requires reverse_offload   /* { dg-error "'reverse_offload' clause used lexically after first target construct or offloading API" } */
index 33ca3a6534d7c0549c9adba708f00e535b522f2b..82ab25722e741a79b4cc33d97ecfa1c63373a4b7 100644 (file)
@@ -68,18 +68,26 @@ void
 bar (void)
 {
   int i;
-  #pragma omp for schedule (nonmonotonic: static, 2)   /* { dg-error ".nonmonotonic. modifier specified for .static. schedule kind" } */
+  #pragma omp for schedule (nonmonotonic: static, 2)
   for (i = 0; i < 64; i++)
     ;
-  #pragma omp for schedule (nonmonotonic : static)     /* { dg-error ".nonmonotonic. modifier specified for .static. schedule kind" } */
+  #pragma omp for schedule (nonmonotonic : static)
   for (i = 0; i < 64; i++)
     ;
-  #pragma omp for schedule (nonmonotonic : runtime)    /* { dg-error ".nonmonotonic. modifier specified for .runtime. schedule kind" } */
+  #pragma omp for schedule (nonmonotonic : runtime)
   for (i = 0; i < 64; i++)
     ;
-  #pragma omp for schedule (nonmonotonic : auto)       /* { dg-error ".nonmonotonic. modifier specified for .auto. schedule kind" } */
+  #pragma omp for schedule (nonmonotonic : auto)
   for (i = 0; i < 64; i++)
     ;
+  #pragma omp for schedule (nonmonotonic : static) ordered     /* { dg-error ".nonmonotonic. schedule modifier specified together with .ordered. clause" } */
+  for (i = 0; i < 64; i++)
+    #pragma omp ordered
+      ;
+  #pragma omp for ordered schedule (nonmonotonic: static, 4)   /* { dg-error ".nonmonotonic. schedule modifier specified together with .ordered. clause" } */
+  for (i = 0; i < 64; i++)
+    #pragma omp ordered
+      ;
   #pragma omp for schedule (nonmonotonic : dynamic) ordered    /* { dg-error ".nonmonotonic. schedule modifier specified together with .ordered. clause" } */
   for (i = 0; i < 64; i++)
     #pragma omp ordered
@@ -95,6 +103,12 @@ bar (void)
       #pragma omp ordered depend(source)
     }
   #pragma omp for ordered(1) schedule(nonmonotonic : guided, 2)        /* { dg-error ".nonmonotonic. schedule modifier specified together with .ordered. clause" } */
+  for (i = 0; i < 64; i++)
+    {
+      #pragma omp ordered depend(source)
+      #pragma omp ordered depend(sink: i - 1)
+    }
+  #pragma omp for schedule(nonmonotonic : runtime) ordered(1)  /* { dg-error ".nonmonotonic. schedule modifier specified together with .ordered. clause" } */
   for (i = 0; i < 64; i++)
     {
       #pragma omp ordered depend(source)
diff --git a/gcc/testsuite/c-c++-common/gomp/simd7.c b/gcc/testsuite/c-c++-common/gomp/simd7.c
new file mode 100644 (file)
index 0000000..83d5325
--- /dev/null
@@ -0,0 +1,21 @@
+int a[64];
+
+#pragma omp declare simd linear(x)
+int
+bar (int x, int y)
+{
+  int v;
+  #pragma omp atomic capture
+  v = a[x] += y;
+  return v;
+}
+
+void
+foo (void)
+{
+  int i;
+  #pragma omp simd
+  for (i = 0; i < 64; i++)
+    #pragma omp atomic
+    a[i] += 1;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/target-data-1.c b/gcc/testsuite/c-c++-common/gomp/target-data-1.c
new file mode 100644 (file)
index 0000000..0d4975b
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+
+void
+foo (void)
+{
+  int a[4] = { 1, 2, 3, 4 };
+  #pragma omp target data map(to:a)
+  #pragma omp target data use_device_ptr(a)
+  #pragma omp target is_device_ptr(a)
+  {
+    a[0]++;
+  }
+  #pragma omp target data              /* { dg-error "must contain at least one" } */
+  a[0]++;
+  #pragma omp target data map(to:a)
+  #pragma omp target data use_device_ptr(a) use_device_ptr(a) /* { dg-error "appears more than once in data clauses" } */
+  a[0]++;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/taskloop-reduction-1.c b/gcc/testsuite/c-c++-common/gomp/taskloop-reduction-1.c
new file mode 100644 (file)
index 0000000..0df073f
--- /dev/null
@@ -0,0 +1,10 @@
+int
+foo (int *a)
+{
+  int x = 0;
+  #pragma omp taskloop reduction (+:x) nogroup /* { dg-error "'nogroup' clause must not be used together with 'reduction' clause" } */
+  for (int i = 0; i < 64; i++)
+    x += a[i];
+  #pragma omp taskwait
+  return x;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/taskwait-depend-1.c b/gcc/testsuite/c-c++-common/gomp/taskwait-depend-1.c
new file mode 100644 (file)
index 0000000..1fcce74
--- /dev/null
@@ -0,0 +1,11 @@
+void
+foo (int *p)
+{
+  #pragma omp taskwait depend(iterator(i = 0:16) , in : p[i]) depend(out : p[32])
+}
+
+void
+bar (int *p)
+{
+  #pragma omp taskwait depend(mutexinoutset : p[0])    /* { dg-error "'mutexinoutset' kind in 'depend' clause on a 'taskwait' construct" } */
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/teams-1.c b/gcc/testsuite/c-c++-common/gomp/teams-1.c
new file mode 100644 (file)
index 0000000..0ef3bb9
--- /dev/null
@@ -0,0 +1,64 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int omp_get_num_teams (void);
+int omp_get_team_num (void);
+
+#ifdef __cplusplus
+}
+#endif
+
+void bar (int *, int *, int *, int, int, int, int);
+
+void
+foo (void)
+{
+  int a = 1, b = 2, c = 3, d = 4, e = 5, f = 6;
+  #pragma omp teams num_teams (4) shared (b) firstprivate (c, d) private (e, f)
+  {
+    f = 7;
+    bar (&a, &c, &e, b, d, f, 0);
+  }
+  bar (&a, (int *) 0, (int *) 0, b, 0, 0, 1);
+}
+
+void
+baz (void)
+{
+  #pragma omp teams
+  {
+    #pragma omp distribute
+    for (int i = 0; i < 64; i++)
+      ;
+    #pragma omp distribute simd
+    for (int i = 0; i < 64; i++)
+      ;
+    #pragma omp distribute parallel for
+    for (int i = 0; i < 64; i++)
+      ;
+    #pragma omp distribute parallel for
+    for (int i = 0; i < 64; i++)
+      ;
+    #pragma omp distribute parallel for simd
+    for (int i = 0; i < 64; i++)
+      ;
+    #pragma omp parallel
+    ;
+    #pragma omp parallel for
+    for (int i = 0; i < 64; i++)
+      ;
+    #pragma omp parallel for simd
+    for (int i = 0; i < 64; i++)
+      ;
+    int a, b;
+    #pragma omp parallel sections
+    {
+      a = 5;
+      #pragma omp section
+      b = 6;
+    }
+    int c = omp_get_num_teams ();
+    int d = omp_get_team_num ();
+  }
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/teams-2.c b/gcc/testsuite/c-c++-common/gomp/teams-2.c
new file mode 100644 (file)
index 0000000..011c284
--- /dev/null
@@ -0,0 +1,119 @@
+void
+foo (void)
+{
+  int i;
+
+  #pragma omp parallel
+  {
+    #pragma omp teams  /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */
+    ;
+  }
+  #pragma omp teams
+  {
+    #pragma omp teams  /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    ;
+  }
+  #pragma omp target
+  {
+    #pragma omp parallel
+    {
+      #pragma omp teams        /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */
+      ;
+    }
+  }
+  #pragma omp for
+  for (i = 0; i < 4; i++)
+    if (i == 0)
+      {
+       #pragma omp teams       /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */
+       ;
+      }
+  #pragma omp single
+  #pragma omp teams    /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */
+  ;
+  #pragma omp master
+  {
+    #pragma omp teams  /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */
+    ;
+  }
+  #pragma omp critical
+  #pragma omp teams    /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */
+  ;
+  #pragma omp sections
+  {
+    #pragma omp teams  /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */
+    ;
+    #pragma omp section
+    {
+      #pragma omp teams        /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */
+      ;
+    }
+  }
+  #pragma omp target data map (to: i)
+  {
+    #pragma omp teams  /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */
+    ;
+  }
+  #pragma omp task
+  {
+    #pragma omp teams  /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */
+    ;
+  }
+  #pragma omp taskgroup
+  {
+    #pragma omp teams  /* { dg-error "'teams' construct must be closely nested inside of 'target' construct or not nested in any OpenMP construct" } */
+    ;
+  }
+}
+
+void
+bar (void)
+{
+  #pragma omp teams
+  {
+    int x, y, v = 4;
+    #pragma omp target                 /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    ;
+    #pragma omp target data map (to: v)        /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    ;
+    #pragma omp for                    /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    for (int i = 0; i < 64; ++i)
+      ;
+    #pragma omp simd                   /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    for (int i = 0; i < 64; ++i)
+      ;
+    #pragma omp for simd               /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    for (int i = 0; i < 64; ++i)
+      ;
+    #pragma omp single                 /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    ;
+    #pragma omp master                 /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    ;
+    #pragma omp sections               /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    {
+      x = 1;
+      #pragma omp section
+      y = 2;
+    }
+    #pragma omp critical               /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    ;
+    #pragma omp target enter data map (to: v)  /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    #pragma omp target exit data map (from: v) /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    #pragma omp cancel parallel                /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    #pragma omp cancellation point parallel /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    #pragma omp barrier                        /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    #pragma omp ordered                        /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    ;
+    #pragma omp task                   /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    ;
+    #pragma omp taskloop               /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    for (int i = 0; i < 64; ++i)
+      ;
+    #pragma omp atomic                 /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    v++;
+    #pragma omp taskgroup              /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    ;
+    #pragma omp taskwait               /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+    #pragma omp taskyield              /* { dg-error "only 'distribute' or 'parallel' regions are allowed to be strictly nested inside 'teams' region" } */
+  }
+}
diff --git a/gcc/testsuite/g++.dg/gomp/atomic-18.C b/gcc/testsuite/g++.dg/gomp/atomic-18.C
new file mode 100644 (file)
index 0000000..c93e732
--- /dev/null
@@ -0,0 +1,50 @@
+// { dg-do compile }
+// { dg-additional-options "-fdump-tree-original" }
+// { dg-final { scan-tree-dump-times "omp atomic release" 5 "original" } }
+// { dg-final { scan-tree-dump-times "omp atomic seq_cst" 1 "original" } }
+// { dg-final { scan-tree-dump-times "omp atomic relaxed" 2 "original" } }
+// { dg-final { scan-tree-dump-times "omp atomic capture acq_rel" 3 "original" } }
+// { dg-final { scan-tree-dump-times "omp atomic capture acquire" 1 "original" } }
+// { dg-final { scan-tree-dump-times "omp atomic read acquire" 1 "original" } }
+
+int i, v;
+float f;
+
+template <int N, int M, typename T>
+void
+foo (T *p)
+{
+  #pragma omp atomic release, hint (N), update
+  i = i + 1;
+  #pragma omp atomic hint(0)seq_cst
+  i = i + 1;
+  #pragma omp atomic relaxed,update,hint (N)
+  i = i + 1;
+  #pragma omp atomic release
+  i = i + 1;
+  #pragma omp atomic relaxed
+  i = i + 1;
+  #pragma omp atomic acq_rel capture
+  v = i = i + 1;
+  #pragma omp atomic capture,acq_rel , hint (M)
+  v = i = i + 1;
+  #pragma omp atomic hint(N),acquire capture
+  v = i = i + 1;
+  #pragma omp atomic read acquire
+  v = i;
+  #pragma omp atomic release,write
+  i = v;
+  #pragma omp atomic hint(1),update,release
+  f = f + 2.0;
+  #pragma omp requires atomic_default_mem_order (acq_rel)
+  #pragma omp atomic hint (M - 1) update
+  *p += 1;
+  #pragma omp atomic capture, hint (M)
+  v = *p = *p + 1;
+}
+
+void
+bar ()
+{
+  foo <0, 1, int> (&i);
+}
diff --git a/gcc/testsuite/g++.dg/gomp/atomic-19.C b/gcc/testsuite/g++.dg/gomp/atomic-19.C
new file mode 100644 (file)
index 0000000..93f6613
--- /dev/null
@@ -0,0 +1,17 @@
+int i;
+
+template <int N, typename T>
+void
+foo (T x)
+{
+  #pragma omp atomic hint (x)          // { dg-error "must be integral" }
+  i = i + 1;
+  #pragma omp atomic hint (N + i)      // { dg-error "constant integer expression" }
+  i = i + 1;
+}
+
+void
+bar ()
+{
+  foo <0, float> (1.0f);
+}
index b277ebf3ddef6ab047418241ded987bc910a0226..78f6344361be0ad7378442cc383959f06c131c49 100644 (file)
@@ -12,18 +12,18 @@ void f1(void)
     x = x + 1;
   #pragma omp atomic
     x = 1;             /* { dg-error "invalid form" } */
-  #pragma omp atomic
+  #pragma omp atomic   /* { dg-error "read-only variable" } */
     ++y;               /* { dg-error "read-only variable" } */
-  #pragma omp atomic
+  #pragma omp atomic   /* { dg-error "read-only variable" } */
     y--;               /* { dg-error "read-only variable" } */
-  #pragma omp atomic
-    y += 1;            /* { dg-error "read-only variable" } */
+  #pragma omp atomic   /* { dg-error "read-only variable" } */
+    y += 1;
   #pragma omp atomic
     bar();             /* { dg-error "invalid operator" } */
   #pragma omp atomic
     bar() += 1;                /* { dg-error "lvalue required" } */
   #pragma omp atomic a /* { dg-error "expected end of line" } */
-    x++;
+    x++;               /* { dg-error "expected 'read', 'write', 'update', 'capture', 'seq_cst', 'acq_rel', 'release', 'relaxed' or 'hint' clause" "" { target *-*-* } .-1 } */
   #pragma omp atomic
     ;                  /* { dg-error "expected primary-expression" } */
   #pragma omp atomic
index 54f795717dd81920635062cd1b824846ef99936f..e0edc873483d0c4d50bdb864fb533374536bc921 100644 (file)
@@ -86,18 +86,18 @@ foo (int x)
 #pragma omp p for linear (t) // { dg-error "predetermined 'threadprivate'" }
   for (i = 0; i < 10; i++)
     ;
-#pragma omp p shared (c) // { dg-error "predetermined 'shared'" }
+#pragma omp p shared (c)
     ;
-#pragma omp p private (c) // { dg-error "predetermined 'shared'" }
+#pragma omp p private (c) // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" }
     ;
 #pragma omp p firstprivate (c)
     ;
-#pragma omp p for lastprivate (c) // { dg-error "predetermined 'shared'" }
+#pragma omp p for lastprivate (c) // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" }
   for (i = 0; i < 10; i++)
     ;
-#pragma omp p reduction (*:c) // { dg-error "predetermined 'shared'" }
+#pragma omp p reduction (*:c) // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" }
     ;
-#pragma omp p for linear (c:2) // { dg-error "predetermined 'shared'" }
+#pragma omp p for linear (c:2) // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" }
   for (i = 0; i < 10; i++)
     ;
 }
diff --git a/gcc/testsuite/g++.dg/gomp/critical-3.C b/gcc/testsuite/g++.dg/gomp/critical-3.C
new file mode 100644 (file)
index 0000000..b8dc496
--- /dev/null
@@ -0,0 +1,33 @@
+int i;
+
+template <int N>
+void
+foo (void)
+{
+  #pragma omp critical (foo), hint (N + 1)
+  i++;
+}
+
+template <int N>
+void
+bar (void)
+{
+  #pragma omp critical (bar), hint (N + i)     // { dg-error "constant integer expression" }
+  i++;
+}
+
+template <typename T>
+void
+baz (T x)
+{
+  #pragma omp critical (baz) hint (x)  // { dg-error "expression must be integral" }
+  i++;
+}
+
+void
+test ()
+{
+  foo <0> ();
+  bar <0> ();
+  baz (0.0);
+}
diff --git a/gcc/testsuite/g++.dg/gomp/depend-iterator-1.C b/gcc/testsuite/g++.dg/gomp/depend-iterator-1.C
new file mode 100644 (file)
index 0000000..6f4aa97
--- /dev/null
@@ -0,0 +1,86 @@
+int arr[64], arr2[64];
+struct S { int a[4]; } k;
+short arr4[4];
+volatile int v;
+#define TEST_EQ(x,y) ({ int o[x == y ? 1 : -1]; 0; })
+
+template <typename T, typename U, typename V, typename W, int N>
+void
+foo (unsigned char i, signed char j)
+{
+  #pragma omp task depend (iterator (T j=6:N:-2) , out : \
+       arr[TEST_EQ (sizeof (j), sizeof (int)), \
+           TEST_EQ (sizeof (i), sizeof (unsigned char)), \
+           TEST_EQ (sizeof (k), sizeof (struct S)), j], \
+       arr2[TEST_EQ (((__typeof (j)) -1) < 0, 1), \
+            TEST_EQ (((__typeof (i)) -1) < 0, 0), \
+            TEST_EQ (((__typeof (k.a[0])) -1) < 0, 1), j]) \
+       depend(out: arr[0]) \
+       depend (iterator (U i=__LONG_LONG_MAX__ - 4:__LONG_LONG_MAX__ - N:N, \
+                         V j=~0U-16:~0U-8:3, \
+                         W *k=&arr4[1]:&arr4[2]:1) , in : \
+       arr[TEST_EQ (sizeof (i), sizeof (long long)), \
+           TEST_EQ (sizeof (j), sizeof (unsigned short)), \
+           TEST_EQ (sizeof (k), sizeof (short *)), \
+           TEST_EQ (sizeof (*k), sizeof (short)), i - __LONG_LONG_MAX__ + 4], \
+       arr2[TEST_EQ (((__typeof (i)) -1) < 0, 1), \
+            TEST_EQ (((__typeof (j)) -1) < 0, 0), \
+            TEST_EQ (((__typeof (*k)) -1) < 0, 1), j - (~0U-16)], \
+       arr2[k - &arr4[0]]) \
+       depend(in : k)
+    v++;
+}
+
+template <typename U, typename W, int N>
+void
+bar (unsigned char i, signed char j)
+{
+  int m = j;
+  int n = j + 2;
+  #pragma omp task depend (iterator (j=N:2:m) , out : \
+       arr[TEST_EQ (sizeof (j), sizeof (int)), \
+           TEST_EQ (sizeof (i), sizeof (unsigned char)), \
+           TEST_EQ (sizeof (k), sizeof (struct S)), j], \
+       arr2[TEST_EQ (((__typeof (j)) -1) < 0, 1), \
+            TEST_EQ (((__typeof (i)) -1) < 0, 0), \
+            TEST_EQ (((__typeof (k.a[0])) -1) < 0, 1), j]) \
+       depend(out: arr[0]) \
+       depend (iterator (U i=__LONG_LONG_MAX__ - 4 - n:__LONG_LONG_MAX__ - 2:2, \
+                         unsigned short j=~0U-16:~0U-8-n:3, \
+                         W k=&arr4[N-5]:&arr4[n + 2]:1) , in : \
+       arr[TEST_EQ (sizeof (i), sizeof (long long)), \
+           TEST_EQ (sizeof (j), sizeof (unsigned short)), \
+           TEST_EQ (sizeof (k), sizeof (short *)), \
+           TEST_EQ (sizeof (*k), sizeof (short)), i - __LONG_LONG_MAX__ + 4], \
+       arr2[TEST_EQ (((__typeof (i)) -1) < 0, 1), \
+            TEST_EQ (((__typeof (j)) -1) < 0, 0), \
+            TEST_EQ (((__typeof (*k)) -1) < 0, 1), j - (~0U-16)], \
+       arr2[k - &arr4[0]:10]) \
+       depend(in : k)
+    v++;
+}
+
+template <typename T, typename U, int N>
+void
+baz (void)
+{
+  #pragma omp parallel
+  #pragma omp master
+  {
+    #pragma omp task depend(iterator(T k = N : 2) , inout : \
+       arr[TEST_EQ (sizeof (k), sizeof (unsigned long)), \
+           TEST_EQ (((__typeof (k)) -1) < N, 0), k]) \
+       depend(iterator(U s = -3 : -12 : -1 + N) , out : \
+       arr[TEST_EQ (sizeof (s), sizeof (signed char)), \
+           TEST_EQ (((__typeof (s)) -1) < 0, 1), s + 12])
+      v++;
+  }
+}
+
+void
+test (void)
+{
+  foo <int, long long, unsigned short, short, 2> (0, 0);
+  bar <long long, short *, 6> (0, -2);
+  baz <unsigned long int, signed char, 0> ();
+}
diff --git a/gcc/testsuite/g++.dg/gomp/depend-iterator-2.C b/gcc/testsuite/g++.dg/gomp/depend-iterator-2.C
new file mode 100644 (file)
index 0000000..a0119eb
--- /dev/null
@@ -0,0 +1,121 @@
+int a, b[64];
+struct S { int c; } *d, *e;
+struct T;
+struct T *f, *g;
+int *h;
+
+template <typename U, typename V, typename W, W N>
+void
+f1 ()
+{
+  #pragma omp task depend (iterator , in : a)  // { dg-error "expected" }
+  ;
+  #pragma omp task depend (iterator (for = 0 : 2) , in : a)    // { dg-error "expected" }
+  ;
+  #pragma omp task depend (iterator (5 = 0 : 2) , in : a)      // { dg-error "expected" }
+  ;
+  #pragma omp task depend (iterator (i : N : 2) , in : a)      // { dg-error "expected '='|name a type|expected" }
+  ;
+  #pragma omp task depend (iterator (i = 0, 1 : 2) , in : a)   // { dg-error "expected" }
+  ;
+  #pragma omp task depend (iterator (i = (0, 1) : 2) , in : a)
+  ;
+  #pragma omp task depend (iterator (i = 0 : 1 : 2 : 3) , in : a)      // { dg-error "expected '.'" }
+  ;
+  #pragma omp task depend (iterator (i = 0 : 2, 3) , in : a)   // { dg-error "expected" }
+  ;
+  #pragma omp task depend (iterator (i = N : 10 : 2, 3) , in : a)      // { dg-error "expected" }
+  ;
+  #pragma omp task depend (iterator (i = 0:1), iterator (j = 0:1) , in : a)    // { dg-error "invalid depend kind" }
+  ;
+  #pragma omp task depend (iterator (i = N:32) , in : b[i*2:2])
+  ;
+  #pragma omp task depend (iterator (void i = 0:1) , in : a)           // { dg-error "iterator 'i' has neither integral nor pointer type" }
+  ;
+  #pragma omp task depend (iterator (U *p = d:e:2) , in : a)
+  ;
+  #pragma omp task depend (iterator (W i = N:4, \
+                                    struct U2 { W *p; } *p = 0:2) , in : a) // { dg-error "types may not be defined in iterator type" }
+  ;
+  #pragma omp task depend (iterator (i = 0:4, j = i:16) , in : a)      // { dg-error "begin expression refers to outer iterator 'i'" }
+  ;
+  #pragma omp task depend (iterator (i = N:4, j = 2:i:1) , in : a)     // { dg-error "end expression refers to outer iterator 'i'" }
+  ;
+  #pragma omp task depend (iterator (i = 0:4, j = 2:8:i) , in : a)     // { dg-error "step expression refers to outer iterator 'i'" }
+  ;
+  #pragma omp task depend (iterator (i = 1.25:2.5:3) , in : a)
+  ;
+  #pragma omp task depend (iterator (i = 1:2:3.5) , in : a)            // { dg-error "iterator step with non-integral type" }
+  ;
+  #pragma omp task depend (iterator (W *p = 23 : h) , in : a)
+  ;
+  #pragma omp task depend (iterator (const int i = N : 2) , in : a)    // { dg-error "const qualified" }
+  ;
+  #pragma omp task depend (iterator (const long long unsigned i = 0 : 2) , in : a)     // { dg-error "const qualified" }
+  ;
+}
+
+template <typename W, int N>
+void
+f2 ()
+{
+  int i, j;
+  #pragma omp for ordered(2)
+  for (i = 0; i < 64; i++)
+    for (j = 0; j < 64; j++)
+      {
+      #pragma omp ordered depend (iterator (k=0:N) , sink: i - 1, j - 1)       // { dg-error "'iterator' modifier incompatible with 'sink'" }
+      #pragma omp ordered depend (iterator (W l = 0:2:3) , source)             // { dg-error "'iterator' modifier incompatible with 'source'" }
+      }
+}
+
+template <typename U, typename V, typename W, W N, typename X, typename Y>
+void
+f3 ()
+{
+  #pragma omp task depend (iterator (U i = 0:1), in : a)               // { dg-error "iterator 'i' has neither integral nor pointer type" }
+  ;
+  #pragma omp task depend (iterator (V f = 0.2:0.4) , in : a)  // { dg-error "iterator 'f' has neither integral nor pointer type" }
+  ;
+  #pragma omp task depend (iterator (struct T *p = f:g) , in : a)      // { dg-error "invalid use of" }
+  ;
+  #pragma omp task depend (iterator (i = *d:2) , in : a)       // { dg-error "invalid cast from type 'S' to type 'int'" }
+  ;
+  #pragma omp task depend (iterator (i = 2:*d:2) , in : a)     // { dg-error "invalid cast from type 'S' to type 'int'" }
+  ;
+  #pragma omp task depend (iterator (i = 2:4:*d) , in : a)     // { dg-error "iterator step with non-integral type" }
+  ;
+  #pragma omp task depend (iterator (i = 1.25:2.5:3) , in : a)
+  ;
+  #pragma omp task depend (iterator (i = 1:2:3.5) , in : a)    // { dg-error "iterator step with non-integral type" }
+  ;
+  #pragma omp task depend (iterator (W *p = 23 : h) , in : a)
+  ;
+  #pragma omp task depend (iterator (short i=1:3:N) , in : a)  // { dg-error "iterator 'i' has zero step" }
+  ;
+  #pragma omp task depend (iterator (i = 1 : 3 : N + 3 - 3) , in : a)  // { dg-error "iterator 'i' has zero step" }
+  ;
+  #pragma omp task depend (iterator (int *p = &b[6]:&b[9]:4 - 4) , in : a)     // { dg-error "iterator 'p' has zero step" }
+  ;
+  #pragma omp task depend (iterator (X i = N : 2) , in : a)    // { dg-error "const qualified" }
+  ;
+  #pragma omp task depend (iterator (Y i = 0 : 2) , in : a)    // { dg-error "const qualified" }
+  ;
+}
+
+template <int N>
+void
+f4 ()
+{
+  #pragma omp task depend (iterator (i = 0:1), iterator (j = 0:1) , in : a)    // { dg-error "invalid depend kind" }
+  ;
+}
+
+void
+f5 ()
+{
+  f1 <struct S, float, int, 0> ();
+  f2 <int, 1> ();
+  f3 <struct S, float, int, 0, const int, const long long unsigned> ();
+  f4 <0> ();
+}
diff --git a/gcc/testsuite/g++.dg/gomp/depobj-1.C b/gcc/testsuite/g++.dg/gomp/depobj-1.C
new file mode 100644 (file)
index 0000000..6004f1e
--- /dev/null
@@ -0,0 +1,118 @@
+typedef struct __attribute__((__aligned__ (sizeof (void *)))) omp_depend_t {
+  char __omp_depend_t__[2 * sizeof (void *)];
+} omp_depend_t;
+
+omp_depend_t bar (void);
+extern const omp_depend_t cdepobj;
+extern omp_depend_t depobj, depobj4;
+extern omp_depend_t depobja[4];
+extern omp_depend_t *pdepobj;
+int a, b, i, j;
+
+template <int N>
+void
+f1 (bool x)
+{
+  #pragma omp depobj(x ? depobj : depobj4) depend(in : x ? a : b)
+  #pragma omp depobj(x ? depobj : depobj4) update(inout)
+  #pragma omp task depend (depobj:depobj)
+  ;
+  #pragma omp depobj(depobj) destroy
+  #pragma omp task depend (iterator (i=1:3) , depobj: *(depobja + i))
+  ;
+  #pragma omp depobj(pdepobj[0]) depend(mutexinoutset:a)
+  #pragma omp depobj(*pdepobj) destroy
+}
+
+template <typename T, typename T2>
+void
+f2 (T &depobj2, T2 depobj3, T *pdepobj)
+{
+  T depobj1;
+  T depobja[4];
+  #pragma omp depobj(depobj1) depend(in : --a)
+  #pragma omp depobj(depobj1) update(inout)
+  #pragma omp task depend (depobj: depobj1)
+  ;
+  #pragma omp depobj(depobj1) destroy
+  #pragma omp depobj(depobj2) depend(in : a)
+  #pragma omp depobj(depobj2) update(inout)
+  #pragma omp task depend (depobj :depobj2)
+  ;
+  #pragma omp depobj(depobj2) destroy
+  #pragma omp depobj(depobj3) depend(in : a)
+  #pragma omp depobj(depobj3) update(inout)
+  #pragma omp task depend (depobj  :  depobj3)
+  ;
+  #pragma omp depobj(depobj3) destroy
+  for (int q = 1; q < 3; q++)
+    {
+      #pragma omp depobj(depobja[q]) depend (in:a)
+    }
+  #pragma omp task depend (iterator (i=1:3) , depobj : *(depobja + i))
+  ;
+  for (int q = 1; q < 3; q++)
+    {
+      #pragma omp depobj(depobja[q]) destroy
+    }
+  #pragma omp depobj(pdepobj[0]) depend(mutexinoutset:a)
+  #pragma omp depobj(*pdepobj) destroy
+}
+
+void
+f3 (bool x)
+{
+  omp_depend_t depobjx, depobjy;
+  f1 <0> (x);
+  f2 <omp_depend_t, omp_depend_t &> (depobjx, depobjy, pdepobj);
+}
+
+template <int N>
+void
+f4 (void)
+{
+  omp_depend_t depobjb[4];
+  #pragma omp depobj                                   // { dg-error "expected" }
+  #pragma omp depobj destroy                           // { dg-error "expected" }
+  #pragma omp depobj (depobj)                          // { dg-error "expected 'depend', 'destroy' or 'update' clause" }
+  #pragma omp depobj (depobj) foobar                   // { dg-error "expected 'depend', 'destroy' or 'update' clause" }
+  #pragma omp depobj(bar ()) update(inout)             // { dg-error "'depobj' expression is not lvalue expression" }
+  #pragma omp depobj (cdepobj) update(in)              // { dg-error "'const' qualified 'depobj' expression" }
+  #pragma omp depobj (depobjb) depend(in: a)           // { dg-error "type of 'depobj' expression is not 'omp_depend_t'" }
+  #pragma omp depobj (pdepobj) depend(in: a)           // { dg-error "type of 'depobj' expression is not 'omp_depend_t'" }
+  #pragma omp depobj (a) destroy                       // { dg-error "type of 'depobj' expression is not 'omp_depend_t'" }
+  #pragma omp depobj (depobj) depend(depobj:a)         // { dg-error "does not have 'omp_depend_t' type in 'depend' clause with 'depobj' dependence type" }
+  #pragma omp depobj (depobj) depend(depobj:*depobjb)  // { dg-error "'depobj' dependence type specified in 'depend' clause on 'depobj' construct" }
+  #pragma omp depobj (depobj) update(foobar)           // { dg-error "expected 'in', 'out', 'inout' or 'mutexinoutset'" }
+  #pragma omp depobj (depobj) depend(in: *depobja)     // { dg-error "should not have 'omp_depend_t' type in 'depend' clause with dependence type" }
+  #pragma omp depobj (depobj) depend(in: a) depend(in: b)      // { dg-error "expected" }
+  #pragma omp depobj (depobj) depend(in: a) update(out)        // { dg-error "expected" }
+  #pragma omp depobj (depobj) depend(in: a, b)         // { dg-error "more than one locator in 'depend' clause on 'depobj' construct" }
+  #pragma omp depobj (depobj) depend(source)           // { dg-error "'depend\\(source\\)' is only allowed in 'omp ordered'" }
+  #pragma omp depobj (depobj) depend(sink: i + 1, j - 1)       // { dg-error "'depend\\(sink\\)' is only allowed in 'omp ordered'" }
+  #pragma omp depobj (depobj) depend(iterator (i = 0:2) , in : a)      // { dg-error "'iterator' modifier may not be specified on 'depobj' construct" }
+  if (0)
+    #pragma omp depobj (depobj) destroy                        // { dg-error "'#pragma omp depobj' may only be used in compound statements" }
+    ;
+}
+
+template <int N>
+void
+f5 (void)
+{
+  #pragma omp task depend (depobj:depobja[1:2])                // { dg-error "'depend' clause with 'depobj' dependence type on array section" }
+  ;
+  #pragma omp task depend (depobj : a)                 // { dg-error "'a' does not have 'omp_depend_t' type in 'depend' clause with 'depobj' dependence type" }
+  ;
+  #pragma omp task depend (in: depobj)                 // { dg-error "'depobj' should not have 'omp_depend_t' type in 'depend' clause with dependence type" }
+  ;
+}
+
+void
+f6 (omp_depend_t &x)
+{
+  f4 <0> ();
+  f5 <0> ();
+  #pragma omp depobj (x) depend(in: a)
+  #pragma omp depobj (depobj) depend(in: x)            // { dg-error "should not have 'omp_depend_t' type in 'depend' clause with dependence type" }
+}
diff --git a/gcc/testsuite/g++.dg/gomp/doacross-1.C b/gcc/testsuite/g++.dg/gomp/doacross-1.C
new file mode 100644 (file)
index 0000000..9381b3a
--- /dev/null
@@ -0,0 +1,21 @@
+// { dg-do compile { target c++11 } }
+// { dg-options "-fopenmp" }
+
+int a[42];
+
+void
+foo ()
+{
+  #pragma omp for ordered (1)  // { dg-error "'ordered' clause with parameter on range-based 'for' loop" }
+  for (auto x : a)
+    ;
+}
+
+void
+bar ()
+{
+  #pragma omp for ordered (2)  // { dg-error "'ordered' clause with parameter on range-based 'for' loop" }
+  for (int i = 0; i < 1; i++)
+    for (auto x : a)
+      ;
+}
diff --git a/gcc/testsuite/g++.dg/gomp/for-21.C b/gcc/testsuite/g++.dg/gomp/for-21.C
new file mode 100644 (file)
index 0000000..774f888
--- /dev/null
@@ -0,0 +1,104 @@
+// { dg-do compile { target c++17 } }
+
+void
+f1 (int a[10][10])
+{
+  #pragma omp for collapse (2)
+  for (int i = 0; i < 10; ++i)
+    for (auto j : a[i])                // { dg-error "initializer expression refers to iteration variable 'i'" }
+      ;
+}
+
+void
+f2 (int (&a)[10])
+{
+  #pragma omp for collapse (2)
+  for (auto i : a)
+    for (int j = i * 2; j < i * 4; j++)                // { dg-error "initializer expression refers to iteration variable 'i'" }
+      ;
+}
+
+struct S { int a, b, c; };
+
+void
+f3 (S (&a)[10])
+{
+  #pragma omp for collapse (2)
+  for (auto [i, j, k] : a)                     // { dg-error "use of 'i' before deduction of 'auto'" "" { target *-*-* } .+1 }
+    for (int l = i; l < j; l += k)             // { dg-error "use of 'j' before deduction of 'auto'" }
+      ;                                                // { dg-error "use of 'k' before deduction of 'auto'" "" { target *-*-* } .-1 }
+}
+
+template <int N>
+void
+f4 (int a[10][10])
+{
+  #pragma omp for collapse (2)
+  for (int i = 0; i < 10; ++i)         // { dg-error "initializer expression refers to iteration variable 'i'" }
+    for (auto j : a[i])
+      ;
+}
+
+template <int N>
+void
+f5 (int (&a)[10])
+{
+  #pragma omp for collapse (2)
+  for (auto i : a)
+    for (int j = i * 2; j < i * 4; j++)                // { dg-error "initializer expression refers to iteration variable 'i'" }
+      ;
+}
+
+template <int N>
+void
+f6 (S (&a)[10])
+{
+  #pragma omp for collapse (2)
+  for (auto [i, j, k] : a)                     // { dg-error "use of 'i' before deduction of 'auto'" "" { target *-*-* } .-1 }
+    for (int l = i; l < j; l += k)             // { dg-error "use of 'j' before deduction of 'auto'" }
+      ;                                                // { dg-error "use of 'k' before deduction of 'auto'" "" { target *-*-* } .-3 }
+}
+
+template <typename T>
+void
+f7 (T a[10][10])
+{
+  #pragma omp for collapse (2)
+  for (T i = 0; i < 10; ++i)
+    for (auto j : a[i])                // { dg-error "initializer expression refers to iteration variable 'i'" }
+      ;
+}
+
+template <typename T>
+void
+f8 (T (&a)[10])
+{
+  #pragma omp for collapse (2)
+  for (auto i : a)
+    for (T j = i * 2; j < i * 4; j++)          // { dg-error "initializer expression refers to iteration variable 'i'" }
+      ;
+}
+
+template <typename T, typename U>
+void
+f9 (U (&a)[10])
+{
+  #pragma omp for collapse (2)
+  for (auto [i, j, k] : a)                     // { dg-error "use of 'i' before deduction of 'auto'" "" { target *-*-* } .-1 }
+    for (T l = i; l < j; l += k)               // { dg-error "use of 'j' before deduction of 'auto'" }
+      ;                                                // { dg-error "use of 'k' before deduction of 'auto'" "" { target *-*-* } .-3 }
+}
+
+void
+test ()
+{
+  int a[10][10] {};
+  int b[10] {};
+  S c[10] {};
+  f4 <0> (a);
+  f5 <0> (b);
+  f6 <0> (c);
+  f7 (a);
+  f8 (b);
+  f9 <int, S> (c);
+}
index 989d4b2a8f3e9e609670d7666c6811e1d86bd08e..d3351f5a60971ce777fc0ea33f038f8de9e0b5b0 100644 (file)
@@ -12,5 +12,5 @@ void foo (int n)
     bar(i);
 }
 
-/* { dg-final { scan-tree-dump-times "GOMP_loop_dynamic_start" 1 "ompexp" } } */
-/* { dg-final { scan-tree-dump-times "GOMP_loop_dynamic_next" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_dynamic_start" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_dynamic_next" 1 "ompexp" } } */
index fca2697c9a4327a3b0d040cd6f320d3389f476fb..3bc8d514ad09dcea4cb73e6d9fc192b9d0d2be31 100644 (file)
@@ -12,5 +12,5 @@ void foo (int n)
     bar(i);
 }
 
-/* { dg-final { scan-tree-dump-times "GOMP_loop_guided_start" 1 "ompexp" } } */
-/* { dg-final { scan-tree-dump-times "GOMP_loop_guided_next" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_guided_start" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_guided_next" 1 "ompexp" } } */
index 9f9db4102fd29d006284fd364694167e431cc55d..9762be6fd06ec7fe5185a12f91ab329198517346 100644 (file)
@@ -12,5 +12,5 @@ void foo (int n)
     bar(i);
 }
 
-/* { dg-final { scan-tree-dump-times "GOMP_loop_runtime_start" 1 "ompexp" } } */
-/* { dg-final { scan-tree-dump-times "GOMP_loop_runtime_next" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_maybe_nonmonotonic_runtime_start" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_maybe_nonmonotonic_runtime_next" 1 "ompexp" } } */
diff --git a/gcc/testsuite/g++.dg/gomp/loop-4.C b/gcc/testsuite/g++.dg/gomp/loop-4.C
new file mode 100644 (file)
index 0000000..cd85dbd
--- /dev/null
@@ -0,0 +1,227 @@
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+
+template <typename T>
+class I
+{
+public:
+  typedef ptrdiff_t difference_type;
+  I ();
+  ~I ();
+  I (T *);
+  I (const I &);
+  T &operator * ();
+  T *operator -> ();
+  T &operator [] (const difference_type &) const;
+  I &operator = (const I &);
+  I &operator ++ ();
+  I operator ++ (int);
+  I &operator -- ();
+  I operator -- (int);
+  I &operator += (const difference_type &);
+  I &operator -= (const difference_type &);
+  I operator + (const difference_type &) const;
+  I operator - (const difference_type &) const;
+  template <typename S> friend bool operator == (I<S> &, I<S> &);
+  template <typename S> friend bool operator == (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator < (I<S> &, I<S> &);
+  template <typename S> friend bool operator < (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator <= (I<S> &, I<S> &);
+  template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator > (I<S> &, I<S> &);
+  template <typename S> friend bool operator > (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator >= (I<S> &, I<S> &);
+  template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
+  template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
+private:
+  T *p;
+};
+
+template <typename T> bool operator == (I<T> &, I<T> &);
+template <typename T> bool operator == (const I<T> &, const I<T> &);
+template <typename T> bool operator != (I<T> &, I<T> &);
+template <typename T> bool operator != (const I<T> &, const I<T> &);
+template <typename T> bool operator < (I<T> &, I<T> &);
+template <typename T> bool operator < (const I<T> &, const I<T> &);
+template <typename T> bool operator <= (I<T> &, I<T> &);
+template <typename T> bool operator <= (const I<T> &, const I<T> &);
+template <typename T> bool operator > (I<T> &, I<T> &);
+template <typename T> bool operator > (const I<T> &, const I<T> &);
+template <typename T> bool operator >= (I<T> &, I<T> &);
+template <typename T> bool operator >= (const I<T> &, const I<T> &);
+template <typename T> typename I<T>::difference_type operator - (I<T> &, I<T> &);
+template <typename T> typename I<T>::difference_type operator - (const I<T> &, const I<T> &);
+template <typename T> I<T> operator + (typename I<T>::difference_type, const I<T> &);
+
+ptrdiff_t foo (I<int> &);
+I<int> &bar (I<int> &);
+I<int> &baz (I<int> *);
+
+void
+f0 ()
+{
+  int i;
+  const int j = 1;
+  const int k = -1;
+  const int m = 2;
+  const int n = -7;
+  int o = 1;
+  int p = -1;
+  #pragma omp for
+  for (i = 0; i != 64; i += j)
+    ;
+  #pragma omp for
+  for (i = 64; i != 0; i -= j)
+    ;
+  #pragma omp for
+  for (i = 0; i != 64; i -= k)
+    ;
+  #pragma omp for
+  for (i = 64; i != 0; i += k)
+    ;
+  #pragma omp for
+  for (i = 0; i != 64; i += m) // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = 64; i != 0; i -= m) // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = 0; i != 64; i -= n) // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = 64; i != 0; i += n) // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = 0; i != 64; i += o) // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = 64; i != 0; i -= o) // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = 0; i != 64; i -= p) // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = 64; i != 0; i += p) // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+}
+
+void
+f1 (I<int> &x, I<int> &y, I<int> &u, I<int> &v)
+{
+  I<int> i, j;
+  const int k = 1;
+  const int l = -1;
+  const int m = 2;
+  const int n = -7;
+  int o = 1;
+  int p = -1;
+  #pragma omp for
+  for (i = x; i != y; i++)
+    ;
+  #pragma omp for
+  for (i = x; y != i; ++i)
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = i + 1)
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = 1 + i)
+    ;
+  #pragma omp for
+  for (i = y; i != x; i--)
+    ;
+  #pragma omp for
+  for (i = y; x != i; --i)
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = i - 1)
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = -1 + i)
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = i + k)
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = k + i)
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = i - k)
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = -k + i)
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = i - l)
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = -l + i)
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = i + l)
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = l + i)
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = i + 2)       // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = 7 + i)       // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = i - 2)       // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = -7 + i)      // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = i + m)       // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = m + i)       // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = i - m)       // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = -m + i)      // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = i - n)       // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = -n + i)      // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = i + n)       // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = n + i)       // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = i + o)       // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = o + i)       // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = i - o)       // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = -o + i)      // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = i - p)       // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = x; i != y; i = -p + i)      // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = i + p)       // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+  #pragma omp for
+  for (i = y; i != x; i = p + i)       // { dg-error "increment is not constant 1 or -1 for != condition" }
+    ;
+}
index c51fa2063b2d4bbca0476fa5ab79b32303ae8678..77fc6c339372354d8aec8e82f786ef4ed34f6736 100644 (file)
@@ -60,17 +60,17 @@ B::m1 ()
 int
 B::m2 ()
 {
-  #pragma omp parallel private (h)     // { dg-error "is predetermined .shared. for .private." }
+  #pragma omp parallel private (h)     // { dg-error "may appear only in .shared. or .firstprivate. clauses" }
     ;
   #pragma omp parallel firstprivate (h)
     ;
-  #pragma omp parallel for lastprivate (h)     // { dg-error "is predetermined .shared. for .lastprivate." }
+  #pragma omp parallel for lastprivate (h)     // { dg-error "may appear only in .shared. or .firstprivate. clauses" }
     for (int i = 0; i < 10; i++)
       ;
-  #pragma omp simd linear (h : 1)      // { dg-error "is predetermined .shared. for .linear." }
+  #pragma omp simd linear (h : 1)      // { dg-error "may appear only in .shared. or .firstprivate. clauses" }
     for (int i = 0; i < 10; i++)
       ;
-  #pragma omp parallel for reduction (+:h)     // { dg-error "is predetermined .shared. for .reduction." }
+  #pragma omp parallel for reduction (+:h)     // { dg-error "may appear only in .shared. or .firstprivate. clauses" }
     for (int i = 0; i < 10; i++)
       ;
   #pragma omp parallel for reduction (+:g)     // { dg-error "has const type for .reduction." }
@@ -88,7 +88,7 @@ B::m2 ()
     ;
   #pragma omp parallel shared (g)
     ;
-  #pragma omp parallel shared (h)      // { dg-error "is predetermined .shared. for .shared." }
+  #pragma omp parallel shared (h)
     ;
   return 0;
 }
@@ -118,30 +118,30 @@ B::m3 () const
 int
 B::m4 () const
 {
-  #pragma omp parallel private (a)     // { dg-error "is predetermined .shared. for .private." }
+  #pragma omp parallel private (a)     // { dg-error "may appear only in .shared. or .firstprivate. clauses" }
     ;
   #pragma omp parallel firstprivate (a)
     ;
-  #pragma omp parallel for lastprivate (a)     // { dg-error "is predetermined .shared. for .lastprivate." }
+  #pragma omp parallel for lastprivate (a)     // { dg-error "may appear only in .shared. or .firstprivate. clauses" }
     for (int i = 0; i < 10; i++)
       ;
-  #pragma omp simd linear (a : 1)      // { dg-error "is predetermined .shared. for .linear." }
+  #pragma omp simd linear (a : 1)      // { dg-error "may appear only in .shared. or .firstprivate. clauses" }
     for (int i = 0; i < 10; i++)
       ;
-  #pragma omp parallel for reduction (+:a)     // { dg-error "is predetermined .shared. for .reduction." }
+  #pragma omp parallel for reduction (+:a)     // { dg-error "may appear only in .shared. or .firstprivate. clauses" }
     for (int i = 0; i < 10; i++)
       ;
-  #pragma omp parallel private (h)     // { dg-error "is predetermined .shared. for .private." }
+  #pragma omp parallel private (h)     // { dg-error "may appear only in .shared. or .firstprivate. clauses" }
     ;
   #pragma omp parallel firstprivate (h)
     ;
-  #pragma omp parallel for lastprivate (h)     // { dg-error "is predetermined .shared. for .lastprivate." }
+  #pragma omp parallel for lastprivate (h)     // { dg-error "may appear only in .shared. or .firstprivate. clauses" }
     for (int i = 0; i < 10; i++)
       ;
-  #pragma omp simd linear (h : 1)      // { dg-error "is predetermined .shared. for .linear." }
+  #pragma omp simd linear (h : 1)      // { dg-error "may appear only in .shared. or .firstprivate. clauses" }
     for (int i = 0; i < 10; i++)
       ;
-  #pragma omp parallel for reduction (+:h)     // { dg-error "is predetermined .shared. for .reduction." }
+  #pragma omp parallel for reduction (+:h)     // { dg-error "may appear only in .shared. or .firstprivate. clauses" }
     for (int i = 0; i < 10; i++)
       ;
   #pragma omp parallel for reduction (+:e)     // { dg-error "has const type for .reduction." }
@@ -150,7 +150,7 @@ B::m4 () const
   #pragma omp parallel for reduction (+:g)     // { dg-error "has const type for .reduction." }
     for (int i = 0; i < 10; i++)
       ;
-  #pragma omp parallel shared (a)      // { dg-error "is predetermined .shared. for .shared." }
+  #pragma omp parallel shared (a)
     ;
   #pragma omp parallel shared (b)
     ;
@@ -162,7 +162,7 @@ B::m4 () const
     ;
   #pragma omp parallel shared (g)
     ;
-  #pragma omp parallel shared (h)      // { dg-error "is predetermined .shared. for .shared." }
+  #pragma omp parallel shared (h)
     ;
   return 0;
 }
index e9da25956879737ba371ea7a43b64916b9796614..8bb18cc0a5e43c1a7e2f106386ece77c1711bddf 100644 (file)
@@ -8,8 +8,8 @@ void f ()
   extern T n ();
 #pragma omp parallel num_threads(n)    // { dg-error "'num_threads' expression must be integral" }
   ;
-#pragma omp parallel for schedule(static, n)
-  for (int i = 0; i < 10; i++)         // { dg-error "chunk size expression must be integral" }
+#pragma omp parallel for schedule(static, n)   // { dg-error "chunk size expression must be integral" }
+  for (int i = 0; i < 10; i++)
     ;
 }
 
index f0a1910bf42ea8ad35468a2f951ffe4c92750c23..47a3dfa3f1dda4d2c6189a3dffe5d53861fd4c30 100644 (file)
@@ -8,8 +8,8 @@ void f ()
   T n = 6;
 #pragma omp parallel num_threads(n)    // { dg-error "'num_threads' expression must be integral" }
   ;
-#pragma omp parallel for schedule(static, n)
-  for (int i = 0; i < 10; i++)         // { dg-error "chunk size expression must be integral" }
+#pragma omp parallel for schedule(static, n)   // { dg-error "chunk size expression must be integral" }
+  for (int i = 0; i < 10; i++)
     ;
 }
 
index f8b0f23183cf10d20c0871dbd11351afe237f9a6..8b31ce8f10f135db3e1f82b61fd771f7048a77b3 100644 (file)
@@ -13,25 +13,25 @@ foo (void)
   unsigned int u;
 
 #pragma omp for
-  for (i = INT_MIN + 6; i != INT_MIN; i--)     // { dg-error "invalid controlling predicate" }
+  for (i = INT_MIN + 6; i != INT_MIN; i--)
     ;
 #pragma omp for
   for (i = INT_MIN + 6; i == INT_MIN; i--)     // { dg-error "invalid controlling predicate" }
     ;
 #pragma omp for
-  for (i = INT_MAX - 6; i != INT_MAX; i++)     // { dg-error "invalid controlling predicate" }
+  for (i = INT_MAX - 6; i != INT_MAX; i++)
     ;
 #pragma omp for
   for (i = INT_MAX - 6; i == INT_MAX; i++)     // { dg-error "invalid controlling predicate" }
     ;
 #pragma omp for
-  for (u = 6; u != 0; u--)                     // { dg-error "invalid controlling predicate" }
+  for (u = 6; u != 0; u--)
     ;
 #pragma omp for
   for (u = 6; u == 0; u--)                     // { dg-error "invalid controlling predicate" }
     ;
 #pragma omp for
-  for (u = UINT_MAX - 6; u != UINT_MAX; u++)   // { dg-error "invalid controlling predicate" }
+  for (u = UINT_MAX - 6; u != UINT_MAX; u++)
     ;
 #pragma omp for
   for (u = UINT_MAX - 6; u == UINT_MAX; u++)   // { dg-error "invalid controlling predicate" }
index 495c09e7dd8833648c1a28e73f21f7fb44a6a2bb..084f04ec90f253cf9980cb5963c6c8459de90c02 100644 (file)
@@ -15,18 +15,18 @@ const A foo (const A d, const C e)
   const A f;
   const B b = { 4 };
   A g;
-  #pragma omp parallel default (none)
-    bar (&a);
-  #pragma omp parallel default (none)
-    bar (&b);
+  #pragma omp parallel default (none)  // { dg-error "enclosing 'parallel'" }
+    bar (&a);                          // { dg-error "not specified" }
+  #pragma omp parallel default (none)  // { dg-error "enclosing 'parallel'" }
+    bar (&b);                          // { dg-error "not specified" }
   #pragma omp parallel default (none)  // { dg-error "enclosing 'parallel'" }
     bar (&c);                          // { dg-error "not specified" }
-  #pragma omp parallel default (none)
-    bar (&d);
+  #pragma omp parallel default (none)  // { dg-error "enclosing 'parallel'" }
+    bar (&d);                          // { dg-error "not specified" }
   #pragma omp parallel default (none)  // { dg-error "enclosing 'parallel'" }
     bar (&e);                          // { dg-error "not specified" }
-  #pragma omp parallel default (none)
-    bar (&f);
+  #pragma omp parallel default (none)  // { dg-error "enclosing 'parallel'" }
+    bar (&f);                          // { dg-error "not specified" }
   #pragma omp parallel default (none)  // { dg-error "enclosing 'parallel'" }
     bar (&g);                          // { dg-error "not specified" }
   return f;
index 09f15e39661d06d040b867f6a43aabc8d95512a7..1c24aebbe57c3a6748a38f19b79abe927aa211bd 100644 (file)
@@ -15,17 +15,17 @@ const A foo (const A d, const C e)
   const A f;
   const B b = { 4 };
   A g;
-  #pragma omp parallel private (a)     // { dg-error "predetermined" }
+  #pragma omp parallel private (a)     // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" }
     bar (&a);
-  #pragma omp parallel private (b)     // { dg-error "predetermined" }
+  #pragma omp parallel private (b)     // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" }
     bar (&b);
   #pragma omp parallel private (c)
     bar (&c);
-  #pragma omp parallel private (d)     // { dg-error "predetermined" }
+  #pragma omp parallel private (d)     // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" }
     bar (&d);
   #pragma omp parallel private (e)
     bar (&e);
-  #pragma omp parallel private (f)     // { dg-error "predetermined" }
+  #pragma omp parallel private (f)     // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" }
     bar (&f);
   #pragma omp parallel private (g)
     bar (&g);
index 9dca5d9d656ae50839781c51026d8b3ef1efe7e4..ac6908b68ac5d58ca2b09dd476c242df119e943d 100644 (file)
@@ -61,7 +61,7 @@ main (void)
       thrglobalvar++;  /* Predetermined - threadprivate.  */
       thrlocvar++;     /* Predetermined - threadprivate.  */
       foo (i);         /* Predetermined - private (omp for loop variable).  */
-      foo (constvar.x);        /* Predetermined - shared (const qualified type).  */
+      foo (constvar.x);        /* { dg-error "not specified in" } */
       foo (T::t.i);    /* Predetermined - shared (static data member).  */
       foo (*p);                /* *p predetermined - shared (heap allocated */
       (*p)++;          /* storage).  */
index 6145b92fcf8183d05400ce35ac5349f66f2d4ff8..23e9133e9b8861d0ddfaa38b50420afa6e6b398b 100644 (file)
@@ -5,15 +5,21 @@ struct T
   int i;
   mutable int j;
 };
+struct U
+{
+  int i, j;
+};
 struct S
 {
   const static int d = 1;
   const static T e;
+  const static U f;
   void foo (int, T);
 };
 
 const int S::d;
 const T S::e = { 2, 3 };
+const U S::f = { 4, 5 };
 
 void bar (const int &);
 
@@ -28,15 +34,19 @@ S::foo (const int x, const T y)
     bar (y.i);
   #pragma omp parallel firstprivate (e)        // { dg-error "is predetermined" }
     bar (e.i);
-  #pragma omp parallel shared (x)      // { dg-error "is predetermined" }
+  #pragma omp parallel firstprivate (f)
+    bar (f.i);
+  #pragma omp parallel shared (x)
     bar (x);
   #pragma omp parallel shared (d)      // { dg-error "is predetermined" }
     bar (d);
   #pragma omp parallel shared (e)      // { dg-error "is predetermined" }
     bar (e.i);
+  #pragma omp parallel shared (f)      // { dg-error "is predetermined" }
+    bar (f.i);
   #pragma omp parallel shared (y)
     bar (y.i);
-  #pragma omp parallel private (x)     // { dg-error "is predetermined" }
+  #pragma omp parallel private (x)     // { dg-error "may appear only in 'shared' or 'firstprivate' clauses" }
     bar (x);
   #pragma omp parallel private (d)     // { dg-error "is predetermined" }
     bar (d);
@@ -44,4 +54,6 @@ S::foo (const int x, const T y)
     bar (y.i);
   #pragma omp parallel private (e)     // { dg-error "is predetermined" }
     bar (e.i);
+  #pragma omp parallel private (f)     // { dg-error "is predetermined" }
+    bar (f.i);
 }
diff --git a/gcc/testsuite/g++.dg/gomp/simd-2.C b/gcc/testsuite/g++.dg/gomp/simd-2.C
new file mode 100644 (file)
index 0000000..3903814
--- /dev/null
@@ -0,0 +1,21 @@
+int a[32], b[32];
+
+void
+foo (void)
+{
+  int i, j;
+  #pragma omp simd linear(i, j) collapse(2)    // { dg-error "iteration variable 'i' should not be linear" }
+  for (i = 0; i < 32; ++i)                     // { dg-error "iteration variable 'j' should not be linear" "" { target *-*-* } .-1 }
+    for (j = 0; j < 32; ++j)
+      a[i] += b[j];
+}
+
+void
+bar (void)
+{
+  static int i, j;
+  #pragma omp for simd linear(i, j) collapse(2)        // { dg-error "iteration variable 'i' should not be linear" "" { target *-*-* } .+1 }
+  for (i = 0; i < 32; ++i)                     // { dg-error "iteration variable 'j' should not be linear" }
+    for (j = 0; j < 32; ++j)
+      a[i] += b[j];
+}
index c27f20193971462b8f55ad3c5a2fb5d62a7d44c4..627c6c6e2a9082bebb5f68151d830159585a85ac 100644 (file)
@@ -6,21 +6,21 @@ struct S { int x; } s;
 // even when the templates are never instantiated.
 template<typename T> void f1()
 {
-  #pragma omp atomic
-  s += 1;              // { dg-error "invalid" }
+  #pragma omp atomic   // { dg-error "invalid" }
+  s += 1;
 }
 
 template<typename T> void f2(float *f)
 {
-  #pragma omp atomic
-  *f |= 1;             // { dg-error "invalid|evaluation" }
+  #pragma omp atomic   // { dg-error "invalid" }
+  *f |= 1;             // { dg-error "evaluation" }
 }
 
 // Here the rhs is dependent, but not type dependent.
 template<typename T> void f3(float *f)
 {
-  #pragma omp atomic
-  *f |= sizeof (T);    // { dg-error "invalid|evaluation" }
+  #pragma omp atomic   // { dg-error "invalid" }
+  *f |= sizeof (T);    // { dg-error "evaluation" }
 }
 
 // And the converse, no error here because we're never fed a T.
@@ -35,6 +35,6 @@ template<typename T> void f4(T *t)
 // of the semantic analysis concurrent with that.
 template<typename T> void f5(float *f)
 {
-  #pragma omp atomic
-  *f |= (T)sizeof(T);  // { dg-error "invalid|evaluation" "" { xfail *-*-* } }
+  #pragma omp atomic   // { dg-error "invalid" "" { xfail *-*-* } }
+  *f |= (T)sizeof(T);  // { dg-error "evaluation" "" { xfail *-*-* } }
 }
index e0f0eca2fa51e37d11c5c07429aaba5fedab0c99..099f03fe89d3ec4a296aec8324fa4c275b4296bc 100644 (file)
@@ -10,14 +10,15 @@ a24 (int a)
   const int c = 1;
   int i = 0;
   int l = 0;
-#pragma omp parallel default(none) private(a) shared(z) /* { dg-line omp_parallel } */
+#pragma omp parallel default(none) private(a) shared(z, c) /* { dg-line omp_parallel } */
   {
     int j = omp_get_num_threads ();
-    /* O.K. - j is declared within parallel region */
-    /* O.K.  -  a is listed in private clause */
-    /*       -  z is listed in shared clause */
+       /* O.K. - j is declared within parallel region */
+    a = z[j]; /* O.K.  -  a is listed in private clause */
+             /*       -  z is listed in shared clause */
     x = c;                     /* O.K.  -  x is threadprivate */
-                               /*       -  c has const-qualified type */
+                               /*       -  c has const-qualified type and
+                                             is listed in shared clause */
     z[i] = y;
     /* { dg-error "'i' not specified" "" { target *-*-* } .-1 } */
     /* { dg-error "enclosing 'parallel'" "" { target *-*-* } omp_parallel } */
index 68ead29b86d49c84c838997a647e51318feb5290..70cfb35f47006927952ac8484bf4b70d6e5f7bb6 100644 (file)
@@ -27,7 +27,7 @@ void f1(void)
   #pragma omp atomic
     bar() += 1;                /* { dg-error "lvalue required" } */
   #pragma omp atomic a /* { dg-error "expected end of line" } */
-    x++;
+    x++;               /* { dg-error "expected 'read', 'write', 'update', 'capture', 'seq_cst', 'acq_rel', 'release', 'relaxed' or 'hint' clause" "" { target *-*-* } .-1 } */
   #pragma omp atomic
     ;                  /* { dg-error "expected expression" } */
   #pragma omp atomic
index c2d1fc69ed49859f9e8b77b8f2a05f554e3f7ec0..9d34b04160698c5071b0186de3f780023045c0c4 100644 (file)
@@ -86,18 +86,18 @@ foo (int x)
 #pragma omp p for linear (t) /* { dg-error "predetermined 'threadprivate" } */
   for (i = 0; i < 10; i++)
     ;
-#pragma omp p shared (c) /* { dg-error "predetermined 'shared'" } */
+#pragma omp p shared (c)
     ;
-#pragma omp p private (c) /* { dg-error "predetermined 'shared'" } */
+#pragma omp p private (c) /* { dg-error "'const' qualified 'c' may appear only in 'shared' or 'firstprivate' clauses" } */
     ;
 #pragma omp p firstprivate (c)
     ;
-#pragma omp p for lastprivate (c) /* { dg-error "predetermined 'shared'" } */
+#pragma omp p for lastprivate (c) /* { dg-error "'const' qualified 'c' may appear only in 'shared' or 'firstprivate' clauses" } */
   for (i = 0; i < 10; i++)
     ;
-#pragma omp p reduction (*:c) /* { dg-error "predetermined 'shared'" } */
+#pragma omp p reduction (*:c) /* { dg-error "'const' qualified 'c' may appear only in 'shared' or 'firstprivate' clauses" } */
     ;
-#pragma omp p for linear (c) /* { dg-error "predetermined 'shared'" } */
+#pragma omp p for linear (c) /* { dg-error "'const' qualified 'c' may appear only in 'shared' or 'firstprivate' clauses" } */
   for (i = 0; i < 10; i++)
     ;
 }
index 0c0848c5e7c013b8c6e0908530039bd2c70857f7..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,23 +0,0 @@
-/* { dg-do compile } */
-/* { dg-options "-O1 -fopenmp -fdump-tree-optimized" } */
-
-int a[10];
-int foo (void)
-{
-    int i;
-#pragma omp parallel for schedule(runtime)
-    for (i = 0; i < 10; i++)
-      a[i] = i;
-#pragma omp parallel
-#pragma omp for schedule(runtime)
-    for (i = 0; i < 10; i++)
-      a[i] = 10 - i;
-#pragma omp parallel
-      {
-#pragma omp for schedule(runtime)
-       for (i = 0; i < 10; i++)
-         a[i] = i;
-      }
-}
-
-/* { dg-final { scan-tree-dump-times "GOMP_parallel_loop_runtime" 3 "optimized" } } */
index 989d4b2a8f3e9e609670d7666c6811e1d86bd08e..d3351f5a60971ce777fc0ea33f038f8de9e0b5b0 100644 (file)
@@ -12,5 +12,5 @@ void foo (int n)
     bar(i);
 }
 
-/* { dg-final { scan-tree-dump-times "GOMP_loop_dynamic_start" 1 "ompexp" } } */
-/* { dg-final { scan-tree-dump-times "GOMP_loop_dynamic_next" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_dynamic_start" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_dynamic_next" 1 "ompexp" } } */
index fca2697c9a4327a3b0d040cd6f320d3389f476fb..3bc8d514ad09dcea4cb73e6d9fc192b9d0d2be31 100644 (file)
@@ -12,5 +12,5 @@ void foo (int n)
     bar(i);
 }
 
-/* { dg-final { scan-tree-dump-times "GOMP_loop_guided_start" 1 "ompexp" } } */
-/* { dg-final { scan-tree-dump-times "GOMP_loop_guided_next" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_guided_start" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_nonmonotonic_guided_next" 1 "ompexp" } } */
index 9f9db4102fd29d006284fd364694167e431cc55d..9762be6fd06ec7fe5185a12f91ab329198517346 100644 (file)
@@ -12,5 +12,5 @@ void foo (int n)
     bar(i);
 }
 
-/* { dg-final { scan-tree-dump-times "GOMP_loop_runtime_start" 1 "ompexp" } } */
-/* { dg-final { scan-tree-dump-times "GOMP_loop_runtime_next" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_maybe_nonmonotonic_runtime_start" 1 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_maybe_nonmonotonic_runtime_next" 1 "ompexp" } } */
index a276c24ed982a3e4e88e02faaf1aedd254fb0978..c0b05cbe9b39182474093a2a75bd2ac3da280c3a 100644 (file)
@@ -13,25 +13,25 @@ foo (void)
   unsigned int u;
 
 #pragma omp for
-  for (i = INT_MIN + 6; i != INT_MIN; i--)     /* { dg-error "invalid controlling predicate" } */
+  for (i = INT_MIN + 6; i != INT_MIN; i--)
     ;
 #pragma omp for
   for (i = INT_MIN + 6; i == INT_MIN; i--)     /* { dg-error "invalid controlling predicate" } */
     ;
 #pragma omp for
-  for (i = INT_MAX - 6; i != INT_MAX; i++)     /* { dg-error "invalid controlling predicate" } */
+  for (i = INT_MAX - 6; i != INT_MAX; i++)
     ;
 #pragma omp for
   for (i = INT_MAX - 6; i == INT_MAX; i++)     /* { dg-error "invalid controlling predicate" } */
     ;
 #pragma omp for
-  for (u = 6; u != 0; u--)                     /* { dg-error "invalid controlling predicate" } */
+  for (u = 6; u != 0; u--)
     ;
 #pragma omp for
   for (u = 6; u == 0; u--)                     /* { dg-error "invalid controlling predicate" } */
     ;
 #pragma omp for
-  for (u = UINT_MAX - 6; u != UINT_MAX; u++)   /* { dg-error "invalid controlling predicate" } */
+  for (u = UINT_MAX - 6; u != UINT_MAX; u++)
     ;
 #pragma omp for
   for (u = UINT_MAX - 6; u == UINT_MAX; u++)   /* { dg-error "invalid controlling predicate" } */
diff --git a/gcc/testsuite/gcc.dg/gomp/reduction-2.c b/gcc/testsuite/gcc.dg/gomp/reduction-2.c
new file mode 100644 (file)
index 0000000..f8ac8b6
--- /dev/null
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+struct S {};
+void foo (void *, void *);
+void bar (void *, void *);
+void baz (void *);
+#pragma omp declare reduction(+:struct S:foo (&omp_out, &omp_in))initializer(bar(&omp_priv, &omp_orig))
+
+void
+test1 (void)
+{
+  struct S s;
+  int i;
+  #pragma omp parallel reduction(+:s)
+    baz (&s);
+  #pragma omp parallel reduction(task, +:s)    /* { dg-error "zero sized type 'struct S' in 'reduction' clause" } */
+    baz (&s);
+  #pragma omp taskloop reduction(+:s)          /* { dg-error "zero sized type 'struct S' in 'reduction' clause" } */
+  for (i = 0; i < 1; i++)
+    baz (&s);
+  #pragma omp taskloop simd reduction(+:s)     /* { dg-error "zero sized type 'struct S' in 'reduction' clause" } */
+  for (i = 0; i < 1; i++)
+    baz (&s);
+  #pragma omp taskgroup task_reduction(+:s)    /* { dg-error "zero sized type 'struct S' in 'task_reduction' clause" } */
+  {
+    #pragma omp task in_reduction(+:s)         /* { dg-error "zero sized type 'struct S' in 'in_reduction' clause" } */
+    baz (&s);
+  }
+}
index 0e2b60fc0d5ef58d7091585bd8a432e32b164d70..79abb64cdd7fd6d0c3c66f22f43dcd6f574f8868 100644 (file)
@@ -44,7 +44,7 @@ main (void)
       thrglobalvar++;  /* Predetermined - threadprivate.  */
       thrlocvar++;     /* Predetermined - threadprivate.  */
       foo (i);         /* Predetermined - private (omp for loop variable).  */
-      foo (constvar);  /* Predetermined - shared (const qualified type).  */
+      foo (constvar);  /* { dg-error "not specified in" } */
       foo (*p);                /* *p predetermined - shared (heap allocated */
       (*p)++;          /* storage).  */
       bar (p);         /* Explicitly determined - private.  */
diff --git a/gcc/testsuite/gcc.dg/gomp/simd-1.c b/gcc/testsuite/gcc.dg/gomp/simd-1.c
new file mode 100644 (file)
index 0000000..00aa159
--- /dev/null
@@ -0,0 +1,21 @@
+int a[32], b[32];
+
+void
+foo (void)
+{
+  int i, j;
+  #pragma omp simd linear(i, j) collapse(2)    /* { dg-error "iteration variable 'i' should not be linear" } */
+  for (i = 0; i < 32; ++i)                     /* { dg-error "iteration variable 'j' should not be linear" "" { target *-*-* } .-1 } */
+    for (j = 0; j < 32; ++j)
+      a[i] += b[j];
+}
+
+void
+bar (void)
+{
+  static int i, j;
+  #pragma omp for simd linear(i, j) collapse(2)        /* { dg-error "iteration variable 'i' should not be linear" } */
+  for (i = 0; i < 32; ++i)                     /* { dg-error "iteration variable 'j' should not be linear" "" { target *-*-* } .-1 } */
+    for (j = 0; j < 32; ++j)
+      a[i] += b[j];
+}
index a5370470cde6b754cd83077e9d6faf16d4cc3ea6..db7f50b2cde7381db3426c5dad08784ed52ffadd 100644 (file)
@@ -23,8 +23,8 @@ foo (int x)
 
   switch (x) // { dg-error "invalid entry to OpenMP structured block" }
   {
-  #pragma omp target teams
-    { case 0:; } // { dg-warning "statement will never be executed" }
+  #pragma omp target teams // { dg-warning "statement will never be executed" }
+    { case 0:; }
   }
 }
 
index 7df5c40a3a4e28b13e3fdff6497f2ee961411e0c..cec95e72c54efca9783c7397ba895cd2a32485ba 100644 (file)
@@ -258,6 +258,12 @@ enum omp_clause_code {
                reductions.  */
   OMP_CLAUSE_REDUCTION,
 
+  /* OpenMP clause: task_reduction (operator:variable_list).  */
+  OMP_CLAUSE_TASK_REDUCTION,
+
+  /* OpenMP clause: in_reduction (operator:variable_list).  */
+  OMP_CLAUSE_IN_REDUCTION,
+
   /* OpenMP clause: copyin (variable_list).  */
   OMP_CLAUSE_COPYIN,
 
@@ -273,6 +279,9 @@ enum omp_clause_code {
   /* OpenMP clause: depend ({in,out,inout}:variable-list).  */
   OMP_CLAUSE_DEPEND,
 
+  /* OpenMP clause: nontemporal (variable-list).  */
+  OMP_CLAUSE_NONTEMPORAL,
+
   /* OpenMP clause: uniform (argument-list).  */
   OMP_CLAUSE_UNIFORM,
 
@@ -331,6 +340,9 @@ enum omp_clause_code {
   /* Internal clause: temporary for combined loops expansion.  */
   OMP_CLAUSE__LOOPTEMP_,
 
+  /* Internal clause: temporary for task reductions.  */
+  OMP_CLAUSE__REDUCTEMP_,
+
   /* OpenACC/OpenMP clause: if (scalar-expression).  */
   OMP_CLAUSE_IF,
 
@@ -493,6 +505,36 @@ enum omp_clause_default_kind {
   OMP_CLAUSE_DEFAULT_LAST
 };
 
+enum omp_clause_defaultmap_kind {
+  OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED,
+  OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR,
+  OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE,
+  OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALLOCATABLE,
+  OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER,
+  OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK = 7,
+  OMP_CLAUSE_DEFAULTMAP_ALLOC = 1 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1),
+  OMP_CLAUSE_DEFAULTMAP_TO = 2 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1),
+  OMP_CLAUSE_DEFAULTMAP_FROM = 3 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1),
+  OMP_CLAUSE_DEFAULTMAP_TOFROM = 4 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1),
+  OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE
+    = 5 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1),
+  OMP_CLAUSE_DEFAULTMAP_NONE = 6 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1),
+  OMP_CLAUSE_DEFAULTMAP_DEFAULT
+    = 7 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1),
+  OMP_CLAUSE_DEFAULTMAP_MASK = 7 * (OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK + 1)
+};
+
+/* memory-order-clause on OpenMP atomic/flush constructs or
+   argument of atomic_default_mem_order clause.  */
+enum omp_memory_order {
+  OMP_MEMORY_ORDER_UNSPECIFIED,
+  OMP_MEMORY_ORDER_RELAXED,
+  OMP_MEMORY_ORDER_ACQUIRE,
+  OMP_MEMORY_ORDER_RELEASE,
+  OMP_MEMORY_ORDER_ACQ_REL,
+  OMP_MEMORY_ORDER_SEQ_CST
+};
+
 /* There is a TYPE_QUAL value for each type qualifier.  They can be
    combined by bitwise-or to form the complete set of qualifiers for a
    type.  */
@@ -983,6 +1025,9 @@ struct GTY(()) tree_base {
     /* Internal function code.  */
     enum internal_fn ifn;
 
+    /* OMP_ATOMIC* memory order.  */
+    enum omp_memory_order omp_atomic_memory_order;
+
     /* The following two fields are used for MEM_REF and TARGET_MEM_REF
        expression trees and specify known data non-dependences.  For
        two memory references in a function they are known to not
@@ -1095,7 +1140,7 @@ struct GTY(()) tree_base {
           OMP_CLAUSE_MAP
 
        OMP_CLAUSE_REDUCTION_OMP_ORIG_REF in
-          OMP_CLAUSE_REDUCTION
+          OMP_CLAUSE_{,TASK_,IN_}REDUCTION
 
        TRANSACTION_EXPR_RELAXED in
           TRANSACTION_EXPR
@@ -1123,9 +1168,6 @@ struct GTY(()) tree_base {
        OMP_PARALLEL_COMBINED in
            OMP_PARALLEL
 
-       OMP_ATOMIC_SEQ_CST in
-          OMP_ATOMIC*
-
        OMP_CLAUSE_PRIVATE_OUTER_REF in
           OMP_CLAUSE_PRIVATE
 
@@ -1373,8 +1415,10 @@ enum omp_clause_depend_kind
   OMP_CLAUSE_DEPEND_IN,
   OMP_CLAUSE_DEPEND_OUT,
   OMP_CLAUSE_DEPEND_INOUT,
+  OMP_CLAUSE_DEPEND_MUTEXINOUTSET,
   OMP_CLAUSE_DEPEND_SOURCE,
   OMP_CLAUSE_DEPEND_SINK,
+  OMP_CLAUSE_DEPEND_DEPOBJ,
   OMP_CLAUSE_DEPEND_LAST
 };
 
@@ -1463,6 +1507,7 @@ struct GTY(()) tree_omp_clause {
     enum tree_code                 reduction_code;
     enum omp_clause_linear_kind    linear_kind;
     enum tree_code                 if_modifier;
+    enum omp_clause_defaultmap_kind defaultmap_kind;
     /* The dimension a OMP_CLAUSE__GRIDDIM_ clause of a gridified target
        construct describes.  */
     unsigned int                  dimension;
index 5ce319af4a5998225be8c83d165075e590719e15..5aa782b1edbdca06d68f60d5583c18a88ba781e1 100644 (file)
@@ -1515,7 +1515,8 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id)
 
        case GIMPLE_OMP_TASKGROUP:
          s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
-         copy = gimple_build_omp_taskgroup (s1);
+         copy = gimple_build_omp_taskgroup
+                  (s1, gimple_omp_taskgroup_clauses (stmt));
          break;
 
        case GIMPLE_OMP_ORDERED:
index 4579b4c58390a78f70ff07cd33383f8ff609052e..c964b7a15b2d7b82fa45de03f7536cb0855f4200 100644 (file)
@@ -1314,6 +1314,8 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
              convert_nonlocal_reference_op
                (&OMP_CLAUSE_ALIGNED_ALIGNMENT (clause), &dummy, wi);
            }
+         /* FALLTHRU */
+       case OMP_CLAUSE_NONTEMPORAL:
          /* Like do_decl_clause, but don't add any suppression.  */
          decl = OMP_CLAUSE_DECL (clause);
          if (VAR_P (decl)
@@ -1322,8 +1324,7 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
          if (decl_function_context (decl) != info->context)
            {
              OMP_CLAUSE_DECL (clause) = get_nonlocal_debug_decl (info, decl);
-             if (OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_PRIVATE)
-               need_chain = true;
+             need_chain = true;
            }
          break;
 
@@ -1365,6 +1366,7 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
          /* The following clauses are only added during OMP lowering; nested
             function decomposition happens before that.  */
        case OMP_CLAUSE__LOOPTEMP_:
+       case OMP_CLAUSE__REDUCTEMP_:
        case OMP_CLAUSE__SIMDUID_:
        case OMP_CLAUSE__GRIDDIM_:
          /* Anything else.  */
@@ -2000,6 +2002,8 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
              convert_local_reference_op
                (&OMP_CLAUSE_ALIGNED_ALIGNMENT (clause), &dummy, wi);
            }
+         /* FALLTHRU */
+       case OMP_CLAUSE_NONTEMPORAL:
          /* Like do_decl_clause, but don't add any suppression.  */
          decl = OMP_CLAUSE_DECL (clause);
          if (VAR_P (decl)
@@ -2056,6 +2060,7 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
          /* The following clauses are only added during OMP lowering; nested
             function decomposition happens before that.  */
        case OMP_CLAUSE__LOOPTEMP_:
+       case OMP_CLAUSE__REDUCTEMP_:
        case OMP_CLAUSE__SIMDUID_:
        case OMP_CLAUSE__GRIDDIM_:
          /* Anything else.  */
index 5935cf4092759841167530ad20ea8ea632684324..94824a0236f0dd2a3ff546ef6b2a6aff39e15478 100644 (file)
@@ -1130,7 +1130,8 @@ create_call_for_reduction_1 (reduction_info **slot, struct clsn_data *clsn_data)
 
   tmp_load = create_tmp_var (TREE_TYPE (TREE_TYPE (addr)));
   tmp_load = make_ssa_name (tmp_load);
-  load = gimple_build_omp_atomic_load (tmp_load, addr);
+  load = gimple_build_omp_atomic_load (tmp_load, addr,
+                                      OMP_MEMORY_ORDER_RELAXED);
   SSA_NAME_DEF_STMT (tmp_load) = load;
   gsi = gsi_start_bb (new_bb);
   gsi_insert_after (&gsi, load, GSI_NEW_STMT);
@@ -1146,7 +1147,9 @@ create_call_for_reduction_1 (reduction_info **slot, struct clsn_data *clsn_data)
   name = force_gimple_operand_gsi (&gsi, x, true, NULL_TREE, true,
                                   GSI_CONTINUE_LINKING);
 
-  gsi_insert_after (&gsi, gimple_build_omp_atomic_store (name), GSI_NEW_STMT);
+  gimple *store = gimple_build_omp_atomic_store (name,
+                                                OMP_MEMORY_ORDER_RELAXED);
+  gsi_insert_after (&gsi, store, GSI_NEW_STMT);
   return 1;
 }
 
index 81414d117e154bd393c2b96a03ebe1ff8213739e..99eca4ae4043d3305a2745f46c4a7b1f225761b5 100644 (file)
@@ -392,6 +392,31 @@ dump_array_domain (pretty_printer *pp, tree domain, int spc, dump_flags_t flags)
 }
 
 
+/* Dump OpenMP iterators ITER.  */
+
+static void
+dump_omp_iterators (pretty_printer *pp, tree iter, int spc, dump_flags_t flags)
+{
+  pp_string (pp, "iterator(");
+  for (tree it = iter; it; it = TREE_CHAIN (it))
+    {
+      if (it != iter)
+       pp_string (pp, ", ");
+      dump_generic_node (pp, TREE_TYPE (TREE_VEC_ELT (it, 0)), spc, flags,
+                        false);
+      pp_space (pp);
+      dump_generic_node (pp, TREE_VEC_ELT (it, 0), spc, flags, false);
+      pp_equal (pp);
+      dump_generic_node (pp, TREE_VEC_ELT (it, 1), spc, flags, false);
+      pp_colon (pp);
+      dump_generic_node (pp, TREE_VEC_ELT (it, 2), spc, flags, false);
+      pp_colon (pp);
+      dump_generic_node (pp, TREE_VEC_ELT (it, 3), spc, flags, false);
+    }
+  pp_right_paren (pp);
+}
+
+
 /* Dump OpenMP clause CLAUSE.  PP, CLAUSE, SPC and FLAGS are as in
    dump_generic_node.  */
 
@@ -413,7 +438,13 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags)
       goto print_remap;
     case OMP_CLAUSE_LASTPRIVATE:
       name = "lastprivate";
-      goto print_remap;
+      if (!OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (clause))
+       goto print_remap;
+      pp_string (pp, "lastprivate(conditional:");
+      dump_generic_node (pp, OMP_CLAUSE_DECL (clause),
+                        spc, flags, false);
+      pp_right_paren (pp);
+      break;
     case OMP_CLAUSE_COPYIN:
       name = "copyin";
       goto print_remap;
@@ -432,12 +463,18 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags)
     case OMP_CLAUSE__LOOPTEMP_:
       name = "_looptemp_";
       goto print_remap;
+    case OMP_CLAUSE__REDUCTEMP_:
+      name = "_reductemp_";
+      goto print_remap;
     case OMP_CLAUSE_TO_DECLARE:
       name = "to";
       goto print_remap;
     case OMP_CLAUSE_LINK:
       name = "link";
       goto print_remap;
+    case OMP_CLAUSE_NONTEMPORAL:
+      name = "nontemporal";
+      goto print_remap;
   print_remap:
       pp_string (pp, name);
       pp_left_paren (pp);
@@ -446,8 +483,20 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags)
       pp_right_paren (pp);
       break;
 
+    case OMP_CLAUSE_TASK_REDUCTION:
+    case OMP_CLAUSE_IN_REDUCTION:
+      pp_string (pp, OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_IN_REDUCTION
+                    ? "in_" : "task_");
+      /* FALLTHRU */
     case OMP_CLAUSE_REDUCTION:
       pp_string (pp, "reduction(");
+      if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_REDUCTION)
+       {
+         if (OMP_CLAUSE_REDUCTION_TASK (clause))
+           pp_string (pp, "task,");
+         else if (OMP_CLAUSE_REDUCTION_INSCAN (clause))
+           pp_string (pp, "inscan,");
+       }
       if (OMP_CLAUSE_REDUCTION_CODE (clause) != ERROR_MARK)
        {
          pp_string (pp,
@@ -464,7 +513,9 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags)
       switch (OMP_CLAUSE_IF_MODIFIER (clause))
        {
        case ERROR_MARK: break;
+       case VOID_CST: pp_string (pp, "cancel:"); break;
        case OMP_PARALLEL: pp_string (pp, "parallel:"); break;
+       case OMP_SIMD: pp_string (pp, "simd:"); break;
        case OMP_TASK: pp_string (pp, "task:"); break;
        case OMP_TASKLOOP: pp_string (pp, "taskloop:"); break;
        case OMP_TARGET_DATA: pp_string (pp, "target data:"); break;
@@ -643,18 +694,27 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags)
       pp_string (pp, "depend(");
       switch (OMP_CLAUSE_DEPEND_KIND (clause))
        {
+       case OMP_CLAUSE_DEPEND_DEPOBJ:
+         name = "depobj";
+         break;
        case OMP_CLAUSE_DEPEND_IN:
-         pp_string (pp, "in");
+         name = "in";
          break;
        case OMP_CLAUSE_DEPEND_OUT:
-         pp_string (pp, "out");
+         name = "out";
          break;
        case OMP_CLAUSE_DEPEND_INOUT:
-         pp_string (pp, "inout");
+         name = "inout";
+         break;
+       case OMP_CLAUSE_DEPEND_MUTEXINOUTSET:
+         name = "mutexinoutset";
          break;
        case OMP_CLAUSE_DEPEND_SOURCE:
          pp_string (pp, "source)");
          return;
+       case OMP_CLAUSE_DEPEND_LAST:
+         name = "__internal__";
+         break;
        case OMP_CLAUSE_DEPEND_SINK:
          pp_string (pp, "sink:");
          for (tree t = OMP_CLAUSE_DECL (clause); t; t = TREE_CHAIN (t))
@@ -680,10 +740,21 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags)
        default:
          gcc_unreachable ();
        }
-      pp_colon (pp);
-      dump_generic_node (pp, OMP_CLAUSE_DECL (clause),
-                        spc, flags, false);
-      pp_right_paren (pp);
+      {
+       tree t = OMP_CLAUSE_DECL (clause);
+       if (TREE_CODE (t) == TREE_LIST
+           && TREE_PURPOSE (t)
+           && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC)
+         {
+           dump_omp_iterators (pp, TREE_PURPOSE (t), spc, flags);
+           pp_colon (pp);
+           t = TREE_VALUE (t);
+         }
+       pp_string (pp, name);
+       pp_colon (pp);
+       dump_generic_node (pp, t, spc, flags, false);
+       pp_right_paren (pp);
+      }
       break;
 
     case OMP_CLAUSE_MAP:
@@ -900,7 +971,53 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags)
       break;
 
     case OMP_CLAUSE_DEFAULTMAP:
-      pp_string (pp, "defaultmap(tofrom:scalar)");
+      pp_string (pp, "defaultmap(");
+      switch (OMP_CLAUSE_DEFAULTMAP_BEHAVIOR (clause))
+       {
+       case OMP_CLAUSE_DEFAULTMAP_ALLOC:
+         pp_string (pp, "alloc");
+         break;
+       case OMP_CLAUSE_DEFAULTMAP_TO:
+         pp_string (pp, "to");
+         break;
+       case OMP_CLAUSE_DEFAULTMAP_FROM:
+         pp_string (pp, "from");
+         break;
+       case OMP_CLAUSE_DEFAULTMAP_TOFROM:
+         pp_string (pp, "tofrom");
+         break;
+       case OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE:
+         pp_string (pp, "firstprivate");
+         break;
+       case OMP_CLAUSE_DEFAULTMAP_NONE:
+         pp_string (pp, "none");
+         break;
+       case OMP_CLAUSE_DEFAULTMAP_DEFAULT:
+         pp_string (pp, "default");
+         break;
+       default:
+         gcc_unreachable ();
+       }
+      switch (OMP_CLAUSE_DEFAULTMAP_CATEGORY (clause))
+       {
+       case OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED:
+         break;
+       case OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR:
+         pp_string (pp, ":scalar");
+         break;
+       case OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE:
+         pp_string (pp, ":aggregate");
+         break;
+       case OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALLOCATABLE:
+         pp_string (pp, ":allocatable");
+         break;
+       case OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER:
+         pp_string (pp, ":pointer");
+         break;
+       default:
+         gcc_unreachable ();
+       }
+      pp_right_paren (pp);
       break;
 
     case OMP_CLAUSE__SIMDUID_:
@@ -1218,6 +1335,34 @@ dump_block_node (pretty_printer *pp, tree block, int spc, dump_flags_t flags)
     }
 }
 
+/* Dump #pragma omp atomic memory order clause.  */
+
+void
+dump_omp_atomic_memory_order (pretty_printer *pp, enum omp_memory_order mo)
+{
+  switch (mo)
+    {
+    case OMP_MEMORY_ORDER_RELAXED:
+      pp_string (pp, " relaxed");
+      break;
+    case OMP_MEMORY_ORDER_SEQ_CST:
+      pp_string (pp, " seq_cst");
+      break;
+    case OMP_MEMORY_ORDER_ACQ_REL:
+      pp_string (pp, " acq_rel");
+      break;
+    case OMP_MEMORY_ORDER_ACQUIRE:
+      pp_string (pp, " acquire");
+      break;
+    case OMP_MEMORY_ORDER_RELEASE:
+      pp_string (pp, " release");
+      break;
+    case OMP_MEMORY_ORDER_UNSPECIFIED:
+      break;
+    default:
+      gcc_unreachable ();
+    }
+}
 
 /* Dump the node NODE on the pretty_printer PP, SPC spaces of
    indent.  FLAGS specifies details to show in the dump (see TDF_* in
@@ -2991,7 +3136,8 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags,
       break;
 
     case OMP_TASK:
-      pp_string (pp, "#pragma omp task");
+      pp_string (pp, OMP_TASK_BODY (node) ? "#pragma omp task"
+                                         : "#pragma omp taskwait");
       dump_omp_clauses (pp, OMP_TASK_CLAUSES (node), spc, flags);
       goto dump_omp_body;
 
@@ -3122,6 +3268,7 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags,
 
     case OMP_TASKGROUP:
       pp_string (pp, "#pragma omp taskgroup");
+      dump_omp_clauses (pp, OMP_TASKGROUP_CLAUSES (node), spc, flags);
       goto dump_omp_body;
 
     case OMP_ORDERED:
@@ -3144,8 +3291,7 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags,
 
     case OMP_ATOMIC:
       pp_string (pp, "#pragma omp atomic");
-      if (OMP_ATOMIC_SEQ_CST (node))
-       pp_string (pp, " seq_cst");
+      dump_omp_atomic_memory_order (pp, OMP_ATOMIC_MEMORY_ORDER (node));
       newline_and_indent (pp, spc + 2);
       dump_generic_node (pp, TREE_OPERAND (node, 0), spc, flags, false);
       pp_space (pp);
@@ -3156,8 +3302,7 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags,
 
     case OMP_ATOMIC_READ:
       pp_string (pp, "#pragma omp atomic read");
-      if (OMP_ATOMIC_SEQ_CST (node))
-       pp_string (pp, " seq_cst");
+      dump_omp_atomic_memory_order (pp, OMP_ATOMIC_MEMORY_ORDER (node));
       newline_and_indent (pp, spc + 2);
       dump_generic_node (pp, TREE_OPERAND (node, 0), spc, flags, false);
       pp_space (pp);
@@ -3166,8 +3311,7 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags,
     case OMP_ATOMIC_CAPTURE_OLD:
     case OMP_ATOMIC_CAPTURE_NEW:
       pp_string (pp, "#pragma omp atomic capture");
-      if (OMP_ATOMIC_SEQ_CST (node))
-       pp_string (pp, " seq_cst");
+      dump_omp_atomic_memory_order (pp, OMP_ATOMIC_MEMORY_ORDER (node));
       newline_and_indent (pp, spc + 2);
       dump_generic_node (pp, TREE_OPERAND (node, 0), spc, flags, false);
       pp_space (pp);
index 4de0e090cbaadd73ec14ed26a02105ee94a6c41f..ea4ebee2301be4580321efd4b471cff9dbc3b0cc 100644 (file)
@@ -40,6 +40,8 @@ extern void print_generic_stmt_indented (FILE *, tree, dump_flags_t, int);
 extern void print_generic_expr (FILE *, tree, dump_flags_t = TDF_NONE);
 extern char *print_generic_expr_to_str (tree);
 extern void dump_omp_clauses (pretty_printer *, tree, int, dump_flags_t);
+extern void dump_omp_atomic_memory_order (pretty_printer *,
+                                         enum omp_memory_order);
 extern int dump_generic_node (pretty_printer *, tree, int, dump_flags_t, bool);
 extern void print_declaration (pretty_printer *, tree, int, dump_flags_t);
 extern int op_code_prio (enum tree_code);
index a1e67d624d83dfad1c8198ddfd9349abf4830a44..811d673bf2e2f7b1e34d2d824defc3736ae60786 100644 (file)
@@ -447,6 +447,8 @@ unpack_ts_omp_clause_value_fields (struct data_in *data_in,
                          OMP_CLAUSE_PROC_BIND_LAST);
       break;
     case OMP_CLAUSE_REDUCTION:
+    case OMP_CLAUSE_TASK_REDUCTION:
+    case OMP_CLAUSE_IN_REDUCTION:
       OMP_CLAUSE_REDUCTION_CODE (expr)
        = bp_unpack_enum (bp, tree_code, MAX_TREE_CODES);
       break;
index 55abd3cc503cba431b993c0a6af3231273989b2e..ac798a3e9344e6bb349773f68e14f85d966cc487 100644 (file)
@@ -395,6 +395,8 @@ pack_ts_omp_clause_value_fields (struct output_block *ob,
                    OMP_CLAUSE_PROC_BIND_KIND (expr));
       break;
     case OMP_CLAUSE_REDUCTION:
+    case OMP_CLAUSE_TASK_REDUCTION:
+    case OMP_CLAUSE_IN_REDUCTION:
       bp_pack_enum (bp, tree_code, MAX_TREE_CODES,
                    OMP_CLAUSE_REDUCTION_CODE (expr));
       break;
@@ -836,12 +838,18 @@ write_ts_omp_clause_tree_pointers (struct output_block *ob, tree expr,
   int i;
   for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (expr)]; i++)
     stream_write_tree (ob, OMP_CLAUSE_OPERAND (expr, i), ref_p);
-  if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_REDUCTION)
+  switch (OMP_CLAUSE_CODE (expr))
     {
+    case OMP_CLAUSE_REDUCTION:
+    case OMP_CLAUSE_TASK_REDUCTION:
+    case OMP_CLAUSE_IN_REDUCTION:
       /* We don't stream these right now, handle it if streaming
         of them is needed.  */
       gcc_assert (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (expr) == NULL);
       gcc_assert (OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (expr) == NULL);
+      break;
+    default:
+      break;
     }
   stream_write_tree (ob, OMP_CLAUSE_CHAIN (expr), ref_p);
 }
index 50124721278d101bf5c1b4e783d99bb7f771c168..766e8a9fc29beb3ef1acf584b111d9e5e238c71d 100644 (file)
@@ -282,11 +282,14 @@ unsigned const char omp_clause_num_ops[] =
   1, /* OMP_CLAUSE_FIRSTPRIVATE  */
   2, /* OMP_CLAUSE_LASTPRIVATE  */
   5, /* OMP_CLAUSE_REDUCTION  */
+  5, /* OMP_CLAUSE_TASK_REDUCTION  */
+  5, /* OMP_CLAUSE_IN_REDUCTION  */
   1, /* OMP_CLAUSE_COPYIN  */
   1, /* OMP_CLAUSE_COPYPRIVATE  */
   3, /* OMP_CLAUSE_LINEAR  */
   2, /* OMP_CLAUSE_ALIGNED  */
   1, /* OMP_CLAUSE_DEPEND  */
+  1, /* OMP_CLAUSE_NONTEMPORAL  */
   1, /* OMP_CLAUSE_UNIFORM  */
   1, /* OMP_CLAUSE_TO_DECLARE  */
   1, /* OMP_CLAUSE_LINK  */
@@ -302,6 +305,7 @@ unsigned const char omp_clause_num_ops[] =
   0, /* OMP_CLAUSE_AUTO  */
   0, /* OMP_CLAUSE_SEQ  */
   1, /* OMP_CLAUSE__LOOPTEMP_  */
+  1, /* OMP_CLAUSE__REDUCTEMP_  */
   1, /* OMP_CLAUSE_IF  */
   1, /* OMP_CLAUSE_NUM_THREADS  */
   1, /* OMP_CLAUSE_SCHEDULE  */
@@ -355,11 +359,14 @@ const char * const omp_clause_code_name[] =
   "firstprivate",
   "lastprivate",
   "reduction",
+  "task_reduction",
+  "in_reduction",
   "copyin",
   "copyprivate",
   "linear",
   "aligned",
   "depend",
+  "nontemporal",
   "uniform",
   "to",
   "link",
@@ -375,6 +382,7 @@ const char * const omp_clause_code_name[] =
   "auto",
   "seq",
   "_looptemp_",
+  "_reductemp_",
   "if",
   "num_threads",
   "schedule",
@@ -11886,6 +11894,7 @@ walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
        case OMP_CLAUSE_SCHEDULE:
        case OMP_CLAUSE_UNIFORM:
        case OMP_CLAUSE_DEPEND:
+       case OMP_CLAUSE_NONTEMPORAL:
        case OMP_CLAUSE_NUM_TEAMS:
        case OMP_CLAUSE_THREAD_LIMIT:
        case OMP_CLAUSE_DEVICE:
@@ -11902,6 +11911,7 @@ walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
        case OMP_CLAUSE_USE_DEVICE_PTR:
        case OMP_CLAUSE_IS_DEVICE_PTR:
        case OMP_CLAUSE__LOOPTEMP_:
+       case OMP_CLAUSE__REDUCTEMP_:
        case OMP_CLAUSE__SIMDUID_:
          WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, 0));
          /* FALLTHRU */
@@ -11959,6 +11969,8 @@ walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
          WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
 
        case OMP_CLAUSE_REDUCTION:
+       case OMP_CLAUSE_TASK_REDUCTION:
+       case OMP_CLAUSE_IN_REDUCTION:
          {
            int i;
            for (i = 0; i < 5; i++)
index 78b499a1d21268e2ef33e2b9b1aab53f49712995..b75204ded83a394f9d7cfa13e45f23351a66bad4 100644 (file)
@@ -1186,6 +1186,11 @@ DEFTREECODE (OMP_CRITICAL, "omp_critical", tcc_statement, 3)
    Operand 1: OMP_SINGLE_CLAUSES: List of clauses.  */
 DEFTREECODE (OMP_SINGLE, "omp_single", tcc_statement, 2)
 
+/* OpenMP - #pragma omp taskgroup
+   Operand 0: OMP_TASKGROUP_BODY: Taskgroup body.
+   Operand 1: OMP_SINGLE_CLAUSES: List of clauses.  */
+DEFTREECODE (OMP_TASKGROUP, "omp_taskgroup", tcc_statement, 2)
+
 /* OpenMP - #pragma omp section
    Operand 0: OMP_SECTION_BODY: Section body.  */
 DEFTREECODE (OMP_SECTION, "omp_section", tcc_statement, 1)
@@ -1194,10 +1199,6 @@ DEFTREECODE (OMP_SECTION, "omp_section", tcc_statement, 1)
    Operand 0: OMP_MASTER_BODY: Master section body.  */
 DEFTREECODE (OMP_MASTER, "omp_master", tcc_statement, 1)
 
-/* OpenMP - #pragma omp taskgroup
-   Operand 0: OMP_TASKGROUP_BODY: Taskgroup body.  */
-DEFTREECODE (OMP_TASKGROUP, "omp_taskgroup", tcc_statement, 1)
-
 /* OpenACC - #pragma acc cache (variable1 ... variableN)
    Operand 0: OACC_CACHE_CLAUSES: List of variables (transformed into
        OMP_CLAUSE__CACHE_ clauses).  */
index 0ef96ba561285406e4e3e7aceb5fd1ab58ca9d56..b825cade61e449ed770c355c0dcd69107f7ba750 100644 (file)
@@ -1306,9 +1306,9 @@ extern tree maybe_wrap_with_location (tree, location_t);
 /* Generic accessors for OMP nodes that keep the body as operand 0, and clauses
    as operand 1.  */
 #define OMP_BODY(NODE) \
-  TREE_OPERAND (TREE_RANGE_CHECK (NODE, OACC_PARALLEL, OMP_TASKGROUP), 0)
+  TREE_OPERAND (TREE_RANGE_CHECK (NODE, OACC_PARALLEL, OMP_MASTER), 0)
 #define OMP_CLAUSES(NODE) \
-  TREE_OPERAND (TREE_RANGE_CHECK (NODE, OACC_PARALLEL, OMP_SINGLE), 1)
+  TREE_OPERAND (TREE_RANGE_CHECK (NODE, OACC_PARALLEL, OMP_TASKGROUP), 1)
 
 /* Generic accessors for OMP nodes that keep clauses as operand 0.  */
 #define OMP_STANDALONE_CLAUSES(NODE) \
@@ -1369,6 +1369,8 @@ extern tree maybe_wrap_with_location (tree, location_t);
 #define OMP_MASTER_BODY(NODE)     TREE_OPERAND (OMP_MASTER_CHECK (NODE), 0)
 
 #define OMP_TASKGROUP_BODY(NODE)   TREE_OPERAND (OMP_TASKGROUP_CHECK (NODE), 0)
+#define OMP_TASKGROUP_CLAUSES(NODE) \
+  TREE_OPERAND (OMP_TASKGROUP_CHECK (NODE), 1)
 
 #define OMP_ORDERED_BODY(NODE)    TREE_OPERAND (OMP_ORDERED_CHECK (NODE), 0)
 #define OMP_ORDERED_CLAUSES(NODE)  TREE_OPERAND (OMP_ORDERED_CHECK (NODE), 1)
@@ -1406,7 +1408,7 @@ extern tree maybe_wrap_with_location (tree, location_t);
 #define OMP_CLAUSE_DECL(NODE)                                          \
   OMP_CLAUSE_OPERAND (OMP_CLAUSE_RANGE_CHECK (OMP_CLAUSE_CHECK (NODE), \
                                              OMP_CLAUSE_PRIVATE,       \
-                                             OMP_CLAUSE__LOOPTEMP_), 0)
+                                             OMP_CLAUSE__REDUCTEMP_), 0)
 #define OMP_CLAUSE_HAS_LOCATION(NODE) \
   (LOCATION_LOCUS ((OMP_CLAUSE_CHECK (NODE))->omp_clause.locus)                \
   != UNKNOWN_LOCATION)
@@ -1432,11 +1434,10 @@ extern tree maybe_wrap_with_location (tree, location_t);
 #define OMP_TARGET_COMBINED(NODE) \
   (OMP_TARGET_CHECK (NODE)->base.private_flag)
 
-/* True if OMP_ATOMIC* is supposed to be sequentially consistent
-   as opposed to relaxed.  */
-#define OMP_ATOMIC_SEQ_CST(NODE) \
+/* Memory order for OMP_ATOMIC*.  */
+#define OMP_ATOMIC_MEMORY_ORDER(NODE) \
   (TREE_RANGE_CHECK (NODE, OMP_ATOMIC, \
-                    OMP_ATOMIC_CAPTURE_NEW)->base.private_flag)
+                    OMP_ATOMIC_CAPTURE_NEW)->base.u.omp_atomic_memory_order)
 
 /* True on a PRIVATE clause if its decl is kept around for debugging
    information only and its DECL_VALUE_EXPR is supposed to point
@@ -1459,6 +1460,11 @@ extern tree maybe_wrap_with_location (tree, location_t);
 #define OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT(NODE) \
   (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_FIRSTPRIVATE)->base.public_flag)
 
+/* True on a FIRSTPRIVATE clause if only the reference and not what it refers
+   to should be firstprivatized.  */
+#define OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE(NODE) \
+  TREE_PRIVATE (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_FIRSTPRIVATE))
+
 /* True on a LASTPRIVATE clause if a FIRSTPRIVATE clause for the same
    decl is present in the chain.  */
 #define OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE(NODE) \
@@ -1476,6 +1482,10 @@ extern tree maybe_wrap_with_location (tree, location_t);
 #define OMP_CLAUSE_LASTPRIVATE_TASKLOOP_IV(NODE) \
   TREE_PROTECTED (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_LASTPRIVATE))
 
+/* True if a LASTPRIVATE clause has CONDITIONAL: modifier.  */
+#define OMP_CLAUSE_LASTPRIVATE_CONDITIONAL(NODE) \
+  TREE_PRIVATE (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_LASTPRIVATE))
+
 /* True on a SHARED clause if a FIRSTPRIVATE clause for the same
    decl is present in the chain (this can happen only for taskloop
    with FIRSTPRIVATE/LASTPRIVATE on it originally.  */
@@ -1579,24 +1589,38 @@ extern tree maybe_wrap_with_location (tree, location_t);
   OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_ORDERED), 0)
 
 #define OMP_CLAUSE_REDUCTION_CODE(NODE)        \
-  (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION)->omp_clause.subcode.reduction_code)
+  (OMP_CLAUSE_RANGE_CHECK (NODE, OMP_CLAUSE_REDUCTION, \
+     OMP_CLAUSE_IN_REDUCTION)->omp_clause.subcode.reduction_code)
 #define OMP_CLAUSE_REDUCTION_INIT(NODE) \
-  OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION), 1)
+  OMP_CLAUSE_OPERAND (OMP_CLAUSE_RANGE_CHECK (NODE, OMP_CLAUSE_REDUCTION, \
+                                             OMP_CLAUSE_IN_REDUCTION), 1)
 #define OMP_CLAUSE_REDUCTION_MERGE(NODE) \
-  OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION), 2)
+  OMP_CLAUSE_OPERAND (OMP_CLAUSE_RANGE_CHECK (NODE, OMP_CLAUSE_REDUCTION, \
+                                             OMP_CLAUSE_IN_REDUCTION), 2)
 #define OMP_CLAUSE_REDUCTION_GIMPLE_INIT(NODE) \
   (OMP_CLAUSE_CHECK (NODE))->omp_clause.gimple_reduction_init
 #define OMP_CLAUSE_REDUCTION_GIMPLE_MERGE(NODE) \
   (OMP_CLAUSE_CHECK (NODE))->omp_clause.gimple_reduction_merge
 #define OMP_CLAUSE_REDUCTION_PLACEHOLDER(NODE) \
-  OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION), 3)
+  OMP_CLAUSE_OPERAND (OMP_CLAUSE_RANGE_CHECK (NODE, OMP_CLAUSE_REDUCTION, \
+                                             OMP_CLAUSE_IN_REDUCTION), 3)
 #define OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER(NODE) \
-  OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION), 4)
+  OMP_CLAUSE_OPERAND (OMP_CLAUSE_RANGE_CHECK (NODE, OMP_CLAUSE_REDUCTION, \
+                                             OMP_CLAUSE_IN_REDUCTION), 4)
 
 /* True if a REDUCTION clause may reference the original list item (omp_orig)
    in its OMP_CLAUSE_REDUCTION_{,GIMPLE_}INIT.  */
 #define OMP_CLAUSE_REDUCTION_OMP_ORIG_REF(NODE) \
-  (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION)->base.public_flag)
+  (OMP_CLAUSE_RANGE_CHECK (NODE, OMP_CLAUSE_REDUCTION, \
+                          OMP_CLAUSE_IN_REDUCTION)->base.public_flag)
+
+/* True if a REDUCTION clause has task reduction-modifier.  */
+#define OMP_CLAUSE_REDUCTION_TASK(NODE) \
+  TREE_PROTECTED (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION))
+
+/* True if a REDUCTION clause has inscan reduction-modifier.  */
+#define OMP_CLAUSE_REDUCTION_INSCAN(NODE) \
+  TREE_PRIVATE (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION))
 
 /* True if a LINEAR clause doesn't need copy in.  True for iterator vars which
    are always initialized inside of the loop construct, false otherwise.  */
@@ -1665,6 +1689,18 @@ extern tree maybe_wrap_with_location (tree, location_t);
 #define OMP_CLAUSE_DEFAULT_KIND(NODE) \
   (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_DEFAULT)->omp_clause.subcode.default_kind)
 
+#define OMP_CLAUSE_DEFAULTMAP_KIND(NODE) \
+  (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_DEFAULTMAP)->omp_clause.subcode.defaultmap_kind)
+#define OMP_CLAUSE_DEFAULTMAP_CATEGORY(NODE) \
+  ((enum omp_clause_defaultmap_kind) \
+   (OMP_CLAUSE_DEFAULTMAP_KIND (NODE) & OMP_CLAUSE_DEFAULTMAP_CATEGORY_MASK))
+#define OMP_CLAUSE_DEFAULTMAP_BEHAVIOR(NODE) \
+  ((enum omp_clause_defaultmap_kind) \
+   (OMP_CLAUSE_DEFAULTMAP_KIND (NODE) & OMP_CLAUSE_DEFAULTMAP_MASK))
+#define OMP_CLAUSE_DEFAULTMAP_SET_KIND(NODE, BEHAVIOR, CATEGORY) \
+  (OMP_CLAUSE_DEFAULTMAP_KIND (NODE) \
+   = (enum omp_clause_defaultmap_kind) (CATEGORY | BEHAVIOR))
+
 #define OMP_CLAUSE_TILE_LIST(NODE) \
   OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_TILE), 0)
 #define OMP_CLAUSE_TILE_ITERVAR(NODE) \
index 19f515d59b3cad43c8cee3dbf764137015670a86..d52f998b9b2a751d0d408458d8d0851e995d0cf5 100644 (file)
@@ -1,3 +1,9 @@
+2018-11-08  Jakub Jelinek  <jakub@redhat.com>
+
+       * gomp-constants.h (GOMP_TASK_FLAG_REDUCTION,
+       GOMP_DEPEND_IN, GOMP_DEPEND_OUT, GOMP_DEPEND_INOUT,
+       GOMP_DEPEND_MUTEXINOUTSET): Define.
+
 2018-10-19  Jason Merrill  <jason@redhat.com>
 
        * demangle.h (enum demangle_component_type): Add
index ccfb657c735e61d07ebefc1d31170c0cd41806af..d3e64d4e352ae5524461e13e1758df5689b18f4d 100644 (file)
@@ -189,6 +189,7 @@ enum gomp_map_kind
 #define GOMP_TASK_FLAG_GRAINSIZE       (1 << 9)
 #define GOMP_TASK_FLAG_IF              (1 << 10)
 #define GOMP_TASK_FLAG_NOGROUP         (1 << 11)
+#define GOMP_TASK_FLAG_REDUCTION       (1 << 12)
 
 /* GOMP_target{_ext,update_ext,enter_exit_data} flags argument.  */
 #define GOMP_TARGET_FLAG_NOWAIT                (1 << 0)
@@ -251,6 +252,12 @@ enum gomp_map_kind
    at most and shifted by this many bits.  */
 #define GOMP_TARGET_ARG_VALUE_SHIFT            16
 
+/* Dependence types in omp_depend_t objects.  */
+#define GOMP_DEPEND_IN                 1
+#define GOMP_DEPEND_OUT                        2
+#define GOMP_DEPEND_INOUT              3
+#define GOMP_DEPEND_MUTEXINOUTSET      4
+
 /* HSA specific data structures.  */
 
 /* Identifiers of device-specific target arguments.  */
index 81bfc77a0e0fe89e39f4a5ebd0d449a0ccb1fb5a..b9d1f96b36a73d2923f8dfe814576d9690a064b1 100644 (file)
@@ -1,3 +1,342 @@
+2018-11-08  Jakub Jelinek  <jakub@redhat.com>
+
+       * affinity.c (gomp_display_affinity_place): New function.
+       * affinity-fmt.c: New file.
+       * alloc.c (gomp_aligned_alloc, gomp_aligned_free): New functions.
+       * config/linux/affinity.c (gomp_display_affinity_place): New function.
+       * config/nvptx/icv-device.c (omp_get_num_teams, omp_get_team_num):
+       Move these functions to ...
+       * config/nvptx/teams.c: ... here.  New file.
+       * config/nvptx/target.c (omp_pause_resource, omp_pause_resource_all):
+       New functions.
+       * config/nvptx/team.c (gomp_team_start, gomp_pause_host): New
+       functions.
+       * configure.ac: Check for aligned_alloc, posix_memalign, memalign
+       and _aligned_malloc.
+       (HAVE_UNAME, HAVE_GETHOSTNAME, HAVE_GETPID): Add new tests.
+       * configure.tgt: Add -DUSING_INITIAL_EXEC_TLS to XCFLAGS for Linux.
+       * env.c (gomp_display_affinity_var, gomp_affinity_format_var,
+       gomp_affinity_format_len): New variables.
+       (parse_schedule): Parse monotonic and nonmonotonic modifiers in
+       OMP_SCHEDULE variable.  Set GFS_MONOTONIC for monotonic schedules.
+       (handle_omp_display_env): Display monotonic/nonmonotonic schedule
+       modifiers.  Display (non-default) chunk sizes.  Print
+       OMP_DISPLAY_AFFINITY and OMP_AFFINITY_FORMAT.
+       (initialize_env): Don't call pthread_attr_setdetachstate.  Handle
+       OMP_DISPLAY_AFFINITY and OMP_AFFINITY_FORMAT env vars.
+       * fortran.c: Include stdio.h and string.h.
+       (omp_pause_resource, omp_pause_resource_all): Add ialias_redirect.
+       (omp_get_schedule_, omp_get_schedule_8_): Mask off GFS_MONOTONIC bit.
+       (omp_set_affinity_format_, omp_get_affinity_format_,
+       omp_display_affinity_, omp_capture_affinity_, omp_pause_resource_,
+       omp_pause_resource_all_): New functions.
+       * icv.c (omp_set_schedule): Mask off omp_sched_monotonic bit in
+       switch.
+       * icv-device.c (omp_get_num_teams, omp_get_team_num): Move these
+       functions to ...
+       * teams.c: ... here.  New file.
+       * libgomp_g.h: Include gstdint.h.
+       (GOMP_loop_nonmonotonic_runtime_start,
+       GOMP_loop_maybe_nonmonotonic_runtime_start, GOMP_loop_start,
+       GOMP_loop_ordered_start, GOMP_loop_nonmonotonic_runtime_next,
+       GOMP_loop_maybe_nonmonotonic_runtime_next, GOMP_loop_doacross_start,
+       GOMP_parallel_loop_nonmonotonic_runtime,
+       GOMP_parallel_loop_maybe_nonmonotonic_runtime,
+       GOMP_loop_ull_nonmonotonic_runtime_start,
+       GOMP_loop_ull_maybe_nonmonotonic_runtime_start, GOMP_loop_ull_start,
+       GOMP_loop_ull_ordered_start, GOMP_loop_ull_nonmonotonic_runtime_next,
+       GOMP_loop_ull_maybe_nonmonotonic_runtime_next,
+       GOMP_loop_ull_doacross_start, GOMP_parallel_reductions,
+       GOMP_taskwait_depend, GOMP_taskgroup_reduction_register,
+       GOMP_taskgroup_reduction_unregister, GOMP_task_reduction_remap,
+       GOMP_workshare_task_reduction_unregister, GOMP_sections2_start,
+       GOMP_teams_reg): Declare.
+       * libgomp.h (GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC): Define unless
+       gomp_aligned_alloc uses fallback implementation.
+       (gomp_aligned_alloc, gomp_aligned_free): Declare.
+       (enum gomp_schedule_type): Add GFS_MONOTONIC.
+       (struct gomp_doacross_work_share): Add extra field.
+       (struct gomp_work_share): Add task_reductions field.
+       (struct gomp_taskgroup): Add workshare and reductions fields.
+       (GOMP_NEEDS_THREAD_HANDLE): Define if needed.
+       (gomp_thread_handle): New typedef.
+       (gomp_display_affinity_place, gomp_set_affinity_format,
+       gomp_display_string, gomp_display_affinity,
+       gomp_display_affinity_thread): Declare.
+       (gomp_doacross_init, gomp_doacross_ull_init): Add size_t argument.
+       (gomp_parallel_reduction_register, gomp_workshare_taskgroup_start,
+       gomp_workshare_task_reduction_register): Declare.
+       (gomp_team_start): Add taskgroup argument.
+       (gomp_pause_host): Declare.
+       (gomp_init_work_share, gomp_work_share_start): Change bool argument
+       to size_t.
+       (gomp_thread_self, gomp_thread_to_pthread_t): New inline functions.
+       * libgomp.map (GOMP_5.0): Export GOMP_loop_start,
+       GOMP_loop_ordered_start, GOMP_loop_doacross_start,
+       GOMP_loop_ull_start, GOMP_loop_ull_ordered_start,
+       GOMP_loop_ull_doacross_start,
+       GOMP_workshare_task_reduction_unregister, GOMP_sections2_start,
+       GOMP_loop_maybe_nonmonotonic_runtime_next,
+       GOMP_loop_maybe_nonmonotonic_runtime_start,
+       GOMP_loop_nonmonotonic_runtime_next,
+       GOMP_loop_nonmonotonic_runtime_start,
+       GOMP_loop_ull_maybe_nonmonotonic_runtime_next,
+       GOMP_loop_ull_maybe_nonmonotonic_runtime_start,
+       GOMP_loop_ull_nonmonotonic_runtime_next,
+       GOMP_loop_ull_nonmonotonic_runtime_start,
+       GOMP_parallel_loop_maybe_nonmonotonic_runtime,
+       GOMP_parallel_loop_nonmonotonic_runtime, GOMP_parallel_reductions,
+       GOMP_taskgroup_reduction_register,
+       GOMP_taskgroup_reduction_unregister, GOMP_task_reduction_remap,
+       GOMP_teams_reg and GOMP_taskwait_depend.
+       (OMP_5.0): Export omp_pause_resource{,_all}{,_},
+       omp_{capture,display}_affinity{,_}, and
+       omp_[gs]et_affinity_format{,_}.
+       * loop.c: Include string.h.
+       (GOMP_loop_runtime_next): Add ialias.
+       (GOMP_taskgroup_reduction_register): Add ialias_redirect.
+       (gomp_loop_static_start, gomp_loop_dynamic_start,
+       gomp_loop_guided_start, gomp_loop_ordered_static_start,
+       gomp_loop_ordered_dynamic_start, gomp_loop_ordered_guided_start,
+       gomp_loop_doacross_static_start, gomp_loop_doacross_dynamic_start,
+       gomp_loop_doacross_guided_start): Adjust gomp_work_share_start
+       or gomp_doacross_init callers.
+       (gomp_adjust_sched, GOMP_loop_start, GOMP_loop_ordered_start,
+       GOMP_loop_doacross_start): New functions.
+       (GOMP_loop_runtime_start, GOMP_loop_ordered_runtime_start,
+       GOMP_loop_doacross_runtime_start, GOMP_parallel_loop_runtime_start):
+       Mask off GFS_MONOTONIC bit.
+       (GOMP_loop_maybe_nonmonotonic_runtime_next,
+       GOMP_loop_maybe_nonmonotonic_runtime_start,
+       GOMP_loop_nonmonotonic_runtime_next,
+       GOMP_loop_nonmonotonic_runtime_start,
+       GOMP_parallel_loop_maybe_nonmonotonic_runtime,
+       GOMP_parallel_loop_nonmonotonic_runtime): New aliases or wrapper
+       functions.
+       (gomp_parallel_loop_start): Pass NULL as taskgroup to
+       gomp_team_start.
+       * loop_ull.c: Include string.h.
+       (GOMP_loop_ull_runtime_next): Add ialias.
+       (GOMP_taskgroup_reduction_register): Add ialias_redirect.
+       (gomp_loop_ull_static_start, gomp_loop_ull_dynamic_start,
+       gomp_loop_ull_guided_start, gomp_loop_ull_ordered_static_start,
+       gomp_loop_ull_ordered_dynamic_start,
+       gomp_loop_ull_ordered_guided_start,
+       gomp_loop_ull_doacross_static_start,
+       gomp_loop_ull_doacross_dynamic_start,
+       gomp_loop_ull_doacross_guided_start): Adjust gomp_work_share_start
+       and gomp_doacross_ull_init callers.
+       (gomp_adjust_sched, GOMP_loop_ull_start, GOMP_loop_ull_ordered_start,
+       GOMP_loop_ull_doacross_start): New functions.
+       (GOMP_loop_ull_runtime_start,
+       GOMP_loop_ull_ordered_runtime_start,
+       GOMP_loop_ull_doacross_runtime_start): Mask off GFS_MONOTONIC bit.
+       (GOMP_loop_ull_maybe_nonmonotonic_runtime_next,
+       GOMP_loop_ull_maybe_nonmonotonic_runtime_start,
+       GOMP_loop_ull_nonmonotonic_runtime_next,
+       GOMP_loop_ull_nonmonotonic_runtime_start): Likewise.
+       * Makefile.am (libgomp_la_SOURCES): Add teams.c and affinity-fmt.c.
+       * omp.h.in (enum omp_sched_t): Add omp_sched_monotonic.
+       (omp_pause_resource_t, omp_depend_t): New typedefs.
+       (enum omp_lock_hint_t): Renamed to ...
+       (enum omp_sync_hint_t): ... this.  Define omp_sync_hint_*
+       enumerators using numbers and omp_lock_hint_* as their aliases.
+       (omp_lock_hint_t): New typedef.  Rename to ...
+       (omp_sync_hint_t): ... this.
+       (omp_init_lock_with_hint, omp_init_nest_lock_with_hint): Use
+       omp_sync_hint_t instead of omp_lock_hint_t.
+       (omp_pause_resource, omp_pause_resource_all, omp_set_affinity_format,
+       omp_get_affinity_format, omp_display_affinity, omp_capture_affinity):
+       Declare.
+       (omp_target_is_present, omp_target_disassociate_ptr):
+       Change first argument from void * to const void *.
+       (omp_target_memcpy, omp_target_memcpy_rect): Change second argument
+       from void * to const void *.
+       (omp_target_associate_ptr): Change first and second arguments from
+       void * to const void *.
+       * omp_lib.f90.in (omp_pause_resource_kind, omp_pause_soft,
+       omp_pause_hard): New parameters.
+       (omp_pause_resource, omp_pause_resource_all, omp_set_affinity_format,
+       omp_get_affinity_format, omp_display_affinity, omp_capture_affinity):
+       New interfaces.
+       * omp_lib.h.in (omp_pause_resource_kind, omp_pause_soft,
+       omp_pause_hard): New parameters.
+       (omp_pause_resource, omp_pause_resource_all, omp_set_affinity_format,
+       omp_get_affinity_format, omp_display_affinity, omp_capture_affinity):
+       New externals.
+       * ordered.c (gomp_doacross_init, gomp_doacross_ull_init): Add
+       EXTRA argument.  If not needed to prepare array, if extra is 0,
+       clear ws->doacross, otherwise allocate just doacross structure and
+       extra payload.  If array is needed, allocate also extra payload.
+       (GOMP_doacross_post, GOMP_doacross_wait, GOMP_doacross_ull_post,
+       GOMP_doacross_ull_wait): Handle doacross->array == NULL like
+       doacross == NULL.
+       * parallel.c (GOMP_parallel_start): Pass NULL as taskgroup to
+       gomp_team_start.
+       (GOMP_parallel): Likewise.  Formatting fix.
+       (GOMP_parallel_reductions): New function.
+       (GOMP_cancellation_point): If taskgroup has workshare
+       flag set, check cancelled of prev taskgroup if any.
+       (GOMP_cancel): If taskgroup has workshare flag set, set cancelled
+       on prev taskgroup if any.
+       * sections.c: Include string.h.
+       (GOMP_taskgroup_reduction_register): Add ialias_redirect.
+       (GOMP_sections_start): Adjust gomp_work_share_start caller.
+       (GOMP_sections2_start): New function.
+       (GOMP_parallel_sections_start, GOMP_parallel_sections):
+       Pass NULL as taskgroup to gomp_team_start.
+       * single.c (GOMP_single_start, GOMP_single_copy_start): Adjust
+       gomp_work_share_start callers.
+       * target.c (GOMP_target_update_ext, GOMP_target_enter_exit_data):
+       If taskgroup has workshare flag set, check cancelled on prev
+       taskgroup if any.  Guard all cancellation tests with
+       gomp_cancel_var test.
+       (omp_target_is_present, omp_target_disassociate_ptr):
+       Change ptr argument from void * to const void *.
+       (omp_target_memcpy): Change src argument from void * to const void *.
+       (omp_target_memcpy_rect): Likewise.
+       (omp_target_memcpy_rect_worker): Likewise.  Use const char * casts
+       instead of char * where needed.
+       (omp_target_associate_ptr): Change host_ptr and device_ptr arguments
+       from void * to const void *.
+       (omp_pause_resource, omp_pause_resource_all): New functions.
+       * task.c (gomp_task_handle_depend): Handle new depend array format
+       in addition to the old.  Handle mutexinoutset kinds the same as
+       inout for now, handle unspecified kinds.
+       (gomp_create_target_task): If taskgroup has workshare flag set, check
+       cancelled on prev taskgroup if any.  Guard all cancellation tests with
+       gomp_cancel_var test.  Handle new depend array format count in
+       addition to the old.
+       (GOMP_task): Likewise.  Adjust function comment.
+       (gomp_task_run_pre): If taskgroup has workshare flag set, check
+       cancelled on prev taskgroup if any.  Guard all cancellation tests with
+       gomp_cancel_var test.
+       (GOMP_taskwait_depend): New function.
+       (gomp_task_maybe_wait_for_dependencies): Handle new depend array
+       format in addition to the old.  Handle mutexinoutset kinds the same as
+       inout for now, handle unspecified kinds.  Fix a function comment typo.
+       (gomp_taskgroup_init): New function.
+       (GOMP_taskgroup_start): Use it.
+       (gomp_reduction_register, gomp_create_artificial_team,
+       GOMP_taskgroup_reduction_register,
+       GOMP_taskgroup_reduction_unregister, GOMP_task_reduction_remap,
+       gomp_parallel_reduction_register,
+       gomp_workshare_task_reduction_register,
+       gomp_workshare_taskgroup_start,
+       GOMP_workshare_task_reduction_unregister): New functions.
+       * taskloop.c (GOMP_taskloop): If taskgroup has workshare flag set,
+       check cancelled on prev taskgroup if any.  Guard all cancellation
+       tests with gomp_cancel_var test.  Handle GOMP_TASK_FLAG_REDUCTION flag
+       by calling GOMP_taskgroup_reduction_register.
+       * team.c (gomp_thread_attr): Remove comment.
+       (struct gomp_thread_start_data): Add handle field.
+       (gomp_thread_start): Call pthread_detach.
+       (gomp_new_team): Adjust gomp_init_work_share caller.
+       (gomp_free_pool_helper): Call pthread_detach.
+       (gomp_team_start): Add taskgroup argument, initialize implicit
+       tasks' taskgroup field to that.  Don't call
+       pthread_attr_setdetachstate.  Handle OMP_DISPLAY_AFFINITY env var.
+       (gomp_team_end): Determine nesting by thr->ts.level != 0
+       rather than thr->ts.team != NULL.
+       (gomp_pause_pool_helper, gomp_pause_host): New functions.
+       * work.c (alloc_work_share): Use gomp_aligned_alloc instead of
+       gomp_malloc if GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC is defined.
+       (gomp_init_work_share): Change ORDERED argument from bool to size_t,
+       if more than 1 allocate also extra payload at the end of array.  Never
+       keep ordered_team_ids NULL, set it to inline_ordered_team_ids instead.
+       (gomp_work_share_start): Change ORDERED argument from bool to size_t,
+       return true instead of ws.
+       * Makefile.in: Regenerated.
+       * configure: Regenerated.
+       * config.h.in: Regenerated.
+       * testsuite/libgomp.c/cancel-for-2.c (foo): Use cancel modifier
+       in some cases.
+       * testsuite/libgomp.c-c++-common/cancel-parallel-1.c: New test.
+       * testsuite/libgomp.c-c++-common/cancel-taskgroup-3.c: New test.
+       * testsuite/libgomp.c-c++-common/depend-iterator-1.c: New test.
+       * testsuite/libgomp.c-c++-common/depend-iterator-2.c: New test.
+       * testsuite/libgomp.c-c++-common/depend-mutexinout-1.c: New test.
+       * testsuite/libgomp.c-c++-common/depend-mutexinout-2.c: New test.
+       * testsuite/libgomp.c-c++-common/depobj-1.c: New test.
+       * testsuite/libgomp.c-c++-common/display-affinity-1.c: New test.
+       * testsuite/libgomp.c-c++-common/for-10.c: New test.
+       * testsuite/libgomp.c-c++-common/for-11.c: New test.
+       * testsuite/libgomp.c-c++-common/for-12.c: New test.
+       * testsuite/libgomp.c-c++-common/for-13.c: New test.
+       * testsuite/libgomp.c-c++-common/for-14.c: New test.
+       * testsuite/libgomp.c-c++-common/for-15.c: New test.
+       * testsuite/libgomp.c-c++-common/for-2.h: If CONDNE macro is defined,
+       define a different N(test), don't define N(f0) to N(f14), but instead
+       define N(f20) to N(f34) using != comparisons.
+       * testsuite/libgomp.c-c++-common/for-7.c: New test.
+       * testsuite/libgomp.c-c++-common/for-8.c: New test.
+       * testsuite/libgomp.c-c++-common/for-9.c: New test.
+       * testsuite/libgomp.c-c++-common/master-combined-1.c: New test.
+       * testsuite/libgomp.c-c++-common/pause-1.c: New test.
+       * testsuite/libgomp.c-c++-common/pause-2.c: New test.
+       * testsuite/libgomp.c-c++-common/pr66199-10.c: New test.
+       * testsuite/libgomp.c-c++-common/pr66199-11.c: New test.
+       * testsuite/libgomp.c-c++-common/pr66199-12.c: New test.
+       * testsuite/libgomp.c-c++-common/pr66199-13.c: New test.
+       * testsuite/libgomp.c-c++-common/pr66199-14.c: New test.
+       * testsuite/libgomp.c-c++-common/simd-1.c: New test.
+       * testsuite/libgomp.c-c++-common/taskloop-reduction-1.c: New test.
+       * testsuite/libgomp.c-c++-common/taskloop-reduction-2.c: New test.
+       * testsuite/libgomp.c-c++-common/taskloop-reduction-3.c: New test.
+       * testsuite/libgomp.c-c++-common/taskloop-reduction-4.c: New test.
+       * testsuite/libgomp.c-c++-common/task-reduction-11.c: New test.
+       * testsuite/libgomp.c-c++-common/task-reduction-12.c: New test.
+       * testsuite/libgomp.c-c++-common/task-reduction-1.c: New test.
+       * testsuite/libgomp.c-c++-common/task-reduction-2.c: New test.
+       * testsuite/libgomp.c-c++-common/task-reduction-3.c: New test.
+       * testsuite/libgomp.c-c++-common/task-reduction-4.c: New test.
+       * testsuite/libgomp.c-c++-common/task-reduction-5.c: New test.
+       * testsuite/libgomp.c-c++-common/task-reduction-6.c: New test.
+       * testsuite/libgomp.c-c++-common/task-reduction-7.c: New test.
+       * testsuite/libgomp.c-c++-common/task-reduction-8.c: New test.
+       * testsuite/libgomp.c-c++-common/task-reduction-9.c: New test.
+       * testsuite/libgomp.c-c++-common/taskwait-depend-1.c: New test.
+       * testsuite/libgomp.c++/depend-1.C: New test.
+       * testsuite/libgomp.c++/depend-iterator-1.C: New test.
+       * testsuite/libgomp.c++/depobj-1.C: New test.
+       * testsuite/libgomp.c++/for-16.C: New test.
+       * testsuite/libgomp.c++/for-21.C: New test.
+       * testsuite/libgomp.c++/for-22.C: New test.
+       * testsuite/libgomp.c++/for-23.C: New test.
+       * testsuite/libgomp.c++/for-24.C: New test.
+       * testsuite/libgomp.c++/for-25.C: New test.
+       * testsuite/libgomp.c++/for-26.C: New test.
+       * testsuite/libgomp.c++/taskloop-reduction-1.C: New test.
+       * testsuite/libgomp.c++/taskloop-reduction-2.C: New test.
+       * testsuite/libgomp.c++/taskloop-reduction-3.C: New test.
+       * testsuite/libgomp.c++/taskloop-reduction-4.C: New test.
+       * testsuite/libgomp.c++/task-reduction-10.C: New test.
+       * testsuite/libgomp.c++/task-reduction-11.C: New test.
+       * testsuite/libgomp.c++/task-reduction-12.C: New test.
+       * testsuite/libgomp.c++/task-reduction-13.C: New test.
+       * testsuite/libgomp.c++/task-reduction-14.C: New test.
+       * testsuite/libgomp.c++/task-reduction-15.C: New test.
+       * testsuite/libgomp.c++/task-reduction-16.C: New test.
+       * testsuite/libgomp.c++/task-reduction-17.C: New test.
+       * testsuite/libgomp.c++/task-reduction-18.C: New test.
+       * testsuite/libgomp.c++/task-reduction-19.C: New test.
+       * testsuite/libgomp.c/task-reduction-1.c: New test.
+       * testsuite/libgomp.c++/task-reduction-1.C: New test.
+       * testsuite/libgomp.c/task-reduction-2.c: New test.
+       * testsuite/libgomp.c++/task-reduction-2.C: New test.
+       * testsuite/libgomp.c++/task-reduction-3.C: New test.
+       * testsuite/libgomp.c++/task-reduction-4.C: New test.
+       * testsuite/libgomp.c++/task-reduction-5.C: New test.
+       * testsuite/libgomp.c++/task-reduction-6.C: New test.
+       * testsuite/libgomp.c++/task-reduction-7.C: New test.
+       * testsuite/libgomp.c++/task-reduction-8.C: New test.
+       * testsuite/libgomp.c++/task-reduction-9.C: New test.
+       * testsuite/libgomp.c/teams-1.c: New test.
+       * testsuite/libgomp.c/teams-2.c: New test.
+       * testsuite/libgomp.c/thread-limit-4.c: New test.
+       * testsuite/libgomp.c/thread-limit-5.c: New test.
+       * testsuite/libgomp.fortran/display-affinity-1.f90: New test.
+
 2018-11-06  Chung-Lin Tang <cltang@codesourcery.com>
 
        * oacc-mem.c (memcpy_tofrom_device): New function, combined from
index 604085c3d72a97dc6fe035da3075dc3bc302afdc..062fded0805a4added66a45e84c9cb4303983024 100644 (file)
@@ -64,7 +64,8 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c error.c \
        parallel.c sections.c single.c task.c team.c work.c lock.c mutex.c \
        proc.c sem.c bar.c ptrlock.c time.c fortran.c affinity.c target.c \
        splay-tree.c libgomp-plugin.c oacc-parallel.c oacc-host.c oacc-init.c \
-       oacc-mem.c oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c
+       oacc-mem.c oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \
+       affinity-fmt.c teams.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
index dfd087927152fa44a77edbad6af802430039662a..98499b8dc8f60818f24295f95cec5b0abe1d071e 100644 (file)
@@ -216,7 +216,8 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo critical.lo \
        sem.lo bar.lo ptrlock.lo time.lo fortran.lo affinity.lo \
        target.lo splay-tree.lo libgomp-plugin.lo oacc-parallel.lo \
        oacc-host.lo oacc-init.lo oacc-mem.lo oacc-async.lo \
-       oacc-plugin.lo oacc-cuda.lo priority_queue.lo $(am__objects_1)
+       oacc-plugin.lo oacc-cuda.lo priority_queue.lo affinity-fmt.lo \
+       teams.lo $(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -549,7 +550,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c \
        affinity.c target.c splay-tree.c libgomp-plugin.c \
        oacc-parallel.c oacc-host.c oacc-init.c oacc-mem.c \
        oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \
-       $(am__append_3)
+       affinity-fmt.c teams.c $(am__append_3)
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info $(libtool_VERSION)
@@ -724,6 +725,7 @@ distclean-compile:
        -rm -f *.tab.c
 
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/affinity.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/affinity-fmt.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alloc.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atomic.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bar.Plo@am__quote@
@@ -762,6 +764,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/target.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/task.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/team.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/teams.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/work.Plo@am__quote@
 
diff --git a/libgomp/affinity-fmt.c b/libgomp/affinity-fmt.c
new file mode 100644 (file)
index 0000000..08937b6
--- /dev/null
@@ -0,0 +1,481 @@
+/* Copyright (C) 2018 Free Software Foundation, Inc.
+   Contributed by Jakub Jelinek <jakub@redhat.com>.
+
+   This file is part of the GNU Offloading and Multi Processing Library
+   (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "libgomp.h"
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_UNAME
+#include <sys/utsname.h>
+#endif
+
+void
+gomp_set_affinity_format (const char *format, size_t len)
+{
+  if (len < gomp_affinity_format_len)
+    memcpy (gomp_affinity_format_var, format, len);
+  else
+    {
+      char *p;
+      if (gomp_affinity_format_len)
+       p = gomp_realloc (gomp_affinity_format_var, len + 1);
+      else
+       p = gomp_malloc (len + 1);
+      memcpy (p, format, len);
+      gomp_affinity_format_var = p;
+      gomp_affinity_format_len = len + 1;
+    }
+  gomp_affinity_format_var[len] = '\0';
+}
+
+void
+omp_set_affinity_format (const char *format)
+{
+  gomp_set_affinity_format (format, strlen (format));
+}
+
+size_t
+omp_get_affinity_format (char *buffer, size_t size)
+{
+  size_t len = strlen (gomp_affinity_format_var);
+  if (size)
+    {
+      if (len < size)
+       memcpy (buffer, gomp_affinity_format_var, len + 1);
+      else
+       {
+         memcpy (buffer, gomp_affinity_format_var, size - 1);
+         buffer[size - 1] = '\0';
+       }
+    }
+  return len;
+}
+
+void
+gomp_display_string (char *buffer, size_t size, size_t *ret,
+                    const char *str, size_t len)
+{
+  size_t r = *ret;
+  if (size && r < size)
+    {
+      size_t l = len;
+      if (size - r < len)
+       l = size - r;
+      memcpy (buffer + r, str, l);
+    }
+  *ret += len;
+  if (__builtin_expect (r > *ret, 0))
+    gomp_fatal ("overflow in omp_capture_affinity");
+}
+
+static void
+gomp_display_repeat (char *buffer, size_t size, size_t *ret,
+                    char c, size_t len)
+{
+  size_t r = *ret;
+  if (size && r < size)
+    {
+      size_t l = len;
+      if (size - r < len)
+       l = size - r;
+      memset (buffer + r, c, l);
+    }
+  *ret += len;
+  if (__builtin_expect (r > *ret, 0))
+    gomp_fatal ("overflow in omp_capture_affinity");
+}
+
+static void
+gomp_display_num (char *buffer, size_t size, size_t *ret,
+                 bool zero, bool right, size_t sz, char *buf)
+{
+  size_t l = strlen (buf);
+  if (sz == (size_t) -1 || l >= sz)
+    {
+      gomp_display_string (buffer, size, ret, buf, l);
+      return;
+    }
+  if (zero)
+    {
+      if (buf[0] == '-')
+       gomp_display_string (buffer, size, ret, buf, 1);
+      else if (buf[0] == '0' && buf[1] == 'x')
+       gomp_display_string (buffer, size, ret, buf, 2);
+      gomp_display_repeat (buffer, size, ret, '0', sz - l);
+      if (buf[0] == '-')
+       gomp_display_string (buffer, size, ret, buf + 1, l - 1);
+      else if (buf[0] == '0' && buf[1] == 'x')
+       gomp_display_string (buffer, size, ret, buf + 2, l - 2);
+      else
+       gomp_display_string (buffer, size, ret, buf, l);
+    }
+  else if (right)
+    {
+      gomp_display_repeat (buffer, size, ret, ' ', sz - l);
+      gomp_display_string (buffer, size, ret, buf, l);
+    }
+  else
+    {
+      gomp_display_string (buffer, size, ret, buf, l);
+      gomp_display_repeat (buffer, size, ret, ' ', sz - l);
+    }
+}
+
+static void
+gomp_display_int (char *buffer, size_t size, size_t *ret,
+                 bool zero, bool right, size_t sz, int num)
+{
+  char buf[3 * sizeof (int) + 2];
+  sprintf (buf, "%d", num);
+  gomp_display_num (buffer, size, ret, zero, right, sz, buf);
+}
+
+static void
+gomp_display_string_len (char *buffer, size_t size, size_t *ret,
+                        bool right, size_t sz, char *str, size_t len)
+{
+  if (sz == (size_t) -1 || len >= sz)
+    {
+      gomp_display_string (buffer, size, ret, str, len);
+      return;
+    }
+
+  if (right)
+    {
+      gomp_display_repeat (buffer, size, ret, ' ', sz - len);
+      gomp_display_string (buffer, size, ret, str, len);
+    }
+  else
+    {
+      gomp_display_string (buffer, size, ret, str, len);
+      gomp_display_repeat (buffer, size, ret, ' ', sz - len);
+    }
+}
+
+static void
+gomp_display_hostname (char *buffer, size_t size, size_t *ret,
+                      bool right, size_t sz)
+{
+#ifdef HAVE_GETHOSTNAME
+  {
+    char buf[256];
+    char *b = buf;
+    size_t len = 256;
+    do
+      {
+       b[len - 1] = '\0';
+       if (gethostname (b, len - 1) == 0)
+         {
+           size_t l = strlen (b);
+           if (l < len - 1)
+             {
+               gomp_display_string_len (buffer, size, ret,
+                                        right, sz, b, l);
+               if (b != buf)
+                 free (b);
+               return;
+             }
+         }
+       if (len == 1048576)
+         break;
+       len = len * 2;
+       if (len == 512)
+         b = gomp_malloc (len);
+       else
+         b = gomp_realloc (b, len);
+      }
+    while (1);
+    if (b != buf)
+      free (b);
+  }
+#endif
+#ifdef HAVE_UNAME
+  {
+    struct utsname buf;
+    if (uname (&buf) == 0)
+      {
+       gomp_display_string_len (buffer, size, ret, right, sz,
+                                buf.nodename, strlen (buf.nodename));
+       return;
+      }
+  }
+#endif
+  gomp_display_string_len (buffer, size, ret, right, sz, "node", 4);
+}
+
+struct affinity_types_struct {
+  char long_str[18];
+  char long_len;
+  char short_c; };
+
+static struct affinity_types_struct affinity_types[] =
+{
+#define AFFINITY_TYPE(l, s) \
+  { #l, sizeof (#l) - 1, s }
+  AFFINITY_TYPE (team_num, 't'),
+  AFFINITY_TYPE (num_teams, 'T'),
+  AFFINITY_TYPE (nesting_level, 'L'),
+  AFFINITY_TYPE (thread_num, 'n'),
+  AFFINITY_TYPE (num_threads, 'N'),
+  AFFINITY_TYPE (ancestor_tnum, 'a'),
+  AFFINITY_TYPE (host, 'H'),
+  AFFINITY_TYPE (process_id, 'P'),
+  AFFINITY_TYPE (native_thread_id, 'i'),
+  AFFINITY_TYPE (thread_affinity, 'A')
+#undef AFFINITY_TYPE
+};
+
+size_t
+gomp_display_affinity (char *buffer, size_t size,
+                      const char *format, gomp_thread_handle handle,
+                      struct gomp_team_state *ts, unsigned int place)
+{
+  size_t ret = 0;
+  do
+    {
+      const char *p = strchr (format, '%');
+      bool zero = false;
+      bool right = false;
+      size_t sz = -1;
+      char c;
+      int val;
+      if (p == NULL)
+       p = strchr (format, '\0');
+      if (p != format)
+       gomp_display_string (buffer, size, &ret,
+                            format, p - format);
+      if (*p == '\0')
+       break;
+      p++;
+      if (*p == '%')
+       {
+         gomp_display_string (buffer, size, &ret, "%", 1);
+         format = p + 1;
+         continue;
+       }
+      if (*p == '0')
+       {
+         zero = true;
+         p++;
+         if (*p != '.')
+           gomp_fatal ("leading zero not followed by dot in affinity format");
+       }
+      if (*p == '.')
+       {
+         right = true;
+         p++;
+       }
+      if (*p >= '1' && *p <= '9')
+       {
+         char *end;
+         sz = strtoul (p, &end, 10);
+         p = end;
+       }
+      else if (zero || right)
+       gomp_fatal ("leading zero or right justification in affinity format "
+                   "requires size");
+      c = *p;
+      if (c == '{')
+       {
+         int i;
+         for (i = 0;
+              i < sizeof (affinity_types) / sizeof (affinity_types[0]); ++i)
+           if (strncmp (p + 1, affinity_types[i].long_str,
+                        affinity_types[i].long_len) == 0
+               && p[affinity_types[i].long_len + 1] == '}')
+             {
+               c = affinity_types[i].short_c;
+               p += affinity_types[i].long_len + 1;
+               break;
+             }
+         if (c == '{')
+           {
+             char *q = strchr (p + 1, '}');
+             if (q)
+               gomp_fatal ("unsupported long type name '%.*s' in affinity "
+                           "format", (int) (q - (p + 1)), p + 1);
+             else
+               gomp_fatal ("unterminated long type name '%s' in affinity "
+                           "format", p + 1);
+           }
+       }
+      switch (c)
+       {
+       case 't':
+         val = omp_get_team_num ();
+         goto do_int;
+       case 'T':
+         val = omp_get_num_teams ();
+         goto do_int;
+       case 'L':
+         val = ts->level;
+         goto do_int;
+       case 'n':
+         val = ts->team_id;
+         goto do_int;
+       case 'N':
+         val = ts->team ? ts->team->nthreads : 1;
+         goto do_int;
+       case 'a':
+         val = ts->team ? ts->team->prev_ts.team_id : -1;
+         goto do_int;
+       case 'H':
+         gomp_display_hostname (buffer, size, &ret, right, sz);
+         break;
+       case 'P':
+#ifdef HAVE_GETPID
+         val = getpid ();
+#else
+         val = 0;
+#endif
+         goto do_int;
+       case 'i':
+#if defined(LIBGOMP_USE_PTHREADS) && defined(__GNUC__)
+         /* Handle integral pthread_t.  */
+         if (__builtin_classify_type (handle) == 1)
+           {
+             char buf[3 * (sizeof (handle) + sizeof (int)) + 4];
+
+             if (sizeof (handle) == sizeof (long))
+               sprintf (buf, "0x%lx", (long) handle);
+             else if (sizeof (handle) == sizeof (long long))
+               sprintf (buf, "0x%llx", (long long) handle);
+             else
+               sprintf (buf, "0x%x", (int) handle);
+             gomp_display_num (buffer, size, &ret, zero, right, sz, buf);
+             break;
+           }
+         /* And pointer pthread_t.  */
+         else if (__builtin_classify_type (handle) == 5)
+           {
+             char buf[3 * (sizeof (uintptr_t) + sizeof (int)) + 4];
+
+             if (sizeof (uintptr_t) == sizeof (long))
+               sprintf (buf, "0x%lx", (long) (uintptr_t) handle);
+             else if (sizeof (uintptr_t) == sizeof (long long))
+               sprintf (buf, "0x%llx", (long long) (uintptr_t) handle);
+             else
+               sprintf (buf, "0x%x", (int) (uintptr_t) handle);
+             gomp_display_num (buffer, size, &ret, zero, right, sz, buf);
+             break;
+           }
+#endif
+         val = 0;
+         goto do_int;
+       case 'A':
+         if (sz == (size_t) -1)
+           gomp_display_affinity_place (buffer, size, &ret,
+                                        place - 1);
+         else if (right)
+           {
+             size_t len = 0;
+             gomp_display_affinity_place (NULL, 0, &len, place - 1);
+             if (len < sz)
+               gomp_display_repeat (buffer, size, &ret, ' ', sz - len);
+             gomp_display_affinity_place (buffer, size, &ret, place - 1);
+           }
+         else
+           {
+             size_t start = ret;
+             gomp_display_affinity_place (buffer, size, &ret, place - 1);
+             if (ret - start < sz)
+               gomp_display_repeat (buffer, size, &ret, ' ', sz - (ret - start));
+           }
+         break;
+       do_int:
+         gomp_display_int (buffer, size, &ret, zero, right, sz, val);
+         break;
+       default:
+         gomp_fatal ("unsupported type %c in affinity format", c);
+       }
+      format = p + 1;
+    }
+  while (1);
+  return ret;
+}
+
+size_t
+omp_capture_affinity (char *buffer, size_t size, const char *format)
+{
+  struct gomp_thread *thr = gomp_thread ();
+  size_t ret
+    = gomp_display_affinity (buffer, size,
+                            format && *format
+                            ? format : gomp_affinity_format_var,
+                            gomp_thread_self (), &thr->ts, thr->place);
+  if (size)
+    {
+      if (ret >= size)
+       buffer[size - 1] = '\0';
+      else
+       buffer[ret] = '\0';
+    }
+  return ret;
+}
+ialias (omp_capture_affinity)
+
+void
+omp_display_affinity (const char *format)
+{
+  char buf[512];
+  char *b;
+  size_t ret = ialias_call (omp_capture_affinity) (buf, sizeof buf, format);
+  if (ret < sizeof buf)
+    {
+      buf[ret] = '\n';
+      fwrite (buf, 1, ret + 1, stderr);
+      return;
+    }
+  b = gomp_malloc (ret + 1);
+  ialias_call (omp_capture_affinity) (b, ret + 1, format);
+  b[ret] = '\n';
+  fwrite (b, 1, ret + 1, stderr);
+  free (b);
+}
+
+void
+gomp_display_affinity_thread (gomp_thread_handle handle,
+                             struct gomp_team_state *ts, unsigned int place)
+{
+  char buf[512];
+  char *b;
+  size_t ret = gomp_display_affinity (buf, sizeof buf, gomp_affinity_format_var,
+                                     handle, ts, place);
+  if (ret < sizeof buf)
+    {
+      buf[ret] = '\n';
+      fwrite (buf, 1, ret + 1, stderr);
+      return;
+    }
+  b = gomp_malloc (ret + 1);
+  gomp_display_affinity (b, ret + 1, gomp_affinity_format_var,
+                        handle, ts, place);
+  b[ret] = '\n';
+  fwrite (b, 1, ret + 1, stderr);
+  free (b);
+}
index 3f98e56c0029f30793432a9dfe93ee5c70f9950f..99a45dcd3a0c6b2344159b9abaa002f24888a044 100644 (file)
@@ -138,5 +138,18 @@ gomp_get_place_proc_ids_8 (int place_num, int64_t *ids)
   (void) ids;
 }
 
+void
+gomp_display_affinity_place (char *buffer, size_t size, size_t *ret,
+                            int place)
+{
+  cpu_set_t *cpusetp;
+  char buf[sizeof (long) * 3 + 4];
+  if (gomp_available_cpus > 1)
+    sprintf (buf, "0-%lu", gomp_available_cpus - 1);
+  else
+    strcpy (buf, "0");
+  gomp_display_string (buffer, size, ret, buf, strlen (buf));
+}
+
 ialias(omp_get_place_num_procs)
 ialias(omp_get_place_proc_ids)
index 1bf404235797509f54ee8a3d0061bcbb929d189d..296f1af1eaa3ce4cbb3be386dbd36e9c65155d17 100644 (file)
@@ -57,3 +57,50 @@ gomp_realloc (void *old, size_t size)
     gomp_fatal ("Out of memory allocating %lu bytes", (unsigned long) size);
   return ret;
 }
+
+void *
+gomp_aligned_alloc (size_t al, size_t size)
+{
+  void *ret;
+  if (al < sizeof (void *))
+    al = sizeof (void *);
+#ifdef HAVE_ALIGNED_ALLOC
+  ret = aligned_alloc (al, size);
+#elif defined(HAVE__ALIGNED_MALLOC)
+  ret = _aligned_malloc (size, al);
+#elif defined(HAVE_POSIX_MEMALIGN)
+  if (posix_memalign (&ret, al, size) != 0)
+    ret = NULL;
+#elif defined(HAVE_MEMALIGN)
+  {
+    extern void *memalign (size_t, size_t);
+    ret = memalign (al, size);
+  }
+#else
+  ret = NULL;
+  if ((al & (al - 1)) == 0 && size)
+    {
+      void *p = malloc (size + al);
+      if (p)
+       {
+         void *ap = (void *) (((uintptr_t) p + al) & -al);
+         ((void **) ap)[-1] = p;
+         ret = ap;
+       }
+    }
+#endif
+  if (ret == NULL)
+    gomp_fatal ("Out of memory allocating %lu bytes", (unsigned long) size);
+  return ret;
+}
+
+void
+gomp_aligned_free (void *ptr)
+{
+#ifdef GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC
+  free (ptr);
+#else
+  if (ptr)
+    free (((void **) ptr)[-1]);
+#endif
+}
index e7bc4d9737441e344eba04dcc118dd3e18eb44a3..52f4ed44412a0d7dde02458f55efcf138b083f87 100644 (file)
@@ -1,5 +1,8 @@
 /* config.h.in.  Generated from configure.ac by autoheader.  */
 
+/* Define to 1 if you have the `aligned_alloc' function. */
+#undef HAVE_ALIGNED_ALLOC
+
 /* Define to 1 if the target assembler supports .symver directive. */
 #undef HAVE_AS_SYMVER_DIRECTIVE
 
 /* Define to 1 if you have the `getgid' function. */
 #undef HAVE_GETGID
 
+/* Define if gethostname is supported. */
+#undef HAVE_GETHOSTNAME
+
 /* Define to 1 if you have the `getloadavg' function. */
 #undef HAVE_GETLOADAVG
 
+/* Define if getpid is supported. */
+#undef HAVE_GETPID
+
 /* Define to 1 if you have the `getuid' function. */
 #undef HAVE_GETUID
 
 /* Define to 1 if you have the `dl' library (-ldl). */
 #undef HAVE_LIBDL
 
+/* Define to 1 if you have the `memalign' function. */
+#undef HAVE_MEMALIGN
+
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
+/* Define to 1 if you have the `posix_memalign' function. */
+#undef HAVE_POSIX_MEMALIGN
+
 /* Define if pthread_{,attr_}{g,s}etaffinity_np is supported. */
 #undef HAVE_PTHREAD_AFFINITY_NP
 
 /* Define to 1 if the target supports thread-local storage. */
 #undef HAVE_TLS
 
+/* Define if uname is supported and struct utsname has nodename field. */
+#undef HAVE_UNAME
+
 /* Define to 1 if you have the <unistd.h> header file. */
 #undef HAVE_UNISTD_H
 
+/* Define to 1 if you have the `_aligned_malloc' function. */
+#undef HAVE__ALIGNED_MALLOC
+
 /* Define to 1 if you have the `__secure_getenv' function. */
 #undef HAVE___SECURE_GETENV
 
index a2aefb8977c5f84731c295f88092ece3f84a0be3..d2dcc1ea852514ca5cbb58f8fdf9976a736880e1 100644 (file)
@@ -396,6 +396,56 @@ gomp_get_place_proc_ids_8 (int place_num, int64_t *ids)
       *ids++ = i;
 }
 
+void
+gomp_display_affinity_place (char *buffer, size_t size, size_t *ret,
+                            int place)
+{
+  cpu_set_t *cpusetp;
+  char buf[sizeof (long) * 3 + 4];
+  if (place >= 0 && place < gomp_places_list_len)
+    cpusetp = (cpu_set_t *) gomp_places_list[place];
+  else if (gomp_cpusetp)
+    cpusetp = gomp_cpusetp;
+  else
+    {
+      if (gomp_available_cpus > 1)
+       sprintf (buf, "0-%lu", gomp_available_cpus - 1);
+      else
+       strcpy (buf, "0");
+      gomp_display_string (buffer, size, ret, buf, strlen (buf));
+      return;
+    }
+
+  unsigned long i, max = 8 * gomp_cpuset_size, start;
+  bool prev_set = false;
+  start = max;
+  for (i = 0; i <= max; i++)
+    {
+      bool this_set;
+      if (i == max)
+       this_set = false;
+      else
+       this_set = CPU_ISSET_S (i, gomp_cpuset_size, cpusetp);
+      if (this_set != prev_set)
+       {
+         prev_set = this_set;
+         if (this_set)
+           {
+             char *p = buf;
+             if (start != max)
+               *p++ = ',';
+             sprintf (p, "%lu", i);
+             start = i;
+           }
+         else if (i == start + 1)
+           continue;
+         else
+           sprintf (buf, "-%lu", i - 1);
+         gomp_display_string (buffer, size, ret, buf, strlen (buf));
+       }
+    }
+}
+
 ialias(omp_get_place_num_procs)
 ialias(omp_get_place_proc_ids)
 
index 562db95f328e23974f7edf37372ba7a3cd60b14b..8cb464bb61ccd2fc039800c9af5ca51ebe1ee446 100644 (file)
@@ -45,20 +45,6 @@ omp_get_num_devices (void)
   return 0;
 }
 
-int
-omp_get_num_teams (void)
-{
-  return gomp_num_teams_var + 1;
-}
-
-int
-omp_get_team_num (void)
-{
-  int ctaid;
-  asm ("mov.u32 %0, %%ctaid.x;" : "=r" (ctaid));
-  return ctaid;
-}
-
 int
 omp_is_initial_device (void)
 {
@@ -69,6 +55,4 @@ omp_is_initial_device (void)
 ialias (omp_set_default_device)
 ialias (omp_get_default_device)
 ialias (omp_get_num_devices)
-ialias (omp_get_num_teams)
-ialias (omp_get_team_num)
 ialias (omp_is_initial_device)
index 64004acb422f7874c2d25de9c26abfb25030bc1d..3878227a27fa79443a9d0cf73c6569d18c9f7801 100644 (file)
@@ -47,3 +47,21 @@ GOMP_teams (unsigned int num_teams, unsigned int thread_limit)
     }
   gomp_num_teams_var = num_teams - 1;
 }
+
+int
+omp_pause_resource (omp_pause_resource_t kind, int device_num)
+{
+  (void) kind;
+  (void) device_num;
+  return -1;
+}
+
+int
+omp_pause_resource_all (omp_pause_resource_t kind)
+{
+  (void) kind;
+  return -1;
+}
+
+ialias (omp_pause_resource)
+ialias (omp_pause_resource_all)
index 34059d389f2e2d2b7c430775552e0daf7828babc..8b0a0903641bf7035eec122d1788e78bdc706c2f 100644 (file)
@@ -116,7 +116,8 @@ gomp_thread_start (struct gomp_thread_pool *pool)
 
 void
 gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
-                unsigned flags, struct gomp_team *team)
+                unsigned flags, struct gomp_team *team,
+                struct gomp_taskgroup *taskgroup)
 {
   struct gomp_thread *thr, *nthr;
   struct gomp_task *task;
@@ -147,6 +148,7 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
   nthreads_var = icv->nthreads_var;
   gomp_init_task (thr->task, task, icv);
   team->implicit_task[0].icv.nthreads_var = nthreads_var;
+  team->implicit_task[0].taskgroup = taskgroup;
 
   if (nthreads == 1)
     return;
@@ -166,6 +168,7 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
       nthr->task = &team->implicit_task[i];
       gomp_init_task (nthr->task, task, icv);
       team->implicit_task[i].icv.nthreads_var = nthreads_var;
+      team->implicit_task[i].taskgroup = taskgroup;
       nthr->fn = fn;
       nthr->data = data;
       team->ordered_release[i] = &nthr->release;
@@ -174,5 +177,11 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
   gomp_simple_barrier_wait (&pool->threads_dock);
 }
 
+int
+gomp_pause_host (void)
+{
+  return -1;
+}
+
 #include "../../team.c"
 #endif
diff --git a/libgomp/config/nvptx/teams.c b/libgomp/config/nvptx/teams.c
new file mode 100644 (file)
index 0000000..9bed032
--- /dev/null
@@ -0,0 +1,57 @@
+/* Copyright (C) 2015-2018 Free Software Foundation, Inc.
+   Contributed by Alexander Monakov <amonakov@ispras.ru>
+
+   This file is part of the GNU Offloading and Multi Processing Library
+   (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* This file defines OpenMP API entry points that accelerator targets are
+   expected to replace.  */
+
+#include "libgomp.h"
+
+void
+GOMP_teams_reg (void (*fn) (void *), void *data, unsigned int num_teams,
+               unsigned int thread_limit, unsigned int flags)
+{
+  (void) fn;
+  (void) data;
+  (void) flags;
+  (void) num_teams;
+  (void) thread_limit;
+}
+
+int
+omp_get_num_teams (void)
+{
+  return gomp_num_teams_var + 1;
+}
+
+int
+omp_get_team_num (void)
+{
+  int ctaid;
+  asm ("mov.u32 %0, %%ctaid.x;" : "=r" (ctaid));
+  return ctaid;
+}
+
+ialias (omp_get_num_teams)
+ialias (omp_get_team_num)
index e56fa21cd943f6d31c0a0648464faf08a9e3ee1d..013e37c0ba5293fe88010b8a8e9d7fb87e72de54 100755 (executable)
@@ -15812,6 +15812,19 @@ _ACEOF
 fi
 done
 
+for ac_func in aligned_alloc posix_memalign memalign _aligned_malloc
+do :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+eval as_val=\$$as_ac_var
+   if test "x$as_val" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
 
 # Check for broken semaphore implementation on darwin.
 # sem_init returns: sem_init error: Function not implemented.
 
 fi
 
+# Check for uname.
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <string.h>
+   #include <stdlib.h>
+   #include <sys/utsname.h>
+int
+main ()
+{
+struct utsname buf;
+   volatile size_t len = 0;
+   if (!uname (buf))
+     len = strlen (buf.nodename);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+$as_echo "#define HAVE_UNAME 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+# Check for gethostname.
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <unistd.h>
+int
+main ()
+{
+
+   char buf[256];
+   if (gethostname (buf, sizeof (buf) - 1) == 0)
+     buf[255] = '\0';
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+$as_echo "#define HAVE_GETHOSTNAME 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+# Check for getpid.
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <unistd.h>
+int
+main ()
+{
+int pid = getpid ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+$as_echo "#define HAVE_GETPID 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
 # See if we support thread-local storage.
 
 
index e94edc76c295e30dd1d3f41b018bdd01a7d4e30c..f75c6226566cd8a8281f155e1112a155ff9c9697 100644 (file)
@@ -218,6 +218,7 @@ m4_include([plugin/configfrag.ac])
 
 # Check for functions needed.
 AC_CHECK_FUNCS(getloadavg clock_gettime strtoull)
+AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc)
 
 # Check for broken semaphore implementation on darwin.
 # sem_init returns: sem_init error: Function not implemented.
@@ -265,6 +266,41 @@ if test $ac_cv_func_clock_gettime = no; then
               [Define to 1 if you have the `clock_gettime' function.])])
 fi
 
+# Check for uname.
+AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+  [#include <string.h>
+   #include <stdlib.h>
+   #include <sys/utsname.h>],
+  [struct utsname buf;
+   volatile size_t len = 0;
+   if (!uname (buf))
+     len = strlen (buf.nodename);])],
+  AC_DEFINE(HAVE_UNAME, 1,
+[      Define if uname is supported and struct utsname has nodename field.]))
+
+# Check for gethostname.
+AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+  [#include <unistd.h>],
+  [
+changequote(,)dnl
+   char buf[256];
+   if (gethostname (buf, sizeof (buf) - 1) == 0)
+     buf[255] = '\0';
+changequote([,])dnl
+  ])],
+  AC_DEFINE(HAVE_GETHOSTNAME, 1,
+[      Define if gethostname is supported.]))
+
+# Check for getpid.
+AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+  [#include <unistd.h>],
+  [int pid = getpid ();])],
+  AC_DEFINE(HAVE_GETPID, 1,
+[      Define if getpid is supported.]))
+
 # See if we support thread-local storage.
 GCC_CHECK_TLS
 
index 74d95a570c7f295acbd25c069096266e450d0f15..b88bf72fe3de3735929635c874b8da375c841b1d 100644 (file)
@@ -18,7 +18,7 @@ if test $gcc_cv_have_tls = yes ; then
        ;;
 
     *-*-linux* | *-*-gnu*)
-       XCFLAGS="${XCFLAGS} -ftls-model=initial-exec"
+       XCFLAGS="${XCFLAGS} -ftls-model=initial-exec -DUSING_INITIAL_EXEC_TLS"
        ;;
 
     *-*-rtems*)
index 18c90bb09d096ae2207a6efe413e4fdcd55f8985..2c9a609d6072385f3c1b47bc2d97cee130fa4be8 100644 (file)
@@ -88,6 +88,9 @@ void **gomp_places_list;
 unsigned long gomp_places_list_len;
 int gomp_debug_var;
 unsigned int gomp_num_teams_var;
+bool gomp_display_affinity_var;
+char *gomp_affinity_format_var = "level %L thread %i affinity %A";
+size_t gomp_affinity_format_len;
 char *goacc_device_type;
 int goacc_device_num;
 int goacc_default_dims[GOMP_DIM_MAX];
@@ -101,6 +104,7 @@ parse_schedule (void)
 {
   char *env, *end;
   unsigned long value;
+  int monotonic = 0;
 
   env = getenv ("OMP_SCHEDULE");
   if (env == NULL)
@@ -108,6 +112,26 @@ parse_schedule (void)
 
   while (isspace ((unsigned char) *env))
     ++env;
+  if (strncasecmp (env, "monotonic", 9) == 0)
+    {
+      monotonic = 1;
+      env += 9;
+    }
+  else if (strncasecmp (env, "nonmonotonic", 12) == 0)
+    {
+      monotonic = -1;
+      env += 12;
+    }
+  if (monotonic)
+    {
+      while (isspace ((unsigned char) *env))
+       ++env;
+      if (*env != ':')
+       goto unknown;
+      ++env;
+      while (isspace ((unsigned char) *env))
+       ++env;
+    }
   if (strncasecmp (env, "static", 6) == 0)
     {
       gomp_global_icv.run_sched_var = GFS_STATIC;
@@ -131,12 +155,16 @@ parse_schedule (void)
   else
     goto unknown;
 
+  if (monotonic == 1
+      || (monotonic == 0 && gomp_global_icv.run_sched_var == GFS_STATIC))
+    gomp_global_icv.run_sched_var |= GFS_MONOTONIC;
+
   while (isspace ((unsigned char) *env))
     ++env;
   if (*env == '\0')
     {
       gomp_global_icv.run_sched_chunk_size
-       = gomp_global_icv.run_sched_var != GFS_STATIC;
+       = (gomp_global_icv.run_sched_var & ~GFS_MONOTONIC) != GFS_STATIC;
       return;
     }
   if (*env++ != ',')
@@ -159,7 +187,8 @@ parse_schedule (void)
   if ((int)value != value)
     goto invalid;
 
-  if (value == 0 && gomp_global_icv.run_sched_var != GFS_STATIC)
+  if (value == 0
+      && (gomp_global_icv.run_sched_var & ~GFS_MONOTONIC) != GFS_STATIC)
     value = 1;
   gomp_global_icv.run_sched_chunk_size = value;
   return;
@@ -1150,19 +1179,34 @@ handle_omp_display_env (unsigned long stacksize, int wait_policy)
   fputs ("'\n", stderr);
 
   fprintf (stderr, "  OMP_SCHEDULE = '");
-  switch (gomp_global_icv.run_sched_var)
+  if ((gomp_global_icv.run_sched_var & GFS_MONOTONIC))
+    {
+      if (gomp_global_icv.run_sched_var != (GFS_MONOTONIC | GFS_STATIC))
+       fputs ("MONOTONIC:", stderr);
+    }
+  else if (gomp_global_icv.run_sched_var == GFS_STATIC)
+    fputs ("NONMONOTONIC:", stderr);
+  switch (gomp_global_icv.run_sched_var & ~GFS_MONOTONIC)
     {
     case GFS_RUNTIME:
       fputs ("RUNTIME", stderr);
+      if (gomp_global_icv.run_sched_chunk_size != 1)
+       fprintf (stderr, ",%d", gomp_global_icv.run_sched_chunk_size);
       break;
     case GFS_STATIC:
       fputs ("STATIC", stderr);
+      if (gomp_global_icv.run_sched_chunk_size != 0)
+       fprintf (stderr, ",%d", gomp_global_icv.run_sched_chunk_size);
       break;
     case GFS_DYNAMIC:
       fputs ("DYNAMIC", stderr);
+      if (gomp_global_icv.run_sched_chunk_size != 1)
+       fprintf (stderr, ",%d", gomp_global_icv.run_sched_chunk_size);
       break;
     case GFS_GUIDED:
       fputs ("GUIDED", stderr);
+      if (gomp_global_icv.run_sched_chunk_size != 1)
+       fprintf (stderr, ",%d", gomp_global_icv.run_sched_chunk_size);
       break;
     case GFS_AUTO:
       fputs ("AUTO", stderr);
@@ -1228,6 +1272,10 @@ handle_omp_display_env (unsigned long stacksize, int wait_policy)
           gomp_global_icv.default_device_var);
   fprintf (stderr, "  OMP_MAX_TASK_PRIORITY = '%d'\n",
           gomp_max_task_priority_var);
+  fprintf (stderr, "  OMP_DISPLAY_AFFINITY = '%s'\n",
+          gomp_display_affinity_var ? "TRUE" : "FALSE");
+  fprintf (stderr, "  OMP_AFFINITY_FORMAT = '%s'\n",
+          gomp_affinity_format_var);
 
   if (verbose)
     {
@@ -1259,6 +1307,7 @@ initialize_env (void)
   parse_boolean ("OMP_DYNAMIC", &gomp_global_icv.dyn_var);
   parse_boolean ("OMP_NESTED", &gomp_global_icv.nest_var);
   parse_boolean ("OMP_CANCELLATION", &gomp_cancel_var);
+  parse_boolean ("OMP_DISPLAY_AFFINITY", &gomp_display_affinity_var);
   parse_int ("OMP_DEFAULT_DEVICE", &gomp_global_icv.default_device_var, true);
   parse_int ("OMP_MAX_TASK_PRIORITY", &gomp_max_task_priority_var, true);
   parse_unsigned_long ("OMP_MAX_ACTIVE_LEVELS", &gomp_max_active_levels_var,
@@ -1308,6 +1357,13 @@ initialize_env (void)
     }
   if (gomp_global_icv.bind_var != omp_proc_bind_false)
     gomp_init_affinity ();
+
+  {
+    const char *env = getenv ("OMP_AFFINITY_FORMAT");
+    if (env != NULL)
+      gomp_set_affinity_format (env, strlen (env));
+  }
+
   wait_policy = parse_wait_policy ();
   if (!parse_spincount ("GOMP_SPINCOUNT", &gomp_spin_count_var))
     {
@@ -1333,7 +1389,6 @@ initialize_env (void)
 
   /* Not strictly environment related, but ordering constructors is tricky.  */
   pthread_attr_init (&gomp_thread_attr);
-  pthread_attr_setdetachstate (&gomp_thread_attr, PTHREAD_CREATE_DETACHED);
 
   if (parse_stacksize ("OMP_STACKSIZE", &stacksize)
       || parse_stacksize ("GOMP_STACKSIZE", &stacksize)
index 24172a0f01ae1ee1201338bda4666e4ee9eb2762..0157baec648dbdb18ec2ac662d624c15ef909766 100644 (file)
@@ -28,6 +28,8 @@
 #include "libgomp.h"
 #include "libgomp_f.h"
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 #include <limits.h>
 
 #ifdef HAVE_ATTRIBUTE_ALIAS
@@ -82,6 +84,8 @@ ialias_redirect (omp_get_team_num)
 ialias_redirect (omp_is_initial_device)
 ialias_redirect (omp_get_initial_device)
 ialias_redirect (omp_get_max_task_priority)
+ialias_redirect (omp_pause_resource)
+ialias_redirect (omp_pause_resource_all)
 #endif
 
 #ifndef LIBGOMP_GNU_SYMBOL_VERSIONING
@@ -368,7 +372,9 @@ omp_get_schedule_ (int32_t *kind, int32_t *chunk_size)
   omp_sched_t k;
   int cs;
   omp_get_schedule (&k, &cs);
-  *kind = k;
+  /* For now mask off GFS_MONOTONIC, because OpenMP 4.5 code will not
+     expect to see it.  */
+  *kind = k & ~GFS_MONOTONIC;
   *chunk_size = cs;
 }
 
@@ -378,7 +384,8 @@ omp_get_schedule_8_ (int32_t *kind, int64_t *chunk_size)
   omp_sched_t k;
   int cs;
   omp_get_schedule (&k, &cs);
-  *kind = k;
+  /* See above.  */
+  *kind = k & ~GFS_MONOTONIC;
   *chunk_size = cs;
 }
 
@@ -576,3 +583,96 @@ omp_get_max_task_priority_ (void)
 {
   return omp_get_max_task_priority ();
 }
+
+void
+omp_set_affinity_format_ (const char *format, size_t format_len)
+{
+  gomp_set_affinity_format (format, format_len);
+}
+
+int32_t
+omp_get_affinity_format_ (char *buffer, size_t buffer_len)
+{
+  size_t len = strlen (gomp_affinity_format_var);
+  if (buffer_len)
+    {
+      if (len < buffer_len)
+       {
+         memcpy (buffer, gomp_affinity_format_var, len);
+         memset (buffer + len, ' ', buffer_len - len);
+       }
+      else
+       memcpy (buffer, gomp_affinity_format_var, buffer_len);
+    }
+  return len;
+}
+
+void
+omp_display_affinity_ (const char *format, size_t format_len)
+{
+  char *fmt = NULL, fmt_buf[256];
+  char buf[512];
+  if (format_len)
+    {
+      fmt = format_len < 256 ? fmt_buf : gomp_malloc (format_len + 1);
+      memcpy (fmt, format, format_len);
+      fmt[format_len] = '\0';
+    }
+  struct gomp_thread *thr = gomp_thread ();
+  size_t ret
+    = gomp_display_affinity (buf, sizeof buf,
+                            format_len ? fmt : gomp_affinity_format_var,
+                            gomp_thread_self (), &thr->ts, thr->place);
+  if (ret < sizeof buf)
+    {
+      buf[ret] = '\n';
+      fwrite (buf, 1, ret + 1, stderr);
+    }
+  else
+    {
+      char *b = gomp_malloc (ret + 1);
+      gomp_display_affinity (buf, sizeof buf,
+                            format_len ? fmt : gomp_affinity_format_var,
+                            gomp_thread_self (), &thr->ts, thr->place);
+      b[ret] = '\n';
+      fwrite (b, 1, ret + 1, stderr);
+      free (b);
+    }
+  if (fmt && fmt != fmt_buf)
+    free (fmt);
+}
+
+int32_t
+omp_capture_affinity_ (char *buffer, const char *format,
+                      size_t buffer_len, size_t format_len)
+{
+  char *fmt = NULL, fmt_buf[256];
+  if (format_len)
+    {
+      fmt = format_len < 256 ? fmt_buf : gomp_malloc (format_len + 1);
+      memcpy (fmt, format, format_len);
+      fmt[format_len] = '\0';
+    }
+  struct gomp_thread *thr = gomp_thread ();
+  size_t ret
+    = gomp_display_affinity (buffer, buffer_len,
+                            format_len ? fmt : gomp_affinity_format_var,
+                            gomp_thread_self (), &thr->ts, thr->place);
+  if (fmt && fmt != fmt_buf)
+    free (fmt);
+  if (ret < buffer_len)
+    memset (buffer + ret, ' ', buffer_len - ret);
+  return ret;
+}
+
+int32_t
+omp_pause_resource_ (const int32_t *kind, const int32_t *device_num)
+{
+  return omp_pause_resource (*kind, *device_num);
+}
+
+int32_t
+omp_pause_resource_all_ (const int32_t *kind)
+{
+  return omp_pause_resource_all (*kind);
+}
index b643cb29ee7653907e8e5f612dbaaae7465f9cc2..9cb394e74dced7bef1303f9aeec961ff9c0471a7 100644 (file)
@@ -48,20 +48,6 @@ omp_get_num_devices (void)
   return gomp_get_num_devices ();
 }
 
-int
-omp_get_num_teams (void)
-{
-  /* Hardcoded to 1 on host, MIC, HSAIL?  Maybe variable on PTX.  */
-  return 1;
-}
-
-int
-omp_get_team_num (void)
-{
-  /* Hardcoded to 0 on host, MIC, HSAIL?  Maybe variable on PTX.  */
-  return 0;
-}
-
 int
 omp_is_initial_device (void)
 {
@@ -72,6 +58,4 @@ omp_is_initial_device (void)
 ialias (omp_set_default_device)
 ialias (omp_get_default_device)
 ialias (omp_get_num_devices)
-ialias (omp_get_num_teams)
-ialias (omp_get_team_num)
 ialias (omp_is_initial_device)
index 42db4fe6c88bb2b9020d06a500e918b1c0f93b4e..68c400aec817eb0cc148d3dcfa8fe68a792e823e 100644 (file)
@@ -69,7 +69,7 @@ void
 omp_set_schedule (omp_sched_t kind, int chunk_size)
 {
   struct gomp_task_icv *icv = gomp_icv (true);
-  switch (kind)
+  switch (kind & ~omp_sched_monotonic)
     {
     case omp_sched_static:
       if (chunk_size < 1)
index 3a8cc2bd7d6e7f07eb755b81f1a500d0fa18da15..828e9b0095b3128998b10617ee637f4044535b65 100644 (file)
@@ -86,9 +86,21 @@ enum memmodel
 
 /* alloc.c */
 
+#if defined(HAVE_ALIGNED_ALLOC) \
+    || defined(HAVE__ALIGNED_MALLOC) \
+    || defined(HAVE_POSIX_MEMALIGN) \
+    || defined(HAVE_MEMALIGN)
+/* Defined if gomp_aligned_alloc doesn't use fallback version
+   and free can be used instead of gomp_aligned_free.  */
+#define GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC 1
+#endif
+
 extern void *gomp_malloc (size_t) __attribute__((malloc));
 extern void *gomp_malloc_cleared (size_t) __attribute__((malloc));
 extern void *gomp_realloc (void *, size_t);
+extern void *gomp_aligned_alloc (size_t, size_t)
+  __attribute__((malloc, alloc_size (2)));
+extern void gomp_aligned_free (void *);
 
 /* Avoid conflicting prototypes of alloca() in system headers by using
    GCC's builtin alloca().  */
@@ -138,7 +150,8 @@ enum gomp_schedule_type
   GFS_STATIC,
   GFS_DYNAMIC,
   GFS_GUIDED,
-  GFS_AUTO
+  GFS_AUTO,
+  GFS_MONOTONIC = 0x80000000U
 };
 
 struct gomp_doacross_work_share
@@ -175,6 +188,8 @@ struct gomp_doacross_work_share
     /* Likewise, but for the ull implementation.  */
     unsigned long long boundary_ull;
   };
+  /* Pointer to extra memory if needed for lastprivate(conditional).  */
+  void *extra;
   /* Array of shift counts for each dimension if they can be flattened.  */
   unsigned int shift_counts[];
 };
@@ -276,6 +291,9 @@ struct gomp_work_share
     struct gomp_work_share *next_free;
   };
 
+  /* Task reductions for this work-sharing construct.  */
+  uintptr_t *task_reductions;
+
   /* If only few threads are in the team, ordered_team_ids can point
      to this array which fills the padding at the end of this struct.  */
   unsigned inline_ordered_team_ids[0];
@@ -366,6 +384,9 @@ extern void **gomp_places_list;
 extern unsigned long gomp_places_list_len;
 extern unsigned int gomp_num_teams_var;
 extern int gomp_debug_var;
+extern bool gomp_display_affinity_var;
+extern char *gomp_affinity_format_var;
+extern size_t gomp_affinity_format_len;
 extern int goacc_device_num;
 extern char *goacc_device_type;
 extern int goacc_default_dims[GOMP_DIM_MAX];
@@ -471,8 +492,10 @@ struct gomp_taskgroup
   struct gomp_taskgroup *prev;
   /* Queue of tasks that belong in this taskgroup.  */
   struct priority_queue taskgroup_queue;
+  uintptr_t *reductions;
   bool in_taskgroup_wait;
   bool cancelled;
+  bool workshare;
   gomp_sem_t taskgroup_sem;
   size_t num_children;
 };
@@ -615,6 +638,19 @@ struct gomp_thread
 
   /* User pthread thread pool */
   struct gomp_thread_pool *thread_pool;
+
+#if defined(LIBGOMP_USE_PTHREADS) \
+    && (!defined(HAVE_TLS) \
+       || !defined(__GLIBC__) \
+       || !defined(USING_INITIAL_EXEC_TLS))
+  /* pthread_t of the thread containing this gomp_thread.
+     On Linux when using initial-exec TLS,
+     (typeof (pthread_t)) gomp_thread () - pthread_self ()
+     is constant in all threads, so we can optimize and not
+     store it.  */
+#define GOMP_NEEDS_THREAD_HANDLE 1
+  pthread_t handle;
+#endif
 };
 
 
@@ -711,6 +747,24 @@ extern bool gomp_affinity_finalize_place_list (bool);
 extern bool gomp_affinity_init_level (int, unsigned long, bool);
 extern void gomp_affinity_print_place (void *);
 extern void gomp_get_place_proc_ids_8 (int, int64_t *);
+extern void gomp_display_affinity_place (char *, size_t, size_t *, int);
+
+/* affinity-fmt.c */
+
+extern void gomp_set_affinity_format (const char *, size_t);
+extern void gomp_display_string (char *, size_t, size_t *, const char *,
+                                size_t);
+#ifdef LIBGOMP_USE_PTHREADS
+typedef pthread_t gomp_thread_handle;
+#else
+typedef struct {} gomp_thread_handle;
+#endif
+extern size_t gomp_display_affinity (char *, size_t, const char *,
+                                    gomp_thread_handle,
+                                    struct gomp_team_state *, unsigned int);
+extern void gomp_display_affinity_thread (gomp_thread_handle,
+                                         struct gomp_team_state *,
+                                         unsigned int) __attribute__((cold));
 
 /* iter.c */
 
@@ -747,9 +801,9 @@ extern void gomp_ordered_next (void);
 extern void gomp_ordered_static_init (void);
 extern void gomp_ordered_static_next (void);
 extern void gomp_ordered_sync (void);
-extern void gomp_doacross_init (unsigned, long *, long);
+extern void gomp_doacross_init (unsigned, long *, long, size_t);
 extern void gomp_doacross_ull_init (unsigned, unsigned long long *,
-                                   unsigned long long);
+                                   unsigned long long, size_t);
 
 /* parallel.c */
 
@@ -772,6 +826,10 @@ extern bool gomp_create_target_task (struct gomp_device_descr *,
                                     size_t *, unsigned short *, unsigned int,
                                     void **, void **,
                                     enum gomp_target_task_state);
+extern struct gomp_taskgroup *gomp_parallel_reduction_register (uintptr_t *,
+                                                               unsigned);
+extern void gomp_workshare_taskgroup_start (void);
+extern void gomp_workshare_task_reduction_register (uintptr_t *, uintptr_t *);
 
 static void inline
 gomp_finish_task (struct gomp_task *task)
@@ -784,9 +842,11 @@ gomp_finish_task (struct gomp_task *task)
 
 extern struct gomp_team *gomp_new_team (unsigned);
 extern void gomp_team_start (void (*) (void *), void *, unsigned,
-                            unsigned, struct gomp_team *);
+                            unsigned, struct gomp_team *,
+                            struct gomp_taskgroup *);
 extern void gomp_team_end (void);
 extern void gomp_free_thread (void *);
+extern int gomp_pause_host (void);
 
 /* target.c */
 
@@ -1009,9 +1069,9 @@ extern bool gomp_remove_var (struct gomp_device_descr *, splay_tree_key);
 
 /* work.c */
 
-extern void gomp_init_work_share (struct gomp_work_share *, bool, unsigned);
+extern void gomp_init_work_share (struct gomp_work_share *, size_t, unsigned);
 extern void gomp_fini_work_share (struct gomp_work_share *);
-extern bool gomp_work_share_start (bool);
+extern bool gomp_work_share_start (size_t);
 extern void gomp_work_share_end (void);
 extern bool gomp_work_share_end_cancel (void);
 extern void gomp_work_share_end_nowait (void);
@@ -1138,4 +1198,42 @@ task_to_priority_node (enum priority_queue_type type,
   return (struct priority_node *) ((char *) task
                                   + priority_queue_offset (type));
 }
+
+#ifdef LIBGOMP_USE_PTHREADS
+static inline gomp_thread_handle
+gomp_thread_self (void)
+{
+  return pthread_self ();
+}
+
+static inline gomp_thread_handle
+gomp_thread_to_pthread_t (struct gomp_thread *thr)
+{
+  struct gomp_thread *this_thr = gomp_thread ();
+  if (thr == this_thr)
+    return pthread_self ();
+#ifdef GOMP_NEEDS_THREAD_HANDLE
+  return thr->handle;
+#else
+  /* On Linux with initial-exec TLS, the pthread_t of the thread containing
+     thr can be computed from thr, this_thr and pthread_self (),
+     as the distance between this_thr and pthread_self () is constant.  */
+  return pthread_self () + ((uintptr_t) thr - (uintptr_t) this_thr);
+#endif
+}
+#else
+static inline gomp_thread_handle
+gomp_thread_self (void)
+{
+  return (gomp_thread_handle) {};
+}
+
+static inline gomp_thread_handle
+gomp_thread_to_pthread_t (struct gomp_thread *thr)
+{
+  (void) thr;
+  return gomp_thread_self ();
+}
+#endif
+
 #endif /* LIBGOMP_H */
index e3f0c648e45b37e674bddc97a73adc81945a1e3e..d8e2fd1818b9a754e6da75abd0661a23a9b99b85 100644 (file)
@@ -164,6 +164,22 @@ OMP_4.5 {
        omp_target_disassociate_ptr;
 } OMP_4.0;
 
+OMP_5.0 {
+  global:
+       omp_capture_affinity;
+       omp_capture_affinity_;
+       omp_display_affinity;
+       omp_display_affinity_;
+       omp_get_affinity_format;
+       omp_get_affinity_format_;
+       omp_set_affinity_format;
+       omp_set_affinity_format_;
+       omp_pause_resource;
+       omp_pause_resource_;
+       omp_pause_resource_all;
+       omp_pause_resource_all_;
+} OMP_4.5;
+
 GOMP_1.0 {
   global:
        GOMP_atomic_end;
@@ -298,6 +314,34 @@ GOMP_4.5 {
        GOMP_parallel_loop_nonmonotonic_guided;
 } GOMP_4.0.1;
 
+GOMP_5.0 {
+  global:
+       GOMP_loop_doacross_start;
+       GOMP_loop_maybe_nonmonotonic_runtime_next;
+       GOMP_loop_maybe_nonmonotonic_runtime_start;
+       GOMP_loop_nonmonotonic_runtime_next;
+       GOMP_loop_nonmonotonic_runtime_start;
+       GOMP_loop_ordered_start;
+       GOMP_loop_start;
+       GOMP_loop_ull_doacross_start;
+       GOMP_loop_ull_maybe_nonmonotonic_runtime_next;
+       GOMP_loop_ull_maybe_nonmonotonic_runtime_start;
+       GOMP_loop_ull_nonmonotonic_runtime_next;
+       GOMP_loop_ull_nonmonotonic_runtime_start;
+       GOMP_loop_ull_ordered_start;
+       GOMP_loop_ull_start;
+       GOMP_parallel_loop_maybe_nonmonotonic_runtime;
+       GOMP_parallel_loop_nonmonotonic_runtime;
+       GOMP_parallel_reductions;
+       GOMP_sections2_start;
+       GOMP_taskgroup_reduction_register;
+       GOMP_taskgroup_reduction_unregister;
+       GOMP_task_reduction_remap;
+       GOMP_taskwait_depend;
+       GOMP_teams_reg;
+       GOMP_workshare_task_reduction_unregister;
+} GOMP_4.5;
+
 OACC_2.0 {
   global:
        acc_get_num_devices;
index c99b5129f703f89ec393b98cf01db45ddb781fd4..5b54839b29e5aeb5bee5a71775c25790e01754a0 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <stdbool.h>
 #include <stddef.h>
+#include "gstdint.h"
 
 /* barrier.c */
 
@@ -56,6 +57,12 @@ extern bool GOMP_loop_nonmonotonic_dynamic_start (long, long, long, long,
                                                  long *, long *);
 extern bool GOMP_loop_nonmonotonic_guided_start (long, long, long, long,
                                                 long *, long *);
+extern bool GOMP_loop_nonmonotonic_runtime_start (long, long, long,
+                                                 long *, long *);
+extern bool GOMP_loop_maybe_nonmonotonic_runtime_start (long, long, long,
+                                                       long *, long *);
+extern bool GOMP_loop_start (long, long, long, long, long, long *, long *,
+                            uintptr_t *, void **);
 
 extern bool GOMP_loop_ordered_static_start (long, long, long, long,
                                            long *, long *);
@@ -64,6 +71,8 @@ extern bool GOMP_loop_ordered_dynamic_start (long, long, long, long,
 extern bool GOMP_loop_ordered_guided_start (long, long, long, long,
                                            long *, long *);
 extern bool GOMP_loop_ordered_runtime_start (long, long, long, long *, long *);
+extern bool GOMP_loop_ordered_start (long, long, long, long, long, long *,
+                                    long *, uintptr_t *, void **);
 
 extern bool GOMP_loop_static_next (long *, long *);
 extern bool GOMP_loop_dynamic_next (long *, long *);
@@ -71,6 +80,8 @@ extern bool GOMP_loop_guided_next (long *, long *);
 extern bool GOMP_loop_runtime_next (long *, long *);
 extern bool GOMP_loop_nonmonotonic_dynamic_next (long *, long *);
 extern bool GOMP_loop_nonmonotonic_guided_next (long *, long *);
+extern bool GOMP_loop_nonmonotonic_runtime_next (long *, long *);
+extern bool GOMP_loop_maybe_nonmonotonic_runtime_next (long *, long *);
 
 extern bool GOMP_loop_ordered_static_next (long *, long *);
 extern bool GOMP_loop_ordered_dynamic_next (long *, long *);
@@ -85,6 +96,8 @@ extern bool GOMP_loop_doacross_guided_start (unsigned, long *, long, long *,
                                             long *);
 extern bool GOMP_loop_doacross_runtime_start (unsigned, long *, long *,
                                              long *);
+extern bool GOMP_loop_doacross_start (unsigned, long *, long, long, long *,
+                                     long *, uintptr_t *, void **);
 
 extern void GOMP_parallel_loop_static_start (void (*)(void *), void *,
                                             unsigned, long, long, long, long);
@@ -112,6 +125,13 @@ extern void GOMP_parallel_loop_nonmonotonic_dynamic (void (*)(void *), void *,
 extern void GOMP_parallel_loop_nonmonotonic_guided (void (*)(void *), void *,
                                                    unsigned, long, long,
                                                    long, long, unsigned);
+extern void GOMP_parallel_loop_nonmonotonic_runtime (void (*)(void *), void *,
+                                                    unsigned, long, long,
+                                                    long, unsigned);
+extern void GOMP_parallel_loop_maybe_nonmonotonic_runtime (void (*)(void *),
+                                                          void *, unsigned,
+                                                          long, long,
+                                                          long, unsigned);
 
 extern void GOMP_loop_end (void);
 extern void GOMP_loop_end_nowait (void);
@@ -154,6 +174,21 @@ extern bool GOMP_loop_ull_nonmonotonic_guided_start (bool, unsigned long long,
                                                     unsigned long long,
                                                     unsigned long long *,
                                                     unsigned long long *);
+extern bool GOMP_loop_ull_nonmonotonic_runtime_start (bool, unsigned long long,
+                                                     unsigned long long,
+                                                     unsigned long long,
+                                                     unsigned long long *,
+                                                     unsigned long long *);
+extern bool GOMP_loop_ull_maybe_nonmonotonic_runtime_start (bool,
+                                                           unsigned long long,
+                                                           unsigned long long,
+                                                           unsigned long long,
+                                                           unsigned long long *,
+                                                           unsigned long long *);
+extern bool GOMP_loop_ull_start (bool, unsigned long long, unsigned long long,
+                                unsigned long long, long, unsigned long long,
+                                unsigned long long *, unsigned long long *,
+                                uintptr_t *, void **);
 
 extern bool GOMP_loop_ull_ordered_static_start (bool, unsigned long long,
                                                unsigned long long,
@@ -178,6 +213,13 @@ extern bool GOMP_loop_ull_ordered_runtime_start (bool, unsigned long long,
                                                 unsigned long long,
                                                 unsigned long long *,
                                                 unsigned long long *);
+extern bool GOMP_loop_ull_ordered_start (bool, unsigned long long,
+                                        unsigned long long,
+                                        unsigned long long, long,
+                                        unsigned long long,
+                                        unsigned long long *,
+                                        unsigned long long *,
+                                        uintptr_t *, void **);
 
 extern bool GOMP_loop_ull_static_next (unsigned long long *,
                                       unsigned long long *);
@@ -191,6 +233,10 @@ extern bool GOMP_loop_ull_nonmonotonic_dynamic_next (unsigned long long *,
                                                     unsigned long long *);
 extern bool GOMP_loop_ull_nonmonotonic_guided_next (unsigned long long *,
                                                    unsigned long long *);
+extern bool GOMP_loop_ull_nonmonotonic_runtime_next (unsigned long long *,
+                                                    unsigned long long *);
+extern bool GOMP_loop_ull_maybe_nonmonotonic_runtime_next (unsigned long long *,
+                                                          unsigned long long *);
 
 extern bool GOMP_loop_ull_ordered_static_next (unsigned long long *,
                                               unsigned long long *);
@@ -220,6 +266,11 @@ extern bool GOMP_loop_ull_doacross_runtime_start (unsigned,
                                                  unsigned long long *,
                                                  unsigned long long *,
                                                  unsigned long long *);
+extern bool GOMP_loop_ull_doacross_start (unsigned, unsigned long long *,
+                                         long, unsigned long long,
+                                         unsigned long long *,
+                                         unsigned long long *,
+                                         uintptr_t *, void **);
 
 /* ordered.c */
 
@@ -235,6 +286,8 @@ extern void GOMP_doacross_ull_wait (unsigned long long, ...);
 extern void GOMP_parallel_start (void (*) (void *), void *, unsigned);
 extern void GOMP_parallel_end (void);
 extern void GOMP_parallel (void (*) (void *), void *, unsigned, unsigned);
+extern unsigned GOMP_parallel_reductions (void (*) (void *), void *, unsigned,
+                                         unsigned);
 extern bool GOMP_cancel (int, bool);
 extern bool GOMP_cancellation_point (int);
 
@@ -251,13 +304,19 @@ extern void GOMP_taskloop_ull (void (*) (void *), void *,
                               unsigned long long, unsigned long long,
                               unsigned long long);
 extern void GOMP_taskwait (void);
+extern void GOMP_taskwait_depend (void **);
 extern void GOMP_taskyield (void);
 extern void GOMP_taskgroup_start (void);
 extern void GOMP_taskgroup_end (void);
+extern void GOMP_taskgroup_reduction_register (uintptr_t *);
+extern void GOMP_taskgroup_reduction_unregister (uintptr_t *);
+extern void GOMP_task_reduction_remap (size_t, size_t, void **);
+extern void GOMP_workshare_task_reduction_unregister (bool);
 
 /* sections.c */
 
 extern unsigned GOMP_sections_start (unsigned);
+extern unsigned GOMP_sections2_start (unsigned, uintptr_t *, void **);
 extern unsigned GOMP_sections_next (void);
 extern void GOMP_parallel_sections_start (void (*) (void *), void *,
                                          unsigned, unsigned);
@@ -293,6 +352,11 @@ extern void GOMP_target_enter_exit_data (int, size_t, void **, size_t *,
                                         void **);
 extern void GOMP_teams (unsigned int, unsigned int);
 
+/* teams.c */
+
+extern void GOMP_teams_reg (void (*) (void *), void *, unsigned, unsigned,
+                           unsigned);
+
 /* oacc-parallel.c */
 
 extern void GOACC_parallel_keyed (int, void (*) (void *), size_t,
index a8c7e246333ce50ea83f690e9a5dcf7482d607e4..4e0683ba675ad1a748efadbcb287f165d63a9235 100644 (file)
 
 #include <limits.h>
 #include <stdlib.h>
+#include <string.h>
 #include "libgomp.h"
 
 
+ialias (GOMP_loop_runtime_next)
+ialias_redirect (GOMP_taskgroup_reduction_register)
+
 /* Initialize the given work share construct from the given arguments.  */
 
 static inline void
@@ -79,12 +83,12 @@ gomp_loop_init (struct gomp_work_share *ws, long start, long end, long incr,
 }
 
 /* The *_start routines are called when first encountering a loop construct
-   that is not bound directly to a parallel construct.  The first thread 
+   that is not bound directly to a parallel construct.  The first thread
    that arrives will create the work-share construct; subsequent threads
    will see the construct exists and allocate work from it.
 
    START, END, INCR are the bounds of the loop; due to the restrictions of
-   OpenMP, these values must be the same in every thread.  This is not 
+   OpenMP, these values must be the same in every thread.  This is not
    verified (nor is it entirely verifiable, since START is not necessarily
    retained intact in the work-share data structure).  CHUNK_SIZE is the
    scheduling parameter; again this must be identical in all threads.
@@ -101,7 +105,7 @@ gomp_loop_static_start (long start, long end, long incr, long chunk_size,
   struct gomp_thread *thr = gomp_thread ();
 
   thr->ts.static_trip = 0;
-  if (gomp_work_share_start (false))
+  if (gomp_work_share_start (0))
     {
       gomp_loop_init (thr->ts.work_share, start, end, incr,
                      GFS_STATIC, chunk_size);
@@ -123,7 +127,7 @@ gomp_loop_dynamic_start (long start, long end, long incr, long chunk_size,
   struct gomp_thread *thr = gomp_thread ();
   bool ret;
 
-  if (gomp_work_share_start (false))
+  if (gomp_work_share_start (0))
     {
       gomp_loop_init (thr->ts.work_share, start, end, incr,
                      GFS_DYNAMIC, chunk_size);
@@ -151,7 +155,7 @@ gomp_loop_guided_start (long start, long end, long incr, long chunk_size,
   struct gomp_thread *thr = gomp_thread ();
   bool ret;
 
-  if (gomp_work_share_start (false))
+  if (gomp_work_share_start (0))
     {
       gomp_loop_init (thr->ts.work_share, start, end, incr,
                      GFS_GUIDED, chunk_size);
@@ -174,7 +178,7 @@ GOMP_loop_runtime_start (long start, long end, long incr,
                         long *istart, long *iend)
 {
   struct gomp_task_icv *icv = gomp_icv (false);
-  switch (icv->run_sched_var)
+  switch (icv->run_sched_var & ~GFS_MONOTONIC)
     {
     case GFS_STATIC:
       return gomp_loop_static_start (start, end, incr,
@@ -197,6 +201,100 @@ GOMP_loop_runtime_start (long start, long end, long incr,
     }
 }
 
+static long
+gomp_adjust_sched (long sched, long *chunk_size)
+{
+  sched &= ~GFS_MONOTONIC;
+  switch (sched)
+    {
+    case GFS_STATIC:
+    case GFS_DYNAMIC:
+    case GFS_GUIDED:
+      return sched;
+    /* GFS_RUNTIME is used for runtime schedule without monotonic
+       or nonmonotonic modifiers on the clause.
+       GFS_RUNTIME|GFS_MONOTONIC for runtime schedule with monotonic
+       modifier.  */
+    case GFS_RUNTIME:
+    /* GFS_AUTO is used for runtime schedule with nonmonotonic
+       modifier.  */
+    case GFS_AUTO:
+      {
+       struct gomp_task_icv *icv = gomp_icv (false);
+       sched = icv->run_sched_var & ~GFS_MONOTONIC;
+       switch (sched)
+         {
+         case GFS_STATIC:
+         case GFS_DYNAMIC:
+         case GFS_GUIDED:
+           *chunk_size = icv->run_sched_chunk_size;
+           break;
+         case GFS_AUTO:
+           sched = GFS_STATIC;
+           *chunk_size = 0;
+           break;
+         default:
+           abort ();
+         }
+       return sched;
+      }
+    default:
+      abort ();
+    }
+}
+
+bool
+GOMP_loop_start (long start, long end, long incr, long sched,
+                long chunk_size, long *istart, long *iend,
+                uintptr_t *reductions, void **mem)
+{
+  struct gomp_thread *thr = gomp_thread ();
+
+  thr->ts.static_trip = 0;
+  if (reductions)
+    gomp_workshare_taskgroup_start ();
+  if (gomp_work_share_start (0))
+    {
+      sched = gomp_adjust_sched (sched, &chunk_size);
+      gomp_loop_init (thr->ts.work_share, start, end, incr,
+                     sched, chunk_size);
+      if (reductions)
+       {
+         GOMP_taskgroup_reduction_register (reductions);
+         thr->task->taskgroup->workshare = true;
+         thr->ts.work_share->task_reductions = reductions;
+       }
+      if (mem)
+       {
+         uintptr_t size = (uintptr_t) *mem;
+         if (size > (sizeof (struct gomp_work_share)
+                     - offsetof (struct gomp_work_share,
+                                 inline_ordered_team_ids)))
+           thr->ts.work_share->ordered_team_ids
+             = gomp_malloc_cleared (size);
+         else
+           memset (thr->ts.work_share->ordered_team_ids, '\0', size);
+         *mem = (void *) thr->ts.work_share->ordered_team_ids;
+       }
+      gomp_work_share_init_done ();
+    }
+  else
+    {
+      if (reductions)
+       {
+         uintptr_t *first_reductions = thr->ts.work_share->task_reductions;
+         gomp_workshare_task_reduction_register (reductions,
+                                                 first_reductions);
+       }
+      if (mem)
+       *mem = (void *) thr->ts.work_share->ordered_team_ids;
+    }
+
+  if (!istart)
+    return true;
+  return ialias_call (GOMP_loop_runtime_next) (istart, iend);
+}
+
 /* The *_ordered_*_start routines are similar.  The only difference is that
    this work-share construct is initialized to expect an ORDERED section.  */
 
@@ -207,7 +305,7 @@ gomp_loop_ordered_static_start (long start, long end, long incr,
   struct gomp_thread *thr = gomp_thread ();
 
   thr->ts.static_trip = 0;
-  if (gomp_work_share_start (true))
+  if (gomp_work_share_start (1))
     {
       gomp_loop_init (thr->ts.work_share, start, end, incr,
                      GFS_STATIC, chunk_size);
@@ -225,7 +323,7 @@ gomp_loop_ordered_dynamic_start (long start, long end, long incr,
   struct gomp_thread *thr = gomp_thread ();
   bool ret;
 
-  if (gomp_work_share_start (true))
+  if (gomp_work_share_start (1))
     {
       gomp_loop_init (thr->ts.work_share, start, end, incr,
                      GFS_DYNAMIC, chunk_size);
@@ -250,7 +348,7 @@ gomp_loop_ordered_guided_start (long start, long end, long incr,
   struct gomp_thread *thr = gomp_thread ();
   bool ret;
 
-  if (gomp_work_share_start (true))
+  if (gomp_work_share_start (1))
     {
       gomp_loop_init (thr->ts.work_share, start, end, incr,
                      GFS_GUIDED, chunk_size);
@@ -273,7 +371,7 @@ GOMP_loop_ordered_runtime_start (long start, long end, long incr,
                                 long *istart, long *iend)
 {
   struct gomp_task_icv *icv = gomp_icv (false);
-  switch (icv->run_sched_var)
+  switch (icv->run_sched_var & ~GFS_MONOTONIC)
     {
     case GFS_STATIC:
       return gomp_loop_ordered_static_start (start, end, incr,
@@ -297,6 +395,81 @@ GOMP_loop_ordered_runtime_start (long start, long end, long incr,
     }
 }
 
+bool
+GOMP_loop_ordered_start (long start, long end, long incr, long sched,
+                        long chunk_size, long *istart, long *iend,
+                        uintptr_t *reductions, void **mem)
+{
+  struct gomp_thread *thr = gomp_thread ();
+  size_t ordered = 1;
+  bool ret;
+
+  thr->ts.static_trip = 0;
+  if (reductions)
+    gomp_workshare_taskgroup_start ();
+  if (mem)
+    ordered += (uintptr_t) *mem;
+  if (gomp_work_share_start (ordered))
+    {
+      sched = gomp_adjust_sched (sched, &chunk_size);
+      gomp_loop_init (thr->ts.work_share, start, end, incr,
+                     sched, chunk_size);
+      if (reductions)
+       {
+         GOMP_taskgroup_reduction_register (reductions);
+         thr->task->taskgroup->workshare = true;
+         thr->ts.work_share->task_reductions = reductions;
+       }
+      if (sched == GFS_STATIC)
+       gomp_ordered_static_init ();
+      else
+       gomp_mutex_lock (&thr->ts.work_share->lock);
+      gomp_work_share_init_done ();
+    }
+  else
+    {
+      if (reductions)
+       {
+         uintptr_t *first_reductions = thr->ts.work_share->task_reductions;
+         gomp_workshare_task_reduction_register (reductions,
+                                                 first_reductions);
+       }
+      sched = thr->ts.work_share->sched;
+      if (sched != GFS_STATIC)
+       gomp_mutex_lock (&thr->ts.work_share->lock);
+    }
+
+  if (mem)
+    {
+      uintptr_t p
+       = (uintptr_t) (thr->ts.work_share->ordered_team_ids
+                      + (thr->ts.team ? thr->ts.team->nthreads : 1));
+      p += __alignof__ (long long) - 1;
+      p &= ~(__alignof__ (long long) - 1);
+      *mem = (void *) p;
+    }
+
+  switch (sched)
+    {
+    case GFS_STATIC:
+    case GFS_AUTO:
+      return !gomp_iter_static_next (istart, iend);
+    case GFS_DYNAMIC:
+      ret = gomp_iter_dynamic_next_locked (istart, iend);
+      break;
+    case GFS_GUIDED:
+      ret = gomp_iter_guided_next_locked (istart, iend);
+      break;
+    default:
+      abort ();
+    }
+
+  if (ret)
+    gomp_ordered_first ();
+  gomp_mutex_unlock (&thr->ts.work_share->lock);
+  return ret;
+}
+
 /* The *_doacross_*_start routines are similar.  The only difference is that
    this work-share construct is initialized to expect an ORDERED(N) - DOACROSS
    section, and the worksharing loop iterates always from 0 to COUNTS[0] - 1
@@ -310,11 +483,11 @@ gomp_loop_doacross_static_start (unsigned ncounts, long *counts,
   struct gomp_thread *thr = gomp_thread ();
 
   thr->ts.static_trip = 0;
-  if (gomp_work_share_start (false))
+  if (gomp_work_share_start (0))
     {
       gomp_loop_init (thr->ts.work_share, 0, counts[0], 1,
                      GFS_STATIC, chunk_size);
-      gomp_doacross_init (ncounts, counts, chunk_size);
+      gomp_doacross_init (ncounts, counts, chunk_size, 0);
       gomp_work_share_init_done ();
     }
 
@@ -328,11 +501,11 @@ gomp_loop_doacross_dynamic_start (unsigned ncounts, long *counts,
   struct gomp_thread *thr = gomp_thread ();
   bool ret;
 
-  if (gomp_work_share_start (false))
+  if (gomp_work_share_start (0))
     {
       gomp_loop_init (thr->ts.work_share, 0, counts[0], 1,
                      GFS_DYNAMIC, chunk_size);
-      gomp_doacross_init (ncounts, counts, chunk_size);
+      gomp_doacross_init (ncounts, counts, chunk_size, 0);
       gomp_work_share_init_done ();
     }
 
@@ -354,11 +527,11 @@ gomp_loop_doacross_guided_start (unsigned ncounts, long *counts,
   struct gomp_thread *thr = gomp_thread ();
   bool ret;
 
-  if (gomp_work_share_start (false))
+  if (gomp_work_share_start (0))
     {
       gomp_loop_init (thr->ts.work_share, 0, counts[0], 1,
                      GFS_GUIDED, chunk_size);
-      gomp_doacross_init (ncounts, counts, chunk_size);
+      gomp_doacross_init (ncounts, counts, chunk_size, 0);
       gomp_work_share_init_done ();
     }
 
@@ -378,7 +551,7 @@ GOMP_loop_doacross_runtime_start (unsigned ncounts, long *counts,
                                  long *istart, long *iend)
 {
   struct gomp_task_icv *icv = gomp_icv (false);
-  switch (icv->run_sched_var)
+  switch (icv->run_sched_var & ~GFS_MONOTONIC)
     {
     case GFS_STATIC:
       return gomp_loop_doacross_static_start (ncounts, counts,
@@ -402,8 +575,52 @@ GOMP_loop_doacross_runtime_start (unsigned ncounts, long *counts,
     }
 }
 
-/* The *_next routines are called when the thread completes processing of 
-   the iteration block currently assigned to it.  If the work-share 
+bool
+GOMP_loop_doacross_start (unsigned ncounts, long *counts, long sched,
+                         long chunk_size, long *istart, long *iend,
+                         uintptr_t *reductions, void **mem)
+{
+  struct gomp_thread *thr = gomp_thread ();
+
+  thr->ts.static_trip = 0;
+  if (reductions)
+    gomp_workshare_taskgroup_start ();
+  if (gomp_work_share_start (0))
+    {
+      size_t extra = 0;
+      if (mem)
+       extra = (uintptr_t) *mem;
+      sched = gomp_adjust_sched (sched, &chunk_size);
+      gomp_loop_init (thr->ts.work_share, 0, counts[0], 1,
+                     sched, chunk_size);
+      gomp_doacross_init (ncounts, counts, chunk_size, extra);
+      if (reductions)
+       {
+         GOMP_taskgroup_reduction_register (reductions);
+         thr->task->taskgroup->workshare = true;
+         thr->ts.work_share->task_reductions = reductions;
+       }
+      gomp_work_share_init_done ();
+    }
+  else
+    {
+      if (reductions)
+       {
+         uintptr_t *first_reductions = thr->ts.work_share->task_reductions;
+         gomp_workshare_task_reduction_register (reductions,
+                                                 first_reductions);
+       }
+      sched = thr->ts.work_share->sched;
+    }
+
+  if (mem)
+    *mem = thr->ts.work_share->doacross->extra;
+
+  return ialias_call (GOMP_loop_runtime_next) (istart, iend);
+}
+
+/* The *_next routines are called when the thread completes processing of
+   the iteration block currently assigned to it.  If the work-share
    construct is bound directly to a parallel construct, then the iteration
    bounds may have been set up before the parallel.  In which case, this
    may be the first iteration for the thread.
@@ -456,7 +673,7 @@ bool
 GOMP_loop_runtime_next (long *istart, long *iend)
 {
   struct gomp_thread *thr = gomp_thread ();
-  
+
   switch (thr->ts.work_share->sched)
     {
     case GFS_STATIC:
@@ -534,7 +751,7 @@ bool
 GOMP_loop_ordered_runtime_next (long *istart, long *iend)
 {
   struct gomp_thread *thr = gomp_thread ();
-  
+
   switch (thr->ts.work_share->sched)
     {
     case GFS_STATIC:
@@ -563,7 +780,7 @@ gomp_parallel_loop_start (void (*fn) (void *), void *data,
   num_threads = gomp_resolve_num_threads (num_threads, 0);
   team = gomp_new_team (num_threads);
   gomp_loop_init (&team->work_shares[0], start, end, incr, sched, chunk_size);
-  gomp_team_start (fn, data, num_threads, flags, team);
+  gomp_team_start (fn, data, num_threads, flags, team, NULL);
 }
 
 void
@@ -600,7 +817,8 @@ GOMP_parallel_loop_runtime_start (void (*fn) (void *), void *data,
 {
   struct gomp_task_icv *icv = gomp_icv (false);
   gomp_parallel_loop_start (fn, data, num_threads, start, end, incr,
-                           icv->run_sched_var, icv->run_sched_chunk_size, 0);
+                           icv->run_sched_var & ~GFS_MONOTONIC,
+                           icv->run_sched_chunk_size, 0);
 }
 
 ialias_redirect (GOMP_parallel_end)
@@ -638,11 +856,28 @@ GOMP_parallel_loop_guided (void (*fn) (void *), void *data,
   GOMP_parallel_end ();
 }
 
+void
+GOMP_parallel_loop_runtime (void (*fn) (void *), void *data,
+                           unsigned num_threads, long start, long end,
+                           long incr, unsigned flags)
+{
+  struct gomp_task_icv *icv = gomp_icv (false);
+  gomp_parallel_loop_start (fn, data, num_threads, start, end, incr,
+                           icv->run_sched_var & ~GFS_MONOTONIC,
+                           icv->run_sched_chunk_size, flags);
+  fn (data);
+  GOMP_parallel_end ();
+}
+
 #ifdef HAVE_ATTRIBUTE_ALIAS
 extern __typeof(GOMP_parallel_loop_dynamic) GOMP_parallel_loop_nonmonotonic_dynamic
        __attribute__((alias ("GOMP_parallel_loop_dynamic")));
 extern __typeof(GOMP_parallel_loop_guided) GOMP_parallel_loop_nonmonotonic_guided
        __attribute__((alias ("GOMP_parallel_loop_guided")));
+extern __typeof(GOMP_parallel_loop_runtime) GOMP_parallel_loop_nonmonotonic_runtime
+       __attribute__((alias ("GOMP_parallel_loop_runtime")));
+extern __typeof(GOMP_parallel_loop_runtime) GOMP_parallel_loop_maybe_nonmonotonic_runtime
+       __attribute__((alias ("GOMP_parallel_loop_runtime")));
 #else
 void
 GOMP_parallel_loop_nonmonotonic_dynamic (void (*fn) (void *), void *data,
@@ -667,21 +902,35 @@ GOMP_parallel_loop_nonmonotonic_guided (void (*fn) (void *), void *data,
   fn (data);
   GOMP_parallel_end ();
 }
-#endif
 
 void
-GOMP_parallel_loop_runtime (void (*fn) (void *), void *data,
-                           unsigned num_threads, long start, long end,
-                           long incr, unsigned flags)
+GOMP_parallel_loop_nonmonotonic_runtime (void (*fn) (void *), void *data,
+                                        unsigned num_threads, long start,
+                                        long end, long incr, unsigned flags)
 {
   struct gomp_task_icv *icv = gomp_icv (false);
   gomp_parallel_loop_start (fn, data, num_threads, start, end, incr,
-                           icv->run_sched_var, icv->run_sched_chunk_size,
-                           flags);
+                           icv->run_sched_var & ~GFS_MONOTONIC,
+                           icv->run_sched_chunk_size, flags);
   fn (data);
   GOMP_parallel_end ();
 }
 
+void
+GOMP_parallel_loop_maybe_nonmonotonic_runtime (void (*fn) (void *), void *data,
+                                              unsigned num_threads, long start,
+                                              long end, long incr,
+                                              unsigned flags)
+{
+  struct gomp_task_icv *icv = gomp_icv (false);
+  gomp_parallel_loop_start (fn, data, num_threads, start, end, incr,
+                           icv->run_sched_var & ~GFS_MONOTONIC,
+                           icv->run_sched_chunk_size, flags);
+  fn (data);
+  GOMP_parallel_end ();
+}
+#endif
+
 /* The GOMP_loop_end* routines are called after the thread is told that
    all loop iterations are complete.  The first two versions synchronize
    all threads; the nowait version does not.  */
@@ -721,6 +970,10 @@ extern __typeof(gomp_loop_dynamic_start) GOMP_loop_nonmonotonic_dynamic_start
        __attribute__((alias ("gomp_loop_dynamic_start")));
 extern __typeof(gomp_loop_guided_start) GOMP_loop_nonmonotonic_guided_start
        __attribute__((alias ("gomp_loop_guided_start")));
+extern __typeof(GOMP_loop_runtime_start) GOMP_loop_nonmonotonic_runtime_start
+       __attribute__((alias ("GOMP_loop_runtime_start")));
+extern __typeof(GOMP_loop_runtime_start) GOMP_loop_maybe_nonmonotonic_runtime_start
+       __attribute__((alias ("GOMP_loop_runtime_start")));
 
 extern __typeof(gomp_loop_ordered_static_start) GOMP_loop_ordered_static_start
        __attribute__((alias ("gomp_loop_ordered_static_start")));
@@ -746,6 +999,10 @@ extern __typeof(gomp_loop_dynamic_next) GOMP_loop_nonmonotonic_dynamic_next
        __attribute__((alias ("gomp_loop_dynamic_next")));
 extern __typeof(gomp_loop_guided_next) GOMP_loop_nonmonotonic_guided_next
        __attribute__((alias ("gomp_loop_guided_next")));
+extern __typeof(GOMP_loop_runtime_next) GOMP_loop_nonmonotonic_runtime_next
+       __attribute__((alias ("GOMP_loop_runtime_next")));
+extern __typeof(GOMP_loop_runtime_next) GOMP_loop_maybe_nonmonotonic_runtime_next
+       __attribute__((alias ("GOMP_loop_runtime_next")));
 
 extern __typeof(gomp_loop_ordered_static_next) GOMP_loop_ordered_static_next
        __attribute__((alias ("gomp_loop_ordered_static_next")));
@@ -790,6 +1047,20 @@ GOMP_loop_nonmonotonic_guided_start (long start, long end, long incr,
   return gomp_loop_guided_start (start, end, incr, chunk_size, istart, iend);
 }
 
+bool
+GOMP_loop_nonmonotonic_runtime_start (long start, long end, long incr,
+                                     long *istart, long *iend)
+{
+  return GOMP_loop_runtime_start (start, end, incr, istart, iend);
+}
+
+bool
+GOMP_loop_maybe_nonmonotonic_runtime_start (long start, long end, long incr,
+                                           long *istart, long *iend)
+{
+  return GOMP_loop_runtime_start (start, end, incr, istart, iend);
+}
+
 bool
 GOMP_loop_ordered_static_start (long start, long end, long incr,
                                long chunk_size, long *istart, long *iend)
@@ -868,6 +1139,18 @@ GOMP_loop_nonmonotonic_guided_next (long *istart, long *iend)
   return gomp_loop_guided_next (istart, iend);
 }
 
+bool
+GOMP_loop_nonmonotonic_runtime_next (long *istart, long *iend)
+{
+  return GOMP_loop_runtime_next (istart, iend);
+}
+
+bool
+GOMP_loop_maybe_nonmonotonic_runtime_next (long *istart, long *iend)
+{
+  return GOMP_loop_runtime_next (istart, iend);
+}
+
 bool
 GOMP_loop_ordered_static_next (long *istart, long *iend)
 {
index 3d4ac994f0a9bedef07241d9f2e2bbb2bba2fb9f..ac658023e13baba57575479673f1a8d67e156818 100644 (file)
 
 #include <limits.h>
 #include <stdlib.h>
+#include <string.h>
 #include "libgomp.h"
 
+ialias (GOMP_loop_ull_runtime_next)
+ialias_redirect (GOMP_taskgroup_reduction_register)
+
 typedef unsigned long long gomp_ull;
 
 /* Initialize the given work share construct from the given arguments.  */
@@ -104,7 +108,7 @@ gomp_loop_ull_static_start (bool up, gomp_ull start, gomp_ull end,
   struct gomp_thread *thr = gomp_thread ();
 
   thr->ts.static_trip = 0;
-  if (gomp_work_share_start (false))
+  if (gomp_work_share_start (0))
     {
       gomp_loop_ull_init (thr->ts.work_share, up, start, end, incr,
                          GFS_STATIC, chunk_size);
@@ -122,7 +126,7 @@ gomp_loop_ull_dynamic_start (bool up, gomp_ull start, gomp_ull end,
   struct gomp_thread *thr = gomp_thread ();
   bool ret;
 
-  if (gomp_work_share_start (false))
+  if (gomp_work_share_start (0))
     {
       gomp_loop_ull_init (thr->ts.work_share, up, start, end, incr,
                          GFS_DYNAMIC, chunk_size);
@@ -148,7 +152,7 @@ gomp_loop_ull_guided_start (bool up, gomp_ull start, gomp_ull end,
   struct gomp_thread *thr = gomp_thread ();
   bool ret;
 
-  if (gomp_work_share_start (false))
+  if (gomp_work_share_start (0))
     {
       gomp_loop_ull_init (thr->ts.work_share, up, start, end, incr,
                          GFS_GUIDED, chunk_size);
@@ -171,7 +175,7 @@ GOMP_loop_ull_runtime_start (bool up, gomp_ull start, gomp_ull end,
                             gomp_ull incr, gomp_ull *istart, gomp_ull *iend)
 {
   struct gomp_task_icv *icv = gomp_icv (false);
-  switch (icv->run_sched_var)
+  switch (icv->run_sched_var & ~GFS_MONOTONIC)
     {
     case GFS_STATIC:
       return gomp_loop_ull_static_start (up, start, end, incr,
@@ -195,6 +199,99 @@ GOMP_loop_ull_runtime_start (bool up, gomp_ull start, gomp_ull end,
     }
 }
 
+static long
+gomp_adjust_sched (long sched, gomp_ull *chunk_size)
+{
+  sched &= ~GFS_MONOTONIC;
+  switch (sched)
+    {
+    case GFS_STATIC:
+    case GFS_DYNAMIC:
+    case GFS_GUIDED:
+      return sched;
+    /* GFS_RUNTIME is used for runtime schedule without monotonic
+       or nonmonotonic modifiers on the clause.
+       GFS_RUNTIME|GFS_MONOTONIC for runtime schedule with monotonic
+       modifier.  */
+    case GFS_RUNTIME:
+    /* GFS_AUTO is used for runtime schedule with nonmonotonic
+       modifier.  */
+    case GFS_AUTO:
+      {
+       struct gomp_task_icv *icv = gomp_icv (false);
+       sched = icv->run_sched_var & ~GFS_MONOTONIC;
+       switch (sched)
+         {
+         case GFS_STATIC:
+         case GFS_DYNAMIC:
+         case GFS_GUIDED:
+           *chunk_size = icv->run_sched_chunk_size;
+           break;
+         case GFS_AUTO:
+           sched = GFS_STATIC;
+           *chunk_size = 0;
+           break;
+         default:
+           abort ();
+         }
+       return sched;
+      }
+    default:
+      abort ();
+    }
+}
+
+bool
+GOMP_loop_ull_start (bool up, gomp_ull start, gomp_ull end,
+                    gomp_ull incr, long sched, gomp_ull chunk_size,
+                    gomp_ull *istart, gomp_ull *iend,
+                    uintptr_t *reductions, void **mem)
+{
+  struct gomp_thread *thr = gomp_thread ();
+
+  thr->ts.static_trip = 0;
+  if (reductions)
+    gomp_workshare_taskgroup_start ();
+  if (gomp_work_share_start (0))
+    {
+      sched = gomp_adjust_sched (sched, &chunk_size);
+      gomp_loop_ull_init (thr->ts.work_share, up, start, end, incr,
+                         sched, chunk_size);
+      if (reductions)
+       {
+         GOMP_taskgroup_reduction_register (reductions);
+         thr->task->taskgroup->workshare = true;
+         thr->ts.work_share->task_reductions = reductions;
+       }
+      if (mem)
+       {
+         uintptr_t size = (uintptr_t) *mem;
+         if (size > (sizeof (struct gomp_work_share)
+                     - offsetof (struct gomp_work_share,
+                                 inline_ordered_team_ids)))
+           thr->ts.work_share->ordered_team_ids
+             = gomp_malloc_cleared (size);
+         else
+           memset (thr->ts.work_share->ordered_team_ids, '\0', size);
+         *mem = (void *) thr->ts.work_share->ordered_team_ids;
+       }
+      gomp_work_share_init_done ();
+    }
+  else
+    {
+      if (reductions)
+       {
+         uintptr_t *first_reductions = thr->ts.work_share->task_reductions;
+         gomp_workshare_task_reduction_register (reductions,
+                                                 first_reductions);
+       }
+      if (mem)
+       *mem = (void *) thr->ts.work_share->ordered_team_ids;
+    }
+
+  return ialias_call (GOMP_loop_ull_runtime_next) (istart, iend);
+}
+
 /* The *_ordered_*_start routines are similar.  The only difference is that
    this work-share construct is initialized to expect an ORDERED section.  */
 
@@ -206,7 +303,7 @@ gomp_loop_ull_ordered_static_start (bool up, gomp_ull start, gomp_ull end,
   struct gomp_thread *thr = gomp_thread ();
 
   thr->ts.static_trip = 0;
-  if (gomp_work_share_start (true))
+  if (gomp_work_share_start (1))
     {
       gomp_loop_ull_init (thr->ts.work_share, up, start, end, incr,
                          GFS_STATIC, chunk_size);
@@ -225,7 +322,7 @@ gomp_loop_ull_ordered_dynamic_start (bool up, gomp_ull start, gomp_ull end,
   struct gomp_thread *thr = gomp_thread ();
   bool ret;
 
-  if (gomp_work_share_start (true))
+  if (gomp_work_share_start (1))
     {
       gomp_loop_ull_init (thr->ts.work_share, up, start, end, incr,
                          GFS_DYNAMIC, chunk_size);
@@ -251,7 +348,7 @@ gomp_loop_ull_ordered_guided_start (bool up, gomp_ull start, gomp_ull end,
   struct gomp_thread *thr = gomp_thread ();
   bool ret;
 
-  if (gomp_work_share_start (true))
+  if (gomp_work_share_start (1))
     {
       gomp_loop_ull_init (thr->ts.work_share, up, start, end, incr,
                          GFS_GUIDED, chunk_size);
@@ -275,7 +372,7 @@ GOMP_loop_ull_ordered_runtime_start (bool up, gomp_ull start, gomp_ull end,
                                     gomp_ull *iend)
 {
   struct gomp_task_icv *icv = gomp_icv (false);
-  switch (icv->run_sched_var)
+  switch (icv->run_sched_var & ~GFS_MONOTONIC)
     {
     case GFS_STATIC:
       return gomp_loop_ull_ordered_static_start (up, start, end, incr,
@@ -299,6 +396,82 @@ GOMP_loop_ull_ordered_runtime_start (bool up, gomp_ull start, gomp_ull end,
     }
 }
 
+bool
+GOMP_loop_ull_ordered_start (bool up, gomp_ull start, gomp_ull end,
+                            gomp_ull incr, long sched, gomp_ull chunk_size,
+                            gomp_ull *istart, gomp_ull *iend,
+                            uintptr_t *reductions, void **mem)
+{
+  struct gomp_thread *thr = gomp_thread ();
+  size_t ordered = 1;
+  bool ret;
+
+  thr->ts.static_trip = 0;
+  if (reductions)
+    gomp_workshare_taskgroup_start ();
+  if (mem)
+    ordered += (uintptr_t) *mem;
+  if (gomp_work_share_start (ordered))
+    {
+      sched = gomp_adjust_sched (sched, &chunk_size);
+      gomp_loop_ull_init (thr->ts.work_share, up, start, end, incr,
+                         sched, chunk_size);
+      if (reductions)
+       {
+         GOMP_taskgroup_reduction_register (reductions);
+         thr->task->taskgroup->workshare = true;
+         thr->ts.work_share->task_reductions = reductions;
+       }
+      if (sched == GFS_STATIC)
+       gomp_ordered_static_init ();
+      else
+       gomp_mutex_lock (&thr->ts.work_share->lock);
+      gomp_work_share_init_done ();
+    }
+  else
+    {
+      if (reductions)
+       {
+         uintptr_t *first_reductions = thr->ts.work_share->task_reductions;
+         gomp_workshare_task_reduction_register (reductions,
+                                                 first_reductions);
+       }
+      sched = thr->ts.work_share->sched;
+      if (sched != GFS_STATIC)
+       gomp_mutex_lock (&thr->ts.work_share->lock);
+    }
+
+  if (mem)
+    {
+      uintptr_t p
+       = (uintptr_t) (thr->ts.work_share->ordered_team_ids
+                      + (thr->ts.team ? thr->ts.team->nthreads : 1));
+      p += __alignof__ (long long) - 1;
+      p &= ~(__alignof__ (long long) - 1);
+      *mem = (void *) p;
+    }
+
+  switch (sched)
+    {
+    case GFS_STATIC:
+    case GFS_AUTO:
+      return !gomp_iter_ull_static_next (istart, iend);
+    case GFS_DYNAMIC:
+      ret = gomp_iter_ull_dynamic_next_locked (istart, iend);
+      break;
+    case GFS_GUIDED:
+      ret = gomp_iter_ull_guided_next_locked (istart, iend);
+      break;
+    default:
+      abort ();
+    }
+
+  if (ret)
+    gomp_ordered_first ();
+  gomp_mutex_unlock (&thr->ts.work_share->lock);
+  return ret;
+}
+
 /* The *_doacross_*_start routines are similar.  The only difference is that
    this work-share construct is initialized to expect an ORDERED(N) - DOACROSS
    section, and the worksharing loop iterates always from 0 to COUNTS[0] - 1
@@ -313,11 +486,11 @@ gomp_loop_ull_doacross_static_start (unsigned ncounts, gomp_ull *counts,
   struct gomp_thread *thr = gomp_thread ();
 
   thr->ts.static_trip = 0;
-  if (gomp_work_share_start (false))
+  if (gomp_work_share_start (0))
     {
       gomp_loop_ull_init (thr->ts.work_share, true, 0, counts[0], 1,
                          GFS_STATIC, chunk_size);
-      gomp_doacross_ull_init (ncounts, counts, chunk_size);
+      gomp_doacross_ull_init (ncounts, counts, chunk_size, 0);
       gomp_work_share_init_done ();
     }
 
@@ -332,11 +505,11 @@ gomp_loop_ull_doacross_dynamic_start (unsigned ncounts, gomp_ull *counts,
   struct gomp_thread *thr = gomp_thread ();
   bool ret;
 
-  if (gomp_work_share_start (false))
+  if (gomp_work_share_start (0))
     {
       gomp_loop_ull_init (thr->ts.work_share, true, 0, counts[0], 1,
                          GFS_DYNAMIC, chunk_size);
-      gomp_doacross_ull_init (ncounts, counts, chunk_size);
+      gomp_doacross_ull_init (ncounts, counts, chunk_size, 0);
       gomp_work_share_init_done ();
     }
 
@@ -359,11 +532,11 @@ gomp_loop_ull_doacross_guided_start (unsigned ncounts, gomp_ull *counts,
   struct gomp_thread *thr = gomp_thread ();
   bool ret;
 
-  if (gomp_work_share_start (false))
+  if (gomp_work_share_start (0))
     {
       gomp_loop_ull_init (thr->ts.work_share, true, 0, counts[0], 1,
                          GFS_GUIDED, chunk_size);
-      gomp_doacross_ull_init (ncounts, counts, chunk_size);
+      gomp_doacross_ull_init (ncounts, counts, chunk_size, 0);
       gomp_work_share_init_done ();
     }
 
@@ -383,7 +556,7 @@ GOMP_loop_ull_doacross_runtime_start (unsigned ncounts, gomp_ull *counts,
                                      gomp_ull *istart, gomp_ull *iend)
 {
   struct gomp_task_icv *icv = gomp_icv (false);
-  switch (icv->run_sched_var)
+  switch (icv->run_sched_var & ~GFS_MONOTONIC)
     {
     case GFS_STATIC:
       return gomp_loop_ull_doacross_static_start (ncounts, counts,
@@ -407,6 +580,51 @@ GOMP_loop_ull_doacross_runtime_start (unsigned ncounts, gomp_ull *counts,
     }
 }
 
+bool
+GOMP_loop_ull_doacross_start (unsigned ncounts, gomp_ull *counts,
+                             long sched, gomp_ull chunk_size,
+                             gomp_ull *istart, gomp_ull *iend,
+                             uintptr_t *reductions, void **mem)
+{
+  struct gomp_thread *thr = gomp_thread ();
+
+  thr->ts.static_trip = 0;
+  if (reductions)
+    gomp_workshare_taskgroup_start ();
+  if (gomp_work_share_start (0))
+    {
+      size_t extra = 0;
+      if (mem)
+       extra = (uintptr_t) *mem;
+      sched = gomp_adjust_sched (sched, &chunk_size);
+      gomp_loop_ull_init (thr->ts.work_share, true, 0, counts[0], 1,
+                         sched, chunk_size);
+      gomp_doacross_ull_init (ncounts, counts, chunk_size, extra);
+      if (reductions)
+       {
+         GOMP_taskgroup_reduction_register (reductions);
+         thr->task->taskgroup->workshare = true;
+         thr->ts.work_share->task_reductions = reductions;
+       }
+      gomp_work_share_init_done ();
+    }
+  else
+    {
+      if (reductions)
+       {
+         uintptr_t *first_reductions = thr->ts.work_share->task_reductions;
+         gomp_workshare_task_reduction_register (reductions,
+                                                 first_reductions);
+       }
+      sched = thr->ts.work_share->sched;
+    }
+
+  if (mem)
+    *mem = thr->ts.work_share->doacross->extra;
+
+  return ialias_call (GOMP_loop_ull_runtime_next) (istart, iend);
+}
+
 /* The *_next routines are called when the thread completes processing of
    the iteration block currently assigned to it.  If the work-share
    construct is bound directly to a parallel construct, then the iteration
@@ -570,6 +788,10 @@ extern __typeof(gomp_loop_ull_dynamic_start) GOMP_loop_ull_nonmonotonic_dynamic_
        __attribute__((alias ("gomp_loop_ull_dynamic_start")));
 extern __typeof(gomp_loop_ull_guided_start) GOMP_loop_ull_nonmonotonic_guided_start
        __attribute__((alias ("gomp_loop_ull_guided_start")));
+extern __typeof(GOMP_loop_ull_runtime_start) GOMP_loop_ull_nonmonotonic_runtime_start
+       __attribute__((alias ("GOMP_loop_ull_runtime_start")));
+extern __typeof(GOMP_loop_ull_runtime_start) GOMP_loop_ull_maybe_nonmonotonic_runtime_start
+       __attribute__((alias ("GOMP_loop_ull_runtime_start")));
 
 extern __typeof(gomp_loop_ull_ordered_static_start) GOMP_loop_ull_ordered_static_start
        __attribute__((alias ("gomp_loop_ull_ordered_static_start")));
@@ -595,6 +817,10 @@ extern __typeof(gomp_loop_ull_dynamic_next) GOMP_loop_ull_nonmonotonic_dynamic_n
        __attribute__((alias ("gomp_loop_ull_dynamic_next")));
 extern __typeof(gomp_loop_ull_guided_next) GOMP_loop_ull_nonmonotonic_guided_next
        __attribute__((alias ("gomp_loop_ull_guided_next")));
+extern __typeof(GOMP_loop_ull_runtime_next) GOMP_loop_ull_nonmonotonic_runtime_next
+       __attribute__((alias ("GOMP_loop_ull_runtime_next")));
+extern __typeof(GOMP_loop_ull_runtime_next) GOMP_loop_ull_maybe_nonmonotonic_runtime_next
+       __attribute__((alias ("GOMP_loop_ull_runtime_next")));
 
 extern __typeof(gomp_loop_ull_ordered_static_next) GOMP_loop_ull_ordered_static_next
        __attribute__((alias ("gomp_loop_ull_ordered_static_next")));
@@ -649,6 +875,23 @@ GOMP_loop_ull_nonmonotonic_guided_start (bool up, gomp_ull start, gomp_ull end,
                                     iend);
 }
 
+bool
+GOMP_loop_ull_nonmonotonic_runtime_start (bool up, gomp_ull start,
+                                         gomp_ull end, gomp_ull incr,
+                                         gomp_ull *istart, gomp_ull *iend)
+{
+  return GOMP_loop_ull_runtime_start (up, start, end, incr, istart, iend);
+}
+
+bool
+GOMP_loop_ull_maybe_nonmonotonic_runtime_start (bool up, gomp_ull start,
+                                               gomp_ull end, gomp_ull incr,
+                                               gomp_ull *istart,
+                                               gomp_ull *iend)
+{
+  return GOMP_loop_ull_runtime_start (up, start, end, incr, istart, iend);
+}
+
 bool
 GOMP_loop_ull_ordered_static_start (bool up, gomp_ull start, gomp_ull end,
                                    gomp_ull incr, gomp_ull chunk_size,
@@ -733,6 +976,19 @@ GOMP_loop_ull_nonmonotonic_guided_next (gomp_ull *istart, gomp_ull *iend)
   return gomp_loop_ull_guided_next (istart, iend);
 }
 
+bool
+GOMP_loop_ull_nonmonotonic_runtime_next (gomp_ull *istart, gomp_ull *iend)
+{
+  return GOMP_loop_ull_runtime_next (istart, iend);
+}
+
+bool
+GOMP_loop_ull_maybe_nonmonotonic_runtime_next (gomp_ull *istart,
+                                              gomp_ull *iend)
+{
+  return GOMP_loop_ull_runtime_next (istart, iend);
+}
+
 bool
 GOMP_loop_ull_ordered_static_next (gomp_ull *istart, gomp_ull *iend)
 {
index 654a4d5f42b3cceecb66342fb7923c8067d3215e..a18303470c010ca18c7f4039525aad2e6da621dd 100644 (file)
@@ -50,7 +50,8 @@ typedef enum omp_sched_t
   omp_sched_static = 1,
   omp_sched_dynamic = 2,
   omp_sched_guided = 3,
-  omp_sched_auto = 4
+  omp_sched_auto = 4,
+  omp_sched_monotonic = 0x80000000U
 } omp_sched_t;
 
 typedef enum omp_proc_bind_t
@@ -62,14 +63,32 @@ typedef enum omp_proc_bind_t
   omp_proc_bind_spread = 4
 } omp_proc_bind_t;
 
-typedef enum omp_lock_hint_t
+typedef enum omp_sync_hint_t
 {
-  omp_lock_hint_none = 0,
-  omp_lock_hint_uncontended = 1,
-  omp_lock_hint_contended = 2,
-  omp_lock_hint_nonspeculative = 4,
-  omp_lock_hint_speculative = 8,
-} omp_lock_hint_t;
+  omp_sync_hint_none = 0,
+  omp_lock_hint_none = omp_sync_hint_none,
+  omp_sync_hint_uncontended = 1,
+  omp_lock_hint_uncontended = omp_sync_hint_uncontended,
+  omp_sync_hint_contended = 2,
+  omp_lock_hint_contended = omp_sync_hint_contended,
+  omp_sync_hint_nonspeculative = 4,
+  omp_lock_hint_nonspeculative = omp_sync_hint_nonspeculative,
+  omp_sync_hint_speculative = 8,
+  omp_lock_hint_speculative = omp_sync_hint_speculative
+} omp_sync_hint_t;
+
+typedef omp_sync_hint_t omp_lock_hint_t;
+
+typedef struct __attribute__((__aligned__ (sizeof (void *)))) omp_depend_t
+{
+  char __omp_depend_t__[2 * sizeof (void *)];
+} omp_depend_t;
+
+typedef enum omp_pause_resource_t
+{
+  omp_pause_soft = 1,
+  omp_pause_hard = 2
+} omp_pause_resource_t;
 
 #ifdef __cplusplus
 extern "C" {
@@ -93,7 +112,7 @@ extern void omp_set_nested (int) __GOMP_NOTHROW;
 extern int omp_get_nested (void) __GOMP_NOTHROW;
 
 extern void omp_init_lock (omp_lock_t *) __GOMP_NOTHROW;
-extern void omp_init_lock_with_hint (omp_lock_t *, omp_lock_hint_t)
+extern void omp_init_lock_with_hint (omp_lock_t *, omp_sync_hint_t)
   __GOMP_NOTHROW;
 extern void omp_destroy_lock (omp_lock_t *) __GOMP_NOTHROW;
 extern void omp_set_lock (omp_lock_t *) __GOMP_NOTHROW;
@@ -101,7 +120,7 @@ extern void omp_unset_lock (omp_lock_t *) __GOMP_NOTHROW;
 extern int omp_test_lock (omp_lock_t *) __GOMP_NOTHROW;
 
 extern void omp_init_nest_lock (omp_nest_lock_t *) __GOMP_NOTHROW;
-extern void omp_init_nest_lock_with_hint (omp_nest_lock_t *, omp_lock_hint_t)
+extern void omp_init_nest_lock_with_hint (omp_nest_lock_t *, omp_sync_hint_t)
   __GOMP_NOTHROW;
 extern void omp_destroy_nest_lock (omp_nest_lock_t *) __GOMP_NOTHROW;
 extern void omp_set_nest_lock (omp_nest_lock_t *) __GOMP_NOTHROW;
@@ -144,19 +163,30 @@ extern int omp_get_max_task_priority (void) __GOMP_NOTHROW;
 
 extern void *omp_target_alloc (__SIZE_TYPE__, int) __GOMP_NOTHROW;
 extern void omp_target_free (void *, int) __GOMP_NOTHROW;
-extern int omp_target_is_present (void *, int) __GOMP_NOTHROW;
-extern int omp_target_memcpy (void *, void *, __SIZE_TYPE__, __SIZE_TYPE__,
-                             __SIZE_TYPE__, int, int) __GOMP_NOTHROW;
-extern int omp_target_memcpy_rect (void *, void *, __SIZE_TYPE__, int,
+extern int omp_target_is_present (const void *, int) __GOMP_NOTHROW;
+extern int omp_target_memcpy (void *, const void *, __SIZE_TYPE__,
+                             __SIZE_TYPE__, __SIZE_TYPE__, int, int)
+  __GOMP_NOTHROW;
+extern int omp_target_memcpy_rect (void *, const void *, __SIZE_TYPE__, int,
                                   const __SIZE_TYPE__ *,
                                   const __SIZE_TYPE__ *,
                                   const __SIZE_TYPE__ *,
                                   const __SIZE_TYPE__ *,
                                   const __SIZE_TYPE__ *, int, int)
   __GOMP_NOTHROW;
-extern int omp_target_associate_ptr (void *, void *, __SIZE_TYPE__,
+extern int omp_target_associate_ptr (const void *, const void *, __SIZE_TYPE__,
                                     __SIZE_TYPE__, int) __GOMP_NOTHROW;
-extern int omp_target_disassociate_ptr (void *, int) __GOMP_NOTHROW;
+extern int omp_target_disassociate_ptr (const void *, int) __GOMP_NOTHROW;
+
+extern void omp_set_affinity_format (const char *) __GOMP_NOTHROW;
+extern __SIZE_TYPE__ omp_get_affinity_format (char *, __SIZE_TYPE__)
+  __GOMP_NOTHROW;
+extern void omp_display_affinity (const char *) __GOMP_NOTHROW;
+extern __SIZE_TYPE__ omp_capture_affinity (char *, __SIZE_TYPE__, const char *)
+  __GOMP_NOTHROW;
+
+extern int omp_pause_resource (omp_pause_resource_t, int) __GOMP_NOTHROW;
+extern int omp_pause_resource_all (omp_pause_resource_t) __GOMP_NOTHROW;
 
 #ifdef __cplusplus
 }
index eea33b893d646b7266e0155ba9eef39b910f8d6b..caecfba749dd76a69aaf6824c4bd8daf41b18e8e 100644 (file)
@@ -30,6 +30,7 @@
         integer, parameter :: omp_sched_kind = 4
         integer, parameter :: omp_proc_bind_kind = 4
         integer, parameter :: omp_lock_hint_kind = 4
+        integer, parameter :: omp_pause_resource_kind = 4
         integer (omp_sched_kind), parameter :: omp_sched_static = 1
         integer (omp_sched_kind), parameter :: omp_sched_dynamic = 2
         integer (omp_sched_kind), parameter :: omp_sched_guided = 3
                  parameter :: omp_lock_hint_nonspeculative = 4
         integer (omp_lock_hint_kind), &
                  parameter :: omp_lock_hint_speculative = 8
+        integer (kind=omp_pause_resource_kind), &
+                 parameter :: omp_pause_soft = 1
+        integer (kind=omp_pause_resource_kind), &
+                 parameter :: omp_pause_hard = 2
       end module
 
       module omp_lib
           end function omp_get_max_task_priority
         end interface
 
+        interface
+          subroutine omp_set_affinity_format (format)
+            character(len=*), intent(in) :: format
+          end subroutine omp_set_affinity_format
+        end interface
+
+        interface
+          function omp_get_affinity_format (buffer)
+            integer (4) :: omp_get_affinity_format
+            character(len=*), intent(out) :: buffer
+          end function omp_get_affinity_format
+        end interface
+
+        interface
+          subroutine omp_display_affinity (format)
+            character(len=*), intent(in) :: format
+          end subroutine omp_display_affinity
+        end interface
+
+        interface
+          function omp_capture_affinity (buffer, format)
+            integer (4) :: omp_capture_affinity
+            character(len=*), intent(out) :: buffer
+            character(len=*), intent(in) :: format
+          end function omp_capture_affinity
+        end interface
+
+        interface
+          function omp_pause_resource (kind, device_num)
+            use omp_lib_kinds
+            integer (4) :: omp_pause_resource
+            integer (kind=omp_pause_resource_kind), &
+              intent(in) :: kind
+            integer (4) :: device_num
+          end function
+        end interface
+
+        interface
+          function omp_pause_resource_all (kind)
+            use omp_lib_kinds
+            integer (4) :: omp_pause_resource_all
+            integer (kind=omp_pause_resource_kind), &
+              intent(in) :: kind
+          end function
+        end interface
+
       end module omp_lib
index e57da94a2d5984d25ac4f5f2b84d2a7f6bc57e04..2a553435a451580866a4f8f3e0875663c948c0a2 100644 (file)
       parameter (omp_lock_hint_nonspeculative = 4)
       parameter (omp_lock_hint_speculative = 8)
       parameter (openmp_version = 201511)
+      integer omp_pause_resource_kind
+      parameter (omp_pause_resource_kind = 4)
+      integer (omp_pause_resource_kind) omp_pause_soft
+      integer (omp_pause_resource_kind) omp_pause_hard
+      parameter (omp_pause_soft = 1)
+      parameter (omp_pause_hard = 2)
 
       external omp_init_lock, omp_init_nest_lock
       external omp_init_lock_with_hint
 
       external omp_get_max_task_priority
       integer(4) omp_get_max_task_priority
+
+      external omp_set_affinity_format, omp_get_affinity_format
+      external omp_display_affinity, omp_capture_affinity
+      integer(4) omp_get_affinity_format
+      integer(4) omp_capture_affinity
+
+      external omp_pause_resource, omp_pause_resource_all
+      integer(4) omp_pause_resource
+      integer(4) omp_pause_resource_all
index 1bdd5b2f25bcf4bccf664c4bbb106717a7ced8fc..521e9122d908ecb483519480367ba0da717c75a6 100644 (file)
@@ -259,7 +259,8 @@ GOMP_ordered_end (void)
 #define MAX_COLLAPSED_BITS (__SIZEOF_LONG__ * __CHAR_BIT__)
 
 void
-gomp_doacross_init (unsigned ncounts, long *counts, long chunk_size)
+gomp_doacross_init (unsigned ncounts, long *counts, long chunk_size,
+                   size_t extra)
 {
   struct gomp_thread *thr = gomp_thread ();
   struct gomp_team *team = thr->ts.team;
@@ -269,13 +270,24 @@ gomp_doacross_init (unsigned ncounts, long *counts, long chunk_size)
   struct gomp_doacross_work_share *doacross;
 
   if (team == NULL || team->nthreads == 1)
-    return;
+    {
+    empty:
+      if (!extra)
+       ws->doacross = NULL;
+      else
+       {
+         doacross = gomp_malloc_cleared (sizeof (*doacross) + extra);
+         doacross->extra = (void *) (doacross + 1);
+         ws->doacross = doacross;
+       }
+      return;
+    }
 
   for (i = 0; i < ncounts; i++)
     {
       /* If any count is 0, GOMP_doacross_{post,wait} can't be called.  */
       if (counts[i] == 0)
-       return;
+       goto empty;
 
       if (num_bits <= MAX_COLLAPSED_BITS)
        {
@@ -314,7 +326,7 @@ gomp_doacross_init (unsigned ncounts, long *counts, long chunk_size)
   elt_sz = (elt_sz + 63) & ~63UL;
 
   doacross = gomp_malloc (sizeof (*doacross) + 63 + num_ents * elt_sz
-                         + shift_sz);
+                         + shift_sz + extra);
   doacross->chunk_size = chunk_size;
   doacross->elt_sz = elt_sz;
   doacross->ncounts = ncounts;
@@ -322,6 +334,13 @@ gomp_doacross_init (unsigned ncounts, long *counts, long chunk_size)
   doacross->array = (unsigned char *)
                    ((((uintptr_t) (doacross + 1)) + 63 + shift_sz)
                     & ~(uintptr_t) 63);
+  if (extra)
+    {
+      doacross->extra = doacross->array + num_ents * elt_sz;
+      memset (doacross->extra, '\0', extra);
+    }
+  else
+    doacross->extra = NULL;
   if (num_bits <= MAX_COLLAPSED_BITS)
     {
       unsigned int shift_count = 0;
@@ -360,7 +379,8 @@ GOMP_doacross_post (long *counts)
   unsigned long ent;
   unsigned int i;
 
-  if (__builtin_expect (doacross == NULL, 0))
+  if (__builtin_expect (doacross == NULL, 0)
+      || __builtin_expect (doacross->array == NULL, 0))
     {
       __sync_synchronize ();
       return;
@@ -411,7 +431,8 @@ GOMP_doacross_wait (long first, ...)
   unsigned long ent;
   unsigned int i;
 
-  if (__builtin_expect (doacross == NULL, 0))
+  if (__builtin_expect (doacross == NULL, 0)
+      || __builtin_expect (doacross->array == NULL, 0))
     {
       __sync_synchronize ();
       return;
@@ -488,7 +509,8 @@ GOMP_doacross_wait (long first, ...)
 typedef unsigned long long gomp_ull;
 
 void
-gomp_doacross_ull_init (unsigned ncounts, gomp_ull *counts, gomp_ull chunk_size)
+gomp_doacross_ull_init (unsigned ncounts, gomp_ull *counts,
+                       gomp_ull chunk_size, size_t extra)
 {
   struct gomp_thread *thr = gomp_thread ();
   struct gomp_team *team = thr->ts.team;
@@ -498,13 +520,24 @@ gomp_doacross_ull_init (unsigned ncounts, gomp_ull *counts, gomp_ull chunk_size)
   struct gomp_doacross_work_share *doacross;
 
   if (team == NULL || team->nthreads == 1)
-    return;
+    {
+    empty:
+      if (!extra)
+       ws->doacross = NULL;
+      else
+       {
+         doacross = gomp_malloc_cleared (sizeof (*doacross) + extra);
+         doacross->extra = (void *) (doacross + 1);
+         ws->doacross = doacross;
+       }
+      return;
+    }
 
   for (i = 0; i < ncounts; i++)
     {
       /* If any count is 0, GOMP_doacross_{post,wait} can't be called.  */
       if (counts[i] == 0)
-       return;
+       goto empty;
 
       if (num_bits <= MAX_COLLAPSED_BITS)
        {
@@ -557,6 +590,13 @@ gomp_doacross_ull_init (unsigned ncounts, gomp_ull *counts, gomp_ull chunk_size)
   doacross->array = (unsigned char *)
                    ((((uintptr_t) (doacross + 1)) + 63 + shift_sz)
                     & ~(uintptr_t) 63);
+  if (extra)
+    {
+      doacross->extra = doacross->array + num_ents * elt_sz;
+      memset (doacross->extra, '\0', extra);
+    }
+  else
+    doacross->extra = NULL;
   if (num_bits <= MAX_COLLAPSED_BITS)
     {
       unsigned int shift_count = 0;
@@ -595,7 +635,8 @@ GOMP_doacross_ull_post (gomp_ull *counts)
   unsigned long ent;
   unsigned int i;
 
-  if (__builtin_expect (doacross == NULL, 0))
+  if (__builtin_expect (doacross == NULL, 0)
+      || __builtin_expect (doacross->array == NULL, 0))
     {
       __sync_synchronize ();
       return;
@@ -667,7 +708,8 @@ GOMP_doacross_ull_wait (gomp_ull first, ...)
   unsigned long ent;
   unsigned int i;
 
-  if (__builtin_expect (doacross == NULL, 0))
+  if (__builtin_expect (doacross == NULL, 0)
+      || __builtin_expect (doacross->array == NULL, 0))
     {
       __sync_synchronize ();
       return;
index 803e8b770c83128e41d31a0717fffb14c0ed234b..c7a8c788a3bc629195c243d40e4603d34ce3dd40 100644 (file)
@@ -123,7 +123,8 @@ void
 GOMP_parallel_start (void (*fn) (void *), void *data, unsigned num_threads)
 {
   num_threads = gomp_resolve_num_threads (num_threads, 0);
-  gomp_team_start (fn, data, num_threads, 0, gomp_new_team (num_threads));
+  gomp_team_start (fn, data, num_threads, 0, gomp_new_team (num_threads),
+                  NULL);
 }
 
 void
@@ -161,14 +162,33 @@ GOMP_parallel_end (void)
 ialias (GOMP_parallel_end)
 
 void
-GOMP_parallel (void (*fn) (void *), void *data, unsigned num_threads, unsigned int flags)
+GOMP_parallel (void (*fn) (void *), void *data, unsigned num_threads,
+              unsigned int flags)
 {
   num_threads = gomp_resolve_num_threads (num_threads, 0);
-  gomp_team_start (fn, data, num_threads, flags, gomp_new_team (num_threads));
+  gomp_team_start (fn, data, num_threads, flags, gomp_new_team (num_threads),
+                  NULL);
   fn (data);
   ialias_call (GOMP_parallel_end) ();
 }
 
+unsigned
+GOMP_parallel_reductions (void (*fn) (void *), void *data,
+                         unsigned num_threads, unsigned int flags)
+{
+  struct gomp_taskgroup *taskgroup;
+  num_threads = gomp_resolve_num_threads (num_threads, 0);
+  uintptr_t *rdata = *(uintptr_t **)data;
+  taskgroup = gomp_parallel_reduction_register (rdata, num_threads);
+  gomp_team_start (fn, data, num_threads, flags, gomp_new_team (num_threads),
+                  taskgroup);
+  fn (data);
+  ialias_call (GOMP_parallel_end) ();
+  gomp_sem_destroy (&taskgroup->taskgroup_sem);
+  free (taskgroup);
+  return num_threads;
+}
+
 bool
 GOMP_cancellation_point (int which)
 {
@@ -185,8 +205,15 @@ GOMP_cancellation_point (int which)
     }
   else if (which & GOMP_CANCEL_TASKGROUP)
     {
-      if (thr->task->taskgroup && thr->task->taskgroup->cancelled)
-       return true;
+      if (thr->task->taskgroup)
+       {
+         if (thr->task->taskgroup->cancelled)
+           return true;
+         if (thr->task->taskgroup->workshare
+             && thr->task->taskgroup->prev
+             && thr->task->taskgroup->prev->cancelled)
+           return true;
+       }
       /* FALLTHRU into the GOMP_CANCEL_PARALLEL case,
         as #pragma omp cancel parallel also cancels all explicit
         tasks.  */
@@ -218,11 +245,17 @@ GOMP_cancel (int which, bool do_cancel)
     }
   else if (which & GOMP_CANCEL_TASKGROUP)
     {
-      if (thr->task->taskgroup && !thr->task->taskgroup->cancelled)
+      if (thr->task->taskgroup)
        {
-         gomp_mutex_lock (&team->task_lock);
-         thr->task->taskgroup->cancelled = true;
-         gomp_mutex_unlock (&team->task_lock);
+         struct gomp_taskgroup *taskgroup = thr->task->taskgroup;
+         if (taskgroup->workshare && taskgroup->prev)
+           taskgroup = taskgroup->prev;
+         if (!taskgroup->cancelled)
+           {
+             gomp_mutex_lock (&team->task_lock);
+             taskgroup->cancelled = true;
+             gomp_mutex_unlock (&team->task_lock);
+           }
        }
       return true;
     }
index 65b53b45f73095bc110c6008c26da0346946e6f3..3449e0067ddcdb6803a6de92aaa813a477607f88 100644 (file)
 /* This file handles the SECTIONS construct.  */
 
 #include "libgomp.h"
+#include <string.h>
 
 
+ialias_redirect (GOMP_taskgroup_reduction_register)
+
 /* Initialize the given work share construct from the given arguments.  */
 
 static inline void
@@ -72,7 +75,7 @@ GOMP_sections_start (unsigned count)
   struct gomp_thread *thr = gomp_thread ();
   long s, e, ret;
 
-  if (gomp_work_share_start (false))
+  if (gomp_work_share_start (0))
     {
       gomp_sections_init (thr->ts.work_share, count);
       gomp_work_share_init_done ();
@@ -95,6 +98,66 @@ GOMP_sections_start (unsigned count)
   return ret;
 }
 
+unsigned
+GOMP_sections2_start (unsigned count, uintptr_t *reductions, void **mem)
+{
+  struct gomp_thread *thr = gomp_thread ();
+  long s, e, ret;
+
+  if (reductions)
+    gomp_workshare_taskgroup_start ();
+  if (gomp_work_share_start (0))
+    {
+      gomp_sections_init (thr->ts.work_share, count);
+      if (reductions)
+       {
+         GOMP_taskgroup_reduction_register (reductions);
+         thr->task->taskgroup->workshare = true;
+         thr->ts.work_share->task_reductions = reductions;
+       }
+      if (mem)
+       {
+         uintptr_t size = (uintptr_t) *mem;
+         if (size > (sizeof (struct gomp_work_share)
+                     - offsetof (struct gomp_work_share,
+                                 inline_ordered_team_ids)))
+           thr->ts.work_share->ordered_team_ids
+             = gomp_malloc_cleared (size);
+         else
+           memset (thr->ts.work_share->ordered_team_ids, '\0', size);
+         *mem = (void *) thr->ts.work_share->ordered_team_ids;
+       }
+      gomp_work_share_init_done ();
+    }
+  else
+    {
+      if (reductions)
+       {
+         uintptr_t *first_reductions = thr->ts.work_share->task_reductions;
+         gomp_workshare_task_reduction_register (reductions,
+                                                 first_reductions);
+       }
+      if (mem)
+       *mem = (void *) thr->ts.work_share->ordered_team_ids;
+    }
+
+#ifdef HAVE_SYNC_BUILTINS
+  if (gomp_iter_dynamic_next (&s, &e))
+    ret = s;
+  else
+    ret = 0;
+#else
+  gomp_mutex_lock (&thr->ts.work_share->lock);
+  if (gomp_iter_dynamic_next_locked (&s, &e))
+    ret = s;
+  else
+    ret = 0;
+  gomp_mutex_unlock (&thr->ts.work_share->lock);
+#endif
+
+  return ret;
+}
+
 /* This routine is called when the thread completes processing of the
    section currently assigned to it.  If the work-share construct is
    bound directly to a parallel construct, then the construct may have
@@ -140,7 +203,7 @@ GOMP_parallel_sections_start (void (*fn) (void *), void *data,
   num_threads = gomp_resolve_num_threads (num_threads, count);
   team = gomp_new_team (num_threads);
   gomp_sections_init (&team->work_shares[0], count);
-  gomp_team_start (fn, data, num_threads, 0, team);
+  gomp_team_start (fn, data, num_threads, 0, team, NULL);
 }
 
 ialias_redirect (GOMP_parallel_end)
@@ -154,7 +217,7 @@ GOMP_parallel_sections (void (*fn) (void *), void *data,
   num_threads = gomp_resolve_num_threads (num_threads, count);
   team = gomp_new_team (num_threads);
   gomp_sections_init (&team->work_shares[0], count);
-  gomp_team_start (fn, data, num_threads, flags, team);
+  gomp_team_start (fn, data, num_threads, flags, team, NULL);
   fn (data);
   GOMP_parallel_end ();
 }
index 24a7780ad93acf9f6dff61bbcf605b7e693de4a2..d5093c6730c396221bce4109b5d8208be42fe6e6 100644 (file)
@@ -47,7 +47,7 @@ GOMP_single_start (void)
   return __sync_bool_compare_and_swap (&team->single_count, single_count,
                                       single_count + 1L);
 #else
-  bool ret = gomp_work_share_start (false);
+  bool ret = gomp_work_share_start (0);
   if (ret)
     gomp_work_share_init_done ();
   gomp_work_share_end_nowait ();
@@ -68,7 +68,7 @@ GOMP_single_copy_start (void)
   bool first;
   void *ret;
 
-  first = gomp_work_share_start (false);
+  first = gomp_work_share_start (0);
   
   if (first)
     {
index dda041cdbef1958c4173d06d7e0b313c252e4769..8ebc2a370a1656d0a3e3e68664f3048ef668ffb1 100644 (file)
@@ -1854,11 +1854,20 @@ GOMP_target_update_ext (int device, size_t mapnum, void **hostaddrs,
              struct gomp_team *team = thr->ts.team;
              /* If parallel or taskgroup has been cancelled, don't start new
                 tasks.  */
-             if (team
-                 && (gomp_team_barrier_cancelled (&team->barrier)
-                     || (thr->task->taskgroup
-                         && thr->task->taskgroup->cancelled)))
-               return;
+             if (__builtin_expect (gomp_cancel_var, 0) && team)
+               {
+                 if (gomp_team_barrier_cancelled (&team->barrier))
+                   return;
+                 if (thr->task->taskgroup)
+                   {
+                     if (thr->task->taskgroup->cancelled)
+                       return;
+                     if (thr->task->taskgroup->workshare
+                         && thr->task->taskgroup->prev
+                         && thr->task->taskgroup->prev->cancelled)
+                       return;
+                   }
+               }
 
              gomp_task_maybe_wait_for_dependencies (depend);
            }
@@ -1873,10 +1882,20 @@ GOMP_target_update_ext (int device, size_t mapnum, void **hostaddrs,
   struct gomp_thread *thr = gomp_thread ();
   struct gomp_team *team = thr->ts.team;
   /* If parallel or taskgroup has been cancelled, don't start new tasks.  */
-  if (team
-      && (gomp_team_barrier_cancelled (&team->barrier)
-         || (thr->task->taskgroup && thr->task->taskgroup->cancelled)))
-    return;
+  if (__builtin_expect (gomp_cancel_var, 0) && team)
+    {
+      if (gomp_team_barrier_cancelled (&team->barrier))
+       return;
+      if (thr->task->taskgroup)
+       {
+         if (thr->task->taskgroup->cancelled)
+           return;
+         if (thr->task->taskgroup->workshare
+             && thr->task->taskgroup->prev
+             && thr->task->taskgroup->prev->cancelled)
+           return;
+       }
+    }
 
   gomp_update (devicep, mapnum, hostaddrs, sizes, kinds, true);
 }
@@ -1985,11 +2004,20 @@ GOMP_target_enter_exit_data (int device, size_t mapnum, void **hostaddrs,
              struct gomp_team *team = thr->ts.team;
              /* If parallel or taskgroup has been cancelled, don't start new
                 tasks.  */
-             if (team
-                 && (gomp_team_barrier_cancelled (&team->barrier)
-                     || (thr->task->taskgroup
-                         && thr->task->taskgroup->cancelled)))
-               return;
+             if (__builtin_expect (gomp_cancel_var, 0) && team)
+               {
+                 if (gomp_team_barrier_cancelled (&team->barrier))
+                   return;
+                 if (thr->task->taskgroup)
+                   {
+                     if (thr->task->taskgroup->cancelled)
+                       return;
+                     if (thr->task->taskgroup->workshare
+                         && thr->task->taskgroup->prev
+                         && thr->task->taskgroup->prev->cancelled)
+                       return;
+                   }
+               }
 
              gomp_task_maybe_wait_for_dependencies (depend);
            }
@@ -2004,10 +2032,20 @@ GOMP_target_enter_exit_data (int device, size_t mapnum, void **hostaddrs,
   struct gomp_thread *thr = gomp_thread ();
   struct gomp_team *team = thr->ts.team;
   /* If parallel or taskgroup has been cancelled, don't start new tasks.  */
-  if (team
-      && (gomp_team_barrier_cancelled (&team->barrier)
-         || (thr->task->taskgroup && thr->task->taskgroup->cancelled)))
-    return;
+  if (__builtin_expect (gomp_cancel_var, 0) && team)
+    {
+      if (gomp_team_barrier_cancelled (&team->barrier))
+       return;
+      if (thr->task->taskgroup)
+       {
+         if (thr->task->taskgroup->cancelled)
+           return;
+         if (thr->task->taskgroup->workshare
+             && thr->task->taskgroup->prev
+             && thr->task->taskgroup->prev->cancelled)
+           return;
+       }
+    }
 
   size_t i;
   if ((flags & GOMP_TARGET_FLAG_EXIT_DATA) == 0)
@@ -2164,7 +2202,7 @@ omp_target_free (void *device_ptr, int device_num)
 }
 
 int
-omp_target_is_present (void *ptr, int device_num)
+omp_target_is_present (const void *ptr, int device_num)
 {
   if (ptr == NULL)
     return 1;
@@ -2196,8 +2234,9 @@ omp_target_is_present (void *ptr, int device_num)
 }
 
 int
-omp_target_memcpy (void *dst, void *src, size_t length, size_t dst_offset,
-                  size_t src_offset, int dst_device_num, int src_device_num)
+omp_target_memcpy (void *dst, const void *src, size_t length,
+                  size_t dst_offset, size_t src_offset, int dst_device_num,
+                  int src_device_num)
 {
   struct gomp_device_descr *dst_devicep = NULL, *src_devicep = NULL;
   bool ret;
@@ -2264,7 +2303,7 @@ omp_target_memcpy (void *dst, void *src, size_t length, size_t dst_offset,
 }
 
 static int
-omp_target_memcpy_rect_worker (void *dst, void *src, size_t element_size,
+omp_target_memcpy_rect_worker (void *dst, const void *src, size_t element_size,
                               int num_dims, const size_t *volume,
                               const size_t *dst_offsets,
                               const size_t *src_offsets,
@@ -2286,21 +2325,25 @@ omp_target_memcpy_rect_worker (void *dst, void *src, size_t element_size,
        return EINVAL;
       if (dst_devicep == NULL && src_devicep == NULL)
        {
-         memcpy ((char *) dst + dst_off, (char *) src + src_off, length);
+         memcpy ((char *) dst + dst_off, (const char *) src + src_off,
+                 length);
          ret = 1;
        }
       else if (src_devicep == NULL)
        ret = dst_devicep->host2dev_func (dst_devicep->target_id,
                                          (char *) dst + dst_off,
-                                         (char *) src + src_off, length);
+                                         (const char *) src + src_off,
+                                         length);
       else if (dst_devicep == NULL)
        ret = src_devicep->dev2host_func (src_devicep->target_id,
                                          (char *) dst + dst_off,
-                                         (char *) src + src_off, length);
+                                         (const char *) src + src_off,
+                                         length);
       else if (src_devicep == dst_devicep)
        ret = src_devicep->dev2dev_func (src_devicep->target_id,
                                         (char *) dst + dst_off,
-                                        (char *) src + src_off, length);
+                                        (const char *) src + src_off,
+                                        length);
       else
        ret = 0;
       return ret ? 0 : EINVAL;
@@ -2321,7 +2364,7 @@ omp_target_memcpy_rect_worker (void *dst, void *src, size_t element_size,
   for (j = 0; j < volume[0]; j++)
     {
       ret = omp_target_memcpy_rect_worker ((char *) dst + dst_off,
-                                          (char *) src + src_off,
+                                          (const char *) src + src_off,
                                           element_size, num_dims - 1,
                                           volume + 1, dst_offsets + 1,
                                           src_offsets + 1, dst_dimensions + 1,
@@ -2336,7 +2379,7 @@ omp_target_memcpy_rect_worker (void *dst, void *src, size_t element_size,
 }
 
 int
-omp_target_memcpy_rect (void *dst, void *src, size_t element_size,
+omp_target_memcpy_rect (void *dst, const void *src, size_t element_size,
                        int num_dims, const size_t *volume,
                        const size_t *dst_offsets,
                        const size_t *src_offsets,
@@ -2395,8 +2438,8 @@ omp_target_memcpy_rect (void *dst, void *src, size_t element_size,
 }
 
 int
-omp_target_associate_ptr (void *host_ptr, void *device_ptr, size_t size,
-                         size_t device_offset, int device_num)
+omp_target_associate_ptr (const void *host_ptr, const void *device_ptr,
+                         size_t size, size_t device_offset, int device_num)
 {
   if (device_num == GOMP_DEVICE_HOST_FALLBACK)
     return EINVAL;
@@ -2457,7 +2500,7 @@ omp_target_associate_ptr (void *host_ptr, void *device_ptr, size_t size,
 }
 
 int
-omp_target_disassociate_ptr (void *ptr, int device_num)
+omp_target_disassociate_ptr (const void *ptr, int device_num)
 {
   if (device_num == GOMP_DEVICE_HOST_FALLBACK)
     return EINVAL;
@@ -2498,6 +2541,31 @@ omp_target_disassociate_ptr (void *ptr, int device_num)
   return ret;
 }
 
+int
+omp_pause_resource (omp_pause_resource_t kind, int device_num)
+{
+  (void) kind;
+  if (device_num == GOMP_DEVICE_HOST_FALLBACK)
+    return gomp_pause_host ();
+  if (device_num < 0 || device_num >= gomp_get_num_devices ())
+    return -1;
+  /* Do nothing for target devices for now.  */
+  return 0;
+}
+
+int
+omp_pause_resource_all (omp_pause_resource_t kind)
+{
+  (void) kind;
+  if (gomp_pause_host ())
+    return -1;
+  /* Do nothing for target devices for now.  */
+  return 0;
+}
+
+ialias (omp_pause_resource)
+ialias (omp_pause_resource_all)
+
 #ifdef PLUGIN_SUPPORT
 
 /* This function tries to load a plugin for DEVICE.  Name of plugin is passed
index 80dcd902ab3af12261a53c03673ea17f56c00e64..0c78b3c939cde5e2289b0bf4de69f27a8493426d 100644 (file)
@@ -166,21 +166,72 @@ gomp_task_handle_depend (struct gomp_task *task, struct gomp_task *parent,
                         void **depend)
 {
   size_t ndepend = (uintptr_t) depend[0];
-  size_t nout = (uintptr_t) depend[1];
   size_t i;
   hash_entry_type ent;
 
+  if (ndepend)
+    {
+      /* depend[0] is total # */
+      size_t nout = (uintptr_t) depend[1]; /* # of out: and inout: */
+      /* ndepend - nout is # of in: */
+      for (i = 0; i < ndepend; i++)
+       {
+         task->depend[i].addr = depend[2 + i];
+         task->depend[i].is_in = i >= nout;
+       }
+    }
+  else
+    {
+      ndepend = (uintptr_t) depend[1]; /* total # */
+      size_t nout = (uintptr_t) depend[2]; /* # of out: and inout: */
+      size_t nmutexinoutset = (uintptr_t) depend[3]; /* # of mutexinoutset: */
+      /* For now we treat mutexinoutset like out, which is compliant, but
+        inefficient.  */
+      size_t nin = (uintptr_t) depend[4]; /* # of in: */
+      /* ndepend - nout - nmutexinoutset - nin is # of depobjs */
+      size_t normal = nout + nmutexinoutset + nin;
+      size_t n = 0;
+      for (i = normal; i < ndepend; i++)
+       {
+         void **d = (void **) (uintptr_t) depend[5 + i];
+         switch ((uintptr_t) d[1])
+           {
+           case GOMP_DEPEND_OUT:
+           case GOMP_DEPEND_INOUT:
+           case GOMP_DEPEND_MUTEXINOUTSET:
+             break;
+           case GOMP_DEPEND_IN:
+             continue;
+           default:
+             gomp_fatal ("unknown omp_depend_t dependence type %d",
+                         (int) (uintptr_t) d[1]);
+           }
+         task->depend[n].addr = d[0];
+         task->depend[n++].is_in = 0;
+       }
+      for (i = 0; i < normal; i++)
+       {
+         task->depend[n].addr = depend[5 + i];
+         task->depend[n++].is_in = i >= nout + nmutexinoutset;
+       }
+      for (i = normal; i < ndepend; i++)
+       {
+         void **d = (void **) (uintptr_t) depend[5 + i];
+         if ((uintptr_t) d[1] != GOMP_DEPEND_IN)
+           continue;
+         task->depend[n].addr = d[0];
+         task->depend[n++].is_in = 1;
+       }
+    }
   task->depend_count = ndepend;
   task->num_dependees = 0;
   if (parent->depend_hash == NULL)
     parent->depend_hash = htab_create (2 * ndepend > 12 ? 2 * ndepend : 12);
   for (i = 0; i < ndepend; i++)
     {
-      task->depend[i].addr = depend[2 + i];
       task->depend[i].next = NULL;
       task->depend[i].prev = NULL;
       task->depend[i].task = task;
-      task->depend[i].is_in = i >= nout;
       task->depend[i].redundant = false;
       task->depend[i].redundant_out = false;
 
@@ -205,7 +256,7 @@ gomp_task_handle_depend (struct gomp_task *task, struct gomp_task *parent,
              last = ent;
 
              /* depend(in:...) doesn't depend on earlier depend(in:...).  */
-             if (i >= nout && ent->is_in)
+             if (task->depend[i].is_in && ent->is_in)
                continue;
 
              if (!ent->is_in)
@@ -280,9 +331,18 @@ gomp_task_handle_depend (struct gomp_task *task, struct gomp_task *parent,
    then the task may be executed by any member of the team.
 
    DEPEND is an array containing:
+     if depend[0] is non-zero, then:
        depend[0]: number of depend elements.
-       depend[1]: number of depend elements of type "out".
-       depend[2..N+1]: address of [1..N]th depend element.  */
+       depend[1]: number of depend elements of type "out/inout".
+       depend[2..N+1]: address of [1..N]th depend element.
+     otherwise, when depend[0] is zero, then:
+       depend[1]: number of depend elements.
+       depend[2]: number of depend elements of type "out/inout".
+       depend[3]: number of depend elements of type "mutexinoutset".
+       depend[4]: number of depend elements of type "in".
+       depend[5..4+depend[2]+depend[3]+depend[4]]: address of depend elements
+       depend[5+depend[2]+depend[3]+depend[4]..4+depend[1]]: address of
+                  omp_depend_t objects.  */
 
 void
 GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
@@ -303,10 +363,20 @@ GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
 #endif
 
   /* If parallel or taskgroup has been cancelled, don't start new tasks.  */
-  if (team
-      && (gomp_team_barrier_cancelled (&team->barrier)
-         || (thr->task->taskgroup && thr->task->taskgroup->cancelled)))
-    return;
+  if (__builtin_expect (gomp_cancel_var, 0) && team)
+    {
+      if (gomp_team_barrier_cancelled (&team->barrier))
+       return;
+      if (thr->task->taskgroup)
+       {
+         if (thr->task->taskgroup->cancelled)
+           return;
+         if (thr->task->taskgroup->workshare
+             && thr->task->taskgroup->prev
+             && thr->task->taskgroup->prev->cancelled)
+           return;
+       }
+    }
 
   if ((flags & GOMP_TASK_FLAG_PRIORITY) == 0)
     priority = 0;
@@ -377,7 +447,7 @@ GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
       size_t depend_size = 0;
 
       if (flags & GOMP_TASK_FLAG_DEPEND)
-       depend_size = ((uintptr_t) depend[0]
+       depend_size = ((uintptr_t) (depend[0] ? depend[0] : depend[1])
                       * sizeof (struct gomp_task_depend_entry));
       task = gomp_malloc (sizeof (*task) + depend_size
                          + arg_size + arg_align - 1);
@@ -404,14 +474,26 @@ GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
       gomp_mutex_lock (&team->task_lock);
       /* If parallel or taskgroup has been cancelled, don't start new
         tasks.  */
-      if (__builtin_expect ((gomp_team_barrier_cancelled (&team->barrier)
-                            || (taskgroup && taskgroup->cancelled))
-                           && !task->copy_ctors_done, 0))
+      if (__builtin_expect (gomp_cancel_var, 0)
+         && !task->copy_ctors_done)
        {
-         gomp_mutex_unlock (&team->task_lock);
-         gomp_finish_task (task);
-         free (task);
-         return;
+         if (gomp_team_barrier_cancelled (&team->barrier))
+           {
+           do_cancel:
+             gomp_mutex_unlock (&team->task_lock);
+             gomp_finish_task (task);
+             free (task);
+             return;
+           }
+         if (taskgroup)
+           {
+             if (taskgroup->cancelled)
+               goto do_cancel;
+             if (taskgroup->workshare
+                 && taskgroup->prev
+                 && taskgroup->prev->cancelled)
+               goto do_cancel;
+           }
        }
       if (taskgroup)
        taskgroup->num_children++;
@@ -463,6 +545,7 @@ GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
 
 ialias (GOMP_taskgroup_start)
 ialias (GOMP_taskgroup_end)
+ialias (GOMP_taskgroup_reduction_register)
 
 #define TYPE long
 #define UTYPE unsigned long
@@ -601,10 +684,20 @@ gomp_create_target_task (struct gomp_device_descr *devicep,
   struct gomp_team *team = thr->ts.team;
 
   /* If parallel or taskgroup has been cancelled, don't start new tasks.  */
-  if (team
-      && (gomp_team_barrier_cancelled (&team->barrier)
-         || (thr->task->taskgroup && thr->task->taskgroup->cancelled)))
-    return true;
+  if (__builtin_expect (gomp_cancel_var, 0) && team)
+    {
+      if (gomp_team_barrier_cancelled (&team->barrier))
+       return true;
+      if (thr->task->taskgroup)
+       {
+         if (thr->task->taskgroup->cancelled)
+           return true;
+         if (thr->task->taskgroup->workshare
+             && thr->task->taskgroup->prev
+             && thr->task->taskgroup->prev->cancelled)
+           return true;
+       }
+    }
 
   struct gomp_target_task *ttask;
   struct gomp_task *task;
@@ -617,7 +710,7 @@ gomp_create_target_task (struct gomp_device_descr *devicep,
 
   if (depend != NULL)
     {
-      depend_cnt = (uintptr_t) depend[0];
+      depend_cnt = (uintptr_t) (depend[0] ? depend[0] : depend[1]);
       depend_size = depend_cnt * sizeof (struct gomp_task_depend_entry);
     }
   if (fn)
@@ -687,13 +780,25 @@ gomp_create_target_task (struct gomp_device_descr *devicep,
   task->final_task = 0;
   gomp_mutex_lock (&team->task_lock);
   /* If parallel or taskgroup has been cancelled, don't start new tasks.  */
-  if (__builtin_expect (gomp_team_barrier_cancelled (&team->barrier)
-                       || (taskgroup && taskgroup->cancelled), 0))
+  if (__builtin_expect (gomp_cancel_var, 0))
     {
-      gomp_mutex_unlock (&team->task_lock);
-      gomp_finish_task (task);
-      free (task);
-      return true;
+      if (gomp_team_barrier_cancelled (&team->barrier))
+       {
+       do_cancel:
+         gomp_mutex_unlock (&team->task_lock);
+         gomp_finish_task (task);
+         free (task);
+         return true;
+       }
+      if (taskgroup)
+       {
+         if (taskgroup->cancelled)
+           goto do_cancel;
+         if (taskgroup->workshare
+             && taskgroup->prev
+             && taskgroup->prev->cancelled)
+           goto do_cancel;
+       }
     }
   if (depend_size)
     {
@@ -986,10 +1091,21 @@ gomp_task_run_pre (struct gomp_task *child_task, struct gomp_task *parent,
 
   if (--team->task_queued_count == 0)
     gomp_team_barrier_clear_task_pending (&team->barrier);
-  if ((gomp_team_barrier_cancelled (&team->barrier)
-       || (taskgroup && taskgroup->cancelled))
+  if (__builtin_expect (gomp_cancel_var, 0)
       && !child_task->copy_ctors_done)
-    return true;
+    {
+      if (gomp_team_barrier_cancelled (&team->barrier))
+       return true;
+      if (taskgroup)
+       {
+         if (taskgroup->cancelled)
+           return true;
+         if (taskgroup->workshare
+             && taskgroup->prev
+             && taskgroup->prev->cancelled)
+           return true;
+       }
+    }
   return false;
 }
 
@@ -1456,6 +1572,35 @@ GOMP_taskwait (void)
     }
 }
 
+/* Called when encountering a taskwait directive with depend clause(s).
+   Wait as if it was an mergeable included task construct with empty body.  */
+
+void
+GOMP_taskwait_depend (void **depend)
+{
+  struct gomp_thread *thr = gomp_thread ();
+  struct gomp_team *team = thr->ts.team;
+
+  /* If parallel or taskgroup has been cancelled, return early.  */
+  if (__builtin_expect (gomp_cancel_var, 0) && team)
+    {
+      if (gomp_team_barrier_cancelled (&team->barrier))
+       return;
+      if (thr->task->taskgroup)
+       {
+         if (thr->task->taskgroup->cancelled)
+           return;
+         if (thr->task->taskgroup->workshare
+             && thr->task->taskgroup->prev
+             && thr->task->taskgroup->prev->cancelled)
+           return;
+       }
+    }
+
+  if (thr->task && thr->task->depend_hash)
+    gomp_task_maybe_wait_for_dependencies (depend);
+}
+
 /* An undeferred task is about to run.  Wait for all tasks that this
    undeferred task depends on.
 
@@ -1464,7 +1609,7 @@ GOMP_taskwait (void)
    the scheduling queues.  Then we iterate through these imminently
    ready tasks (and possibly other high priority tasks), and run them.
    If we run out of ready dependencies to execute, we either wait for
-   the reamining dependencies to finish, or wait for them to get
+   the remaining dependencies to finish, or wait for them to get
    scheduled so we can run them.
 
    DEPEND is as in GOMP_task.  */
@@ -1477,21 +1622,50 @@ gomp_task_maybe_wait_for_dependencies (void **depend)
   struct gomp_team *team = thr->ts.team;
   struct gomp_task_depend_entry elem, *ent = NULL;
   struct gomp_taskwait taskwait;
-  size_t ndepend = (uintptr_t) depend[0];
+  size_t orig_ndepend = (uintptr_t) depend[0];
   size_t nout = (uintptr_t) depend[1];
+  size_t ndepend = orig_ndepend;
+  size_t normal = ndepend;
+  size_t n = 2;
   size_t i;
   size_t num_awaited = 0;
   struct gomp_task *child_task = NULL;
   struct gomp_task *to_free = NULL;
   int do_wake = 0;
 
+  if (ndepend == 0)
+    {
+      ndepend = nout;
+      nout = (uintptr_t) depend[2] + (uintptr_t) depend[3];
+      normal = nout + (uintptr_t) depend[4];
+      n = 5;
+    }
   gomp_mutex_lock (&team->task_lock);
   for (i = 0; i < ndepend; i++)
     {
-      elem.addr = depend[i + 2];
+      elem.addr = depend[i + n];
+      elem.is_in = i >= nout;
+      if (__builtin_expect (i >= normal, 0))
+       {
+         void **d = (void **) elem.addr;
+         switch ((uintptr_t) d[1])
+           {
+           case GOMP_DEPEND_IN:
+             break;
+           case GOMP_DEPEND_OUT:
+           case GOMP_DEPEND_INOUT:
+           case GOMP_DEPEND_MUTEXINOUTSET:
+             elem.is_in = 0;
+             break;
+           default:
+             gomp_fatal ("unknown omp_depend_t dependence type %d",
+                         (int) (uintptr_t) d[1]);
+           }
+         elem.addr = d[0];
+       }
       ent = htab_find (task->depend_hash, &elem);
       for (; ent; ent = ent->next)
-       if (i >= nout && ent->is_in)
+       if (elem.is_in && ent->is_in)
          continue;
        else
          {
@@ -1654,13 +1828,28 @@ GOMP_taskyield (void)
   /* Nothing at the moment.  */
 }
 
+static inline struct gomp_taskgroup *
+gomp_taskgroup_init (struct gomp_taskgroup *prev)
+{
+  struct gomp_taskgroup *taskgroup
+    = gomp_malloc (sizeof (struct gomp_taskgroup));
+  taskgroup->prev = prev;
+  priority_queue_init (&taskgroup->taskgroup_queue);
+  taskgroup->reductions = prev ? prev->reductions : NULL;
+  taskgroup->in_taskgroup_wait = false;
+  taskgroup->cancelled = false;
+  taskgroup->workshare = false;
+  taskgroup->num_children = 0;
+  gomp_sem_init (&taskgroup->taskgroup_sem, 0);
+  return taskgroup;
+}
+
 void
 GOMP_taskgroup_start (void)
 {
   struct gomp_thread *thr = gomp_thread ();
   struct gomp_team *team = thr->ts.team;
   struct gomp_task *task = thr->task;
-  struct gomp_taskgroup *taskgroup;
 
   /* If team is NULL, all tasks are executed as
      GOMP_TASK_UNDEFERRED tasks and thus all children tasks of
@@ -1668,14 +1857,7 @@ GOMP_taskgroup_start (void)
      by the time GOMP_taskgroup_end is called.  */
   if (team == NULL)
     return;
-  taskgroup = gomp_malloc (sizeof (struct gomp_taskgroup));
-  taskgroup->prev = task->taskgroup;
-  priority_queue_init (&taskgroup->taskgroup_queue);
-  taskgroup->in_taskgroup_wait = false;
-  taskgroup->cancelled = false;
-  taskgroup->num_children = 0;
-  gomp_sem_init (&taskgroup->taskgroup_sem, 0);
-  task->taskgroup = taskgroup;
+  task->taskgroup = gomp_taskgroup_init (task->taskgroup);
 }
 
 void
@@ -1840,6 +2022,302 @@ GOMP_taskgroup_end (void)
   free (taskgroup);
 }
 
+static inline __attribute__((always_inline)) void
+gomp_reduction_register (uintptr_t *data, uintptr_t *old, uintptr_t *orig,
+                        unsigned nthreads)
+{
+  size_t total_cnt = 0;
+  uintptr_t *d = data;
+  struct htab *old_htab = NULL, *new_htab;
+  do
+    {
+      if (__builtin_expect (orig != NULL, 0))
+       {
+         /* For worksharing task reductions, memory has been allocated
+            already by some other thread that encountered the construct
+            earlier.  */
+         d[2] = orig[2];
+         d[6] = orig[6];
+         orig = (uintptr_t *) orig[4];
+       }
+      else
+       {
+         size_t sz = d[1] * nthreads;
+         /* Should use omp_alloc if d[3] is not -1.  */
+         void *ptr = gomp_aligned_alloc (d[2], sz);
+         memset (ptr, '\0', sz);
+         d[2] = (uintptr_t) ptr;
+         d[6] = d[2] + sz;
+       }
+      d[5] = 0;
+      total_cnt += d[0];
+      if (d[4] == 0)
+       {
+         d[4] = (uintptr_t) old;
+         break;
+       }
+      else
+       d = (uintptr_t *) d[4];
+    }
+  while (1);
+  if (old && old[5])
+    {
+      old_htab = (struct htab *) old[5];
+      total_cnt += htab_elements (old_htab);
+    }
+  new_htab = htab_create (total_cnt);
+  if (old_htab)
+    {
+      /* Copy old hash table, like in htab_expand.  */
+      hash_entry_type *p, *olimit;
+      new_htab->n_elements = htab_elements (old_htab);
+      olimit = old_htab->entries + old_htab->size;
+      p = old_htab->entries;
+      do
+       {
+         hash_entry_type x = *p;
+         if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
+           *find_empty_slot_for_expand (new_htab, htab_hash (x)) = x;
+         p++;
+       }
+      while (p < olimit);
+    }
+  d = data;
+  do
+    {
+      size_t j;
+      for (j = 0; j < d[0]; ++j)
+       {
+         uintptr_t *p = d + 7 + j * 3;
+         p[2] = (uintptr_t) d;
+         /* Ugly hack, hash_entry_type is defined for the task dependencies,
+            which hash on the first element which is a pointer.  We need
+            to hash also on the first sizeof (uintptr_t) bytes which contain
+            a pointer.  Hide the cast from the compiler.  */
+         hash_entry_type n;
+         __asm ("" : "=g" (n) : "0" (p));
+         *htab_find_slot (&new_htab, n, INSERT) = n;
+       }
+      if (d[4] == (uintptr_t) old)
+       break;
+      else
+       d = (uintptr_t *) d[4];
+    }
+  while (1);
+  d[5] = (uintptr_t) new_htab;
+}
+
+static void
+gomp_create_artificial_team (void)
+{
+  struct gomp_thread *thr = gomp_thread ();
+  struct gomp_task_icv *icv;
+  struct gomp_team *team = gomp_new_team (1);
+  struct gomp_task *task = thr->task;
+  icv = task ? &task->icv : &gomp_global_icv;
+  team->prev_ts = thr->ts;
+  thr->ts.team = team;
+  thr->ts.team_id = 0;
+  thr->ts.work_share = &team->work_shares[0];
+  thr->ts.last_work_share = NULL;
+#ifdef HAVE_SYNC_BUILTINS
+  thr->ts.single_count = 0;
+#endif
+  thr->ts.static_trip = 0;
+  thr->task = &team->implicit_task[0];
+  gomp_init_task (thr->task, NULL, icv);
+  if (task)
+    {
+      thr->task = task;
+      gomp_end_task ();
+      free (task);
+      thr->task = &team->implicit_task[0];
+    }
+#ifdef LIBGOMP_USE_PTHREADS
+  else
+    pthread_setspecific (gomp_thread_destructor, thr);
+#endif
+}
+
+/* The format of data is:
+   data[0]     cnt
+   data[1]     size
+   data[2]     alignment (on output array pointer)
+   data[3]     allocator (-1 if malloc allocator)
+   data[4]     next pointer
+   data[5]     used internally (htab pointer)
+   data[6]     used internally (end of array)
+   cnt times
+   ent[0]      address
+   ent[1]      offset
+   ent[2]      used internally (pointer to data[0])
+   The entries are sorted by increasing offset, so that a binary
+   search can be performed.  Normally, data[8] is 0, exception is
+   for worksharing construct task reductions in cancellable parallel,
+   where at offset 0 there should be space for a pointer and an integer
+   which are used internally.  */
+
+void
+GOMP_taskgroup_reduction_register (uintptr_t *data)
+{
+  struct gomp_thread *thr = gomp_thread ();
+  struct gomp_team *team = thr->ts.team;
+  struct gomp_task *task;
+  unsigned nthreads;
+  if (__builtin_expect (team == NULL, 0))
+    {
+      /* The task reduction code needs a team and task, so for
+        orphaned taskgroups just create the implicit team.  */
+      gomp_create_artificial_team ();
+      ialias_call (GOMP_taskgroup_start) ();
+      team = thr->ts.team;
+    }
+  nthreads = team->nthreads;
+  task = thr->task;
+  gomp_reduction_register (data, task->taskgroup->reductions, NULL, nthreads);
+  task->taskgroup->reductions = data;
+}
+
+void
+GOMP_taskgroup_reduction_unregister (uintptr_t *data)
+{
+  uintptr_t *d = data;
+  htab_free ((struct htab *) data[5]);
+  do
+    {
+      gomp_aligned_free ((void *) d[2]);
+      d = (uintptr_t *) d[4];
+    }
+  while (d && !d[5]);
+}
+ialias (GOMP_taskgroup_reduction_unregister)
+
+/* For i = 0 to cnt-1, remap ptrs[i] which is either address of the
+   original list item or address of previously remapped original list
+   item to address of the private copy, store that to ptrs[i].
+   For i < cntorig, additionally set ptrs[cnt+i] to the address of
+   the original list item.  */
+
+void
+GOMP_task_reduction_remap (size_t cnt, size_t cntorig, void **ptrs)
+{
+  struct gomp_thread *thr = gomp_thread ();
+  struct gomp_task *task = thr->task;
+  unsigned id = thr->ts.team_id;
+  uintptr_t *data = task->taskgroup->reductions;
+  uintptr_t *d;
+  struct htab *reduction_htab = (struct htab *) data[5];
+  size_t i;
+  for (i = 0; i < cnt; ++i)
+    {
+      hash_entry_type ent, n;
+      __asm ("" : "=g" (ent) : "0" (ptrs + i));
+      n = htab_find (reduction_htab, ent);
+      if (n)
+       {
+         uintptr_t *p;
+         __asm ("" : "=g" (p) : "0" (n));
+         /* At this point, p[0] should be equal to (uintptr_t) ptrs[i],
+            p[1] is the offset within the allocated chunk for each
+            thread, p[2] is the array registered with
+            GOMP_taskgroup_reduction_register, d[2] is the base of the
+            allocated memory and d[1] is the size of the allocated chunk
+            for one thread.  */
+         d = (uintptr_t *) p[2];
+         ptrs[i] = (void *) (d[2] + id * d[1] + p[1]);
+         if (__builtin_expect (i < cntorig, 0))
+           ptrs[cnt + i] = (void *) p[0];
+         continue;
+       }
+      d = data;
+      while (d != NULL)
+       {
+         if ((uintptr_t) ptrs[i] >= d[2] && (uintptr_t) ptrs[i] < d[6])
+           break;
+         d = (uintptr_t *) d[4];
+       }
+      if (d == NULL)
+       gomp_fatal ("couldn't find matching task_reduction or reduction with "
+                   "task modifier for %p", ptrs[i]);
+      uintptr_t off = ((uintptr_t) ptrs[i] - d[2]) % d[1];
+      ptrs[i] = (void *) (d[2] + id * d[1] + off);
+      if (__builtin_expect (i < cntorig, 0))
+       {
+         size_t lo = 0, hi = d[0] - 1;
+         while (lo <= hi)
+           {
+             size_t m = (lo + hi) / 2;
+             if (d[7 + 3 * m + 1] < off)
+               lo = m + 1;
+             else if (d[7 + 3 * m + 1] == off)
+               {
+                 ptrs[cnt + i] = (void *) d[7 + 3 * m];
+                 break;
+               }
+             else
+               hi = m - 1;
+           }
+         if (lo > hi)
+           gomp_fatal ("couldn't find matching task_reduction or reduction "
+                       "with task modifier for %p", ptrs[i]);
+       }
+    }
+}
+
+struct gomp_taskgroup *
+gomp_parallel_reduction_register (uintptr_t *data, unsigned nthreads)
+{
+  struct gomp_taskgroup *taskgroup = gomp_taskgroup_init (NULL);
+  gomp_reduction_register (data, NULL, NULL, nthreads);
+  taskgroup->reductions = data;
+  return taskgroup;
+}
+
+void
+gomp_workshare_task_reduction_register (uintptr_t *data, uintptr_t *orig)
+{
+  struct gomp_thread *thr = gomp_thread ();
+  struct gomp_team *team = thr->ts.team;
+  struct gomp_task *task = thr->task;
+  unsigned nthreads = team->nthreads;
+  gomp_reduction_register (data, task->taskgroup->reductions, orig, nthreads);
+  task->taskgroup->reductions = data;
+}
+
+void
+gomp_workshare_taskgroup_start (void)
+{
+  struct gomp_thread *thr = gomp_thread ();
+  struct gomp_team *team = thr->ts.team;
+  struct gomp_task *task;
+
+  if (team == NULL)
+    {
+      gomp_create_artificial_team ();
+      team = thr->ts.team;
+    }
+  task = thr->task;
+  task->taskgroup = gomp_taskgroup_init (task->taskgroup);
+  task->taskgroup->workshare = true;
+}
+
+void
+GOMP_workshare_task_reduction_unregister (bool cancelled)
+{
+  struct gomp_thread *thr = gomp_thread ();
+  struct gomp_task *task = thr->task;
+  struct gomp_team *team = thr->ts.team;
+  uintptr_t *data = task->taskgroup->reductions;
+  ialias_call (GOMP_taskgroup_end) ();
+  if (thr->ts.team_id == 0)
+    ialias_call (GOMP_taskgroup_reduction_unregister) (data);
+  else
+    htab_free ((struct htab *) data[5]);
+
+  if (!cancelled)
+    gomp_team_barrier_wait (&team->barrier);
+}
+
 int
 omp_in_final (void)
 {
index 5515b355f000c652d43ff53a43997d831de8aa13..4621405aa58e599e3a0c5de0623312c40ed434b2 100644 (file)
@@ -149,11 +149,28 @@ GOMP_taskloop (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
 
   if (flags & GOMP_TASK_FLAG_NOGROUP)
     {
-      if (thr->task && thr->task->taskgroup && thr->task->taskgroup->cancelled)
-       return;
+      if (__builtin_expect (gomp_cancel_var, 0)
+         && thr->task
+         && thr->task->taskgroup)
+       {
+         if (thr->task->taskgroup->cancelled)
+           return;
+         if (thr->task->taskgroup->workshare
+             && thr->task->taskgroup->prev
+             && thr->task->taskgroup->prev->cancelled)
+           return;
+       }
     }
   else
-    ialias_call (GOMP_taskgroup_start) ();
+    {
+      ialias_call (GOMP_taskgroup_start) ();
+      if (flags & GOMP_TASK_FLAG_REDUCTION)
+       {
+         struct gomp_data_head { TYPE t1, t2; uintptr_t *ptr; };
+         uintptr_t *ptr = ((struct gomp_data_head *) data)->ptr;
+         ialias_call (GOMP_taskgroup_reduction_register) (ptr);
+       }
+    }
 
   if (priority > gomp_max_task_priority_var)
     priority = gomp_max_task_priority_var;
@@ -284,19 +301,31 @@ GOMP_taskloop (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
       gomp_mutex_lock (&team->task_lock);
       /* If parallel or taskgroup has been cancelled, don't start new
         tasks.  */
-      if (__builtin_expect ((gomp_team_barrier_cancelled (&team->barrier)
-                            || (taskgroup && taskgroup->cancelled))
-                           && cpyfn == NULL, 0))
+      if (__builtin_expect (gomp_cancel_var, 0)
+         && cpyfn == NULL)
        {
-         gomp_mutex_unlock (&team->task_lock);
-         for (i = 0; i < num_tasks; i++)
+         if (gomp_team_barrier_cancelled (&team->barrier))
+           {
+           do_cancel:
+             gomp_mutex_unlock (&team->task_lock);
+             for (i = 0; i < num_tasks; i++)
+               {
+                 gomp_finish_task (tasks[i]);
+                 free (tasks[i]);
+               }
+             if ((flags & GOMP_TASK_FLAG_NOGROUP) == 0)
+               ialias_call (GOMP_taskgroup_end) ();
+             return;
+           }
+         if (taskgroup)
            {
-             gomp_finish_task (tasks[i]);
-             free (tasks[i]);
+             if (taskgroup->cancelled)
+               goto do_cancel;
+             if (taskgroup->workshare
+                 && taskgroup->prev
+                 && taskgroup->prev->cancelled)
+               goto do_cancel;
            }
-         if ((flags & GOMP_TASK_FLAG_NOGROUP) == 0)
-           ialias_call (GOMP_taskgroup_end) ();
-         return;
        }
       if (taskgroup)
        taskgroup->num_children += num_tasks;
index 87cdcfd52a9272af7e5a84ff0e2d442cfcc41cc5..e3e4c4d1ef2771c260ce7239e02422a873bdac8f 100644 (file)
@@ -32,7 +32,6 @@
 #include <string.h>
 
 #ifdef LIBGOMP_USE_PTHREADS
-/* This attribute contains PTHREAD_CREATE_DETACHED.  */
 pthread_attr_t gomp_thread_attr;
 
 /* This key is for the thread destructor.  */
@@ -58,6 +57,7 @@ struct gomp_thread_start_data
   struct gomp_thread_pool *thread_pool;
   unsigned int place;
   bool nested;
+  pthread_t handle;
 };
 
 
@@ -89,6 +89,9 @@ gomp_thread_start (void *xdata)
   thr->ts = data->ts;
   thr->task = data->task;
   thr->place = data->place;
+#ifdef GOMP_NEEDS_THREAD_HANDLE
+  thr->handle = data->handle;
+#endif
 
   thr->ts.team->ordered_release[thr->ts.team_id] = &thr->release;
 
@@ -131,6 +134,7 @@ gomp_thread_start (void *xdata)
     }
 
   gomp_sem_destroy (&thr->release);
+  pthread_detach (pthread_self ());
   thr->thread_pool = NULL;
   thr->task = NULL;
   return NULL;
@@ -183,7 +187,7 @@ gomp_new_team (unsigned nthreads)
   team->single_count = 0;
 #endif
   team->work_shares_to_free = &team->work_shares[0];
-  gomp_init_work_share (&team->work_shares[0], false, nthreads);
+  gomp_init_work_share (&team->work_shares[0], 0, nthreads);
   team->work_shares[0].next_alloc = NULL;
   team->work_share_list_free = NULL;
   team->work_share_list_alloc = &team->work_shares[1];
@@ -231,6 +235,7 @@ gomp_free_pool_helper (void *thread_pool)
   thr->thread_pool = NULL;
   thr->task = NULL;
 #ifdef LIBGOMP_USE_PTHREADS
+  pthread_detach (pthread_self ());
   pthread_exit (NULL);
 #elif defined(__nvptx__)
   asm ("exit;");
@@ -297,7 +302,8 @@ gomp_free_thread (void *arg __attribute__((unused)))
 #ifdef LIBGOMP_USE_PTHREADS
 void
 gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
-                unsigned flags, struct gomp_team *team)
+                unsigned flags, struct gomp_team *team,
+                struct gomp_taskgroup *taskgroup)
 {
   struct gomp_thread_start_data *start_data;
   struct gomp_thread *thr, *nthr;
@@ -312,6 +318,7 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
   unsigned int s = 0, rest = 0, p = 0, k = 0;
   unsigned int affinity_count = 0;
   struct gomp_thread **affinity_thr = NULL;
+  bool force_display = false;
 
   thr = gomp_thread ();
   nested = thr->ts.level;
@@ -319,7 +326,12 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
   task = thr->task;
   icv = task ? &task->icv : &gomp_global_icv;
   if (__builtin_expect (gomp_places_list != NULL, 0) && thr->place == 0)
-    gomp_init_affinity ();
+    {
+      gomp_init_affinity ();
+      if (__builtin_expect (gomp_display_affinity_var, 0) && nthreads == 1)
+       gomp_display_affinity_thread (gomp_thread_self (), &thr->ts,
+                                     thr->place);
+    }
 
   /* Always save the previous state, even if this isn't a nested team.
      In particular, we should save any work share state from an outer
@@ -338,6 +350,9 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
 #endif
   thr->ts.static_trip = 0;
   thr->task = &team->implicit_task[0];
+#ifdef GOMP_NEEDS_THREAD_HANDLE
+  thr->handle = pthread_self ();
+#endif
   nthreads_var = icv->nthreads_var;
   if (__builtin_expect (gomp_nthreads_var_list != NULL, 0)
       && thr->ts.level < gomp_nthreads_var_list_len)
@@ -350,6 +365,7 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
       && thr->ts.level < gomp_bind_var_list_len)
     bind_var = gomp_bind_var_list[thr->ts.level];
   gomp_init_task (thr->task, task, icv);
+  thr->task->taskgroup = taskgroup;
   team->implicit_task[0].icv.nthreads_var = nthreads_var;
   team->implicit_task[0].icv.bind_var = bind_var;
 
@@ -465,7 +481,7 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
          pool->threads
            = gomp_realloc (pool->threads,
                            pool->threads_size
-                           * sizeof (struct gomp_thread_data *));
+                           * sizeof (struct gomp_thread *));
        }
 
       /* Release existing idle threads.  */
@@ -540,6 +556,7 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
                                                + place_partition_len))
                {
                  unsigned int l;
+                 force_display = true;
                  if (affinity_thr == NULL)
                    {
                      unsigned int j;
@@ -623,6 +640,7 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
          gomp_init_task (nthr->task, task, icv);
          team->implicit_task[i].icv.nthreads_var = nthreads_var;
          team->implicit_task[i].icv.bind_var = bind_var;
+         nthr->task->taskgroup = taskgroup;
          nthr->fn = fn;
          nthr->data = data;
          team->ordered_release[i] = &nthr->release;
@@ -712,19 +730,17 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
     {
       size_t stacksize;
       pthread_attr_init (&thread_attr);
-      pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED);
       if (! pthread_attr_getstacksize (&gomp_thread_attr, &stacksize))
        pthread_attr_setstacksize (&thread_attr, stacksize);
       attr = &thread_attr;
     }
 
   start_data = gomp_alloca (sizeof (struct gomp_thread_start_data)
-                           * (nthreads-i));
+                           * (nthreads - i));
 
   /* Launch new threads.  */
   for (; i < nthreads; ++i)
     {
-      pthread_t pt;
       int err;
 
       start_data->ts.place_partition_off = thr->ts.place_partition_off;
@@ -810,11 +826,14 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
       gomp_init_task (start_data->task, task, icv);
       team->implicit_task[i].icv.nthreads_var = nthreads_var;
       team->implicit_task[i].icv.bind_var = bind_var;
+      start_data->task->taskgroup = taskgroup;
       start_data->thread_pool = pool;
       start_data->nested = nested;
 
       attr = gomp_adjust_thread_attr (attr, &thread_attr);
-      err = pthread_create (&pt, attr, gomp_thread_start, start_data++);
+      err = pthread_create (&start_data->handle, attr, gomp_thread_start,
+                           start_data);
+      start_data++;
       if (err != 0)
        gomp_fatal ("Thread creation failed: %s", strerror (err));
     }
@@ -854,6 +873,42 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
       gomp_mutex_unlock (&gomp_managed_threads_lock);
 #endif
     }
+  if (__builtin_expect (gomp_display_affinity_var, 0))
+    {
+      if (nested
+         || nthreads != old_threads_used
+         || force_display)
+       {
+         gomp_display_affinity_thread (gomp_thread_self (), &thr->ts,
+                                       thr->place);
+         if (nested)
+           {
+             start_data -= nthreads - 1;
+             for (i = 1; i < nthreads; ++i)
+               {
+                 gomp_display_affinity_thread (
+#ifdef LIBGOMP_USE_PTHREADS
+                                               start_data->handle,
+#else
+                                               gomp_thread_self (),
+#endif
+                                               &start_data->ts,
+                                               start_data->place);
+                 start_data++;
+               }
+           }
+         else
+           {
+             for (i = 1; i < nthreads; ++i)
+               {
+                 gomp_thread_handle handle
+                   = gomp_thread_to_pthread_t (pool->threads[i]);
+                 gomp_display_affinity_thread (handle, &pool->threads[i]->ts,
+                                               pool->threads[i]->place);
+               }
+           }
+       }
+    }
   if (__builtin_expect (affinity_thr != NULL, 0)
       && team->prev_ts.place_partition_len > 64)
     free (affinity_thr);
@@ -894,7 +949,7 @@ gomp_team_end (void)
   gomp_end_task ();
   thr->ts = team->prev_ts;
 
-  if (__builtin_expect (thr->ts.team != NULL, 0))
+  if (__builtin_expect (thr->ts.level != 0, 0))
     {
 #ifdef HAVE_SYNC_BUILTINS
       __sync_fetch_and_add (&gomp_managed_threads, 1L - team->nthreads);
@@ -959,6 +1014,76 @@ team_destructor (void)
      crashes.  */
   pthread_key_delete (gomp_thread_destructor);
 }
+
+/* Similar to gomp_free_pool_helper, but don't detach itself,
+   gomp_pause_host will pthread_join those threads.  */
+
+static void
+gomp_pause_pool_helper (void *thread_pool)
+{
+  struct gomp_thread *thr = gomp_thread ();
+  struct gomp_thread_pool *pool
+    = (struct gomp_thread_pool *) thread_pool;
+  gomp_simple_barrier_wait_last (&pool->threads_dock);
+  gomp_sem_destroy (&thr->release);
+  thr->thread_pool = NULL;
+  thr->task = NULL;
+  pthread_exit (NULL);
+}
+
+/* Free a thread pool and release its threads.  Return non-zero on
+   failure.  */
+
+int
+gomp_pause_host (void)
+{
+  struct gomp_thread *thr = gomp_thread ();
+  struct gomp_thread_pool *pool = thr->thread_pool;
+  if (thr->ts.level)
+    return -1;
+  if (pool)
+    {
+      if (pool->threads_used > 0)
+       {
+         int i;
+         pthread_t *thrs
+           = gomp_alloca (sizeof (pthread_t) * pool->threads_used);
+         for (i = 1; i < pool->threads_used; i++)
+           {
+             struct gomp_thread *nthr = pool->threads[i];
+             nthr->fn = gomp_pause_pool_helper;
+             nthr->data = pool;
+             thrs[i] = gomp_thread_to_pthread_t (nthr);
+           }
+         /* This barrier undocks threads docked on pool->threads_dock.  */
+         gomp_simple_barrier_wait (&pool->threads_dock);
+         /* And this waits till all threads have called gomp_barrier_wait_last
+            in gomp_pause_pool_helper.  */
+         gomp_simple_barrier_wait (&pool->threads_dock);
+         /* Now it is safe to destroy the barrier and free the pool.  */
+         gomp_simple_barrier_destroy (&pool->threads_dock);
+
+#ifdef HAVE_SYNC_BUILTINS
+         __sync_fetch_and_add (&gomp_managed_threads,
+                               1L - pool->threads_used);
+#else
+         gomp_mutex_lock (&gomp_managed_threads_lock);
+         gomp_managed_threads -= pool->threads_used - 1L;
+         gomp_mutex_unlock (&gomp_managed_threads_lock);
+#endif
+         for (i = 1; i < pool->threads_used; i++)
+           pthread_join (thrs[i], NULL);
+       }
+      if (pool->last_team)
+       free_team (pool->last_team);
+#ifndef __nvptx__
+      free (pool->threads);
+      free (pool);
+#endif
+      thr->thread_pool = NULL;
+    }
+  return 0;
+}
 #endif
 
 struct gomp_task_icv *
diff --git a/libgomp/teams.c b/libgomp/teams.c
new file mode 100644 (file)
index 0000000..5aa0eae
--- /dev/null
@@ -0,0 +1,73 @@
+/* Copyright (C) 2018 Free Software Foundation, Inc.
+   Contributed by Jakub Jelinek <jakub@redhat.com>.
+
+   This file is part of the GNU Offloading and Multi Processing Library
+   (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* This file handles the host TEAMS construct.  */
+
+#include "libgomp.h"
+
+static unsigned gomp_num_teams = 1, gomp_team_num = 0;
+
+void
+GOMP_teams_reg (void (*fn) (void *), void *data, unsigned int num_teams,
+               unsigned int thread_limit, unsigned int flags)
+{
+  (void) flags;
+  (void) num_teams;
+  unsigned old_thread_limit_var = 0;
+  if (thread_limit)
+    {
+      struct gomp_task_icv *icv = gomp_icv (true);
+      old_thread_limit_var = icv->thread_limit_var;
+      icv->thread_limit_var
+       = thread_limit > INT_MAX ? UINT_MAX : thread_limit;
+    }
+  if (num_teams == 0)
+    num_teams = 3;
+  gomp_num_teams = num_teams;
+  for (gomp_team_num = 0; gomp_team_num < num_teams; gomp_team_num++)
+    fn (data);
+  gomp_num_teams = 1;
+  gomp_team_num = 0;
+  if (thread_limit)
+    {
+      struct gomp_task_icv *icv = gomp_icv (true);
+      icv->thread_limit_var = old_thread_limit_var;
+    }
+}
+
+int
+omp_get_num_teams (void)
+{
+  return gomp_num_teams;
+}
+
+int
+omp_get_team_num (void)
+{
+  return gomp_team_num;
+}
+
+ialias (omp_get_num_teams)
+ialias (omp_get_team_num)
diff --git a/libgomp/testsuite/libgomp.c++/depend-1.C b/libgomp/testsuite/libgomp.c++/depend-1.C
new file mode 100644 (file)
index 0000000..71a24d1
--- /dev/null
@@ -0,0 +1,31 @@
+extern "C" void abort ();
+int a, b, c, d, e;
+
+void
+foo (int &x, bool y)
+{
+  #pragma omp task depend (out: x)
+    a = 1;
+  #pragma omp task depend (out: y ? b : c)
+    (y ? b : c) = 2;
+  #pragma omp task depend (inout: --d)
+    d += 4;
+  #pragma omp task depend (in : a, (y ? b : c), d)
+    e = a + b * 10 + c * 100 + d * 1000;
+}
+
+int
+main ()
+{
+  #pragma omp parallel
+  #pragma omp single
+  foo (a, true);
+  if (e != 1 + 20 + 0 + 3000)
+    abort ();
+  a = b = c = d = e = 0;
+  #pragma omp parallel
+  #pragma omp single
+  foo (a, false);
+  if (e != 1 + 0 + 200 + 3000)
+    abort ();
+}
diff --git a/libgomp/testsuite/libgomp.c++/depend-iterator-1.C b/libgomp/testsuite/libgomp.c++/depend-iterator-1.C
new file mode 100644 (file)
index 0000000..2cff5e8
--- /dev/null
@@ -0,0 +1,167 @@
+extern "C" void abort ();
+int arr[64], arr2[64], arr3[64];
+
+int *
+foo (int x, int y, long z)
+{
+  int v;
+  switch (x)
+    {
+    case 1:
+      if (z != 0 || y < 0 || y >= 64)
+       abort ();
+      #pragma omp atomic capture
+      {
+       v = arr2[y];
+       arr2[y]++;
+      }
+      if (v != 0) abort ();
+      return &arr[y];
+    case 2:
+      if (y < 0 || y > 60 || (y & 3) || z < 0 || z >= 4)
+       abort ();
+      #pragma omp atomic
+      arr2[y + z] = arr2[y + z] + 4;
+      return &arr[y + z];
+    case 3:
+      if (z < 0 || z > 60 || (z & 3) || y < 0 || y >= 4)
+       abort ();
+      #pragma omp atomic
+      arr2[y + z] = arr2[y + z] + 16;
+      return &arr[y + z];
+    case 4:
+      if (y != 0 || z > 64 || z <= 0)
+       abort ();
+      #pragma omp atomic
+      arr2[z - 1] = arr2[z - 1] + 64;
+      return &arr[z - 1];
+    case 5:
+      if ((y & 3) != 0 || y < 64 || y >= 96
+         || (z & 127) != 0 || z < 512 || z >= 1024)
+       abort ();
+      y = (y - 64) + (z - 512) / 128;
+      #pragma omp atomic
+      arr2[y] = arr2[y] + 256;
+      return &arr[y];
+    case 6:
+      if ((y & 3) != 0 || y <= 64 || y > 96
+         || (z & 127) != 1 || z <= 513 || z > 1025)
+       abort ();
+      y = (y - 68) + (z - 641) / 128;
+      #pragma omp atomic
+      arr2[y] = arr2[y] + 1024;
+      return &arr[y];
+    default:
+      abort ();
+    }
+}
+
+volatile int beg, end, step, step2;
+volatile unsigned int begu, endu;
+
+template <int N>
+void
+bar ()
+{
+  #pragma omp parallel
+  #pragma omp master
+  {
+    int i;
+    for (i = 0; i < 64; i++)
+      #pragma omp task depend (iterator (j=i:i+1) , out : foo (1, j, 0)[0])
+       arr[i] = i;
+    #pragma omp task depend (iterator (int k=beg:end:step,long int l=0:4:1) , inout : \
+                            foo (2, k, l)[0], foo (3, l, k)[0]) private (i)
+    for (i = 0; i < 64; i++)
+      if (arr[i] != i)
+       abort ();
+      else
+       arr[i] = arr[i] + 1;
+    #pragma omp task depend (iterator (int *p=&arr3[64]:&arr3[0]:-1), inout : \
+                            foo (4, 0, p - &arr3[0])[0]) depend (in : beg)
+    for (i = 0; i < 64; i++)
+      if (arr[i] != i + 1)
+       abort ();
+      else
+       arr[i] = arr[i] + 2;
+    #pragma omp task depend (iterator (unsigned n=begu:endu:step2, unsigned int o = 512: 1024U: (unsigned char) 128), inout : \
+                            foo (5, n + 128, o)[0])
+    for (i = 0; i < 64; i++)
+      if (arr[i] != i + 3)
+       abort ();
+      else
+       arr[i] = arr[i] + 4;
+    #pragma omp task depend (iterator (int unsigned p=endu:begu:step,unsigned q= 1025U:513U:(signed char) -128), in : \
+                            foo (6, p + 128, q)[0])
+    for (i = 0; i < 64; i++)
+      if (arr[i] != i + 7)
+       abort ();
+      else
+       arr[i] = arr[i] + 8;
+  }
+}
+
+template <typename A, typename B, typename C, typename D, typename E, typename F>
+void
+baz (A beg, A end, A step, D begu, D endu, A step2)
+{
+  #pragma omp parallel
+  #pragma omp master
+  {
+    int i;
+    for (i = 0; i < 64; i++)
+      #pragma omp task depend (iterator (A j=i:i+1),out : foo (1, j, 0)[0])
+       arr[i] = i;
+    #pragma omp task depend (iterator (A k=beg:end:step,B l=0:4:1), inout : \
+                            foo (2, k, l)[0], foo (3, l, k)[0]) private (i)
+    for (i = 0; i < 64; i++)
+      if (arr[i] != i)
+       abort ();
+      else
+       arr[i] = arr[i] + 1;
+    #pragma omp task depend (iterator (C p=&arr3[64]:&arr3[0]:-1), in : \
+                            foo (4, 0, p - &arr3[0])[0]) depend (in : beg)
+    for (i = 0; i < 64; i++)
+      if (arr[i] != i + 1)
+       abort ();
+      else
+       arr[i] = arr[i] + 2;
+    #pragma omp task depend (iterator (D n=begu:endu:step2, D o = 512: 1024U:(E) 128), inout : \
+                            foo (5, n + 128, o)[0])
+    for (i = 0; i < 64; i++)
+      if (arr[i] != i + 3)
+       abort ();
+      else
+       arr[i] = arr[i] + 4;
+    #pragma omp task depend (iterator (D p=endu:begu:step,D q= 1025U:513U:(F) -128), in : \
+                            foo (6, p + 128, q)[0])
+    for (i = 0; i < 64; i++)
+      if (arr[i] != i + 7)
+       abort ();
+      else
+       arr[i] = arr[i] + 8;
+  }
+}
+
+int
+main ()
+{
+  int m;
+  beg = 60;
+  end = -4;
+  step = -4;
+  step2 = 4;
+  begu = -64U;
+  endu = -32U;
+  bar<0> ();
+  for (m = 0; m < 64; m++)
+    if (arr[m] != m + 15 || arr2[m] != (m < 32 ? 1365 : 85))
+      abort ();
+    else
+      arr[m] = arr2[m] = 0;
+  baz<int, long int, int *, unsigned int, unsigned char, signed char> (beg, end, step, begu, endu, step2);
+  for (m = 0; m < 64; m++)
+    if (arr[m] != m + 15 || arr2[m] != (m < 32 ? 1365 : 85))
+      abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/depobj-1.C b/libgomp/testsuite/libgomp.c++/depobj-1.C
new file mode 100644 (file)
index 0000000..91edf8c
--- /dev/null
@@ -0,0 +1,103 @@
+#include <stdlib.h>
+#include <omp.h>
+
+void
+dep (omp_depend_t &d1, omp_depend_t *d2)
+{
+  int x = 1;
+  #pragma omp depobj (d1) depend(in: x)
+  #pragma omp depobj (*d2) depend(in: x)
+
+  #pragma omp depobj (d2[0]) update(out)
+  #pragma omp parallel
+  #pragma omp single
+  {
+    #pragma omp task shared (x) depend(depobj:*d2)
+    x = 2;
+    #pragma omp task shared (x) depend(depobj : d1)
+    if (x != 2)
+      abort ();
+  }
+  #pragma omp depobj (d2[0]) destroy
+  #pragma omp depobj (d1) destroy
+}
+
+template <typename T>
+void
+dep2 (T &d2)
+{
+  T d1;
+  #pragma omp parallel
+  #pragma omp single
+  {
+    int x = 1;
+    #pragma omp depobj (d1) depend(out: x)
+    #pragma omp depobj (*&d2) depend (in:x)
+    #pragma omp depobj(d2)update(in)
+    #pragma omp task shared (x) depend(depobj :d1)
+    x = 2;
+    #pragma omp task shared (x) depend(depobj: d2)
+    if (x != 2)
+      abort ();
+    #pragma omp taskwait
+    #pragma omp depobj(d1)destroy
+    #pragma omp depobj((&d2)[0]) destroy
+  }
+}
+
+template <typename T>
+void
+dep3 (void)
+{
+  T d[2];
+  #pragma omp parallel
+  {
+    int x = 1;
+    #pragma omp single
+    {
+      #pragma omp depobj(d[0]) depend(out:x)
+      #pragma omp depobj(d[1]) depend(in: x)
+      #pragma omp task shared (x) depend(depobj:*d)
+      x = 2;
+      #pragma omp task shared (x) depend(depobj:*(d + 1))
+      if (x != 2)
+       abort ();
+    }
+  }
+  #pragma omp depobj(d[0]) destroy
+  #pragma omp depobj(d[1]) destroy
+}
+
+int xx;
+omp_depend_t dd1, dd2;
+
+template <int N>
+void
+antidep (void)
+{
+  xx = 1;
+  #pragma omp parallel
+  #pragma omp single
+  {
+    #pragma omp task shared(xx) depend(depobj:dd2)
+    if (xx != 1)
+      abort ();
+    #pragma omp task shared(xx) depend(depobj:dd1)
+    xx = 2;
+  }
+}
+
+int
+main ()
+{
+  omp_depend_t d1, d2, d3;
+  dep (d1, &d2);
+  dep2 <omp_depend_t> (d3);
+  dep3 <omp_depend_t> ();
+  #pragma omp depobj (dd1) depend (inout: xx)
+  #pragma omp depobj (dd2) depend (in : xx)
+  antidep <0> ();
+  #pragma omp depobj (dd2) destroy
+  #pragma omp depobj (dd1) destroy
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/for-16.C b/libgomp/testsuite/libgomp.c++/for-16.C
new file mode 100644 (file)
index 0000000..e7e5b85
--- /dev/null
@@ -0,0 +1,218 @@
+// PR c++/86443
+// { dg-do run }
+// { dg-additional-options "-std=c++17" }
+
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+extern "C" void abort ();
+
+template <typename T>
+class I
+{
+public:
+  typedef ptrdiff_t difference_type;
+  I ();
+  ~I ();
+  I (T *);
+  I (const I &);
+  T &operator * ();
+  T *operator -> ();
+  T &operator [] (const difference_type &) const;
+  I &operator = (const I &);
+  I &operator ++ ();
+  I operator ++ (int);
+  I &operator -- ();
+  I operator -- (int);
+  I &operator += (const difference_type &);
+  I &operator -= (const difference_type &);
+  I operator + (const difference_type &) const;
+  I operator - (const difference_type &) const;
+  template <typename S> friend bool operator == (I<S> &, I<S> &);
+  template <typename S> friend bool operator == (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator < (I<S> &, I<S> &);
+  template <typename S> friend bool operator < (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator <= (I<S> &, I<S> &);
+  template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator > (I<S> &, I<S> &);
+  template <typename S> friend bool operator > (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator >= (I<S> &, I<S> &);
+  template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
+  template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
+private:
+  T *p;
+};
+template <typename T> I<T>::I () : p (0) {}
+template <typename T> I<T>::~I () {}
+template <typename T> I<T>::I (T *x) : p (x) {}
+template <typename T> I<T>::I (const I &x) : p (x.p) {}
+template <typename T> T &I<T>::operator * () { return *p; }
+template <typename T> T *I<T>::operator -> () { return p; }
+template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; }
+template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; }
+template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; }
+template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); }
+template <typename T> I<T> &I<T>::operator -- () { --p; return *this; }
+template <typename T> I<T> I<T>::operator -- (int) { return I (p--); }
+template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; }
+template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; }
+template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); }
+template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); }
+template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; }
+template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; }
+template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); }
+template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); }
+template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; }
+template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; }
+template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; }
+template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; }
+template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; }
+template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; }
+template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; }
+template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; }
+template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; }
+template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; }
+template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); }
+
+template <typename T>
+class J
+{
+public:
+  J(const I<T> &x, const I<T> &y) : b (x), e (y) {}
+  const I<T> &begin ();
+  const I<T> &end ();
+private:
+  I<T> b, e;
+};
+
+template <typename T> const I<T> &J<T>::begin () { return b; }
+template <typename T> const I<T> &J<T>::end () { return e; }
+
+int results[2000];
+
+template <typename T>
+void
+baz (I<T> &i)
+{
+  if (*i < 0 || *i >= 2000)
+    abort ();
+  results[*i]++;
+}
+
+void
+baz (int i)
+{
+  if (i < 0 || i >= 2000)
+    abort ();
+  results[i]++;
+}
+
+void
+f1 (J<int> j)
+{
+#pragma omp distribute parallel for default(none)
+  for (I<int> i = j.begin (); i < j.end (); i += 3)
+    baz (*i);
+}
+
+void
+f2 (J<int> j)
+{
+  I<int> i;
+#pragma omp distribute parallel for default(none)
+  for (i = j.begin (); i < j.end (); ++i)
+    baz (*i);
+}
+
+template <int N>
+void
+f3 (J<int> j)
+{
+#pragma omp distribute parallel for default(none)
+  for (I<int> i = j.begin (); i < j.end (); i += 6)
+    baz (*i);
+}
+
+template <int N>
+void
+f4 (J<int> j)
+{
+  I<int> i;
+#pragma omp distribute parallel for default(none)
+  for (i = j.begin (); i < j.end (); i += 9)
+    baz (*i);
+}
+
+template <typename T>
+void
+f5 (J<T> j)
+{
+#pragma omp distribute parallel for default(none)
+  for (I<T> i = j.begin (); i < j.end (); i += 4)
+    baz (*i);
+}
+
+template <typename T>
+void
+f6 (J<T> j)
+{
+  I<T> i;
+#pragma omp distribute parallel for default(none)
+  for (i = j.begin (); i < j.end (); i += 7)
+    baz (*i);
+}
+
+#define check(expr) \
+  for (int i = 0; i < 2000; i++)                       \
+    if (expr)                                          \
+      {                                                        \
+       if (results[i] != 1)                            \
+         abort ();                                     \
+       results[i] = 0;                                 \
+      }                                                        \
+    else if (results[i])                               \
+      abort ()
+
+int
+main ()
+{
+  int a[2000];
+  for (int i = 0; i < 2000; i++)
+    a[i] = i;
+  #pragma omp teams
+  {
+    J<int> j (&a[75], &a[1945]);
+    f1 (j);
+  }
+  check (i >= 75 && i < 1945 && (i - 75) % 3 == 0);
+  #pragma omp teams
+  {
+    J<int> j (&a[63], &a[1949]);
+    f2 (j);
+  }
+  check (i >= 63 && i < 1949);
+  #pragma omp teams
+  {
+    J<int> j (&a[58], &a[1979]);
+    f3 <2> (j);
+  }
+  check (i >= 58 && i < 1979 && (i - 58) % 6 == 0);
+  #pragma omp teams
+  {
+    J<int> j (&a[59], &a[1981]);
+    f4 <9> (j);
+  }
+  check (i >= 59 && i < 1981 && (i - 59) % 9 == 0);
+  #pragma omp teams
+  {
+    J<int> j (&a[52], &a[1972]);
+    f5 (j);
+  }
+  check (i >= 52 && i < 1972 && (i - 52) % 4 == 0);
+  #pragma omp teams
+  {
+    J<int> j (&a[31], &a[1827]);
+    f6 (j);
+  }
+  check (i >= 31 && i < 1827 && (i - 31) % 7 == 0);
+}
diff --git a/libgomp/testsuite/libgomp.c++/for-21.C b/libgomp/testsuite/libgomp.c++/for-21.C
new file mode 100644 (file)
index 0000000..fc0cb0a
--- /dev/null
@@ -0,0 +1,291 @@
+// { dg-do run }
+
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+extern "C" void abort ();
+
+template <typename T>
+class I
+{
+public:
+  typedef ptrdiff_t difference_type;
+  I ();
+  ~I ();
+  I (T *);
+  I (const I &);
+  T &operator * ();
+  T *operator -> ();
+  T &operator [] (const difference_type &) const;
+  I &operator = (const I &);
+  I &operator ++ ();
+  I operator ++ (int);
+  I &operator -- ();
+  I operator -- (int);
+  I &operator += (const difference_type &);
+  I &operator -= (const difference_type &);
+  I operator + (const difference_type &) const;
+  I operator - (const difference_type &) const;
+  template <typename S> friend bool operator == (I<S> &, I<S> &);
+  template <typename S> friend bool operator == (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator < (I<S> &, I<S> &);
+  template <typename S> friend bool operator < (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator <= (I<S> &, I<S> &);
+  template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator > (I<S> &, I<S> &);
+  template <typename S> friend bool operator > (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator >= (I<S> &, I<S> &);
+  template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
+  template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
+private:
+  T *p;
+};
+template <typename T> I<T>::I () : p (0) {}
+template <typename T> I<T>::~I () {}
+template <typename T> I<T>::I (T *x) : p (x) {}
+template <typename T> I<T>::I (const I &x) : p (x.p) {}
+template <typename T> T &I<T>::operator * () { return *p; }
+template <typename T> T *I<T>::operator -> () { return p; }
+template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; }
+template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; }
+template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; }
+template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); }
+template <typename T> I<T> &I<T>::operator -- () { --p; return *this; }
+template <typename T> I<T> I<T>::operator -- (int) { return I (p--); }
+template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; }
+template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; }
+template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); }
+template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); }
+template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; }
+template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; }
+template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); }
+template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); }
+template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; }
+template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; }
+template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; }
+template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; }
+template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; }
+template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; }
+template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; }
+template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; }
+template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; }
+template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; }
+template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); }
+
+template <typename T>
+class J
+{
+public:
+  J(const I<T> &x, const I<T> &y) : b (x), e (y) {}
+  const I<T> &begin ();
+  const I<T> &end ();
+private:
+  I<T> b, e;
+};
+
+template <typename T> const I<T> &J<T>::begin () { return b; }
+template <typename T> const I<T> &J<T>::end () { return e; }
+
+int results[2000];
+
+template <typename T>
+void
+baz (I<T> &i)
+{
+  if (*i < 0 || *i >= 2000)
+    abort ();
+  results[*i]++;
+}
+
+void
+f1 (const I<int> &x, const I<int> &y)
+{
+#pragma omp parallel for
+  for (I<int> i = x; i != y; i++)
+    baz (i);
+}
+
+void
+f2 (const I<int> &x, const I<int> &y)
+{
+  I<int> i;
+#pragma omp parallel for private(i)
+  for (i = x; i != y - 1; i = 2 - 8 + 7 + i)
+    baz (i);
+}
+
+template <typename T>
+void
+f3 (const I<int> &x, const I<int> &y)
+{
+#pragma omp parallel for
+  for (I<int> i = x; i != y; i = i + 9 - 8)
+    baz (i);
+}
+
+template <typename T>
+void
+f4 (const I<int> &x, const I<int> &y)
+{
+  I<int> i;
+#pragma omp parallel for lastprivate(i)
+  for (i = x + 2000 - 64; i != y + 10; --i)
+    baz (i);
+}
+
+void
+f5 (const I<int> &x, const I<int> &y)
+{
+#pragma omp parallel for
+  for (I<int> i = x + 2000 - 64; i != y + 10; i--)
+    baz (i);
+}
+
+template <int N>
+void
+f6 (const I<int> &x, const I<int> &y)
+{
+#pragma omp parallel for
+  for (I<int> i = x + 2000 - 64; i != y + 10; i = i - 12 + 11)
+    {
+      I<int> j = i + N;
+      baz (j);
+    }
+}
+
+template <int N>
+void
+f7 (I<int> i, const I<int> &x, const I<int> &y)
+{
+#pragma omp parallel for
+  for (i = x - 10; i != y + 10; i += N)
+    baz (i);
+}
+
+template <int N>
+void
+f8 (J<int> j)
+{
+  I<int> i;
+#pragma omp parallel for
+  for (i = j.begin (); i != j.end () + N; i += 1)
+    baz (i);
+}
+
+template <typename T, int N>
+void
+f9 (const I<T> &x, const I<T> &y)
+{
+#pragma omp parallel for
+  for (I<T> i = x; i != y; i = i - N)
+    baz (i);
+}
+
+template <typename T, int N>
+void
+f10 (const I<T> &x, const I<T> &y)
+{
+  I<T> i;
+#pragma omp parallel for
+  for (i = x; i != y; i = i + N)
+    baz (i);
+}
+
+template <typename T>
+void
+f11 (const T &x, const T &y)
+{
+#pragma omp parallel
+  {
+#pragma omp for nowait
+    for (T i = x; i != y; i++)
+      baz (i);
+#pragma omp single
+    {
+      T j = y + 3;
+      baz (j);
+    }
+  }
+}
+
+template <typename T>
+void
+f12 (const T &x, const T &y)
+{
+  T i;
+#pragma omp parallel for
+  for (i = x; i != y; --i)
+    baz (i);
+}
+
+template <int N>
+struct K
+{
+  template <typename T>
+  static void
+  f13 (const T &x, const T &y)
+  {
+#pragma omp parallel for
+    for (T i = x; i != y + N; i += N)
+      baz (i);
+  }
+};
+
+#define check(expr) \
+  for (int i = 0; i < 2000; i++)                       \
+    if (expr)                                          \
+      {                                                        \
+       if (results[i] != 1)                            \
+         abort ();                                     \
+       results[i] = 0;                                 \
+      }                                                        \
+    else if (results[i])                               \
+      abort ()
+
+int
+main ()
+{
+  int a[2000];
+  long b[2000];
+  for (int i = 0; i < 2000; i++)
+    {
+      a[i] = i;
+      b[i] = i;
+    }
+  f1 (&a[10], &a[1990]);
+  check (i >= 10 && i < 1990);
+  f2 (&a[0], &a[1999]);
+  check (i < 1998);
+  f3<char> (&a[20], &a[1837]);
+  check (i >= 20 && i < 1837);
+  f4<int> (&a[0], &a[30]);
+  check (i > 40 && i <= 2000 - 64);
+  f5 (&a[0], &a[100]);
+  check (i > 110 && i <= 2000 - 64);
+  f6<-10> (&a[10], &a[110]);
+  check (i > 110 && i <= 2000 - 64);
+  f7<1> (I<int> (), &a[12], &a[1800]);
+  check (i >= 2 && i < 1810);
+  f8<121> (J<int> (&a[14], &a[1803]));
+  check (i >= 14 && i < 1924);
+  f9<int, -1> (&a[33], &a[1967]);
+  check (i >= 33 && i < 1967);
+  f10<int, -1> (&a[1939], &a[17]);
+  check (i > 17 && i <= 1939);
+  f11<I<int> > (&a[16], &a[1981]);
+  check ((i >= 16 && i < 1981) || i == 1984);
+  f12<I<int> > (&a[1761], &a[37]);
+  check (i > 37 && i <= 1761);
+  K<1>::f13<I<int> > (&a[1], &a[1935]);
+  check (i >= 1 && i < 1936);
+  f9<long, 1 - 2> (&b[33], &b[1967]);
+  check (i >= 33 && i < 1967);
+  f10<long, -1> (&b[1939], &b[17]);
+  check (i > 17 && i <= 1939);
+  f11<I<long> > (&b[16], &b[1981]);
+  check ((i >= 16 && i < 1981) || i == 1984);
+  f12<I<long> > (&b[1761], &b[37]);
+  check (i > 37 && i <= 1761);
+  K<1>::f13<I<long> > (&b[1], &b[1935]);
+  check (i >= 1 && i < 1936);
+}
diff --git a/libgomp/testsuite/libgomp.c++/for-22.C b/libgomp/testsuite/libgomp.c++/for-22.C
new file mode 100644 (file)
index 0000000..35fcf1f
--- /dev/null
@@ -0,0 +1,314 @@
+// { dg-do run }
+
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+extern "C" void abort ();
+
+template <typename T>
+class I
+{
+public:
+  typedef ptrdiff_t difference_type;
+  I ();
+  ~I ();
+  I (T *);
+  I (const I &);
+  T &operator * ();
+  T *operator -> ();
+  T &operator [] (const difference_type &) const;
+  I &operator = (const I &);
+  I &operator ++ ();
+  I operator ++ (int);
+  I &operator -- ();
+  I operator -- (int);
+  I &operator += (const difference_type &);
+  I &operator -= (const difference_type &);
+  I operator + (const difference_type &) const;
+  I operator - (const difference_type &) const;
+  template <typename S> friend bool operator == (I<S> &, I<S> &);
+  template <typename S> friend bool operator == (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator < (I<S> &, I<S> &);
+  template <typename S> friend bool operator < (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator <= (I<S> &, I<S> &);
+  template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator > (I<S> &, I<S> &);
+  template <typename S> friend bool operator > (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator >= (I<S> &, I<S> &);
+  template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
+  template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
+private:
+  T *p;
+};
+template <typename T> I<T>::I () : p (0) {}
+template <typename T> I<T>::~I () { p = (T *) 0; }
+template <typename T> I<T>::I (T *x) : p (x) {}
+template <typename T> I<T>::I (const I &x) : p (x.p) {}
+template <typename T> T &I<T>::operator * () { return *p; }
+template <typename T> T *I<T>::operator -> () { return p; }
+template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; }
+template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; }
+template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; }
+template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); }
+template <typename T> I<T> &I<T>::operator -- () { --p; return *this; }
+template <typename T> I<T> I<T>::operator -- (int) { return I (p--); }
+template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; }
+template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; }
+template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); }
+template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); }
+template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; }
+template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; }
+template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); }
+template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); }
+template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; }
+template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; }
+template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; }
+template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; }
+template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; }
+template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; }
+template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; }
+template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; }
+template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; }
+template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; }
+template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); }
+
+template <typename T>
+class J
+{
+public:
+  J(const I<T> &x, const I<T> &y) : b (x), e (y) {}
+  const I<T> &begin ();
+  const I<T> &end ();
+private:
+  I<T> b, e;
+};
+
+template <typename T> const I<T> &J<T>::begin () { return b; }
+template <typename T> const I<T> &J<T>::end () { return e; }
+
+int results[2000];
+
+template <typename T>
+void
+baz (I<T> &i)
+{
+  if (*i < 0 || *i >= 2000)
+    abort ();
+  results[*i]++;
+}
+
+I<int>
+f1 (const I<int> &x, const I<int> &y)
+{
+  I<int> i;
+#pragma omp parallel shared(i)
+  {
+#pragma omp for lastprivate (i) schedule(runtime)
+    for (i = x; i != y; i++)
+      baz (i);
+#pragma omp single
+    i += 3;
+  }
+  return I<int> (i);
+}
+
+I<int>
+f2 (const I<int> &x, const I<int> &y)
+{
+  I<int> i;
+#pragma omp parallel for lastprivate(i)
+  for (i = x; i != y - 1; i = 2 - 8 + 7 + i)
+    baz (i);
+  return I<int> (i);
+}
+
+template <typename T>
+I<int>
+f3 (const I<int> &x, const I<int> &y)
+{
+  I<int> i;
+#pragma omp parallel
+  #pragma omp for lastprivate (i)
+    for (i = x; i != y; i = i + 9 - 8)
+      baz (i);
+  return i;
+}
+
+template <typename T>
+I<int>
+f4 (const I<int> &x, const I<int> &y)
+{
+  I<int> i;
+#pragma omp parallel for lastprivate(i)
+  for (i = x + 2000 - 64; i != y + 10; --i)
+    baz (i);
+  return I<int> (i);
+}
+
+template <typename T>
+I<int>
+f5 (const I<int> &x, const I<int> &y)
+{
+  I<int> i;
+#pragma omp parallel for lastprivate(i)
+  for (i = x + 2000 - 64; i != y + T (10); i--)
+    baz (i);
+  return i;
+}
+
+template <typename T>
+I<int>
+f6 (const I<int> &x, const I<int> &y)
+{
+  I<int> i;
+#pragma omp parallel for lastprivate (i)
+  for (i = x + 2000 - 64; i != y + 10; i = i - T (12) + T (11))
+    {
+      I<int> j = i + -10;
+      baz (j);
+    }
+  return I<int> (i);
+}
+
+template <int N>
+I<int>
+f7 (I<int> i, const I<int> &x, const I<int> &y)
+{
+#pragma omp parallel for lastprivate(i)
+  for (i = x - 10; i != y + 10; i += N)
+    baz (i);
+  return I<int> (i);
+}
+
+template <int N>
+I<int>
+f8 (J<int> j)
+{
+  I<int> i;
+#pragma omp parallel shared \
+(i)
+#pragma omp for lastprivate (i)
+  for (i = j.begin (); i != j.end () + N; i += 1)
+    baz (i);
+  return i;
+}
+
+I<int> i9;
+
+template <long N>
+I<int> &
+f9 (J<int> j)
+{
+#pragma omp parallel for lastprivate(i9)
+  for (i9 = j.begin (); i9 != j.end () - N; i9 = i9 - N)
+    baz (i9);
+  return i9;
+}
+
+template <typename T, int N>
+I<T>
+f10 (const I<T> &x, const I<T> &y)
+{
+  I<T> i;
+#pragma omp parallel for lastprivate (i)
+  for (i = x; i != y; i = i + N)
+    baz (i);
+  return i;
+}
+
+template <typename T, typename U>
+T
+f11 (T i, const T &x, const T &y)
+{
+#pragma omp parallel
+  {
+#pragma omp for lastprivate (i)
+    for (i = x + U (0); i != y + U (2 - 2); i = U(3) + U(-2) + i)
+      baz (i);
+#pragma omp single
+    {
+      T j = y + 3;
+      baz (j);
+    }
+  }
+  return i;
+}
+
+template <typename T>
+T
+f12 (const T &x, const T &y)
+{
+  T i;
+#pragma omp parallel for lastprivate (i)
+  for (i = x; i != y; --i)
+    baz (i);
+  return i;
+}
+
+#define check(expr) \
+  for (int i = 0; i < 2000; i++)                       \
+    if (expr)                                          \
+      {                                                        \
+       if (results[i] != 1)                            \
+         abort ();                                     \
+       results[i] = 0;                                 \
+      }                                                        \
+    else if (results[i])                               \
+      abort ()
+
+int
+main ()
+{
+  int a[2000];
+  long b[2000];
+  for (int i = 0; i < 2000; i++)
+    {
+      a[i] = i;
+      b[i] = i;
+    }
+  if (*f1 (&a[10], &a[1990]) != 1993)
+    abort ();
+  check (i >= 10 && i < 1990);
+  if (*f2 (&a[0], &a[1999]) != 1998)
+    abort ();
+  check (i < 1998);
+  if (*f3<char> (&a[20], &a[1837]) != 1837)
+    abort ();
+  check (i >= 20 && i < 1837);
+  if (*f4<int> (&a[0], &a[30]) != 40)
+    abort ();
+  check (i > 40 && i <= 2000 - 64);
+  if (*f5<int> (&a[0], &a[100]) != 110)
+    abort ();
+  check (i > 110 && i <= 2000 - 64);
+  if (*f6<int> (&a[10], &a[110]) != 120)
+    abort ();
+  check (i > 110 && i <= 2000 - 64);
+  if (*f7<1> (I<int> (), &a[12], &a[1800]) != 1810)
+    abort ();
+  check (i >= 2 && i < 1810);
+  if (*f8<121> (J<int> (&a[14], &a[1803])) != 1924)
+    abort ();
+  check (i >= 14 && i < 1924);
+  if (*f9<-1> (J<int> (&a[33], &a[1967])) != 1968)
+    abort ();
+  check (i >= 33 && i <= 1967);
+  if (*f10<int, -1> (&a[1939], &a[17]) != 17)
+    abort ();
+  check (i > 17 && i <= 1939);
+  if (*f11<I<int>, int> (I<int> (), &a[16], &a[1981]) != 1981)
+    abort ();
+  check ((i >= 16 && i < 1981) || i == 1984);
+  if (*f12<I<int> > (&a[1761], &a[37]) != 37)
+    abort ();
+  check (i > 37 && i <= 1761);
+  if (*f10<long, -1> (&b[1939], &b[17]) != 17)
+    abort ();
+  check (i > 17 && i <= 1939);
+  if (*f11<I<long>, long> (I<long> (), &b[16], &b[1981]) != 1981)
+    abort ();
+  check ((i >= 16 && i < 1981) || i == 1984);
+  if (*f12<I<long> > (&b[1761], &b[37]) != 37)
+    abort ();
+  check (i > 37 && i <= 1761);
+}
diff --git a/libgomp/testsuite/libgomp.c++/for-23.C b/libgomp/testsuite/libgomp.c++/for-23.C
new file mode 100644 (file)
index 0000000..e0d7b7a
--- /dev/null
@@ -0,0 +1,416 @@
+// { dg-do run }
+// { dg-additional-options "-std=c++17" }
+
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+extern "C" void abort ();
+
+namespace std {
+  template<typename T> struct tuple_size;
+  template<int, typename> struct tuple_element;
+}
+
+template <typename T>
+class I
+{
+public:
+  typedef ptrdiff_t difference_type;
+  I ();
+  ~I ();
+  I (T *);
+  I (const I &);
+  T &operator * ();
+  T *operator -> ();
+  T &operator [] (const difference_type &) const;
+  I &operator = (const I &);
+  I &operator ++ ();
+  I operator ++ (int);
+  I &operator -- ();
+  I operator -- (int);
+  I &operator += (const difference_type &);
+  I &operator -= (const difference_type &);
+  I operator + (const difference_type &) const;
+  I operator - (const difference_type &) const;
+  template <typename S> friend bool operator == (I<S> &, I<S> &);
+  template <typename S> friend bool operator == (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator < (I<S> &, I<S> &);
+  template <typename S> friend bool operator < (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator <= (I<S> &, I<S> &);
+  template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator > (I<S> &, I<S> &);
+  template <typename S> friend bool operator > (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator >= (I<S> &, I<S> &);
+  template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
+  template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
+private:
+  T *p;
+};
+template <typename T> I<T>::I () : p (0) {}
+template <typename T> I<T>::~I () {}
+template <typename T> I<T>::I (T *x) : p (x) {}
+template <typename T> I<T>::I (const I &x) : p (x.p) {}
+template <typename T> T &I<T>::operator * () { return *p; }
+template <typename T> T *I<T>::operator -> () { return p; }
+template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; }
+template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; }
+template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; }
+template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); }
+template <typename T> I<T> &I<T>::operator -- () { --p; return *this; }
+template <typename T> I<T> I<T>::operator -- (int) { return I (p--); }
+template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; }
+template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; }
+template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); }
+template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); }
+template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; }
+template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; }
+template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); }
+template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); }
+template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; }
+template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; }
+template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; }
+template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; }
+template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; }
+template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; }
+template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; }
+template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; }
+template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; }
+template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; }
+template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); }
+
+template <typename T>
+class J
+{
+public:
+  J(const I<T> &x, const I<T> &y) : b (x), e (y) {}
+  const I<T> &begin ();
+  const I<T> &end ();
+private:
+  I<T> b, e;
+};
+
+template <typename T> const I<T> &J<T>::begin () { return b; }
+template <typename T> const I<T> &J<T>::end () { return e; }
+
+template <typename T>
+class K
+{
+public:
+  K ();
+  ~K ();
+  template <int N> T &get () { if (N == 0) return c; else if (N == 1) return b; return a; }
+  T a, b, c;
+};
+
+template <typename T> K<T>::K () : a {}, b {}, c {} {}
+template <typename T> K<T>::~K () {}
+template <typename T> struct std::tuple_size<K<T>> { static constexpr int value = 3; };
+template <typename T, int N> struct std::tuple_element<N, K<T>> { using type = T; };
+
+template <typename T>
+class L
+{
+public:
+  L ();
+  ~L ();
+  T a, b, c;
+};
+
+template <typename T> L<T>::L () : a {}, b {}, c {} {}
+template <typename T> L<T>::~L () {}
+
+int a[2000];
+long b[40];
+short c[50];
+int d[1024];
+K<int> e[1089];
+L<int> f[1093];
+int results[2000];
+
+template <typename T>
+void
+baz (I<T> &i)
+{
+  if (*i < 0 || *i >= 2000)
+    abort ();
+  results[*i]++;
+}
+
+void
+baz (int i)
+{
+  if (i < 0 || i >= 2000)
+    abort ();
+  results[i]++;
+}
+
+void
+f1 ()
+{
+#pragma omp parallel for default(none) shared(a)
+  for (auto i : a)
+    baz (i);
+}
+
+void
+f2 ()
+{
+#pragma omp parallel for default(none) shared(a)
+  for (auto &i : a)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+void
+f3 ()
+{
+#pragma omp parallel for collapse(3) default(none) shared(b, c)
+  for (auto &i : b)
+    for (int j = 9; j < 10; j++)
+      for (auto k : c)
+       if (&i != &b[i] || i < 0 || i >= 40 || j != 9 || k < 0 || k >= 50)
+         abort ();
+       else
+         baz (i * 50 + k);
+}
+
+void
+f4 (J<int> j)
+{
+#pragma omp parallel for default(none) shared(j, a)
+  for (auto &i : j)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+void
+f5 ()
+{
+#pragma omp parallel for simd default(none) shared(d, results)
+  for (auto i : d)
+    results[i % 1024] += 2 * ((unsigned) i >> 10) + 1;
+}
+
+void
+f6 (J<K<int>> j)
+{
+#pragma omp parallel for default(none) shared(j, e)
+  for (auto & [k, l, m] : j)
+    if (&k != &e[m].c || &l != &e[m].b || &m != &e[m].a || k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+void
+f7 (J<L<int>> j)
+{
+#pragma omp parallel for default(none) shared(j, f)
+  for (auto & [k, l, m] : j)
+    if (&k != &f[k].a || &l != &f[k].b || &m != &f[k].c || l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+
+void
+f8 (J<K<int>> j)
+{
+#pragma omp parallel for default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+void
+f9 (J<L<int>> j)
+{
+#pragma omp parallel for default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+
+template <int N>
+void
+f10 ()
+{
+#pragma omp parallel for default(none) shared(a)
+  for (auto i : a)
+    baz (i);
+}
+
+template <int N>
+void
+f11 ()
+{
+#pragma omp parallel for default(none) shared(a)
+  for (auto &i : a)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+template <int N>
+void
+f12 ()
+{
+#pragma omp parallel for collapse(3) default(none) shared(a, b, c)
+  for (auto &i : b)
+    for (I<int> j = I<int> (&a[9]); j < I<int> (&a[10]); j++)
+      for (auto k : c)
+       if (&i != &b[i] || i < 0 || i >= 40 || *j != 9 || k < 0 || k >= 50)
+         abort ();
+       else
+         baz (i * 50 + k);
+}
+
+template <typename T>
+void
+f13 (J<T> j)
+{
+#pragma omp parallel for default(none) shared(j, a)
+  for (auto &i : j)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+template <int N>
+void
+f14 ()
+{
+#pragma omp parallel for simd default(none) shared(d, results)
+  for (auto i : d)
+    results[i % N] += 2 * ((unsigned) i >> 10) + 1;
+}
+
+template <typename T>
+void
+f15 (J<K<T>> j)
+{
+#pragma omp parallel for default(none) shared(j, e)
+  for (auto & [k, l, m] : j)
+    if (&k != &e[m].c || &l != &e[m].b || &m != &e[m].a || k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+template <typename T>
+void
+f16 (J<L<T>> j)
+{
+#pragma omp parallel for default(none) shared(j, f)
+  for (auto & [k, l, m] : j)
+    if (&k != &f[k].a || &l != &f[k].b || &m != &f[k].c || l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+
+template <int N>
+void
+f17 (J<K<int>> j)
+{
+#pragma omp parallel for default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+template <int N>
+void
+f18 (J<L<int>> j)
+{
+#pragma omp parallel for default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+
+#define check(expr) \
+  for (int i = 0; i < 2000; i++)                       \
+    if (expr)                                          \
+      {                                                        \
+       if (results[i] != 1)                            \
+         abort ();                                     \
+       results[i] = 0;                                 \
+      }                                                        \
+    else if (results[i])                               \
+      abort ()
+
+int
+main ()
+{
+  for (int i = 0; i < 2000; i++)
+    a[i] = i;
+  for (int i = 0; i < 40; i++)
+    b[i] = i;
+  for (int i = 0; i < 50; i++)
+    c[i] = i;
+  for (int i = 0; i < 1024; i++)
+    d[i] = i;
+  for (int i = 0; i < 1089; i++)
+    {
+      e[i].a = i;
+      e[i].b = 2 * i;
+      e[i].c = 3 * i;
+    }
+  for (int i = 0; i < 1093; i++)
+    {
+      f[i].a = i;
+      f[i].b = 4 * i;
+      f[i].c = 5 * i;
+    }
+  f1 ();
+  check (1);
+  f2 ();
+  check (1);
+  f3 ();
+  check (1);
+  f4 (J<int> (&a[14], &a[1803]));
+  check (i >= 14 && i < 1803);
+  f5 ();
+  check (i >= 0 && i < 1024);
+  f6 (J<K<int>> (&e[19], &e[1029]));
+  check (i >= 19 && i < 1029);
+  f7 (J<L<int>> (&f[15], &f[1091]));
+  check (i >= 15 && i < 1091);
+  f8 (J<K<int>> (&e[27], &e[1037]));
+  check (i >= 27 && i < 1037);
+  f9 (J<L<int>> (&f[1], &f[1012]));
+  check (i >= 1 && i < 1012);
+  f10 <0> ();
+  check (1);
+  f11 <1> ();
+  check (1);
+  f12 <2> ();
+  check (1);
+  f13 (J<int> (&a[24], &a[1703]));
+  check (i >= 24 && i < 1703);
+  f14 <1024> ();
+  check (i >= 0 && i < 1024);
+  f15 (J<K<int>> (&e[39], &e[929]));
+  check (i >= 39 && i < 929);
+  f16 (J<L<int>> (&f[17], &f[1071]));
+  check (i >= 17 && i < 1071);
+  f17 <3> (J<K<int>> (&e[7], &e[1017]));
+  check (i >= 7 && i < 1017);
+  f18 <5> (J<L<int>> (&f[121], &f[1010]));
+  check (i >= 121 && i < 1010);
+}
diff --git a/libgomp/testsuite/libgomp.c++/for-24.C b/libgomp/testsuite/libgomp.c++/for-24.C
new file mode 100644 (file)
index 0000000..cb14add
--- /dev/null
@@ -0,0 +1,427 @@
+// { dg-do run }
+// { dg-additional-options "-std=c++17" }
+
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+extern "C" void abort ();
+
+namespace std {
+  template<typename T> struct tuple_size;
+  template<int, typename> struct tuple_element;
+}
+
+#pragma omp declare target
+template <typename T>
+class I
+{
+public:
+  typedef ptrdiff_t difference_type;
+  I ();
+  ~I ();
+  I (T *);
+  I (const I &);
+  T &operator * ();
+  T *operator -> ();
+  T &operator [] (const difference_type &) const;
+  I &operator = (const I &);
+  I &operator ++ ();
+  I operator ++ (int);
+  I &operator -- ();
+  I operator -- (int);
+  I &operator += (const difference_type &);
+  I &operator -= (const difference_type &);
+  I operator + (const difference_type &) const;
+  I operator - (const difference_type &) const;
+  template <typename S> friend bool operator == (I<S> &, I<S> &);
+  template <typename S> friend bool operator == (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator < (I<S> &, I<S> &);
+  template <typename S> friend bool operator < (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator <= (I<S> &, I<S> &);
+  template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator > (I<S> &, I<S> &);
+  template <typename S> friend bool operator > (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator >= (I<S> &, I<S> &);
+  template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
+  template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
+private:
+  T *p;
+};
+template <typename T> I<T>::I () : p (0) {}
+template <typename T> I<T>::~I () {}
+template <typename T> I<T>::I (T *x) : p (x) {}
+template <typename T> I<T>::I (const I &x) : p (x.p) {}
+template <typename T> T &I<T>::operator * () { return *p; }
+template <typename T> T *I<T>::operator -> () { return p; }
+template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; }
+template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; }
+template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; }
+template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); }
+template <typename T> I<T> &I<T>::operator -- () { --p; return *this; }
+template <typename T> I<T> I<T>::operator -- (int) { return I (p--); }
+template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; }
+template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; }
+template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); }
+template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); }
+template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; }
+template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; }
+template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); }
+template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); }
+template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; }
+template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; }
+template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; }
+template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; }
+template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; }
+template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; }
+template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; }
+template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; }
+template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; }
+template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; }
+template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); }
+
+template <typename T>
+class J
+{
+public:
+  J(const I<T> &x, const I<T> &y) : b (x), e (y) {}
+  const I<T> &begin ();
+  const I<T> &end ();
+private:
+  I<T> b, e;
+};
+
+template <typename T> const I<T> &J<T>::begin () { return b; }
+template <typename T> const I<T> &J<T>::end () { return e; }
+
+struct K
+{
+  template <int N> int &get () { if (N == 0) return c; else if (N == 1) return b; return a; }
+  int a, b, c;
+};
+
+template <> struct std::tuple_size<K> { static constexpr int value = 3; };
+template <int N> struct std::tuple_element<N, K> { using type = int; };
+
+struct L
+{
+  int a, b, c;
+};
+
+int a[2000];
+long b[40];
+short c[50];
+int d[1024];
+K e[1089];
+L f[1093];
+#pragma omp end declare target
+
+int results[2000];
+
+#pragma omp declare target
+template <typename T>
+void
+baz (I<T> &i)
+{
+  if (*i < 0 || *i >= 2000)
+    abort ();
+  results[*i]++;
+}
+
+void
+baz (int i)
+{
+  if (i < 0 || i >= 2000)
+    abort ();
+  results[i]++;
+}
+
+void
+f1 ()
+{
+#pragma omp distribute parallel for default(none) shared(a)
+  for (auto i : a)
+    baz (i);
+}
+
+void
+f2 ()
+{
+#pragma omp distribute parallel for default(none) shared(a)
+  for (auto &i : a)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+void
+f3 ()
+{
+#pragma omp distribute parallel for collapse(3) default(none) shared(b, c)
+  for (auto &i : b)
+    for (int j = 9; j < 10; j++)
+      for (auto k : c)
+       if (&i != &b[i] || i < 0 || i >= 40 || j != 9 || k < 0 || k >= 50)
+         abort ();
+       else
+         baz (i * 50 + k);
+}
+
+void
+f4 (J<int> j)
+{
+#pragma omp distribute parallel for default(none) shared(j, a)
+  for (auto &i : j)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+void
+f5 ()
+{
+#pragma omp distribute parallel for simd default(none) shared(d, results)
+  for (auto i : d)
+    results[i % 1024] += 2 * ((unsigned) i >> 10) + 1;
+}
+
+void
+f6 (J<K> j)
+{
+#pragma omp distribute parallel for default(none) shared(j, e)
+  for (auto & [k, l, m] : j)
+    if (&k != &e[m].c || &l != &e[m].b || &m != &e[m].a || k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+void
+f7 (J<L> j)
+{
+#pragma omp distribute parallel for default(none) shared(j, f)
+  for (auto & [k, l, m] : j)
+    if (&k != &f[k].a || &l != &f[k].b || &m != &f[k].c || l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+
+void
+f8 (J<K> j)
+{
+#pragma omp distribute parallel for default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+void
+f9 (J<L> j)
+{
+#pragma omp distribute parallel for default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+
+template <int N>
+void
+f10 ()
+{
+#pragma omp distribute parallel for default(none) shared(a)
+  for (auto i : a)
+    baz (i);
+}
+
+template <int N>
+void
+f11 ()
+{
+#pragma omp distribute parallel for default(none) shared(a)
+  for (auto &i : a)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+template <int N>
+void
+f12 ()
+{
+#pragma omp distribute parallel for collapse(3) default(none) shared(a, b, c)
+  for (auto &i : b)
+    for (I<int> j = I<int> (&a[9]); j < I<int> (&a[10]); j++)
+      for (auto k : c)
+       if (&i != &b[i] || i < 0 || i >= 40 || *j != 9 || k < 0 || k >= 50)
+         abort ();
+       else
+         baz (i * 50 + k);
+}
+
+template <typename T>
+void
+f13 (J<T> j)
+{
+#pragma omp distribute parallel for default(none) shared(j, a)
+  for (auto &i : j)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+template <int N>
+void
+f14 ()
+{
+#pragma omp distribute parallel for simd default(none) shared(d, results)
+  for (auto i : d)
+    results[i % N] += 2 * ((unsigned) i >> 10) + 1;
+}
+
+template <typename T>
+void
+f15 (J<T> j)
+{
+#pragma omp distribute parallel for default(none) shared(j, e)
+  for (auto & [k, l, m] : j)
+    if (&k != &e[m].c || &l != &e[m].b || &m != &e[m].a || k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+template <typename T>
+void
+f16 (J<T> j)
+{
+#pragma omp distribute parallel for default(none) shared(j, f)
+  for (auto & [k, l, m] : j)
+    if (&k != &f[k].a || &l != &f[k].b || &m != &f[k].c || l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+
+template <int N>
+void
+f17 (J<K> j)
+{
+#pragma omp distribute parallel for default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+template <int N>
+void
+f18 (J<L> j)
+{
+#pragma omp distribute parallel for default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+#pragma omp end declare target
+
+#define check(expr) \
+  for (int i = 0; i < 2000; i++)                       \
+    if (expr)                                          \
+      {                                                        \
+       if (results[i] != 1)                            \
+         abort ();                                     \
+       results[i] = 0;                                 \
+      }                                                        \
+    else if (results[i])                               \
+      abort ()
+
+int
+main ()
+{
+  for (int i = 0; i < 2000; i++)
+    a[i] = i;
+  for (int i = 0; i < 40; i++)
+    b[i] = i;
+  for (int i = 0; i < 50; i++)
+    c[i] = i;
+  for (int i = 0; i < 1024; i++)
+    d[i] = i;
+  for (int i = 0; i < 1089; i++)
+    {
+      e[i].a = i;
+      e[i].b = 2 * i;
+      e[i].c = 3 * i;
+    }
+  for (int i = 0; i < 1093; i++)
+    {
+      f[i].a = i;
+      f[i].b = 4 * i;
+      f[i].c = 5 * i;
+    }
+  #pragma omp target update to (a, b, c, d, e, f)
+  #pragma omp target teams map (tofrom: results)
+  f1 ();
+  check (1);
+  #pragma omp target teams map (tofrom: results)
+  f2 ();
+  check (1);
+  #pragma omp target teams map (tofrom: results)
+  f3 ();
+  check (1);
+  #pragma omp target teams map (tofrom: results)
+  f4 (J<int> (&a[14], &a[1803]));
+  check (i >= 14 && i < 1803);
+  #pragma omp target teams map (tofrom: results)
+  f5 ();
+  check (i >= 0 && i < 1024);
+  #pragma omp target teams map (tofrom: results)
+  f6 (J<K> (&e[19], &e[1029]));
+  check (i >= 19 && i < 1029);
+  #pragma omp target teams map (tofrom: results)
+  f7 (J<L> (&f[15], &f[1091]));
+  check (i >= 15 && i < 1091);
+  #pragma omp target teams map (tofrom: results)
+  f8 (J<K> (&e[27], &e[1037]));
+  check (i >= 27 && i < 1037);
+  #pragma omp target teams map (tofrom: results)
+  f9 (J<L> (&f[1], &f[1012]));
+  check (i >= 1 && i < 1012);
+  #pragma omp target teams map (tofrom: results)
+  f10 <0> ();
+  check (1);
+  #pragma omp target teams map (tofrom: results)
+  f11 <1> ();
+  check (1);
+  #pragma omp target teams map (tofrom: results)
+  f12 <2> ();
+  check (1);
+  #pragma omp target teams map (tofrom: results)
+  f13 (J<int> (&a[24], &a[1703]));
+  check (i >= 24 && i < 1703);
+  #pragma omp target teams map (tofrom: results)
+  f14 <1024> ();
+  check (i >= 0 && i < 1024);
+  #pragma omp target teams map (tofrom: results)
+  f15 (J<K> (&e[39], &e[929]));
+  check (i >= 39 && i < 929);
+  #pragma omp target teams map (tofrom: results)
+  f16 (J<L> (&f[17], &f[1071]));
+  check (i >= 17 && i < 1071);
+  #pragma omp target teams map (tofrom: results)
+  f17 <3> (J<K> (&e[7], &e[1017]));
+  check (i >= 7 && i < 1017);
+  #pragma omp target teams map (tofrom: results)
+  f18 <5> (J<L> (&f[121], &f[1010]));
+  check (i >= 121 && i < 1010);
+}
diff --git a/libgomp/testsuite/libgomp.c++/for-25.C b/libgomp/testsuite/libgomp.c++/for-25.C
new file mode 100644 (file)
index 0000000..3fecb48
--- /dev/null
@@ -0,0 +1,420 @@
+// { dg-do run }
+// { dg-additional-options "-std=c++17" }
+
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+extern "C" void abort ();
+
+namespace std {
+  template<typename T> struct tuple_size;
+  template<int, typename> struct tuple_element;
+}
+
+template <typename T>
+class I
+{
+public:
+  typedef ptrdiff_t difference_type;
+  I ();
+  ~I ();
+  I (T *);
+  I (const I &);
+  T &operator * ();
+  T *operator -> ();
+  T &operator [] (const difference_type &) const;
+  I &operator = (const I &);
+  I &operator ++ ();
+  I operator ++ (int);
+  I &operator -- ();
+  I operator -- (int);
+  I &operator += (const difference_type &);
+  I &operator -= (const difference_type &);
+  I operator + (const difference_type &) const;
+  I operator - (const difference_type &) const;
+  template <typename S> friend bool operator == (I<S> &, I<S> &);
+  template <typename S> friend bool operator == (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator < (I<S> &, I<S> &);
+  template <typename S> friend bool operator < (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator <= (I<S> &, I<S> &);
+  template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator > (I<S> &, I<S> &);
+  template <typename S> friend bool operator > (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator >= (I<S> &, I<S> &);
+  template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
+  template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
+private:
+  T *p;
+};
+template <typename T> I<T>::I () : p (0) {}
+template <typename T> I<T>::~I () {}
+template <typename T> I<T>::I (T *x) : p (x) {}
+template <typename T> I<T>::I (const I &x) : p (x.p) {}
+template <typename T> T &I<T>::operator * () { return *p; }
+template <typename T> T *I<T>::operator -> () { return p; }
+template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; }
+template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; }
+template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; }
+template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); }
+template <typename T> I<T> &I<T>::operator -- () { --p; return *this; }
+template <typename T> I<T> I<T>::operator -- (int) { return I (p--); }
+template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; }
+template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; }
+template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); }
+template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); }
+template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; }
+template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; }
+template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); }
+template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); }
+template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; }
+template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; }
+template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; }
+template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; }
+template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; }
+template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; }
+template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; }
+template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; }
+template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; }
+template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; }
+template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); }
+
+template <typename T>
+class J
+{
+public:
+  J(const I<T> &x, const I<T> &y) : b (x), e (y) {}
+  const I<T> &begin ();
+  const I<T> &end ();
+private:
+  I<T> b, e;
+};
+
+template <typename T> const I<T> &J<T>::begin () { return b; }
+template <typename T> const I<T> &J<T>::end () { return e; }
+
+template <typename T>
+class K
+{
+public:
+  K ();
+  ~K ();
+  template <int N> T &get () { if (N == 0) return c; else if (N == 1) return b; return a; }
+  T a, b, c;
+};
+
+template <typename T> K<T>::K () : a {}, b {}, c {} {}
+template <typename T> K<T>::~K () {}
+template <typename T> struct std::tuple_size<K<T>> { static constexpr int value = 3; };
+template <typename T, int N> struct std::tuple_element<N, K<T>> { using type = T; };
+
+template <typename T>
+class L
+{
+public:
+  L ();
+  ~L ();
+  T a, b, c;
+};
+
+template <typename T> L<T>::L () : a {}, b {}, c {} {}
+template <typename T> L<T>::~L () {}
+
+int a[2000];
+long b[40];
+short c[50];
+int d[1024];
+K<int> e[1089];
+L<int> f[1093];
+int results[2000];
+
+template <typename T>
+void
+baz (I<T> &i)
+{
+  if (*i < 0 || *i >= 2000)
+    abort ();
+  results[*i]++;
+}
+
+void
+baz (int i)
+{
+  if (i < 0 || i >= 2000)
+    abort ();
+  results[i]++;
+}
+
+void
+f1 ()
+{
+#pragma omp taskloop default(none) shared(a)
+  for (auto i : a)
+    baz (i);
+}
+
+void
+f2 ()
+{
+#pragma omp taskloop default(none) shared(a)
+  for (auto &i : a)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+void
+f3 ()
+{
+#pragma omp taskloop collapse(3) default(none) shared(b, c)
+  for (auto &i : b)
+    for (int j = 9; j < 10; j++)
+      for (auto k : c)
+       if (&i != &b[i] || i < 0 || i >= 40 || j != 9 || k < 0 || k >= 50)
+         abort ();
+       else
+         baz (i * 50 + k);
+}
+
+void
+f4 (J<int> j)
+{
+#pragma omp taskloop default(none) shared(j, a)
+  for (auto &i : j)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+void
+f5 ()
+{
+#pragma omp taskloop simd default(none) shared(d, results)
+  for (auto i : d)
+    results[i % 1024] += 2 * ((unsigned) i >> 10) + 1;
+}
+
+void
+f6 (J<K<int>> j)
+{
+#pragma omp taskloop default(none) shared(j, e)
+  for (auto & [k, l, m] : j)
+    if (&k != &e[m].c || &l != &e[m].b || &m != &e[m].a || k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+void
+f7 (J<L<int>> j)
+{
+#pragma omp taskloop default(none) shared(j, f)
+  for (auto & [k, l, m] : j)
+    if (&k != &f[k].a || &l != &f[k].b || &m != &f[k].c || l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+
+void
+f8 (J<K<int>> j)
+{
+#pragma omp taskloop default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+void
+f9 (J<L<int>> j)
+{
+#pragma omp taskloop default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+
+template <int N>
+void
+f10 ()
+{
+#pragma omp taskloop default(none) shared(a)
+  for (auto i : a)
+    baz (i);
+}
+
+template <int N>
+void
+f11 ()
+{
+#pragma omp taskloop default(none) shared(a)
+  for (auto &i : a)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+template <int N>
+void
+f12 ()
+{
+#pragma omp taskloop collapse(3) default(none) shared(a, b, c)
+  for (auto &i : b)
+    for (I<int> j = I<int> (&a[9]); j < I<int> (&a[10]); j++)
+      for (auto k : c)
+       if (&i != &b[i] || i < 0 || i >= 40 || *j != 9 || k < 0 || k >= 50)
+         abort ();
+       else
+         baz (i * 50 + k);
+}
+
+template <typename T>
+void
+f13 (J<T> j)
+{
+#pragma omp taskloop default(none) shared(j, a)
+  for (auto &i : j)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+template <int N>
+void
+f14 ()
+{
+#pragma omp taskloop simd default(none) shared(d, results)
+  for (auto i : d)
+    results[i % N] += 2 * ((unsigned) i >> 10) + 1;
+}
+
+template <typename T>
+void
+f15 (J<K<T>> j)
+{
+#pragma omp taskloop default(none) shared(j, e)
+  for (auto & [k, l, m] : j)
+    if (&k != &e[m].c || &l != &e[m].b || &m != &e[m].a || k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+template <typename T>
+void
+f16 (J<L<T>> j)
+{
+#pragma omp taskloop default(none) shared(j, f)
+  for (auto & [k, l, m] : j)
+    if (&k != &f[k].a || &l != &f[k].b || &m != &f[k].c || l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+
+template <int N>
+void
+f17 (J<K<int>> j)
+{
+#pragma omp taskloop default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+template <int N>
+void
+f18 (J<L<int>> j)
+{
+#pragma omp taskloop default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+
+#define check(expr) \
+  for (int i = 0; i < 2000; i++)                       \
+    if (expr)                                          \
+      {                                                        \
+       if (results[i] != 1)                            \
+         abort ();                                     \
+       results[i] = 0;                                 \
+      }                                                        \
+    else if (results[i])                               \
+      abort ()
+
+int
+main ()
+{
+  for (int i = 0; i < 2000; i++)
+    a[i] = i;
+  for (int i = 0; i < 40; i++)
+    b[i] = i;
+  for (int i = 0; i < 50; i++)
+    c[i] = i;
+  for (int i = 0; i < 1024; i++)
+    d[i] = i;
+  for (int i = 0; i < 1089; i++)
+    {
+      e[i].a = i;
+      e[i].b = 2 * i;
+      e[i].c = 3 * i;
+    }
+  for (int i = 0; i < 1093; i++)
+    {
+      f[i].a = i;
+      f[i].b = 4 * i;
+      f[i].c = 5 * i;
+    }
+  #pragma omp parallel
+  #pragma omp single
+  {
+    f1 ();
+    check (1);
+    f2 ();
+    check (1);
+    f3 ();
+    check (1);
+    f4 (J<int> (&a[14], &a[1803]));
+    check (i >= 14 && i < 1803);
+    f5 ();
+    check (i >= 0 && i < 1024);
+    f6 (J<K<int>> (&e[19], &e[1029]));
+    check (i >= 19 && i < 1029);
+    f7 (J<L<int>> (&f[15], &f[1091]));
+    check (i >= 15 && i < 1091);
+    f8 (J<K<int>> (&e[27], &e[1037]));
+    check (i >= 27 && i < 1037);
+    f9 (J<L<int>> (&f[1], &f[1012]));
+    check (i >= 1 && i < 1012);
+    f10 <0> ();
+    check (1);
+    f11 <1> ();
+    check (1);
+    f12 <2> ();
+    check (1);
+    f13 (J<int> (&a[24], &a[1703]));
+    check (i >= 24 && i < 1703);
+    f14 <1024> ();
+    check (i >= 0 && i < 1024);
+    f15 (J<K<int>> (&e[39], &e[929]));
+    check (i >= 39 && i < 929);
+    f16 (J<L<int>> (&f[17], &f[1071]));
+    check (i >= 17 && i < 1071);
+    f17 <3> (J<K<int>> (&e[7], &e[1017]));
+    check (i >= 7 && i < 1017);
+    f18 <5> (J<L<int>> (&f[121], &f[1010]));
+    check (i >= 121 && i < 1010);
+  }
+}
diff --git a/libgomp/testsuite/libgomp.c++/for-26.C b/libgomp/testsuite/libgomp.c++/for-26.C
new file mode 100644 (file)
index 0000000..bb7ae11
--- /dev/null
@@ -0,0 +1,422 @@
+// { dg-do run }
+// { dg-additional-options "-std=c++17" }
+
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+extern "C" void abort ();
+
+namespace std {
+  template<typename T> struct tuple_size;
+  template<int, typename> struct tuple_element;
+}
+
+template <typename T>
+class I
+{
+public:
+  typedef ptrdiff_t difference_type;
+  I ();
+  ~I ();
+  I (T *);
+  I (const I &);
+  T &operator * ();
+  T *operator -> ();
+  T &operator [] (const difference_type &) const;
+  I &operator = (const I &);
+  I &operator ++ ();
+  I operator ++ (int);
+  I &operator -- ();
+  I operator -- (int);
+  I &operator += (const difference_type &);
+  I &operator -= (const difference_type &);
+  I operator + (const difference_type &) const;
+  I operator - (const difference_type &) const;
+  template <typename S> friend bool operator == (I<S> &, I<S> &);
+  template <typename S> friend bool operator == (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator < (I<S> &, I<S> &);
+  template <typename S> friend bool operator < (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator <= (I<S> &, I<S> &);
+  template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator > (I<S> &, I<S> &);
+  template <typename S> friend bool operator > (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator >= (I<S> &, I<S> &);
+  template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
+  template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
+private:
+  T *p;
+};
+template <typename T> I<T>::I () : p (0) {}
+template <typename T> I<T>::~I () {}
+template <typename T> I<T>::I (T *x) : p (x) {}
+template <typename T> I<T>::I (const I &x) : p (x.p) {}
+template <typename T> T &I<T>::operator * () { return *p; }
+template <typename T> T *I<T>::operator -> () { return p; }
+template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; }
+template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; }
+template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; }
+template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); }
+template <typename T> I<T> &I<T>::operator -- () { --p; return *this; }
+template <typename T> I<T> I<T>::operator -- (int) { return I (p--); }
+template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; }
+template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; }
+template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); }
+template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); }
+template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; }
+template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; }
+template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); }
+template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); }
+template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; }
+template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; }
+template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; }
+template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; }
+template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; }
+template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; }
+template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; }
+template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; }
+template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; }
+template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; }
+template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); }
+
+template <typename T>
+class J
+{
+public:
+  J(const I<T> &x, const I<T> &y) : b (x), e (y) {}
+  const I<T> &begin ();
+  const I<T> &end ();
+private:
+  I<T> b, e;
+};
+
+template <typename T> const I<T> &J<T>::begin () { return b; }
+template <typename T> const I<T> &J<T>::end () { return e; }
+
+struct K
+{
+  template <int N> int &get () { if (N == 0) return c; else if (N == 1) return b; return a; }
+  int a, b, c;
+};
+
+template <> struct std::tuple_size<K> { static constexpr int value = 3; };
+template <int N> struct std::tuple_element<N, K> { using type = int; };
+
+struct L
+{
+  int a, b, c;
+};
+
+int a[2000];
+long b[40];
+short c[50];
+int d[1024];
+K e[1089];
+L f[1093];
+
+int results[2000];
+
+template <typename T>
+void
+baz (I<T> &i)
+{
+  if (*i < 0 || *i >= 2000)
+    abort ();
+  results[*i]++;
+}
+
+void
+baz (int i)
+{
+  if (i < 0 || i >= 2000)
+    abort ();
+  results[i]++;
+}
+
+void
+f1 ()
+{
+#pragma omp distribute parallel for default(none) shared(a)
+  for (auto i : a)
+    baz (i);
+}
+
+void
+f2 ()
+{
+#pragma omp distribute parallel for default(none) shared(a)
+  for (auto &i : a)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+void
+f3 ()
+{
+#pragma omp distribute parallel for collapse(3) default(none) shared(b, c)
+  for (auto &i : b)
+    for (int j = 9; j < 10; j++)
+      for (auto k : c)
+       if (&i != &b[i] || i < 0 || i >= 40 || j != 9 || k < 0 || k >= 50)
+         abort ();
+       else
+         baz (i * 50 + k);
+}
+
+void
+f4 (J<int> j)
+{
+#pragma omp distribute parallel for default(none) shared(j, a)
+  for (auto &i : j)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+void
+f5 ()
+{
+#pragma omp distribute parallel for simd default(none) shared(d, results)
+  for (auto i : d)
+    results[i % 1024] += 2 * ((unsigned) i >> 10) + 1;
+}
+
+void
+f6 (J<K> j)
+{
+#pragma omp distribute parallel for default(none) shared(j, e)
+  for (auto & [k, l, m] : j)
+    if (&k != &e[m].c || &l != &e[m].b || &m != &e[m].a || k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+void
+f7 (J<L> j)
+{
+#pragma omp distribute parallel for default(none) shared(j, f)
+  for (auto & [k, l, m] : j)
+    if (&k != &f[k].a || &l != &f[k].b || &m != &f[k].c || l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+
+void
+f8 (J<K> j)
+{
+#pragma omp distribute parallel for default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+void
+f9 (J<L> j)
+{
+#pragma omp distribute parallel for default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+
+template <int N>
+void
+f10 ()
+{
+#pragma omp distribute parallel for default(none) shared(a)
+  for (auto i : a)
+    baz (i);
+}
+
+template <int N>
+void
+f11 ()
+{
+#pragma omp distribute parallel for default(none) shared(a)
+  for (auto &i : a)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+template <int N>
+void
+f12 ()
+{
+#pragma omp distribute parallel for collapse(3) default(none) shared(a, b, c)
+  for (auto &i : b)
+    for (I<int> j = I<int> (&a[9]); j < I<int> (&a[10]); j++)
+      for (auto k : c)
+       if (&i != &b[i] || i < 0 || i >= 40 || *j != 9 || k < 0 || k >= 50)
+         abort ();
+       else
+         baz (i * 50 + k);
+}
+
+template <typename T>
+void
+f13 (J<T> j)
+{
+#pragma omp distribute parallel for default(none) shared(j, a)
+  for (auto &i : j)
+    if (&i != &a[i])
+      abort ();
+    else
+      baz (i);
+}
+
+template <int N>
+void
+f14 ()
+{
+#pragma omp distribute parallel for simd default(none) shared(d, results)
+  for (auto i : d)
+    results[i % N] += 2 * ((unsigned) i >> 10) + 1;
+}
+
+template <typename T>
+void
+f15 (J<T> j)
+{
+#pragma omp distribute parallel for default(none) shared(j, e)
+  for (auto & [k, l, m] : j)
+    if (&k != &e[m].c || &l != &e[m].b || &m != &e[m].a || k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+template <typename T>
+void
+f16 (J<T> j)
+{
+#pragma omp distribute parallel for default(none) shared(j, f)
+  for (auto & [k, l, m] : j)
+    if (&k != &f[k].a || &l != &f[k].b || &m != &f[k].c || l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+
+template <int N>
+void
+f17 (J<K> j)
+{
+#pragma omp distribute parallel for default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (k != m * 3 || l != m * 2)
+      abort ();
+    else
+      baz (m);
+}
+
+template <int N>
+void
+f18 (J<L> j)
+{
+#pragma omp distribute parallel for default(none) shared(j)
+  for (auto [k, l, m] : j)
+    if (l != k * 4 || m != k * 5)
+      abort ();
+    else
+      baz (k);
+}
+
+#define check(expr) \
+  for (int i = 0; i < 2000; i++)                       \
+    if (expr)                                          \
+      {                                                        \
+       if (results[i] != 1)                            \
+         abort ();                                     \
+       results[i] = 0;                                 \
+      }                                                        \
+    else if (results[i])                               \
+      abort ()
+
+int
+main ()
+{
+  for (int i = 0; i < 2000; i++)
+    a[i] = i;
+  for (int i = 0; i < 40; i++)
+    b[i] = i;
+  for (int i = 0; i < 50; i++)
+    c[i] = i;
+  for (int i = 0; i < 1024; i++)
+    d[i] = i;
+  for (int i = 0; i < 1089; i++)
+    {
+      e[i].a = i;
+      e[i].b = 2 * i;
+      e[i].c = 3 * i;
+    }
+  for (int i = 0; i < 1093; i++)
+    {
+      f[i].a = i;
+      f[i].b = 4 * i;
+      f[i].c = 5 * i;
+    }
+  #pragma omp teams
+  f1 ();
+  check (1);
+  #pragma omp teams
+  f2 ();
+  check (1);
+  #pragma omp teams
+  f3 ();
+  check (1);
+  #pragma omp teams
+  f4 (J<int> (&a[14], &a[1803]));
+  check (i >= 14 && i < 1803);
+  #pragma omp teams
+  f5 ();
+  check (i >= 0 && i < 1024);
+  #pragma omp teams
+  f6 (J<K> (&e[19], &e[1029]));
+  check (i >= 19 && i < 1029);
+  #pragma omp teams
+  f7 (J<L> (&f[15], &f[1091]));
+  check (i >= 15 && i < 1091);
+  #pragma omp teams
+  f8 (J<K> (&e[27], &e[1037]));
+  check (i >= 27 && i < 1037);
+  #pragma omp teams
+  f9 (J<L> (&f[1], &f[1012]));
+  check (i >= 1 && i < 1012);
+  #pragma omp teams
+  f10 <0> ();
+  check (1);
+  #pragma omp teams
+  f11 <1> ();
+  check (1);
+  #pragma omp teams
+  f12 <2> ();
+  check (1);
+  #pragma omp teams
+  f13 (J<int> (&a[24], &a[1703]));
+  check (i >= 24 && i < 1703);
+  #pragma omp teams
+  f14 <1024> ();
+  check (i >= 0 && i < 1024);
+  #pragma omp teams
+  f15 (J<K> (&e[39], &e[929]));
+  check (i >= 39 && i < 929);
+  #pragma omp teams
+  f16 (J<L> (&f[17], &f[1071]));
+  check (i >= 17 && i < 1071);
+  #pragma omp teams
+  f17 <3> (J<K> (&e[7], &e[1017]));
+  check (i >= 7 && i < 1017);
+  #pragma omp teams
+  f18 <5> (J<L> (&f[121], &f[1010]));
+  check (i >= 121 && i < 1010);
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-1.C b/libgomp/testsuite/libgomp.c++/task-reduction-1.C
new file mode 100644 (file)
index 0000000..b3e228e
--- /dev/null
@@ -0,0 +1,63 @@
+extern "C" void abort ();
+
+int as;
+int &a = as;
+long int bs = 1;
+long int &b = bs;
+
+void
+foo (int &c, long long int &d)
+{
+  int i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (*: d) in_reduction (+: c) \
+                    in_reduction (+: a) in_reduction (*: b)
+    {
+      a += 7;
+      b *= 2;
+      c += 9;
+      d *= 3;
+    }
+}
+
+int
+main ()
+{
+  int cs = 0;
+  int &c = cs;
+  long long int ds = 1;
+  #pragma omp parallel
+  #pragma omp single
+  {
+    long long int &d = ds;
+    #pragma omp taskgroup task_reduction (+: a, c) task_reduction (*: b, d)
+    {
+      int i;
+      for (i = 0; i < 4; i++)
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b, d)
+       {
+         int j;
+         a += 7;
+         b *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c) in_reduction (*: b, d)
+           {
+             a += 7;
+             b *= 2;
+             c += 9;
+             d *= 3;
+             foo (c, d);
+           }
+         c += 9;
+         d *= 3;
+       }
+    }
+#define THREEP4 (3LL * 3LL * 3LL * 3LL)
+    if (d != (THREEP4 * THREEP4 * THREEP4 * THREEP4 * THREEP4 * THREEP4
+             * THREEP4))
+      abort ();
+  }
+  if (a != 28 * 7 || b != (1L << 28) || c != 28 * 9)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-10.C b/libgomp/testsuite/libgomp.c++/task-reduction-10.C
new file mode 100644 (file)
index 0000000..0eb94c1
--- /dev/null
@@ -0,0 +1,125 @@
+extern "C" void abort ();
+
+struct S { S (); S (long long int, int); ~S (); static int cnt1, cnt2, cnt3; long long int s; int t; };
+
+int S::cnt1;
+int S::cnt2;
+int S::cnt3;
+
+S::S ()
+{
+  #pragma omp atomic
+  cnt1++;
+}
+
+S::S (long long int x, int y) : s (x), t (y)
+{
+  #pragma omp atomic update
+  ++cnt2;
+}
+
+S::~S ()
+{
+  #pragma omp atomic
+  cnt3 = cnt3 + 1;
+  if (t < 3 || t > 9 || (t & 1) == 0)
+    abort ();
+}
+
+void
+bar (S *p, S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+baz (S *o, S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: S : omp_out.s += omp_in.s) initializer (omp_priv (0, 3))
+#pragma omp declare reduction (*: S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
+
+S as = { 0LL, 7 };
+S &a = as;
+S bs (1LL, 5);
+S &b = bs;
+
+void
+foo (S &c, S &d)
+{
+  int i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: c) in_reduction (*: b, d) in_reduction (+: a)
+    {
+      a.s += 7;
+      b.s *= 2;
+      c.s += 9;
+      d.s *= 3;
+      if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
+         || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
+       abort ();
+    }
+}
+
+void
+test ()
+{
+  S cs = { 0LL, 7 };
+  S &c = cs;
+  S ds (1LL, 5);
+  #pragma omp parallel if (0)
+  {
+    S &d = ds;
+    #pragma omp parallel reduction (task, +: a, c) reduction (task, *: b, d)
+    {
+      #pragma omp for
+      for (int i = 0; i < 4; i++)
+       #pragma omp task in_reduction (*: b, d) in_reduction (+: a, c)
+       {
+         int j;
+         a.s += 7;
+         b.s *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a) in_reduction (*: b) \
+                            in_reduction (+: c) in_reduction (*: d)
+           {
+             a.s += 7;
+             b.s *= 2;
+             c.s += 9;
+             d.s *= 3;
+             foo (c, d);
+             if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
+                 || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
+               abort ();
+           }
+         c.s += 9;
+         d.s *= 3;
+         if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
+             || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
+           abort ();
+       }
+    }
+#define THREEP7 (3LL * 3LL * 3LL * 3LL * 3LL * 3LL * 3LL)
+    if (d.s != (THREEP7 * THREEP7 * THREEP7 * THREEP7) || d.t != 5)
+      abort ();
+  }
+  if (a.s != 28 * 7 || a.t != 7 || b.s != (1L << 28) || b.t != 5
+      || c.s != 28 * 9 || c.t != 7)
+    abort ();
+}
+
+int
+main ()
+{
+  int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
+  test ();
+  if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
+    abort ();
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-11.C b/libgomp/testsuite/libgomp.c++/task-reduction-11.C
new file mode 100644 (file)
index 0000000..542bdd6
--- /dev/null
@@ -0,0 +1,237 @@
+extern "C" void abort ();
+
+int as[2];
+int (&a)[2] = as;
+long long int bs[7] = { 9, 11, 1, 1, 1, 13, 15 };
+long long int (&b)[7] = bs;
+int es[3] = { 5, 0, 5 };
+int (&e)[3] = es;
+int fs[5] = { 6, 7, 0, 0, 9 };
+int (&f)[5] = fs;
+int gs[4] = { 1, 0, 0, 2 };
+int (&g)[4] = gs;
+int hs[3] = { 0, 1, 4 };
+int (&h)[3] = hs;
+int ks[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+int (&k)[4][2] = ks;
+long long *ss;
+long long *&s = ss;
+long long (*ts)[2];
+long long (*&t)[2] = ts;
+
+template <typename T>
+void
+foo (T &n, T *&c, long long int *&d, T (&m)[3], T *&r, T (&o)[4], T *&p, T (&q)[4][2])
+{
+  T i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                    in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
+                    in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
+                    in_reduction (*: s[1:2], t[2:2][:])
+    {
+      a[0] += 7;
+      a[1] += 17;
+      b[2] *= 2;
+      b[4] *= 2;
+      c[0] += 6;
+      d[1] *= 2;
+      e[1] += 19;
+      f[2] += 21;
+      f[3] += 23;
+      g[1] += 25;
+      g[2] += 27;
+      h[0] += 29;
+      k[1][0] += 31;
+      k[2][1] += 33;
+      m[1] += 19;
+      r[2] += 21;
+      r[3] += 23;
+      o[1] += 25;
+      o[2] += 27;
+      p[0] += 29;
+      q[1][0] += 31;
+      q[2][1] += 33;
+      s[1] *= 2;
+      t[2][0] *= 2;
+      t[3][1] *= 2;
+    }
+}
+
+template <typename T>
+void
+test (T &n)
+{
+  T cs[2] = { 0, 0 };
+  T (&c)[2] = cs;
+  T ps[3] = { 0, 1, 4 };
+  T (&p)[3] = ps;
+  T qs[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+  T (&q)[4][2] = qs;
+  long long sb[4] = { 5, 1, 1, 6 };
+  long long tb[5][2] = { { 9, 10 }, { 11, 12 }, { 1, 1 }, { 1, 1 }, { 13, 14 } };
+  T ms[3] = { 5, 0, 5 };
+  T os[4] = { 1, 0, 0, 2 };
+  s = sb;
+  t = tb;
+  #pragma omp parallel if (0)
+  {
+    long long int ds[] = { 1, 1 };
+    long long int (&d)[2] = ds;
+    T (&m)[3] = ms;
+    T rs[5] = { 6, 7, 0, 0, 9 };
+    T (&r)[5] = rs;
+    T (&o)[4] = os;
+    #pragma omp parallel reduction (task,+: a, c) reduction (task,*: b[2 * n:3 * n], d) \
+                        reduction (task,+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                        reduction (task,+: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                        reduction (task,*: t[2:2][:], s[1:n + 1])
+    {
+      #pragma omp for
+      for (int i = 0; i < 4; i++)
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b[2 * n:3 * n], d) \
+                        in_reduction (+: o[n:n*2], q[1:2][:], p[0], m[1], r[2:2]) \
+                        in_reduction (+: g[n:n * 2], e[1], k[1:2][:], h[0], f[2:2]) \
+                        in_reduction (*: s[1:2], t[2:2][:])
+       {
+         T j;
+         a[0] += 2;
+         a[1] += 3;
+         b[2] *= 2;
+         f[3] += 8;
+         g[1] += 9;
+         g[2] += 10;
+         h[0] += 11;
+         k[1][1] += 13;
+         k[2][1] += 15;
+         m[1] += 16;
+         r[2] += 8;
+         s[1] *= 2;
+         t[2][1] *= 2;
+         t[3][1] *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c[:2]) \
+                            in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                            in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                            in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                            in_reduction (*: s[n:2], t[2:2][:])
+           {
+             m[1] += 6;
+             r[2] += 7;
+             q[1][0] += 17;
+             q[2][0] += 19;
+             a[0] += 4;
+             a[1] += 5;
+             b[3] *= 2;
+             b[4] *= 2;
+             f[3] += 18;
+             g[1] += 29;
+             g[2] += 18;
+             h[0] += 19;
+             s[2] *= 2;
+             t[2][0] *= 2;
+             t[3][0] *= 2;
+             T *cp = c;
+             long long int *dp = d;
+             T *rp = r;
+             T *pp = p;
+             foo (n, cp, dp, m, rp, o, pp, q);
+             r[3] += 18;
+             o[1] += 29;
+             o[2] += 18;
+             p[0] += 19;
+             c[0] += 4;
+             c[1] += 5;
+             d[0] *= 2;
+             e[1] += 6;
+             f[2] += 7;
+             k[1][0] += 17;
+             k[2][0] += 19;
+           }
+         r[3] += 8;
+         o[1] += 9;
+         o[2] += 10;
+         p[0] += 11;
+         q[1][1] += 13;
+         q[2][1] += 15;
+         b[3] *= 2;
+         c[0] += 4;
+         c[1] += 9;
+         d[0] *= 2;
+         e[1] += 16;
+         f[2] += 8;
+       }
+    }
+    if (d[0] != 1LL << (8 + 4)
+       || d[1] != 1LL << 16
+       || m[0] != 5
+       || m[1] != 19 * 16 + 6 * 8 + 16 * 4
+       || m[2] != 5
+       || r[0] != 6
+       || r[1] != 7
+       || r[2] != 21 * 16 + 7 * 8 + 8 * 4
+       || r[3] != 23 * 16 + 18 * 8 + 8 * 4
+       || r[4] != 9
+       || o[0] != 1
+       || o[1] != 25 * 16 + 29 * 8 + 9 * 4
+       || o[2] != 27 * 16 + 18 * 8 + 10 * 4
+       || o[3] != 2)
+      abort ();
+  }
+  if (a[0] != 7 * 16 + 4 * 8 + 2 * 4
+      || a[1] != 17 * 16 + 5 * 8 + 3 * 4
+      || b[0] != 9 || b[1] != 11
+      || b[2] != 1LL << (16 + 4)
+      || b[3] != 1LL << (8 + 4)
+      || b[4] != 1LL << (16 + 8)
+      || b[5] != 13 || b[6] != 15
+      || c[0] != 6 * 16 + 4 * 8 + 4 * 4
+      || c[1] != 5 * 8 + 9 * 4
+      || e[0] != 5
+      || e[1] != 19 * 16 + 6 * 8 + 16 * 4
+      || e[2] != 5
+      || f[0] != 6
+      || f[1] != 7
+      || f[2] != 21 * 16 + 7 * 8 + 8 * 4
+      || f[3] != 23 * 16 + 18 * 8 + 8 * 4
+      || f[4] != 9
+      || g[0] != 1
+      || g[1] != 25 * 16 + 29 * 8 + 9 * 4
+      || g[2] != 27 * 16 + 18 * 8 + 10 * 4
+      || g[3] != 2
+      || h[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || h[1] != 1 || h[2] != 4
+      || k[0][0] != 5 || k[0][1] != 6
+      || k[1][0] != 31 * 16 + 17 * 8
+      || k[1][1] != 13 * 4
+      || k[2][0] != 19 * 8
+      || k[2][1] != 33 * 16 + 15 * 4
+      || k[3][0] != 7 || k[3][1] != 8
+      || p[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || p[1] != 1 || p[2] != 4
+      || q[0][0] != 5 || q[0][1] != 6
+      || q[1][0] != 31 * 16 + 17 * 8
+      || q[1][1] != 13 * 4
+      || q[2][0] != 19 * 8
+      || q[2][1] != 33 * 16 + 15 * 4
+      || q[3][0] != 7 || q[3][1] != 8
+      || sb[0] != 5
+      || sb[1] != 1LL << (16 + 4)
+      || sb[2] != 1LL << 8
+      || sb[3] != 6
+      || tb[0][0] != 9 || tb[0][1] != 10 || tb[1][0] != 11 || tb[1][1] != 12
+      || tb[2][0] != 1LL << (16 + 8)
+      || tb[2][1] != 1LL << 4
+      || tb[3][0] != 1LL << 8
+      || tb[3][1] != 1LL << (16 + 4)
+      || tb[4][0] != 13 || tb[4][1] != 14)
+    abort ();
+}
+
+int
+main ()
+{
+  int n = 1;
+  test (n);
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-12.C b/libgomp/testsuite/libgomp.c++/task-reduction-12.C
new file mode 100644 (file)
index 0000000..02c1a78
--- /dev/null
@@ -0,0 +1,321 @@
+extern "C" void abort ();
+
+struct S { S (); S (long int, long int); ~S (); static int cnt1, cnt2, cnt3; long int s, t; };
+
+int S::cnt1;
+int S::cnt2;
+int S::cnt3;
+
+S::S ()
+{
+  #pragma omp atomic
+  cnt1++;
+}
+
+S::S (long int x, long int y) : s (x), t (y)
+{
+  #pragma omp atomic update
+  ++cnt2;
+}
+
+S::~S ()
+{
+  #pragma omp atomic
+  cnt3 = cnt3 + 1;
+  if (t < 3 || t > 9 || (t & 1) == 0)
+    abort ();
+}
+
+void
+bar (S *p, S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+baz (S *o, S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: S : omp_out.s += omp_in.s) initializer (omp_priv (0, 3))
+#pragma omp declare reduction (*: S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
+
+S a[2] = { { 0, 7 }, { 0, 7 } };
+S b[7] = { { 9, 5 }, { 11, 5 }, { 1, 5 }, { 1, 5 }, { 1, 5 }, { 13, 5 }, { 15, 5 } };
+S e[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+S f[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+S g[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+S h[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+S k[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+S *s;
+S (*t)[2];
+
+template <int N>
+void
+foo (int n, S *c, S *d, S m[3], S *r, S o[4], S *p, S q[4][2])
+{
+  int i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                    in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
+                    in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
+                    in_reduction (*: s[1:2], t[2:2][:])
+    {
+      a[0].s += 7;
+      a[1].s += 17;
+      b[2].s *= 2;
+      b[4].s *= 2;
+      c[0].s += 6;
+      d[1].s *= 2;
+      e[1].s += 19;
+      f[2].s += 21;
+      f[3].s += 23;
+      g[1].s += 25;
+      g[2].s += 27;
+      h[0].s += 29;
+      k[1][0].s += 31;
+      k[2][1].s += 33;
+      m[1].s += 19;
+      r[2].s += 21;
+      r[3].s += 23;
+      o[1].s += 25;
+      o[2].s += 27;
+      p[0].s += 29;
+      q[1][0].s += 31;
+      q[2][1].s += 33;
+      s[1].s *= 2;
+      t[2][0].s *= 2;
+      t[3][1].s *= 2;
+      if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+         || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+       abort ();
+      for (int z = 0; z < 2; z++)
+       if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+           || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+           || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+           || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+           || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+           || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+           || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+         abort ();
+      for (int z = 0; z < 3; z++)
+       if (b[z + 2].t != 5 && b[z + 2].t != 9)
+         abort ();
+    }
+}
+
+template <int N>
+void
+test (int n)
+{
+  S c[2] = { { 0, 7 }, { 0, 7 } };
+  S p[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+  S q[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+  S ss[4] = { { 5, 5 }, { 1, 5 }, { 1, 5 }, { 6, 5 } };
+  S tt[5][2] = { { { 9, 5 }, { 10, 5 } }, { { 11, 5 }, { 12, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 13, 5 }, { 14, 5 } } };
+  s = ss;
+  t = tt;
+  #pragma omp parallel num_threads (1) if (0)
+  {
+    S d[] = { { 1, 5 }, { 1, 5 } };
+    S m[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+    S r[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+    S o[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+    #pragma omp parallel reduction (task, +: a, c) reduction (task, *: b[2 * n:3 * n], d) \
+                        reduction (task, +: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                        reduction (task, +: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                        reduction (task, *: t[2:2][:], s[1:n + 1])
+    {
+      #pragma omp for
+      for (int i = 0; i < 4; i++)
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b[2 * n:3 * n], d) \
+                        in_reduction (+: o[n:n*2], q[1:2][:], p[0], m[1], r[2:2]) \
+                        in_reduction (+: g[n:n * 2], e[1], k[1:2][:], h[0], f[2:2]) \
+                        in_reduction (*: s[1:2], t[2:2][:])
+       {
+         int j;
+         a[0].s += 2;
+         a[1].s += 3;
+         b[2].s *= 2;
+         f[3].s += 8;
+         g[1].s += 9;
+         g[2].s += 10;
+         h[0].s += 11;
+         k[1][1].s += 13;
+         k[2][1].s += 15;
+         m[1].s += 16;
+         r[2].s += 8;
+         s[1].s *= 2;
+         t[2][1].s *= 2;
+         t[3][1].s *= 2;
+         if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+             || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+           abort ();
+         for (int z = 0; z < 2; z++)
+           if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+               || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+               || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+               || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+               || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+               || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+               || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+             abort ();
+         for (int z = 0; z < 3; z++)
+           if (b[z + 2].t != 5 && b[z + 2].t != 9)
+             abort ();
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c[:2]) \
+                            in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                            in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                            in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                            in_reduction (*: s[n:2], t[2:2][:])
+           {
+             m[1].s += 6;
+             r[2].s += 7;
+             q[1][0].s += 17;
+             q[2][0].s += 19;
+             a[0].s += 4;
+             a[1].s += 5;
+             b[3].s *= 2;
+             b[4].s *= 2;
+             f[3].s += 18;
+             g[1].s += 29;
+             g[2].s += 18;
+             h[0].s += 19;
+             s[2].s *= 2;
+             t[2][0].s *= 2;
+             t[3][0].s *= 2;
+             foo<N> (n, c, d, m, r, o, p, q);
+             if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+                 || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+               abort ();
+             for (int z = 0; z < 2; z++)
+               if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+                   || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+                   || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+                   || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+                   || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+                   || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+                   || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+                 abort ();
+             for (int z = 0; z < 3; z++)
+               if (b[z + 2].t != 5 && b[z + 2].t != 9)
+                 abort ();
+             r[3].s += 18;
+             o[1].s += 29;
+             o[2].s += 18;
+             p[0].s += 19;
+             c[0].s += 4;
+             c[1].s += 5;
+             d[0].s *= 2;
+             e[1].s += 6;
+             f[2].s += 7;
+             k[1][0].s += 17;
+             k[2][0].s += 19;
+           }
+         r[3].s += 8;
+         o[1].s += 9;
+         o[2].s += 10;
+         p[0].s += 11;
+         q[1][1].s += 13;
+         q[2][1].s += 15;
+         b[3].s *= 2;
+         c[0].s += 4;
+         c[1].s += 9;
+         d[0].s *= 2;
+         e[1].s += 16;
+         f[2].s += 8;
+       }
+    }
+    if (d[0].s != 1LL << (8 + 4)
+       || d[1].s != 1LL << 16
+       || m[0].s != 5
+       || m[1].s != 19 * 16 + 6 * 8 + 16 * 4
+       || m[2].s != 5
+       || r[0].s != 6
+       || r[1].s != 7
+       || r[2].s != 21 * 16 + 7 * 8 + 8 * 4
+       || r[3].s != 23 * 16 + 18 * 8 + 8 * 4
+       || r[4].s != 9
+       || o[0].s != 1
+       || o[1].s != 25 * 16 + 29 * 8 + 9 * 4
+       || o[2].s != 27 * 16 + 18 * 8 + 10 * 4
+       || o[3].s != 2)
+      abort ();
+    if (e[1].t != 7 || h[0].t != 7 || m[1].t != 7 || p[0].t != 7)
+      abort ();
+    for (int z = 0; z < 2; z++)
+      if (a[z].t != 7 || c[z].t != 7 || d[z].t != 5 || f[z + 2].t != 7
+         || g[z + 1].t != 7 || r[z + 2].t != 7 || s[z + 1].t != 5 || o[z + 1].t != 7
+         || k[z + 1][0].t != 7 || k[z + 1][1].t != 7 || q[z + 1][0].t != 7 || q[z + 1][1].t != 7
+         || t[z + 2][0].t != 5 || t[z + 2][1].t != 5)
+       abort ();
+    for (int z = 0; z < 3; z++)
+      if (b[z + 2].t != 5)
+       abort ();
+  }
+  if (a[0].s != 7 * 16 + 4 * 8 + 2 * 4
+      || a[1].s != 17 * 16 + 5 * 8 + 3 * 4
+      || b[0].s != 9 || b[1].s != 11
+      || b[2].s != 1LL << (16 + 4)
+      || b[3].s != 1LL << (8 + 4)
+      || b[4].s != 1LL << (16 + 8)
+      || b[5].s != 13 || b[6].s != 15
+      || c[0].s != 6 * 16 + 4 * 8 + 4 * 4
+      || c[1].s != 5 * 8 + 9 * 4
+      || e[0].s != 5
+      || e[1].s != 19 * 16 + 6 * 8 + 16 * 4
+      || e[2].s != 5
+      || f[0].s != 6
+      || f[1].s != 7
+      || f[2].s != 21 * 16 + 7 * 8 + 8 * 4
+      || f[3].s != 23 * 16 + 18 * 8 + 8 * 4
+      || f[4].s != 9
+      || g[0].s != 1
+      || g[1].s != 25 * 16 + 29 * 8 + 9 * 4
+      || g[2].s != 27 * 16 + 18 * 8 + 10 * 4
+      || g[3].s != 2
+      || h[0].s != 29 * 16 + 19 * 8 + 11 * 4
+      || h[1].s != 1 || h[2].s != 4
+      || k[0][0].s != 5 || k[0][1].s != 6
+      || k[1][0].s != 31 * 16 + 17 * 8
+      || k[1][1].s != 13 * 4
+      || k[2][0].s != 19 * 8
+      || k[2][1].s != 33 * 16 + 15 * 4
+      || k[3][0].s != 7 || k[3][1].s != 8
+      || p[0].s != 29 * 16 + 19 * 8 + 11 * 4
+      || p[1].s != 1 || p[2].s != 4
+      || q[0][0].s != 5 || q[0][1].s != 6
+      || q[1][0].s != 31 * 16 + 17 * 8
+      || q[1][1].s != 13 * 4
+      || q[2][0].s != 19 * 8
+      || q[2][1].s != 33 * 16 + 15 * 4
+      || q[3][0].s != 7 || q[3][1].s != 8
+      || ss[0].s != 5
+      || ss[1].s != 1LL << (16 + 4)
+      || ss[2].s != 1LL << 8
+      || ss[3].s != 6
+      || tt[0][0].s != 9 || tt[0][1].s != 10 || tt[1][0].s != 11 || tt[1][1].s != 12
+      || tt[2][0].s != 1LL << (16 + 8)
+      || tt[2][1].s != 1LL << 4
+      || tt[3][0].s != 1LL << 8
+      || tt[3][1].s != 1LL << (16 + 4)
+      || tt[4][0].s != 13 || tt[4][1].s != 14)
+    abort ();
+}
+
+int
+main ()
+{
+  int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
+  test<0> (1);
+  if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-13.C b/libgomp/testsuite/libgomp.c++/task-reduction-13.C
new file mode 100644 (file)
index 0000000..3d0165d
--- /dev/null
@@ -0,0 +1,342 @@
+extern "C" void abort ();
+
+struct S { S (); S (long int, long int); ~S (); static int cnt1, cnt2, cnt3; long int s, t; };
+
+int S::cnt1;
+int S::cnt2;
+int S::cnt3;
+
+S::S ()
+{
+  #pragma omp atomic
+  cnt1++;
+}
+
+S::S (long int x, long int y) : s (x), t (y)
+{
+  #pragma omp atomic update
+  ++cnt2;
+}
+
+S::~S ()
+{
+  #pragma omp atomic
+  cnt3 = cnt3 + 1;
+  if (t < 3 || t > 9 || (t & 1) == 0)
+    abort ();
+}
+
+void
+bar (S *p, S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+baz (S *o, S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: S : omp_out.s += omp_in.s) initializer (omp_priv (0, 3))
+#pragma omp declare reduction (*: S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
+
+S as[2] = { { 0, 7 }, { 0, 7 } };
+S (&a)[2] = as;
+S bs[7] = { { 9, 5 }, { 11, 5 }, { 1, 5 }, { 1, 5 }, { 1, 5 }, { 13, 5 }, { 15, 5 } };
+S (&b)[7] = bs;
+S es[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+S (&e)[3] = es;
+S fs[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+S (&f)[5] = fs;
+S gs[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+S (&g)[4] = gs;
+S hs[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+S (&h)[3] = hs;
+S ks[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+S (&k)[4][2] = ks;
+S *ss;
+S *&s = ss;
+S (*ts)[2];
+S (*&t)[2] = ts;
+
+template <typename S, typename T>
+void
+foo (T &n, S *&c, S *&d, S (&m)[3], S *&r, S (&o)[4], S *&p, S (&q)[4][2])
+{
+  T i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                    in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
+                    in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
+                    in_reduction (*: s[1:2], t[2:2][:])
+    {
+      a[0].s += 7;
+      a[1].s += 17;
+      b[2].s *= 2;
+      b[4].s *= 2;
+      c[0].s += 6;
+      d[1].s *= 2;
+      e[1].s += 19;
+      f[2].s += 21;
+      f[3].s += 23;
+      g[1].s += 25;
+      g[2].s += 27;
+      h[0].s += 29;
+      k[1][0].s += 31;
+      k[2][1].s += 33;
+      m[1].s += 19;
+      r[2].s += 21;
+      r[3].s += 23;
+      o[1].s += 25;
+      o[2].s += 27;
+      p[0].s += 29;
+      q[1][0].s += 31;
+      q[2][1].s += 33;
+      s[1].s *= 2;
+      t[2][0].s *= 2;
+      t[3][1].s *= 2;
+      if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+         || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+       abort ();
+      for (T z = 0; z < 2; z++)
+       if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+           || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+           || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+           || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+           || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+           || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+           || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+         abort ();
+      for (T z = 0; z < 3; z++)
+       if (b[z + 2].t != 5 && b[z + 2].t != 9)
+         abort ();
+    }
+}
+
+template <typename S, typename T>
+void
+test (T &n)
+{
+  S cs[2] = { { 0, 7 }, { 0, 7 } };
+  S (&c)[2] = cs;
+  S ps[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+  S (&p)[3] = ps;
+  S qs[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+  S (&q)[4][2] = qs;
+  S sb[4] = { { 5, 5 }, { 1, 5 }, { 1, 5 }, { 6, 5 } };
+  S tb[5][2] = { { { 9, 5 }, { 10, 5 } }, { { 11, 5 }, { 12, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 13, 5 }, { 14, 5 } } };
+  S ms[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+  S os[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+  s = sb;
+  t = tb;
+  #pragma omp parallel if (0)
+  {
+    S ds[] = { { 1, 5 }, { 1, 5 } };
+    S (&d)[2] = ds;
+    S (&m)[3] = ms;
+    S rs[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+    S (&r)[5] = rs;
+    S (&o)[4] = os;
+    #pragma omp parallel reduction (task, +: a, c) reduction (task, *: b[2 * n:3 * n], d) \
+                        reduction (task, +: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                        reduction (task, +: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                        reduction (task, *: t[2:2][:], s[1:n + 1])
+    {
+      #pragma omp for
+      for (T i = 0; i < 4; i++)
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b[2 * n:3 * n], d) \
+                        in_reduction (+: o[n:n*2], q[1:2][:], p[0], m[1], r[2:2]) \
+                        in_reduction (+: g[n:n * 2], e[1], k[1:2][:], h[0], f[2:2]) \
+                        in_reduction (*: s[1:2], t[2:2][:])
+       {
+         T j;
+         a[0].s += 2;
+         a[1].s += 3;
+         b[2].s *= 2;
+         f[3].s += 8;
+         g[1].s += 9;
+         g[2].s += 10;
+         h[0].s += 11;
+         k[1][1].s += 13;
+         k[2][1].s += 15;
+         m[1].s += 16;
+         r[2].s += 8;
+         s[1].s *= 2;
+         t[2][1].s *= 2;
+         t[3][1].s *= 2;
+         if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+             || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+           abort ();
+         for (T z = 0; z < 2; z++)
+           if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+               || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+               || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+               || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+               || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+               || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+               || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+             abort ();
+         for (T z = 0; z < 3; z++)
+           if (b[z + 2].t != 5 && b[z + 2].t != 9)
+             abort ();
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c[:2]) \
+                            in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                            in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                            in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                            in_reduction (*: s[n:2], t[2:2][:])
+           {
+             m[1].s += 6;
+             r[2].s += 7;
+             q[1][0].s += 17;
+             q[2][0].s += 19;
+             a[0].s += 4;
+             a[1].s += 5;
+             b[3].s *= 2;
+             b[4].s *= 2;
+             f[3].s += 18;
+             g[1].s += 29;
+             g[2].s += 18;
+             h[0].s += 19;
+             s[2].s *= 2;
+             t[2][0].s *= 2;
+             t[3][0].s *= 2;
+             S *cp = c;
+             S *dp = d;
+             S *rp = r;
+             S *pp = p;
+             if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+                 || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+               abort ();
+             for (T z = 0; z < 2; z++)
+               if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+                   || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+                   || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+                   || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+                   || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+                   || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+                   || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+                 abort ();
+             for (T z = 0; z < 3; z++)
+               if (b[z + 2].t != 5 && b[z + 2].t != 9)
+                 abort ();
+             foo (n, cp, dp, m, rp, o, pp, q);
+             r[3].s += 18;
+             o[1].s += 29;
+             o[2].s += 18;
+             p[0].s += 19;
+             c[0].s += 4;
+             c[1].s += 5;
+             d[0].s *= 2;
+             e[1].s += 6;
+             f[2].s += 7;
+             k[1][0].s += 17;
+             k[2][0].s += 19;
+           }
+         r[3].s += 8;
+         o[1].s += 9;
+         o[2].s += 10;
+         p[0].s += 11;
+         q[1][1].s += 13;
+         q[2][1].s += 15;
+         b[3].s *= 2;
+         c[0].s += 4;
+         c[1].s += 9;
+         d[0].s *= 2;
+         e[1].s += 16;
+         f[2].s += 8;
+       }
+    }
+    if (d[0].s != 1LL << (8 + 4)
+       || d[1].s != 1LL << 16
+       || m[0].s != 5
+       || m[1].s != 19 * 16 + 6 * 8 + 16 * 4
+       || m[2].s != 5
+       || r[0].s != 6
+       || r[1].s != 7
+       || r[2].s != 21 * 16 + 7 * 8 + 8 * 4
+       || r[3].s != 23 * 16 + 18 * 8 + 8 * 4
+       || r[4].s != 9
+       || o[0].s != 1
+       || o[1].s != 25 * 16 + 29 * 8 + 9 * 4
+       || o[2].s != 27 * 16 + 18 * 8 + 10 * 4
+       || o[3].s != 2)
+      abort ();
+    if (e[1].t != 7 || h[0].t != 7 || m[1].t != 7 || p[0].t != 7)
+      abort ();
+    for (T z = 0; z < 2; z++)
+      if (a[z].t != 7 || c[z].t != 7 || d[z].t != 5 || f[z + 2].t != 7
+         || g[z + 1].t != 7 || r[z + 2].t != 7 || s[z + 1].t != 5 || o[z + 1].t != 7
+         || k[z + 1][0].t != 7 || k[z + 1][1].t != 7 || q[z + 1][0].t != 7 || q[z + 1][1].t != 7
+         || t[z + 2][0].t != 5 || t[z + 2][1].t != 5)
+       abort ();
+    for (T z = 0; z < 3; z++)
+      if (b[z + 2].t != 5)
+       abort ();
+  }
+  if (a[0].s != 7 * 16 + 4 * 8 + 2 * 4
+      || a[1].s != 17 * 16 + 5 * 8 + 3 * 4
+      || b[0].s != 9 || b[1].s != 11
+      || b[2].s != 1LL << (16 + 4)
+      || b[3].s != 1LL << (8 + 4)
+      || b[4].s != 1LL << (16 + 8)
+      || b[5].s != 13 || b[6].s != 15
+      || c[0].s != 6 * 16 + 4 * 8 + 4 * 4
+      || c[1].s != 5 * 8 + 9 * 4
+      || e[0].s != 5
+      || e[1].s != 19 * 16 + 6 * 8 + 16 * 4
+      || e[2].s != 5
+      || f[0].s != 6
+      || f[1].s != 7
+      || f[2].s != 21 * 16 + 7 * 8 + 8 * 4
+      || f[3].s != 23 * 16 + 18 * 8 + 8 * 4
+      || f[4].s != 9
+      || g[0].s != 1
+      || g[1].s != 25 * 16 + 29 * 8 + 9 * 4
+      || g[2].s != 27 * 16 + 18 * 8 + 10 * 4
+      || g[3].s != 2
+      || h[0].s != 29 * 16 + 19 * 8 + 11 * 4
+      || h[1].s != 1 || h[2].s != 4
+      || k[0][0].s != 5 || k[0][1].s != 6
+      || k[1][0].s != 31 * 16 + 17 * 8
+      || k[1][1].s != 13 * 4
+      || k[2][0].s != 19 * 8
+      || k[2][1].s != 33 * 16 + 15 * 4
+      || k[3][0].s != 7 || k[3][1].s != 8
+      || p[0].s != 29 * 16 + 19 * 8 + 11 * 4
+      || p[1].s != 1 || p[2].s != 4
+      || q[0][0].s != 5 || q[0][1].s != 6
+      || q[1][0].s != 31 * 16 + 17 * 8
+      || q[1][1].s != 13 * 4
+      || q[2][0].s != 19 * 8
+      || q[2][1].s != 33 * 16 + 15 * 4
+      || q[3][0].s != 7 || q[3][1].s != 8
+      || sb[0].s != 5
+      || sb[1].s != 1LL << (16 + 4)
+      || sb[2].s != 1LL << 8
+      || sb[3].s != 6
+      || tb[0][0].s != 9 || tb[0][1].s != 10 || tb[1][0].s != 11 || tb[1][1].s != 12
+      || tb[2][0].s != 1LL << (16 + 8)
+      || tb[2][1].s != 1LL << 4
+      || tb[3][0].s != 1LL << 8
+      || tb[3][1].s != 1LL << (16 + 4)
+      || tb[4][0].s != 13 || tb[4][1].s != 14)
+    abort ();
+}
+
+int
+main ()
+{
+  int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
+  int n = 1;
+  test<S, int> (n);
+  if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-14.C b/libgomp/testsuite/libgomp.c++/task-reduction-14.C
new file mode 100644 (file)
index 0000000..3f4e79b
--- /dev/null
@@ -0,0 +1,72 @@
+#include <omp.h>
+#include <stdlib.h>
+
+struct A { A (); ~A (); A (const A &); static int cnt1, cnt2, cnt3; int a; };
+int A::cnt1;
+int A::cnt2;
+int A::cnt3;
+A::A () : a (0)
+{
+  #pragma omp atomic
+  cnt1++;
+}
+A::A (const A &x) : a (x.a)
+{
+  #pragma omp atomic
+  cnt2++;
+}
+A::~A ()
+{
+  #pragma omp atomic
+  cnt3++;
+}
+#pragma omp declare reduction (+: A: omp_out.a += omp_in.a)
+
+void
+foo (int x)
+{
+  A a, b[2];
+  int d = 1;
+  long int e[2] = { 1L, 1L };
+  int c = 0;
+  #pragma omp parallel
+  {
+    if (x && omp_get_thread_num () == 0)
+      {
+       for (int i = 0; i < 10000000; ++i)
+         asm volatile ("");
+       c = 1;
+       #pragma omp cancel parallel
+      }
+    #pragma omp for reduction (task, +: a, b) reduction (task, *: d, e)
+    for (int i = 0; i < 64; i++)
+      #pragma omp task in_reduction (+: a, b) in_reduction (*: d, e)
+      {
+       a.a++;
+       b[0].a += 2;
+       b[1].a += 3;
+       d *= ((i & 7) == 0) + 1;
+       e[0] *= ((i & 7) == 3) + 1;
+       e[1] *= ((i & 3) == 2) + 1;
+      }
+    if (x && omp_get_cancellation ())
+      abort ();
+  }
+  if (!c)
+    {
+      if (a.a != 64 || b[0].a != 128 || b[1].a != 192)
+       abort ();
+      if (d != 256 || e[0] != 256L || e[1] != 65536L)
+       abort ();
+    }
+}
+
+int
+main ()
+{
+  int c1 = A::cnt1, c2 = A::cnt2, c3 = A::cnt3;
+  volatile int zero = 0;
+  foo (zero);
+  if (A::cnt1 + A::cnt2 - c1 - c2 != A::cnt3 - c3)
+    abort ();
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-15.C b/libgomp/testsuite/libgomp.c++/task-reduction-15.C
new file mode 100644 (file)
index 0000000..8a01e6b
--- /dev/null
@@ -0,0 +1,75 @@
+extern "C" void abort ();
+
+int as;
+int &a = as;
+long int bs = 1;
+long int &b = bs;
+
+template <typename T, typename U>
+void
+foo (T &c, U &d)
+{
+  T i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (*: d) in_reduction (+: c) \
+                    in_reduction (+: a) in_reduction (*: b)
+    {
+      a += 7;
+      b *= 2;
+      c += 9;
+      d *= 3;
+    }
+}
+
+template <typename T, typename U>
+void
+bar ()
+{
+  T cs = 0;
+  T &c = cs;
+  U ds = 1;
+  #pragma omp parallel if (0)
+  {
+    U &d = ds;
+    #pragma omp parallel
+    {
+      T i;
+      #pragma omp for reduction (task, +: a, c) reduction (task, *: b, d)
+      for (i = 0; i < 4; i++)
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b, d)
+       {
+         T j;
+         a += 7;
+         b *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c) in_reduction (*: b, d)
+           {
+             a += 7;
+             b *= 2;
+             c += 9;
+             d *= 3;
+             foo (c, d);
+           }
+         c += 9;
+         d *= 3;
+       }
+#define THREEP4 (3LL * 3LL * 3LL * 3LL)
+      if (d != (THREEP4 * THREEP4 * THREEP4 * THREEP4 * THREEP4 * THREEP4
+               * THREEP4))
+       abort ();
+      if (a != 28 * 7 || b != (1L << 28) || c != 28 * 9)
+       abort ();
+    }
+  }
+  if (a != 28 * 7 || b != (1L << 28) || c != 28 * 9)
+    abort ();
+  if (ds != (THREEP4 * THREEP4 * THREEP4 * THREEP4 * THREEP4 * THREEP4
+            * THREEP4))
+    abort ();
+}
+
+int
+main ()
+{
+  bar<int, long long int> ();
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-16.C b/libgomp/testsuite/libgomp.c++/task-reduction-16.C
new file mode 100644 (file)
index 0000000..5835edc
--- /dev/null
@@ -0,0 +1,130 @@
+extern "C" void abort ();
+
+struct S { S (); S (long long int, int); ~S (); static int cnt1, cnt2, cnt3; long long int s; int t; };
+
+int S::cnt1;
+int S::cnt2;
+int S::cnt3;
+
+S::S ()
+{
+  #pragma omp atomic
+  cnt1++;
+}
+
+S::S (long long int x, int y) : s (x), t (y)
+{
+  #pragma omp atomic update
+  ++cnt2;
+}
+
+S::~S ()
+{
+  #pragma omp atomic
+  cnt3 = cnt3 + 1;
+  if (t < 3 || t > 9 || (t & 1) == 0)
+    abort ();
+}
+
+void
+bar (S *p, S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+baz (S *o, S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: S : omp_out.s += omp_in.s) initializer (omp_priv (0, 3))
+#pragma omp declare reduction (*: S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
+
+S as = { 0LL, 7 };
+S &a = as;
+S bs (1LL, 5);
+S &b = bs;
+
+void
+foo (S &c, S &d)
+{
+  int i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: c) in_reduction (*: b, d) in_reduction (+: a)
+    {
+      a.s += 7;
+      b.s *= 2;
+      c.s += 9;
+      d.s *= 3;
+      if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
+         || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
+       abort ();
+    }
+}
+
+void
+test ()
+{
+  S cs = { 0LL, 7 };
+  S &c = cs;
+  S ds (1LL, 5);
+  #pragma omp parallel if (0)
+  {
+    S &d = ds;
+    #pragma omp parallel shared (a, b, c, d)
+    {
+      #pragma omp for schedule (static, 1) reduction (task, +: a, c) reduction (task, *: b, d)
+      for (int i = 0; i < 4; i++)
+       #pragma omp task in_reduction (*: b, d) in_reduction (+: a, c)
+       {
+         int j;
+         a.s += 7;
+         b.s *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a) in_reduction (*: b) \
+                            in_reduction (+: c) in_reduction (*: d)
+           {
+             a.s += 7;
+             b.s *= 2;
+             c.s += 9;
+             d.s *= 3;
+             foo (c, d);
+             if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
+                 || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
+               abort ();
+           }
+         c.s += 9;
+         d.s *= 3;
+         if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
+             || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
+           abort ();
+       }
+#define THREEP7 (3LL * 3LL * 3LL * 3LL * 3LL * 3LL * 3LL)
+      if (d.s != (THREEP7 * THREEP7 * THREEP7 * THREEP7) || d.t != 5)
+       abort ();
+      if (a.s != 28 * 7 || a.t != 7 || b.s != (1L << 28) || b.t != 5
+         || c.s != 28 * 9 || c.t != 7)
+       abort ();
+    }
+  }
+  if (a.s != 28 * 7 || a.t != 7 || b.s != (1L << 28) || b.t != 5
+      || c.s != 28 * 9 || c.t != 7)
+    abort ();
+  if (ds.s != (THREEP7 * THREEP7 * THREEP7 * THREEP7) || ds.t != 5)
+    abort ();
+}
+
+int
+main ()
+{
+  int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
+  test ();
+  if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
+    abort ();
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-17.C b/libgomp/testsuite/libgomp.c++/task-reduction-17.C
new file mode 100644 (file)
index 0000000..c00c8e4
--- /dev/null
@@ -0,0 +1,300 @@
+extern "C" void abort ();
+
+int as[2];
+int (&a)[2] = as;
+long long int bs[7] = { 9, 11, 1, 1, 1, 13, 15 };
+long long int (&b)[7] = bs;
+int es[3] = { 5, 0, 5 };
+int (&e)[3] = es;
+int fs[5] = { 6, 7, 0, 0, 9 };
+int (&f)[5] = fs;
+int gs[4] = { 1, 0, 0, 2 };
+int (&g)[4] = gs;
+int hs[3] = { 0, 1, 4 };
+int (&h)[3] = hs;
+int ks[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+int (&k)[4][2] = ks;
+long long *ss;
+long long *&s = ss;
+long long (*ts)[2];
+long long (*&t)[2] = ts;
+
+template <typename T>
+void
+foo (T &n, T *&c, long long int *&d, T (&m)[3], T *&r, T (&o)[4], T *&p, T (&q)[4][2])
+{
+  T i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                    in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
+                    in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
+                    in_reduction (*: s[1:2], t[2:2][:])
+    {
+      a[0] += 7;
+      a[1] += 17;
+      b[2] *= 2;
+      b[4] *= 2;
+      c[0] += 6;
+      d[1] *= 2;
+      e[1] += 19;
+      f[2] += 21;
+      f[3] += 23;
+      g[1] += 25;
+      g[2] += 27;
+      h[0] += 29;
+      k[1][0] += 31;
+      k[2][1] += 33;
+      m[1] += 19;
+      r[2] += 21;
+      r[3] += 23;
+      o[1] += 25;
+      o[2] += 27;
+      p[0] += 29;
+      q[1][0] += 31;
+      q[2][1] += 33;
+      s[1] *= 2;
+      t[2][0] *= 2;
+      t[3][1] *= 2;
+    }
+}
+
+template <typename T, typename I>
+void
+test (T &n, I x, I y)
+{
+  T cs[2] = { 0, 0 };
+  T (&c)[2] = cs;
+  T ps[3] = { 0, 1, 4 };
+  T (&p)[3] = ps;
+  T qs[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+  T (&q)[4][2] = qs;
+  long long sb[4] = { 5, 1, 1, 6 };
+  long long tb[5][2] = { { 9, 10 }, { 11, 12 }, { 1, 1 }, { 1, 1 }, { 13, 14 } };
+  T ms[3] = { 5, 0, 5 };
+  T os[4] = { 1, 0, 0, 2 };
+  s = sb;
+  t = tb;
+  #pragma omp parallel if (0)
+  {
+    long long int ds[] = { 1, 1 };
+    long long int (&d)[2] = ds;
+    T (&m)[3] = ms;
+    T rs[5] = { 6, 7, 0, 0, 9 };
+    T (&r)[5] = rs;
+    T (&o)[4] = os;
+    #pragma omp parallel
+    {
+      #pragma omp for reduction (task,+: a, c) reduction (task,*: b[2 * n:3 * n], d) \
+                     reduction (task,+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                     reduction (task,+: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                     reduction (task,*: t[2:2][:], s[1:n + 1]) schedule (dynamic)
+      for (I i = x; i != y; i++)
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b[2 * n:3 * n], d) \
+                        in_reduction (+: o[n:n*2], q[1:2][:], p[0], m[1], r[2:2]) \
+                        in_reduction (+: g[n:n * 2], e[1], k[1:2][:], h[0], f[2:2]) \
+                        in_reduction (*: s[1:2], t[2:2][:])
+       {
+         T j;
+         a[0] += 2;
+         a[1] += 3;
+         b[2] *= 2;
+         f[3] += 8;
+         g[1] += 9;
+         g[2] += 10;
+         h[0] += 11;
+         k[1][1] += 13;
+         k[2][1] += 15;
+         m[1] += 16;
+         r[2] += 8;
+         s[1] *= 2;
+         t[2][1] *= 2;
+         t[3][1] *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c[:2]) \
+                            in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                            in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                            in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                            in_reduction (*: s[n:2], t[2:2][:])
+           {
+             m[1] += 6;
+             r[2] += 7;
+             q[1][0] += 17;
+             q[2][0] += 19;
+             a[0] += 4;
+             a[1] += 5;
+             b[3] *= 2;
+             b[4] *= 2;
+             f[3] += 18;
+             g[1] += 29;
+             g[2] += 18;
+             h[0] += 19;
+             s[2] *= 2;
+             t[2][0] *= 2;
+             t[3][0] *= 2;
+             T *cp = c;
+             long long int *dp = d;
+             T *rp = r;
+             T *pp = p;
+             foo (n, cp, dp, m, rp, o, pp, q);
+             r[3] += 18;
+             o[1] += 29;
+             o[2] += 18;
+             p[0] += 19;
+             c[0] += 4;
+             c[1] += 5;
+             d[0] *= 2;
+             e[1] += 6;
+             f[2] += 7;
+             k[1][0] += 17;
+             k[2][0] += 19;
+           }
+         r[3] += 8;
+         o[1] += 9;
+         o[2] += 10;
+         p[0] += 11;
+         q[1][1] += 13;
+         q[2][1] += 15;
+         b[3] *= 2;
+         c[0] += 4;
+         c[1] += 9;
+         d[0] *= 2;
+         e[1] += 16;
+         f[2] += 8;
+       }
+      if (d[0] != 1LL << (8 + 4)
+         || d[1] != 1LL << 16
+         || m[0] != 5
+         || m[1] != 19 * 16 + 6 * 8 + 16 * 4
+         || m[2] != 5
+         || r[0] != 6
+         || r[1] != 7
+         || r[2] != 21 * 16 + 7 * 8 + 8 * 4
+         || r[3] != 23 * 16 + 18 * 8 + 8 * 4
+         || r[4] != 9
+         || o[0] != 1
+         || o[1] != 25 * 16 + 29 * 8 + 9 * 4
+         || o[2] != 27 * 16 + 18 * 8 + 10 * 4
+         || o[3] != 2)
+       abort ();
+      if (a[0] != 7 * 16 + 4 * 8 + 2 * 4
+         || a[1] != 17 * 16 + 5 * 8 + 3 * 4
+         || b[0] != 9 || b[1] != 11
+         || b[2] != 1LL << (16 + 4)
+         || b[3] != 1LL << (8 + 4)
+         || b[4] != 1LL << (16 + 8)
+         || b[5] != 13 || b[6] != 15
+         || c[0] != 6 * 16 + 4 * 8 + 4 * 4
+         || c[1] != 5 * 8 + 9 * 4
+         || e[0] != 5
+         || e[1] != 19 * 16 + 6 * 8 + 16 * 4
+         || e[2] != 5
+         || f[0] != 6
+         || f[1] != 7
+         || f[2] != 21 * 16 + 7 * 8 + 8 * 4
+         || f[3] != 23 * 16 + 18 * 8 + 8 * 4
+         || f[4] != 9
+         || g[0] != 1
+         || g[1] != 25 * 16 + 29 * 8 + 9 * 4
+         || g[2] != 27 * 16 + 18 * 8 + 10 * 4
+         || g[3] != 2
+         || h[0] != 29 * 16 + 19 * 8 + 11 * 4
+         || h[1] != 1 || h[2] != 4
+         || k[0][0] != 5 || k[0][1] != 6
+         || k[1][0] != 31 * 16 + 17 * 8
+         || k[1][1] != 13 * 4
+         || k[2][0] != 19 * 8
+         || k[2][1] != 33 * 16 + 15 * 4
+         || k[3][0] != 7 || k[3][1] != 8
+         || p[0] != 29 * 16 + 19 * 8 + 11 * 4
+         || p[1] != 1 || p[2] != 4
+         || q[0][0] != 5 || q[0][1] != 6
+         || q[1][0] != 31 * 16 + 17 * 8
+         || q[1][1] != 13 * 4
+         || q[2][0] != 19 * 8
+         || q[2][1] != 33 * 16 + 15 * 4
+         || q[3][0] != 7 || q[3][1] != 8
+         || sb[0] != 5
+         || sb[1] != 1LL << (16 + 4)
+         || sb[2] != 1LL << 8
+         || sb[3] != 6
+         || tb[0][0] != 9 || tb[0][1] != 10 || tb[1][0] != 11 || tb[1][1] != 12
+         || tb[2][0] != 1LL << (16 + 8)
+         || tb[2][1] != 1LL << 4
+         || tb[3][0] != 1LL << 8
+         || tb[3][1] != 1LL << (16 + 4)
+         || tb[4][0] != 13 || tb[4][1] != 14)
+       abort ();
+    }
+    if (d[0] != 1LL << (8 + 4)
+       || d[1] != 1LL << 16
+       || m[0] != 5
+       || m[1] != 19 * 16 + 6 * 8 + 16 * 4
+       || m[2] != 5
+       || r[0] != 6
+       || r[1] != 7
+       || r[2] != 21 * 16 + 7 * 8 + 8 * 4
+       || r[3] != 23 * 16 + 18 * 8 + 8 * 4
+       || r[4] != 9
+       || o[0] != 1
+       || o[1] != 25 * 16 + 29 * 8 + 9 * 4
+       || o[2] != 27 * 16 + 18 * 8 + 10 * 4
+       || o[3] != 2)
+      abort ();
+  }
+  if (a[0] != 7 * 16 + 4 * 8 + 2 * 4
+      || a[1] != 17 * 16 + 5 * 8 + 3 * 4
+      || b[0] != 9 || b[1] != 11
+      || b[2] != 1LL << (16 + 4)
+      || b[3] != 1LL << (8 + 4)
+      || b[4] != 1LL << (16 + 8)
+      || b[5] != 13 || b[6] != 15
+      || c[0] != 6 * 16 + 4 * 8 + 4 * 4
+      || c[1] != 5 * 8 + 9 * 4
+      || e[0] != 5
+      || e[1] != 19 * 16 + 6 * 8 + 16 * 4
+      || e[2] != 5
+      || f[0] != 6
+      || f[1] != 7
+      || f[2] != 21 * 16 + 7 * 8 + 8 * 4
+      || f[3] != 23 * 16 + 18 * 8 + 8 * 4
+      || f[4] != 9
+      || g[0] != 1
+      || g[1] != 25 * 16 + 29 * 8 + 9 * 4
+      || g[2] != 27 * 16 + 18 * 8 + 10 * 4
+      || g[3] != 2
+      || h[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || h[1] != 1 || h[2] != 4
+      || k[0][0] != 5 || k[0][1] != 6
+      || k[1][0] != 31 * 16 + 17 * 8
+      || k[1][1] != 13 * 4
+      || k[2][0] != 19 * 8
+      || k[2][1] != 33 * 16 + 15 * 4
+      || k[3][0] != 7 || k[3][1] != 8
+      || p[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || p[1] != 1 || p[2] != 4
+      || q[0][0] != 5 || q[0][1] != 6
+      || q[1][0] != 31 * 16 + 17 * 8
+      || q[1][1] != 13 * 4
+      || q[2][0] != 19 * 8
+      || q[2][1] != 33 * 16 + 15 * 4
+      || q[3][0] != 7 || q[3][1] != 8
+      || sb[0] != 5
+      || sb[1] != 1LL << (16 + 4)
+      || sb[2] != 1LL << 8
+      || sb[3] != 6
+      || tb[0][0] != 9 || tb[0][1] != 10 || tb[1][0] != 11 || tb[1][1] != 12
+      || tb[2][0] != 1LL << (16 + 8)
+      || tb[2][1] != 1LL << 4
+      || tb[3][0] != 1LL << 8
+      || tb[3][1] != 1LL << (16 + 4)
+      || tb[4][0] != 13 || tb[4][1] != 14)
+    abort ();
+}
+
+int
+main ()
+{
+  int n = 1;
+  test (n, 0ULL, 4ULL);
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-18.C b/libgomp/testsuite/libgomp.c++/task-reduction-18.C
new file mode 100644 (file)
index 0000000..99c0e37
--- /dev/null
@@ -0,0 +1,325 @@
+extern "C" void abort ();
+
+struct S { S (); S (long int, long int); ~S (); static int cnt1, cnt2, cnt3; long int s, t; };
+
+int S::cnt1;
+int S::cnt2;
+int S::cnt3;
+
+S::S ()
+{
+  #pragma omp atomic
+  cnt1++;
+}
+
+S::S (long int x, long int y) : s (x), t (y)
+{
+  #pragma omp atomic update
+  ++cnt2;
+}
+
+S::~S ()
+{
+  #pragma omp atomic
+  cnt3 = cnt3 + 1;
+  if (t < 3 || t > 9 || (t & 1) == 0)
+    abort ();
+}
+
+void
+bar (S *p, S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+baz (S *o, S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: S : omp_out.s += omp_in.s) initializer (omp_priv (0, 3))
+#pragma omp declare reduction (*: S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
+
+S a[2] = { { 0, 7 }, { 0, 7 } };
+S b[7] = { { 9, 5 }, { 11, 5 }, { 1, 5 }, { 1, 5 }, { 1, 5 }, { 13, 5 }, { 15, 5 } };
+S e[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+S f[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+S g[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+S h[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+S k[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+S *s;
+S (*t)[2];
+
+template <int N>
+void
+foo (int n, S *c, S *d, S m[3], S *r, S o[4], S *p, S q[4][2])
+{
+  int i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                    in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
+                    in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
+                    in_reduction (*: s[1:2], t[2:2][:])
+    {
+      a[0].s += 7;
+      a[1].s += 17;
+      b[2].s *= 2;
+      b[4].s *= 2;
+      c[0].s += 6;
+      d[1].s *= 2;
+      e[1].s += 19;
+      f[2].s += 21;
+      f[3].s += 23;
+      g[1].s += 25;
+      g[2].s += 27;
+      h[0].s += 29;
+      k[1][0].s += 31;
+      k[2][1].s += 33;
+      m[1].s += 19;
+      r[2].s += 21;
+      r[3].s += 23;
+      o[1].s += 25;
+      o[2].s += 27;
+      p[0].s += 29;
+      q[1][0].s += 31;
+      q[2][1].s += 33;
+      s[1].s *= 2;
+      t[2][0].s *= 2;
+      t[3][1].s *= 2;
+      if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+         || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+       abort ();
+      for (int z = 0; z < 2; z++)
+       if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+           || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+           || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+           || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+           || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+           || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+           || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+         abort ();
+      for (int z = 0; z < 3; z++)
+       if (b[z + 2].t != 5 && b[z + 2].t != 9)
+         abort ();
+    }
+}
+
+template <int N>
+void
+test (int n)
+{
+  S c[2] = { { 0, 7 }, { 0, 7 } };
+  S p[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+  S q[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+  S ss[4] = { { 5, 5 }, { 1, 5 }, { 1, 5 }, { 6, 5 } };
+  S tt[5][2] = { { { 9, 5 }, { 10, 5 } }, { { 11, 5 }, { 12, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 13, 5 }, { 14, 5 } } };
+  s = ss;
+  t = tt;
+  #pragma omp parallel num_threads (1) if (0)
+  {
+    S d[] = { { 1, 5 }, { 1, 5 } };
+    S m[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+    S r[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+    S o[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+    volatile unsigned long long x = 0;
+    volatile unsigned long long y = 4;
+    volatile unsigned long long z = 1;
+    #pragma omp parallel
+    {
+      #pragma omp for reduction (task, +: a, c) reduction (task, *: b[2 * n:3 * n], d) \
+                     reduction (task, +: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                     reduction (task, +: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                     reduction (task, *: t[2:2][:], s[1:n + 1]) \
+                     schedule (nonmonotonic: guided, 1)
+      for (unsigned long long i = x; i < y; i += z)
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b[2 * n:3 * n], d) \
+                        in_reduction (+: o[n:n*2], q[1:2][:], p[0], m[1], r[2:2]) \
+                        in_reduction (+: g[n:n * 2], e[1], k[1:2][:], h[0], f[2:2]) \
+                        in_reduction (*: s[1:2], t[2:2][:])
+       {
+         int j;
+         a[0].s += 2;
+         a[1].s += 3;
+         b[2].s *= 2;
+         f[3].s += 8;
+         g[1].s += 9;
+         g[2].s += 10;
+         h[0].s += 11;
+         k[1][1].s += 13;
+         k[2][1].s += 15;
+         m[1].s += 16;
+         r[2].s += 8;
+         s[1].s *= 2;
+         t[2][1].s *= 2;
+         t[3][1].s *= 2;
+         if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+             || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+           abort ();
+         for (int z = 0; z < 2; z++)
+           if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+               || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+               || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+               || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+               || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+               || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+               || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+             abort ();
+         for (int z = 0; z < 3; z++)
+           if (b[z + 2].t != 5 && b[z + 2].t != 9)
+             abort ();
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c[:2]) \
+                            in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                            in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                            in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                            in_reduction (*: s[n:2], t[2:2][:])
+           {
+             m[1].s += 6;
+             r[2].s += 7;
+             q[1][0].s += 17;
+             q[2][0].s += 19;
+             a[0].s += 4;
+             a[1].s += 5;
+             b[3].s *= 2;
+             b[4].s *= 2;
+             f[3].s += 18;
+             g[1].s += 29;
+             g[2].s += 18;
+             h[0].s += 19;
+             s[2].s *= 2;
+             t[2][0].s *= 2;
+             t[3][0].s *= 2;
+             foo<N> (n, c, d, m, r, o, p, q);
+             if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+                 || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+               abort ();
+             for (int z = 0; z < 2; z++)
+               if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+                   || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+                   || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+                   || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+                   || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+                   || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+                   || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+                 abort ();
+             for (int z = 0; z < 3; z++)
+               if (b[z + 2].t != 5 && b[z + 2].t != 9)
+                 abort ();
+             r[3].s += 18;
+             o[1].s += 29;
+             o[2].s += 18;
+             p[0].s += 19;
+             c[0].s += 4;
+             c[1].s += 5;
+             d[0].s *= 2;
+             e[1].s += 6;
+             f[2].s += 7;
+             k[1][0].s += 17;
+             k[2][0].s += 19;
+           }
+         r[3].s += 8;
+         o[1].s += 9;
+         o[2].s += 10;
+         p[0].s += 11;
+         q[1][1].s += 13;
+         q[2][1].s += 15;
+         b[3].s *= 2;
+         c[0].s += 4;
+         c[1].s += 9;
+         d[0].s *= 2;
+         e[1].s += 16;
+         f[2].s += 8;
+       }
+      if (a[0].s != 7 * 16 + 4 * 8 + 2 * 4
+         || a[1].s != 17 * 16 + 5 * 8 + 3 * 4
+         || b[0].s != 9 || b[1].s != 11
+         || b[2].s != 1LL << (16 + 4)
+         || b[3].s != 1LL << (8 + 4)
+         || b[4].s != 1LL << (16 + 8)
+         || b[5].s != 13 || b[6].s != 15
+         || c[0].s != 6 * 16 + 4 * 8 + 4 * 4
+         || c[1].s != 5 * 8 + 9 * 4
+         || e[0].s != 5
+         || e[1].s != 19 * 16 + 6 * 8 + 16 * 4
+         || e[2].s != 5
+         || f[0].s != 6
+         || f[1].s != 7
+         || f[2].s != 21 * 16 + 7 * 8 + 8 * 4
+         || f[3].s != 23 * 16 + 18 * 8 + 8 * 4
+         || f[4].s != 9
+         || g[0].s != 1
+         || g[1].s != 25 * 16 + 29 * 8 + 9 * 4
+         || g[2].s != 27 * 16 + 18 * 8 + 10 * 4
+         || g[3].s != 2
+         || h[0].s != 29 * 16 + 19 * 8 + 11 * 4
+         || h[1].s != 1 || h[2].s != 4
+         || k[0][0].s != 5 || k[0][1].s != 6
+         || k[1][0].s != 31 * 16 + 17 * 8
+         || k[1][1].s != 13 * 4
+         || k[2][0].s != 19 * 8
+         || k[2][1].s != 33 * 16 + 15 * 4
+         || k[3][0].s != 7 || k[3][1].s != 8
+         || p[0].s != 29 * 16 + 19 * 8 + 11 * 4
+         || p[1].s != 1 || p[2].s != 4
+         || q[0][0].s != 5 || q[0][1].s != 6
+         || q[1][0].s != 31 * 16 + 17 * 8
+         || q[1][1].s != 13 * 4
+         || q[2][0].s != 19 * 8
+         || q[2][1].s != 33 * 16 + 15 * 4
+         || q[3][0].s != 7 || q[3][1].s != 8
+         || ss[0].s != 5
+         || ss[1].s != 1LL << (16 + 4)
+         || ss[2].s != 1LL << 8
+         || ss[3].s != 6
+         || tt[0][0].s != 9 || tt[0][1].s != 10 || tt[1][0].s != 11 || tt[1][1].s != 12
+         || tt[2][0].s != 1LL << (16 + 8)
+         || tt[2][1].s != 1LL << 4
+         || tt[3][0].s != 1LL << 8
+         || tt[3][1].s != 1LL << (16 + 4)
+         || tt[4][0].s != 13 || tt[4][1].s != 14)
+       abort ();
+    }
+    if (d[0].s != 1LL << (8 + 4)
+       || d[1].s != 1LL << 16
+       || m[0].s != 5
+       || m[1].s != 19 * 16 + 6 * 8 + 16 * 4
+       || m[2].s != 5
+       || r[0].s != 6
+       || r[1].s != 7
+       || r[2].s != 21 * 16 + 7 * 8 + 8 * 4
+       || r[3].s != 23 * 16 + 18 * 8 + 8 * 4
+       || r[4].s != 9
+       || o[0].s != 1
+       || o[1].s != 25 * 16 + 29 * 8 + 9 * 4
+       || o[2].s != 27 * 16 + 18 * 8 + 10 * 4
+       || o[3].s != 2)
+      abort ();
+    if (e[1].t != 7 || h[0].t != 7 || m[1].t != 7 || p[0].t != 7)
+      abort ();
+    for (int z = 0; z < 2; z++)
+      if (a[z].t != 7 || c[z].t != 7 || d[z].t != 5 || f[z + 2].t != 7
+         || g[z + 1].t != 7 || r[z + 2].t != 7 || s[z + 1].t != 5 || o[z + 1].t != 7
+         || k[z + 1][0].t != 7 || k[z + 1][1].t != 7 || q[z + 1][0].t != 7 || q[z + 1][1].t != 7
+         || t[z + 2][0].t != 5 || t[z + 2][1].t != 5)
+       abort ();
+    for (int z = 0; z < 3; z++)
+      if (b[z + 2].t != 5)
+       abort ();
+  }
+}
+
+int
+main ()
+{
+  int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
+  test<0> (1);
+  if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-19.C b/libgomp/testsuite/libgomp.c++/task-reduction-19.C
new file mode 100644 (file)
index 0000000..15945c5
--- /dev/null
@@ -0,0 +1,343 @@
+extern "C" void abort ();
+
+struct S { S (); S (long int, long int); ~S (); static int cnt1, cnt2, cnt3; long int s, t; };
+
+int S::cnt1;
+int S::cnt2;
+int S::cnt3;
+
+S::S ()
+{
+  #pragma omp atomic
+  cnt1++;
+}
+
+S::S (long int x, long int y) : s (x), t (y)
+{
+  #pragma omp atomic update
+  ++cnt2;
+}
+
+S::~S ()
+{
+  #pragma omp atomic
+  cnt3 = cnt3 + 1;
+  if (t < 3 || t > 9 || (t & 1) == 0)
+    abort ();
+}
+
+void
+bar (S *p, S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+baz (S *o, S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: S : omp_out.s += omp_in.s) initializer (omp_priv (0, 3))
+#pragma omp declare reduction (*: S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
+
+S as[2] = { { 0, 7 }, { 0, 7 } };
+S (&a)[2] = as;
+S bs[7] = { { 9, 5 }, { 11, 5 }, { 1, 5 }, { 1, 5 }, { 1, 5 }, { 13, 5 }, { 15, 5 } };
+S (&b)[7] = bs;
+S es[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+S (&e)[3] = es;
+S fs[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+S (&f)[5] = fs;
+S gs[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+S (&g)[4] = gs;
+S hs[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+S (&h)[3] = hs;
+S ks[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+S (&k)[4][2] = ks;
+S *ss;
+S *&s = ss;
+S (*ts)[2];
+S (*&t)[2] = ts;
+
+template <typename S, typename T>
+void
+foo (T &n, S *&c, S *&d, S (&m)[3], S *&r, S (&o)[4], S *&p, S (&q)[4][2])
+{
+  T i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                    in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
+                    in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
+                    in_reduction (*: s[1:2], t[2:2][:])
+    {
+      a[0].s += 7;
+      a[1].s += 17;
+      b[2].s *= 2;
+      b[4].s *= 2;
+      c[0].s += 6;
+      d[1].s *= 2;
+      e[1].s += 19;
+      f[2].s += 21;
+      f[3].s += 23;
+      g[1].s += 25;
+      g[2].s += 27;
+      h[0].s += 29;
+      k[1][0].s += 31;
+      k[2][1].s += 33;
+      m[1].s += 19;
+      r[2].s += 21;
+      r[3].s += 23;
+      o[1].s += 25;
+      o[2].s += 27;
+      p[0].s += 29;
+      q[1][0].s += 31;
+      q[2][1].s += 33;
+      s[1].s *= 2;
+      t[2][0].s *= 2;
+      t[3][1].s *= 2;
+      if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+         || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+       abort ();
+      for (T z = 0; z < 2; z++)
+       if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+           || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+           || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+           || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+           || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+           || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+           || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+         abort ();
+      for (T z = 0; z < 3; z++)
+       if (b[z + 2].t != 5 && b[z + 2].t != 9)
+         abort ();
+    }
+}
+
+template <typename S, typename T>
+void
+test (T &n)
+{
+  S cs[2] = { { 0, 7 }, { 0, 7 } };
+  S (&c)[2] = cs;
+  S ps[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+  S (&p)[3] = ps;
+  S qs[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+  S (&q)[4][2] = qs;
+  S sb[4] = { { 5, 5 }, { 1, 5 }, { 1, 5 }, { 6, 5 } };
+  S tb[5][2] = { { { 9, 5 }, { 10, 5 } }, { { 11, 5 }, { 12, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 13, 5 }, { 14, 5 } } };
+  S ms[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+  S os[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+  s = sb;
+  t = tb;
+  #pragma omp parallel if (0)
+  {
+    S ds[] = { { 1, 5 }, { 1, 5 } };
+    S (&d)[2] = ds;
+    S (&m)[3] = ms;
+    S rs[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+    S (&r)[5] = rs;
+    S (&o)[4] = os;
+    #pragma omp parallel
+    {
+      #pragma omp for reduction (task, +: a, c) reduction (task, *: b[2 * n:3 * n], d) \
+                     reduction (task, +: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                     reduction (task, +: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                     reduction (task, *: t[2:2][:], s[1:n + 1]) \
+                     schedule (monotonic: runtime)
+      for (T i = 0; i < 4; i++)
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b[2 * n:3 * n], d) \
+                        in_reduction (+: o[n:n*2], q[1:2][:], p[0], m[1], r[2:2]) \
+                        in_reduction (+: g[n:n * 2], e[1], k[1:2][:], h[0], f[2:2]) \
+                        in_reduction (*: s[1:2], t[2:2][:])
+       {
+         T j;
+         a[0].s += 2;
+         a[1].s += 3;
+         b[2].s *= 2;
+         f[3].s += 8;
+         g[1].s += 9;
+         g[2].s += 10;
+         h[0].s += 11;
+         k[1][1].s += 13;
+         k[2][1].s += 15;
+         m[1].s += 16;
+         r[2].s += 8;
+         s[1].s *= 2;
+         t[2][1].s *= 2;
+         t[3][1].s *= 2;
+         if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+             || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+           abort ();
+         for (T z = 0; z < 2; z++)
+           if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+               || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+               || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+               || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+               || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+               || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+               || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+             abort ();
+         for (T z = 0; z < 3; z++)
+           if (b[z + 2].t != 5 && b[z + 2].t != 9)
+             abort ();
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c[:2]) \
+                            in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                            in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                            in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                            in_reduction (*: s[n:2], t[2:2][:])
+           {
+             m[1].s += 6;
+             r[2].s += 7;
+             q[1][0].s += 17;
+             q[2][0].s += 19;
+             a[0].s += 4;
+             a[1].s += 5;
+             b[3].s *= 2;
+             b[4].s *= 2;
+             f[3].s += 18;
+             g[1].s += 29;
+             g[2].s += 18;
+             h[0].s += 19;
+             s[2].s *= 2;
+             t[2][0].s *= 2;
+             t[3][0].s *= 2;
+             S *cp = c;
+             S *dp = d;
+             S *rp = r;
+             S *pp = p;
+             if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+                 || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+               abort ();
+             for (T z = 0; z < 2; z++)
+               if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+                   || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+                   || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+                   || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+                   || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+                   || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+                   || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+                 abort ();
+             for (T z = 0; z < 3; z++)
+               if (b[z + 2].t != 5 && b[z + 2].t != 9)
+                 abort ();
+             foo (n, cp, dp, m, rp, o, pp, q);
+             r[3].s += 18;
+             o[1].s += 29;
+             o[2].s += 18;
+             p[0].s += 19;
+             c[0].s += 4;
+             c[1].s += 5;
+             d[0].s *= 2;
+             e[1].s += 6;
+             f[2].s += 7;
+             k[1][0].s += 17;
+             k[2][0].s += 19;
+           }
+         r[3].s += 8;
+         o[1].s += 9;
+         o[2].s += 10;
+         p[0].s += 11;
+         q[1][1].s += 13;
+         q[2][1].s += 15;
+         b[3].s *= 2;
+         c[0].s += 4;
+         c[1].s += 9;
+         d[0].s *= 2;
+         e[1].s += 16;
+         f[2].s += 8;
+       }
+      if (a[0].s != 7 * 16 + 4 * 8 + 2 * 4
+         || a[1].s != 17 * 16 + 5 * 8 + 3 * 4
+         || b[0].s != 9 || b[1].s != 11
+         || b[2].s != 1LL << (16 + 4)
+         || b[3].s != 1LL << (8 + 4)
+         || b[4].s != 1LL << (16 + 8)
+         || b[5].s != 13 || b[6].s != 15
+         || c[0].s != 6 * 16 + 4 * 8 + 4 * 4
+         || c[1].s != 5 * 8 + 9 * 4
+         || e[0].s != 5
+         || e[1].s != 19 * 16 + 6 * 8 + 16 * 4
+         || e[2].s != 5
+         || f[0].s != 6
+         || f[1].s != 7
+         || f[2].s != 21 * 16 + 7 * 8 + 8 * 4
+         || f[3].s != 23 * 16 + 18 * 8 + 8 * 4
+         || f[4].s != 9
+         || g[0].s != 1
+         || g[1].s != 25 * 16 + 29 * 8 + 9 * 4
+         || g[2].s != 27 * 16 + 18 * 8 + 10 * 4
+         || g[3].s != 2
+         || h[0].s != 29 * 16 + 19 * 8 + 11 * 4
+         || h[1].s != 1 || h[2].s != 4
+         || k[0][0].s != 5 || k[0][1].s != 6
+         || k[1][0].s != 31 * 16 + 17 * 8
+         || k[1][1].s != 13 * 4
+         || k[2][0].s != 19 * 8
+         || k[2][1].s != 33 * 16 + 15 * 4
+         || k[3][0].s != 7 || k[3][1].s != 8
+         || p[0].s != 29 * 16 + 19 * 8 + 11 * 4
+         || p[1].s != 1 || p[2].s != 4
+         || q[0][0].s != 5 || q[0][1].s != 6
+         || q[1][0].s != 31 * 16 + 17 * 8
+         || q[1][1].s != 13 * 4
+         || q[2][0].s != 19 * 8
+         || q[2][1].s != 33 * 16 + 15 * 4
+         || q[3][0].s != 7 || q[3][1].s != 8
+         || sb[0].s != 5
+         || sb[1].s != 1LL << (16 + 4)
+         || sb[2].s != 1LL << 8
+         || sb[3].s != 6
+         || tb[0][0].s != 9 || tb[0][1].s != 10 || tb[1][0].s != 11 || tb[1][1].s != 12
+         || tb[2][0].s != 1LL << (16 + 8)
+         || tb[2][1].s != 1LL << 4
+         || tb[3][0].s != 1LL << 8
+         || tb[3][1].s != 1LL << (16 + 4)
+         || tb[4][0].s != 13 || tb[4][1].s != 14)
+       abort ();
+      if (d[0].s != 1LL << (8 + 4)
+         || d[1].s != 1LL << 16
+         || m[0].s != 5
+         || m[1].s != 19 * 16 + 6 * 8 + 16 * 4
+         || m[2].s != 5
+         || r[0].s != 6
+         || r[1].s != 7
+         || r[2].s != 21 * 16 + 7 * 8 + 8 * 4
+         || r[3].s != 23 * 16 + 18 * 8 + 8 * 4
+         || r[4].s != 9
+         || o[0].s != 1
+         || o[1].s != 25 * 16 + 29 * 8 + 9 * 4
+         || o[2].s != 27 * 16 + 18 * 8 + 10 * 4
+         || o[3].s != 2)
+       abort ();
+      if (e[1].t != 7 || h[0].t != 7 || m[1].t != 7 || p[0].t != 7)
+       abort ();
+      for (T z = 0; z < 2; z++)
+       if (a[z].t != 7 || c[z].t != 7 || d[z].t != 5 || f[z + 2].t != 7
+           || g[z + 1].t != 7 || r[z + 2].t != 7 || s[z + 1].t != 5 || o[z + 1].t != 7
+           || k[z + 1][0].t != 7 || k[z + 1][1].t != 7 || q[z + 1][0].t != 7 || q[z + 1][1].t != 7
+           || t[z + 2][0].t != 5 || t[z + 2][1].t != 5)
+         abort ();
+      for (T z = 0; z < 3; z++)
+       if (b[z + 2].t != 5)
+         abort ();
+    }
+  }
+}
+
+int
+main ()
+{
+  int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
+  int n = 1;
+  test<S, int> (n);
+  if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-2.C b/libgomp/testsuite/libgomp.c++/task-reduction-2.C
new file mode 100644 (file)
index 0000000..75d2ee3
--- /dev/null
@@ -0,0 +1,119 @@
+extern "C" void abort ();
+
+struct S { S (); S (long int, long int); ~S (); static int cnt1, cnt2, cnt3; long int s, t; };
+
+int S::cnt1;
+int S::cnt2;
+int S::cnt3;
+
+S::S ()
+{
+  #pragma omp atomic
+  cnt1++;
+}
+
+S::S (long int x, long int y) : s (x), t (y)
+{
+  #pragma omp atomic update
+  ++cnt2;
+}
+
+S::~S ()
+{
+  #pragma omp atomic
+  cnt3 = cnt3 + 1;
+  if (t < 3 || t > 9 || (t & 1) == 0)
+    abort ();
+}
+
+void
+bar (S *p, S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+baz (S *o, S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: S : omp_out.s += omp_in.s) initializer (omp_priv (0, 3))
+#pragma omp declare reduction (*: S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
+
+S a = { 0, 7 };
+S b (1, 5);
+
+void
+foo ()
+{
+  int i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (*: b) in_reduction (+: a)
+    {
+      a.s += 7;
+      b.s *= 2;
+      if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9))
+       abort ();
+    }
+}
+
+void
+test ()
+{
+  S c = { 0, 7 };
+  #pragma omp parallel
+  #pragma omp single
+  {
+    S d (1, 5);
+    #pragma omp taskgroup task_reduction (+: a, c) task_reduction (*: b, d)
+    {
+      int i;
+      for (i = 0; i < 4; i++)
+       #pragma omp task in_reduction (*: b, d) in_reduction (+: a, c)
+       {
+         int j;
+         a.s += 7;
+         b.s *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a) in_reduction (*: b) \
+                            in_reduction (+: c) in_reduction (*: d)
+           {
+             a.s += 7;
+             b.s *= 2;
+             c.s += 9;
+             d.s *= 3;
+             foo ();
+             if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
+                 || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
+               abort ();
+           }
+         c.s += 9;
+         d.s *= 3;
+         if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
+             || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
+           abort ();
+       }
+    }
+#define THREEP4 (3L * 3L * 3L * 3L)
+    if (d.s != (THREEP4 * THREEP4 * THREEP4) || d.t != 5)
+      abort ();
+  }
+  if (a.s != 28 * 7 || a.t != 7 || b.s != (1L << 28) || b.t != 5
+      || c.s != 12 * 9 || c.t != 7)
+    abort ();
+}
+
+int
+main ()
+{
+  int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
+  test ();
+  if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
+    abort ();
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-3.C b/libgomp/testsuite/libgomp.c++/task-reduction-3.C
new file mode 100644 (file)
index 0000000..a6eccf6
--- /dev/null
@@ -0,0 +1,126 @@
+extern "C" void abort ();
+
+struct S { S (); S (long long int, int); ~S (); static int cnt1, cnt2, cnt3; long long int s; int t; };
+
+int S::cnt1;
+int S::cnt2;
+int S::cnt3;
+
+S::S ()
+{
+  #pragma omp atomic
+  cnt1++;
+}
+
+S::S (long long int x, int y) : s (x), t (y)
+{
+  #pragma omp atomic update
+  ++cnt2;
+}
+
+S::~S ()
+{
+  #pragma omp atomic
+  cnt3 = cnt3 + 1;
+  if (t < 3 || t > 9 || (t & 1) == 0)
+    abort ();
+}
+
+void
+bar (S *p, S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+baz (S *o, S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: S : omp_out.s += omp_in.s) initializer (omp_priv (0, 3))
+#pragma omp declare reduction (*: S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
+
+S as = { 0LL, 7 };
+S &a = as;
+S bs (1LL, 5);
+S &b = bs;
+
+void
+foo (S &c, S &d)
+{
+  int i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: c) in_reduction (*: b, d) in_reduction (+: a)
+    {
+      a.s += 7;
+      b.s *= 2;
+      c.s += 9;
+      d.s *= 3;
+      if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
+         || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
+       abort ();
+    }
+}
+
+void
+test ()
+{
+  S cs = { 0LL, 7 };
+  S &c = cs;
+  S ds (1LL, 5);
+  #pragma omp parallel
+  #pragma omp single
+  {
+    S &d = ds;
+    #pragma omp taskgroup task_reduction (+: a, c) task_reduction (*: b, d)
+    {
+      int i;
+      for (i = 0; i < 4; i++)
+       #pragma omp task in_reduction (*: b, d) in_reduction (+: a, c)
+       {
+         int j;
+         a.s += 7;
+         b.s *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a) in_reduction (*: b) \
+                            in_reduction (+: c) in_reduction (*: d)
+           {
+             a.s += 7;
+             b.s *= 2;
+             c.s += 9;
+             d.s *= 3;
+             foo (c, d);
+             if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
+                 || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
+               abort ();
+           }
+         c.s += 9;
+         d.s *= 3;
+         if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
+             || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
+           abort ();
+       }
+    }
+#define THREEP7 (3LL * 3LL * 3LL * 3LL * 3LL * 3LL * 3LL)
+    if (d.s != (THREEP7 * THREEP7 * THREEP7 * THREEP7) || d.t != 5)
+      abort ();
+  }
+  if (a.s != 28 * 7 || a.t != 7 || b.s != (1L << 28) || b.t != 5
+      || c.s != 28 * 9 || c.t != 7)
+    abort ();
+}
+
+int
+main ()
+{
+  int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
+  test ();
+  if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
+    abort ();
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-4.C b/libgomp/testsuite/libgomp.c++/task-reduction-4.C
new file mode 100644 (file)
index 0000000..1d4da79
--- /dev/null
@@ -0,0 +1,238 @@
+extern "C" void abort ();
+
+int as[2];
+int (&a)[2] = as;
+long long int bs[7] = { 9, 11, 1, 1, 1, 13, 15 };
+long long int (&b)[7] = bs;
+int es[3] = { 5, 0, 5 };
+int (&e)[3] = es;
+int fs[5] = { 6, 7, 0, 0, 9 };
+int (&f)[5] = fs;
+int gs[4] = { 1, 0, 0, 2 };
+int (&g)[4] = gs;
+int hs[3] = { 0, 1, 4 };
+int (&h)[3] = hs;
+int ks[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+int (&k)[4][2] = ks;
+long long *ss;
+long long *&s = ss;
+long long (*ts)[2];
+long long (*&t)[2] = ts;
+
+template <typename T>
+void
+foo (T &n, T *&c, long long int *&d, T (&m)[3], T *&r, T (&o)[4], T *&p, T (&q)[4][2])
+{
+  T i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                    in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
+                    in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
+                    in_reduction (*: s[1:2], t[2:2][:])
+    {
+      a[0] += 7;
+      a[1] += 17;
+      b[2] *= 2;
+      b[4] *= 2;
+      c[0] += 6;
+      d[1] *= 2;
+      e[1] += 19;
+      f[2] += 21;
+      f[3] += 23;
+      g[1] += 25;
+      g[2] += 27;
+      h[0] += 29;
+      k[1][0] += 31;
+      k[2][1] += 33;
+      m[1] += 19;
+      r[2] += 21;
+      r[3] += 23;
+      o[1] += 25;
+      o[2] += 27;
+      p[0] += 29;
+      q[1][0] += 31;
+      q[2][1] += 33;
+      s[1] *= 2;
+      t[2][0] *= 2;
+      t[3][1] *= 2;
+    }
+}
+
+template <typename T>
+void
+test (T &n)
+{
+  T cs[2] = { 0, 0 };
+  T (&c)[2] = cs;
+  T ps[3] = { 0, 1, 4 };
+  T (&p)[3] = ps;
+  T qs[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+  T (&q)[4][2] = qs;
+  long long sb[4] = { 5, 1, 1, 6 };
+  long long tb[5][2] = { { 9, 10 }, { 11, 12 }, { 1, 1 }, { 1, 1 }, { 13, 14 } };
+  T ms[3] = { 5, 0, 5 };
+  T os[4] = { 1, 0, 0, 2 };
+  s = sb;
+  t = tb;
+  #pragma omp parallel
+  #pragma omp single
+  {
+    long long int ds[] = { 1, 1 };
+    long long int (&d)[2] = ds;
+    T (&m)[3] = ms;
+    T rs[5] = { 6, 7, 0, 0, 9 };
+    T (&r)[5] = rs;
+    T (&o)[4] = os;
+    #pragma omp taskgroup task_reduction (+: a, c) task_reduction (*: b[2 * n:3 * n], d) \
+                         task_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                         task_reduction (+: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                         task_reduction (*: t[2:2][:], s[1:n + 1])
+    {
+      T i;
+      for (i = 0; i < 4; i++)
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b[2 * n:3 * n], d) \
+                        in_reduction (+: o[n:n*2], q[1:2][:], p[0], m[1], r[2:2]) \
+                        in_reduction (+: g[n:n * 2], e[1], k[1:2][:], h[0], f[2:2]) \
+                        in_reduction (*: s[1:2], t[2:2][:])
+       {
+         T j;
+         a[0] += 2;
+         a[1] += 3;
+         b[2] *= 2;
+         f[3] += 8;
+         g[1] += 9;
+         g[2] += 10;
+         h[0] += 11;
+         k[1][1] += 13;
+         k[2][1] += 15;
+         m[1] += 16;
+         r[2] += 8;
+         s[1] *= 2;
+         t[2][1] *= 2;
+         t[3][1] *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c[:2]) \
+                            in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                            in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                            in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                            in_reduction (*: s[n:2], t[2:2][:])
+           {
+             m[1] += 6;
+             r[2] += 7;
+             q[1][0] += 17;
+             q[2][0] += 19;
+             a[0] += 4;
+             a[1] += 5;
+             b[3] *= 2;
+             b[4] *= 2;
+             f[3] += 18;
+             g[1] += 29;
+             g[2] += 18;
+             h[0] += 19;
+             s[2] *= 2;
+             t[2][0] *= 2;
+             t[3][0] *= 2;
+             T *cp = c;
+             long long int *dp = d;
+             T *rp = r;
+             T *pp = p;
+             foo (n, cp, dp, m, rp, o, pp, q);
+             r[3] += 18;
+             o[1] += 29;
+             o[2] += 18;
+             p[0] += 19;
+             c[0] += 4;
+             c[1] += 5;
+             d[0] *= 2;
+             e[1] += 6;
+             f[2] += 7;
+             k[1][0] += 17;
+             k[2][0] += 19;
+           }
+         r[3] += 8;
+         o[1] += 9;
+         o[2] += 10;
+         p[0] += 11;
+         q[1][1] += 13;
+         q[2][1] += 15;
+         b[3] *= 2;
+         c[0] += 4;
+         c[1] += 9;
+         d[0] *= 2;
+         e[1] += 16;
+         f[2] += 8;
+       }
+    }
+    if (d[0] != 1LL << (8 + 4)
+       || d[1] != 1LL << 16
+       || m[0] != 5
+       || m[1] != 19 * 16 + 6 * 8 + 16 * 4
+       || m[2] != 5
+       || r[0] != 6
+       || r[1] != 7
+       || r[2] != 21 * 16 + 7 * 8 + 8 * 4
+       || r[3] != 23 * 16 + 18 * 8 + 8 * 4
+       || r[4] != 9
+       || o[0] != 1
+       || o[1] != 25 * 16 + 29 * 8 + 9 * 4
+       || o[2] != 27 * 16 + 18 * 8 + 10 * 4
+       || o[3] != 2)
+      abort ();
+  }
+  if (a[0] != 7 * 16 + 4 * 8 + 2 * 4
+      || a[1] != 17 * 16 + 5 * 8 + 3 * 4
+      || b[0] != 9 || b[1] != 11
+      || b[2] != 1LL << (16 + 4)
+      || b[3] != 1LL << (8 + 4)
+      || b[4] != 1LL << (16 + 8)
+      || b[5] != 13 || b[6] != 15
+      || c[0] != 6 * 16 + 4 * 8 + 4 * 4
+      || c[1] != 5 * 8 + 9 * 4
+      || e[0] != 5
+      || e[1] != 19 * 16 + 6 * 8 + 16 * 4
+      || e[2] != 5
+      || f[0] != 6
+      || f[1] != 7
+      || f[2] != 21 * 16 + 7 * 8 + 8 * 4
+      || f[3] != 23 * 16 + 18 * 8 + 8 * 4
+      || f[4] != 9
+      || g[0] != 1
+      || g[1] != 25 * 16 + 29 * 8 + 9 * 4
+      || g[2] != 27 * 16 + 18 * 8 + 10 * 4
+      || g[3] != 2
+      || h[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || h[1] != 1 || h[2] != 4
+      || k[0][0] != 5 || k[0][1] != 6
+      || k[1][0] != 31 * 16 + 17 * 8
+      || k[1][1] != 13 * 4
+      || k[2][0] != 19 * 8
+      || k[2][1] != 33 * 16 + 15 * 4
+      || k[3][0] != 7 || k[3][1] != 8
+      || p[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || p[1] != 1 || p[2] != 4
+      || q[0][0] != 5 || q[0][1] != 6
+      || q[1][0] != 31 * 16 + 17 * 8
+      || q[1][1] != 13 * 4
+      || q[2][0] != 19 * 8
+      || q[2][1] != 33 * 16 + 15 * 4
+      || q[3][0] != 7 || q[3][1] != 8
+      || sb[0] != 5
+      || sb[1] != 1LL << (16 + 4)
+      || sb[2] != 1LL << 8
+      || sb[3] != 6
+      || tb[0][0] != 9 || tb[0][1] != 10 || tb[1][0] != 11 || tb[1][1] != 12
+      || tb[2][0] != 1LL << (16 + 8)
+      || tb[2][1] != 1LL << 4
+      || tb[3][0] != 1LL << 8
+      || tb[3][1] != 1LL << (16 + 4)
+      || tb[4][0] != 13 || tb[4][1] != 14)
+    abort ();
+}
+
+int
+main ()
+{
+  int n = 1;
+  test (n);
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-5.C b/libgomp/testsuite/libgomp.c++/task-reduction-5.C
new file mode 100644 (file)
index 0000000..59583f1
--- /dev/null
@@ -0,0 +1,320 @@
+extern "C" void abort ();
+
+struct S { S (); S (long int, long int); ~S (); static int cnt1, cnt2, cnt3; long int s, t; };
+
+int S::cnt1;
+int S::cnt2;
+int S::cnt3;
+
+S::S ()
+{
+  #pragma omp atomic
+  cnt1++;
+}
+
+S::S (long int x, long int y) : s (x), t (y)
+{
+  #pragma omp atomic update
+  ++cnt2;
+}
+
+S::~S ()
+{
+  #pragma omp atomic
+  cnt3 = cnt3 + 1;
+  if (t < 3 || t > 9 || (t & 1) == 0)
+    abort ();
+}
+
+void
+bar (S *p, S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+baz (S *o, S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: S : omp_out.s += omp_in.s) initializer (omp_priv (0, 3))
+#pragma omp declare reduction (*: S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
+
+S a[2] = { { 0, 7 }, { 0, 7 } };
+S b[7] = { { 9, 5 }, { 11, 5 }, { 1, 5 }, { 1, 5 }, { 1, 5 }, { 13, 5 }, { 15, 5 } };
+S e[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+S f[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+S g[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+S h[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+S k[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+S *s;
+S (*t)[2];
+
+void
+foo (int n, S *c, S *d, S m[3], S *r, S o[4], S *p, S q[4][2])
+{
+  int i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                    in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
+                    in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
+                    in_reduction (*: s[1:2], t[2:2][:])
+    {
+      a[0].s += 7;
+      a[1].s += 17;
+      b[2].s *= 2;
+      b[4].s *= 2;
+      c[0].s += 6;
+      d[1].s *= 2;
+      e[1].s += 19;
+      f[2].s += 21;
+      f[3].s += 23;
+      g[1].s += 25;
+      g[2].s += 27;
+      h[0].s += 29;
+      k[1][0].s += 31;
+      k[2][1].s += 33;
+      m[1].s += 19;
+      r[2].s += 21;
+      r[3].s += 23;
+      o[1].s += 25;
+      o[2].s += 27;
+      p[0].s += 29;
+      q[1][0].s += 31;
+      q[2][1].s += 33;
+      s[1].s *= 2;
+      t[2][0].s *= 2;
+      t[3][1].s *= 2;
+      if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+         || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+       abort ();
+      for (int z = 0; z < 2; z++)
+       if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+           || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+           || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+           || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+           || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+           || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+           || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+         abort ();
+      for (int z = 0; z < 3; z++)
+       if (b[z + 2].t != 5 && b[z + 2].t != 9)
+         abort ();
+    }
+}
+
+void
+test (int n)
+{
+  S c[2] = { { 0, 7 }, { 0, 7 } };
+  S p[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+  S q[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+  S ss[4] = { { 5, 5 }, { 1, 5 }, { 1, 5 }, { 6, 5 } };
+  S tt[5][2] = { { { 9, 5 }, { 10, 5 } }, { { 11, 5 }, { 12, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 13, 5 }, { 14, 5 } } };
+  s = ss;
+  t = tt;
+  #pragma omp parallel
+  #pragma omp single
+  {
+    S d[] = { { 1, 5 }, { 1, 5 } };
+    S m[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+    S r[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+    S o[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+    #pragma omp taskgroup task_reduction (+: a, c) task_reduction (*: b[2 * n:3 * n], d) \
+                         task_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                         task_reduction (+: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                         task_reduction (*: t[2:2][:], s[1:n + 1])
+    {
+      int i;
+      for (i = 0; i < 4; i++)
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b[2 * n:3 * n], d) \
+                        in_reduction (+: o[n:n*2], q[1:2][:], p[0], m[1], r[2:2]) \
+                        in_reduction (+: g[n:n * 2], e[1], k[1:2][:], h[0], f[2:2]) \
+                        in_reduction (*: s[1:2], t[2:2][:])
+       {
+         int j;
+         a[0].s += 2;
+         a[1].s += 3;
+         b[2].s *= 2;
+         f[3].s += 8;
+         g[1].s += 9;
+         g[2].s += 10;
+         h[0].s += 11;
+         k[1][1].s += 13;
+         k[2][1].s += 15;
+         m[1].s += 16;
+         r[2].s += 8;
+         s[1].s *= 2;
+         t[2][1].s *= 2;
+         t[3][1].s *= 2;
+         if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+             || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+           abort ();
+         for (int z = 0; z < 2; z++)
+           if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+               || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+               || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+               || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+               || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+               || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+               || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+             abort ();
+         for (int z = 0; z < 3; z++)
+           if (b[z + 2].t != 5 && b[z + 2].t != 9)
+             abort ();
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c[:2]) \
+                            in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                            in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                            in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                            in_reduction (*: s[n:2], t[2:2][:])
+           {
+             m[1].s += 6;
+             r[2].s += 7;
+             q[1][0].s += 17;
+             q[2][0].s += 19;
+             a[0].s += 4;
+             a[1].s += 5;
+             b[3].s *= 2;
+             b[4].s *= 2;
+             f[3].s += 18;
+             g[1].s += 29;
+             g[2].s += 18;
+             h[0].s += 19;
+             s[2].s *= 2;
+             t[2][0].s *= 2;
+             t[3][0].s *= 2;
+             foo (n, c, d, m, r, o, p, q);
+             if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+                 || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+               abort ();
+             for (int z = 0; z < 2; z++)
+               if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+                   || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+                   || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+                   || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+                   || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+                   || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+                   || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+                 abort ();
+             for (int z = 0; z < 3; z++)
+               if (b[z + 2].t != 5 && b[z + 2].t != 9)
+                 abort ();
+             r[3].s += 18;
+             o[1].s += 29;
+             o[2].s += 18;
+             p[0].s += 19;
+             c[0].s += 4;
+             c[1].s += 5;
+             d[0].s *= 2;
+             e[1].s += 6;
+             f[2].s += 7;
+             k[1][0].s += 17;
+             k[2][0].s += 19;
+           }
+         r[3].s += 8;
+         o[1].s += 9;
+         o[2].s += 10;
+         p[0].s += 11;
+         q[1][1].s += 13;
+         q[2][1].s += 15;
+         b[3].s *= 2;
+         c[0].s += 4;
+         c[1].s += 9;
+         d[0].s *= 2;
+         e[1].s += 16;
+         f[2].s += 8;
+       }
+    }
+    if (d[0].s != 1LL << (8 + 4)
+       || d[1].s != 1LL << 16
+       || m[0].s != 5
+       || m[1].s != 19 * 16 + 6 * 8 + 16 * 4
+       || m[2].s != 5
+       || r[0].s != 6
+       || r[1].s != 7
+       || r[2].s != 21 * 16 + 7 * 8 + 8 * 4
+       || r[3].s != 23 * 16 + 18 * 8 + 8 * 4
+       || r[4].s != 9
+       || o[0].s != 1
+       || o[1].s != 25 * 16 + 29 * 8 + 9 * 4
+       || o[2].s != 27 * 16 + 18 * 8 + 10 * 4
+       || o[3].s != 2)
+      abort ();
+    if (e[1].t != 7 || h[0].t != 7 || m[1].t != 7 || p[0].t != 7)
+      abort ();
+    for (int z = 0; z < 2; z++)
+      if (a[z].t != 7 || c[z].t != 7 || d[z].t != 5 || f[z + 2].t != 7
+         || g[z + 1].t != 7 || r[z + 2].t != 7 || s[z + 1].t != 5 || o[z + 1].t != 7
+         || k[z + 1][0].t != 7 || k[z + 1][1].t != 7 || q[z + 1][0].t != 7 || q[z + 1][1].t != 7
+         || t[z + 2][0].t != 5 || t[z + 2][1].t != 5)
+       abort ();
+    for (int z = 0; z < 3; z++)
+      if (b[z + 2].t != 5)
+       abort ();
+  }
+  if (a[0].s != 7 * 16 + 4 * 8 + 2 * 4
+      || a[1].s != 17 * 16 + 5 * 8 + 3 * 4
+      || b[0].s != 9 || b[1].s != 11
+      || b[2].s != 1LL << (16 + 4)
+      || b[3].s != 1LL << (8 + 4)
+      || b[4].s != 1LL << (16 + 8)
+      || b[5].s != 13 || b[6].s != 15
+      || c[0].s != 6 * 16 + 4 * 8 + 4 * 4
+      || c[1].s != 5 * 8 + 9 * 4
+      || e[0].s != 5
+      || e[1].s != 19 * 16 + 6 * 8 + 16 * 4
+      || e[2].s != 5
+      || f[0].s != 6
+      || f[1].s != 7
+      || f[2].s != 21 * 16 + 7 * 8 + 8 * 4
+      || f[3].s != 23 * 16 + 18 * 8 + 8 * 4
+      || f[4].s != 9
+      || g[0].s != 1
+      || g[1].s != 25 * 16 + 29 * 8 + 9 * 4
+      || g[2].s != 27 * 16 + 18 * 8 + 10 * 4
+      || g[3].s != 2
+      || h[0].s != 29 * 16 + 19 * 8 + 11 * 4
+      || h[1].s != 1 || h[2].s != 4
+      || k[0][0].s != 5 || k[0][1].s != 6
+      || k[1][0].s != 31 * 16 + 17 * 8
+      || k[1][1].s != 13 * 4
+      || k[2][0].s != 19 * 8
+      || k[2][1].s != 33 * 16 + 15 * 4
+      || k[3][0].s != 7 || k[3][1].s != 8
+      || p[0].s != 29 * 16 + 19 * 8 + 11 * 4
+      || p[1].s != 1 || p[2].s != 4
+      || q[0][0].s != 5 || q[0][1].s != 6
+      || q[1][0].s != 31 * 16 + 17 * 8
+      || q[1][1].s != 13 * 4
+      || q[2][0].s != 19 * 8
+      || q[2][1].s != 33 * 16 + 15 * 4
+      || q[3][0].s != 7 || q[3][1].s != 8
+      || ss[0].s != 5
+      || ss[1].s != 1LL << (16 + 4)
+      || ss[2].s != 1LL << 8
+      || ss[3].s != 6
+      || tt[0][0].s != 9 || tt[0][1].s != 10 || tt[1][0].s != 11 || tt[1][1].s != 12
+      || tt[2][0].s != 1LL << (16 + 8)
+      || tt[2][1].s != 1LL << 4
+      || tt[3][0].s != 1LL << 8
+      || tt[3][1].s != 1LL << (16 + 4)
+      || tt[4][0].s != 13 || tt[4][1].s != 14)
+    abort ();
+}
+
+int
+main ()
+{
+  int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
+  test (1);
+  if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-6.C b/libgomp/testsuite/libgomp.c++/task-reduction-6.C
new file mode 100644 (file)
index 0000000..d7f69da
--- /dev/null
@@ -0,0 +1,341 @@
+extern "C" void abort ();
+
+struct S { S (); S (long int, long int); ~S (); static int cnt1, cnt2, cnt3; long int s, t; };
+
+int S::cnt1;
+int S::cnt2;
+int S::cnt3;
+
+S::S ()
+{
+  #pragma omp atomic
+  cnt1++;
+}
+
+S::S (long int x, long int y) : s (x), t (y)
+{
+  #pragma omp atomic update
+  ++cnt2;
+}
+
+S::~S ()
+{
+  #pragma omp atomic
+  cnt3 = cnt3 + 1;
+  if (t < 3 || t > 9 || (t & 1) == 0)
+    abort ();
+}
+
+void
+bar (S *p, S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+baz (S *o, S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: S : omp_out.s += omp_in.s) initializer (omp_priv (0, 3))
+#pragma omp declare reduction (*: S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
+
+S as[2] = { { 0, 7 }, { 0, 7 } };
+S (&a)[2] = as;
+S bs[7] = { { 9, 5 }, { 11, 5 }, { 1, 5 }, { 1, 5 }, { 1, 5 }, { 13, 5 }, { 15, 5 } };
+S (&b)[7] = bs;
+S es[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+S (&e)[3] = es;
+S fs[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+S (&f)[5] = fs;
+S gs[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+S (&g)[4] = gs;
+S hs[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+S (&h)[3] = hs;
+S ks[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+S (&k)[4][2] = ks;
+S *ss;
+S *&s = ss;
+S (*ts)[2];
+S (*&t)[2] = ts;
+
+void
+foo (int &n, S *&c, S *&d, S (&m)[3], S *&r, S (&o)[4], S *&p, S (&q)[4][2])
+{
+  int i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                    in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
+                    in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
+                    in_reduction (*: s[1:2], t[2:2][:])
+    {
+      a[0].s += 7;
+      a[1].s += 17;
+      b[2].s *= 2;
+      b[4].s *= 2;
+      c[0].s += 6;
+      d[1].s *= 2;
+      e[1].s += 19;
+      f[2].s += 21;
+      f[3].s += 23;
+      g[1].s += 25;
+      g[2].s += 27;
+      h[0].s += 29;
+      k[1][0].s += 31;
+      k[2][1].s += 33;
+      m[1].s += 19;
+      r[2].s += 21;
+      r[3].s += 23;
+      o[1].s += 25;
+      o[2].s += 27;
+      p[0].s += 29;
+      q[1][0].s += 31;
+      q[2][1].s += 33;
+      s[1].s *= 2;
+      t[2][0].s *= 2;
+      t[3][1].s *= 2;
+      if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+         || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+       abort ();
+      for (int z = 0; z < 2; z++)
+       if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+           || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+           || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+           || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+           || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+           || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+           || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+         abort ();
+      for (int z = 0; z < 3; z++)
+       if (b[z + 2].t != 5 && b[z + 2].t != 9)
+         abort ();
+    }
+}
+
+void
+test (int &n)
+{
+  S cs[2] = { { 0, 7 }, { 0, 7 } };
+  S (&c)[2] = cs;
+  S ps[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+  S (&p)[3] = ps;
+  S qs[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+  S (&q)[4][2] = qs;
+  S sb[4] = { { 5, 5 }, { 1, 5 }, { 1, 5 }, { 6, 5 } };
+  S tb[5][2] = { { { 9, 5 }, { 10, 5 } }, { { 11, 5 }, { 12, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 13, 5 }, { 14, 5 } } };
+  S ms[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+  S os[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+  s = sb;
+  t = tb;
+  #pragma omp parallel
+  #pragma omp single
+  {
+    S ds[] = { { 1, 5 }, { 1, 5 } };
+    S (&d)[2] = ds;
+    S (&m)[3] = ms;
+    S rs[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+    S (&r)[5] = rs;
+    S (&o)[4] = os;
+    #pragma omp taskgroup task_reduction (+: a, c) task_reduction (*: b[2 * n:3 * n], d) \
+                         task_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                         task_reduction (+: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                         task_reduction (*: t[2:2][:], s[1:n + 1])
+    {
+      int i;
+      for (i = 0; i < 4; i++)
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b[2 * n:3 * n], d) \
+                        in_reduction (+: o[n:n*2], q[1:2][:], p[0], m[1], r[2:2]) \
+                        in_reduction (+: g[n:n * 2], e[1], k[1:2][:], h[0], f[2:2]) \
+                        in_reduction (*: s[1:2], t[2:2][:])
+       {
+         int j;
+         a[0].s += 2;
+         a[1].s += 3;
+         b[2].s *= 2;
+         f[3].s += 8;
+         g[1].s += 9;
+         g[2].s += 10;
+         h[0].s += 11;
+         k[1][1].s += 13;
+         k[2][1].s += 15;
+         m[1].s += 16;
+         r[2].s += 8;
+         s[1].s *= 2;
+         t[2][1].s *= 2;
+         t[3][1].s *= 2;
+         if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+             || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+           abort ();
+         for (int z = 0; z < 2; z++)
+           if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+               || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+               || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+               || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+               || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+               || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+               || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+             abort ();
+         for (int z = 0; z < 3; z++)
+           if (b[z + 2].t != 5 && b[z + 2].t != 9)
+             abort ();
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c[:2]) \
+                            in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                            in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                            in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                            in_reduction (*: s[n:2], t[2:2][:])
+           {
+             m[1].s += 6;
+             r[2].s += 7;
+             q[1][0].s += 17;
+             q[2][0].s += 19;
+             a[0].s += 4;
+             a[1].s += 5;
+             b[3].s *= 2;
+             b[4].s *= 2;
+             f[3].s += 18;
+             g[1].s += 29;
+             g[2].s += 18;
+             h[0].s += 19;
+             s[2].s *= 2;
+             t[2][0].s *= 2;
+             t[3][0].s *= 2;
+             S *cp = c;
+             S *dp = d;
+             S *rp = r;
+             S *pp = p;
+             if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+                 || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+               abort ();
+             for (int z = 0; z < 2; z++)
+               if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+                   || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+                   || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+                   || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+                   || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+                   || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+                   || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+                 abort ();
+             for (int z = 0; z < 3; z++)
+               if (b[z + 2].t != 5 && b[z + 2].t != 9)
+                 abort ();
+             foo (n, cp, dp, m, rp, o, pp, q);
+             r[3].s += 18;
+             o[1].s += 29;
+             o[2].s += 18;
+             p[0].s += 19;
+             c[0].s += 4;
+             c[1].s += 5;
+             d[0].s *= 2;
+             e[1].s += 6;
+             f[2].s += 7;
+             k[1][0].s += 17;
+             k[2][0].s += 19;
+           }
+         r[3].s += 8;
+         o[1].s += 9;
+         o[2].s += 10;
+         p[0].s += 11;
+         q[1][1].s += 13;
+         q[2][1].s += 15;
+         b[3].s *= 2;
+         c[0].s += 4;
+         c[1].s += 9;
+         d[0].s *= 2;
+         e[1].s += 16;
+         f[2].s += 8;
+       }
+    }
+    if (d[0].s != 1LL << (8 + 4)
+       || d[1].s != 1LL << 16
+       || m[0].s != 5
+       || m[1].s != 19 * 16 + 6 * 8 + 16 * 4
+       || m[2].s != 5
+       || r[0].s != 6
+       || r[1].s != 7
+       || r[2].s != 21 * 16 + 7 * 8 + 8 * 4
+       || r[3].s != 23 * 16 + 18 * 8 + 8 * 4
+       || r[4].s != 9
+       || o[0].s != 1
+       || o[1].s != 25 * 16 + 29 * 8 + 9 * 4
+       || o[2].s != 27 * 16 + 18 * 8 + 10 * 4
+       || o[3].s != 2)
+      abort ();
+    if (e[1].t != 7 || h[0].t != 7 || m[1].t != 7 || p[0].t != 7)
+      abort ();
+    for (int z = 0; z < 2; z++)
+      if (a[z].t != 7 || c[z].t != 7 || d[z].t != 5 || f[z + 2].t != 7
+         || g[z + 1].t != 7 || r[z + 2].t != 7 || s[z + 1].t != 5 || o[z + 1].t != 7
+         || k[z + 1][0].t != 7 || k[z + 1][1].t != 7 || q[z + 1][0].t != 7 || q[z + 1][1].t != 7
+         || t[z + 2][0].t != 5 || t[z + 2][1].t != 5)
+       abort ();
+    for (int z = 0; z < 3; z++)
+      if (b[z + 2].t != 5)
+       abort ();
+  }
+  if (a[0].s != 7 * 16 + 4 * 8 + 2 * 4
+      || a[1].s != 17 * 16 + 5 * 8 + 3 * 4
+      || b[0].s != 9 || b[1].s != 11
+      || b[2].s != 1LL << (16 + 4)
+      || b[3].s != 1LL << (8 + 4)
+      || b[4].s != 1LL << (16 + 8)
+      || b[5].s != 13 || b[6].s != 15
+      || c[0].s != 6 * 16 + 4 * 8 + 4 * 4
+      || c[1].s != 5 * 8 + 9 * 4
+      || e[0].s != 5
+      || e[1].s != 19 * 16 + 6 * 8 + 16 * 4
+      || e[2].s != 5
+      || f[0].s != 6
+      || f[1].s != 7
+      || f[2].s != 21 * 16 + 7 * 8 + 8 * 4
+      || f[3].s != 23 * 16 + 18 * 8 + 8 * 4
+      || f[4].s != 9
+      || g[0].s != 1
+      || g[1].s != 25 * 16 + 29 * 8 + 9 * 4
+      || g[2].s != 27 * 16 + 18 * 8 + 10 * 4
+      || g[3].s != 2
+      || h[0].s != 29 * 16 + 19 * 8 + 11 * 4
+      || h[1].s != 1 || h[2].s != 4
+      || k[0][0].s != 5 || k[0][1].s != 6
+      || k[1][0].s != 31 * 16 + 17 * 8
+      || k[1][1].s != 13 * 4
+      || k[2][0].s != 19 * 8
+      || k[2][1].s != 33 * 16 + 15 * 4
+      || k[3][0].s != 7 || k[3][1].s != 8
+      || p[0].s != 29 * 16 + 19 * 8 + 11 * 4
+      || p[1].s != 1 || p[2].s != 4
+      || q[0][0].s != 5 || q[0][1].s != 6
+      || q[1][0].s != 31 * 16 + 17 * 8
+      || q[1][1].s != 13 * 4
+      || q[2][0].s != 19 * 8
+      || q[2][1].s != 33 * 16 + 15 * 4
+      || q[3][0].s != 7 || q[3][1].s != 8
+      || sb[0].s != 5
+      || sb[1].s != 1LL << (16 + 4)
+      || sb[2].s != 1LL << 8
+      || sb[3].s != 6
+      || tb[0][0].s != 9 || tb[0][1].s != 10 || tb[1][0].s != 11 || tb[1][1].s != 12
+      || tb[2][0].s != 1LL << (16 + 8)
+      || tb[2][1].s != 1LL << 4
+      || tb[3][0].s != 1LL << 8
+      || tb[3][1].s != 1LL << (16 + 4)
+      || tb[4][0].s != 13 || tb[4][1].s != 14)
+    abort ();
+}
+
+int
+main ()
+{
+  int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
+  int n = 1;
+  test (n);
+  if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-7.C b/libgomp/testsuite/libgomp.c++/task-reduction-7.C
new file mode 100644 (file)
index 0000000..2a4d82e
--- /dev/null
@@ -0,0 +1,145 @@
+typedef __SIZE_TYPE__ size_t;
+extern "C" void abort ();
+
+void
+bar (int *a, int *b, int *c, int (*d)[2], int (*e)[4], int *f, int *g, size_t n)
+{
+  #pragma omp task in_reduction (*: a[:n], b[3:n], c[n:n], d[0][:n], e[0][1:n], f[:n], g[1:n])
+  {
+    a[0] *= 12;
+    a[1] *= 13;
+    b[3] *= 14;
+    b[4] *= 15;
+    c[n] *= 16;
+    c[n + 1] *= 17;
+    d[0][0] *= 18;
+    d[0][1] *= 19;
+    e[0][1] *= 20;
+    e[0][2] *= 21;
+    f[0] *= 22;
+    f[1] *= 23;
+    g[1] *= 24;
+    g[2] *= 25;
+  }
+}
+
+void
+foo (size_t n, void *x, void *y)
+{
+  int a[n], b[n + 3], c[2 * n];
+  int (*d)[n] = (int (*)[n]) x;
+  int (*e)[n * 2] = (int (*)[n * 2]) y;
+  int fb[n], gb[n * 2];
+  int (&f)[n] = fb;
+  int (&g)[n * 2] = gb;
+  int i;
+  for (i = 0; i < n; i++)
+    {
+      a[i] = 1;
+      b[i + 3] = 1;
+      c[i + n] = 1;
+      d[0][i] = 1;
+      e[0][i + 1] = 1;
+      f[i] = 1;
+      g[i + 1] = 1;
+    }
+  #pragma omp taskgroup task_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f, g[1:n])
+  {
+    bar (a, b, c, (int (*)[2]) d, (int (*)[4]) e, &f[0], &g[0], n);
+    #pragma omp task in_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f, g[1:n])
+    {
+      a[0] *= 2;
+      a[1] *= 3;
+      b[3] *= 4;
+      b[4] *= 5;
+      c[n] *= 6;
+      c[n + 1] *= 7;
+      d[0][0] *= 8;
+      d[0][1] *= 9;
+      e[0][1] *= 10;
+      e[0][2] *= 11;
+      f[0] *= 12;
+      f[1] *= 13;
+      g[1] *= 14;
+      g[2] *= 15;
+    }
+    n = 0;
+  }
+  if (a[0] != 24 || a[1] != 39 || b[3] != 56 || b[4] != 75)
+    abort ();
+  if (c[2] != 96 || c[3] != 119 || d[0][0] != 144 || d[0][1] != 171)
+    abort ();
+  if (e[0][1] != 200 || e[0][2] != 231 || f[0] != 264 || f[1] != 299)
+    abort ();
+  if (g[1] != 336 || g[2] != 375)
+    abort ();
+}
+
+void
+baz (size_t n, void *x, void *y)
+{
+  int a[n], b[n + 3], c[2 * n];
+  int (*d)[n] = (int (*)[n]) x;
+  int (*e)[n * 2] = (int (*)[n * 2]) y;
+  int fb[n], gb[n * 2];
+  int i;
+  for (i = 0; i < n; i++)
+    {
+      a[i] = 1;
+      b[i + 3] = 1;
+      c[i + n] = 1;
+      d[0][i] = 1;
+      e[0][i + 1] = 1;
+      fb[i] = 1;
+      gb[i + 1] = 1;
+    }
+  #pragma omp parallel num_threads(2)
+  #pragma omp master
+  {
+    int (&f)[n] = fb;
+    int (&g)[n * 2] = gb;
+    #pragma omp taskgroup task_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f, g[1:n])
+    {
+      bar (a, b, c, (int (*)[2]) d, (int (*)[4]) e, &f[0], &g[0], n);
+      #pragma omp task in_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f, g[1:n])
+      {
+       a[0] *= 2;
+       a[1] *= 3;
+       b[3] *= 4;
+       b[4] *= 5;
+       c[n] *= 6;
+       c[n + 1] *= 7;
+       d[0][0] *= 8;
+       d[0][1] *= 9;
+       e[0][1] *= 10;
+       e[0][2] *= 11;
+       f[0] *= 12;
+       f[1] *= 13;
+       g[1] *= 14;
+       g[2] *= 15;
+      }
+      n = 0;
+    }
+  }
+  if (a[0] != 24 || a[1] != 39 || b[3] != 56 || b[4] != 75)
+    abort ();
+  if (c[2] != 96 || c[3] != 119 || d[0][0] != 144 || d[0][1] != 171)
+    abort ();
+  if (e[0][1] != 200 || e[0][2] != 231 || fb[0] != 264 || fb[1] != 299)
+    abort ();
+  if (gb[1] != 336 || gb[2] != 375)
+    abort ();
+}
+
+int
+main ()
+{
+  int d[2], e[4];
+  volatile int two;
+  two = 2;
+  #pragma omp parallel num_threads (2)
+  #pragma omp master
+  foo (two, (void *) d, (void *) e);
+  baz (two, (void *) d, (void *) e);
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-8.C b/libgomp/testsuite/libgomp.c++/task-reduction-8.C
new file mode 100644 (file)
index 0000000..26737a3
--- /dev/null
@@ -0,0 +1,70 @@
+extern "C" void abort ();
+
+int as;
+int &a = as;
+long int bs = 1;
+long int &b = bs;
+
+template <typename T, typename U>
+void
+foo (T &c, U &d)
+{
+  T i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (*: d) in_reduction (+: c) \
+                    in_reduction (+: a) in_reduction (*: b)
+    {
+      a += 7;
+      b *= 2;
+      c += 9;
+      d *= 3;
+    }
+}
+
+template <typename T, typename U>
+void
+bar ()
+{
+  T cs = 0;
+  T &c = cs;
+  U ds = 1;
+  #pragma omp parallel if (0)
+  {
+    U &d = ds;
+    #pragma omp parallel reduction (task, +: a, c) reduction (task, *: b, d)
+    {
+      T i;
+      #pragma omp for
+      for (i = 0; i < 4; i++)
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b, d)
+       {
+         T j;
+         a += 7;
+         b *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c) in_reduction (*: b, d)
+           {
+             a += 7;
+             b *= 2;
+             c += 9;
+             d *= 3;
+             foo (c, d);
+           }
+         c += 9;
+         d *= 3;
+       }
+    }
+#define THREEP4 (3LL * 3LL * 3LL * 3LL)
+    if (d != (THREEP4 * THREEP4 * THREEP4 * THREEP4 * THREEP4 * THREEP4
+             * THREEP4))
+      abort ();
+  }
+  if (a != 28 * 7 || b != (1L << 28) || c != 28 * 9)
+    abort ();
+}
+
+int
+main ()
+{
+  bar<int, long long int> ();
+}
diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-9.C b/libgomp/testsuite/libgomp.c++/task-reduction-9.C
new file mode 100644 (file)
index 0000000..068a7bb
--- /dev/null
@@ -0,0 +1,128 @@
+#include <omp.h>
+#include <stdlib.h>
+
+struct S { S (); S (long int, long int); ~S (); static int cnt1, cnt2, cnt3; long int s, t; };
+
+int S::cnt1;
+int S::cnt2;
+int S::cnt3;
+
+S::S ()
+{
+  #pragma omp atomic
+  cnt1++;
+}
+
+S::S (long int x, long int y) : s (x), t (y)
+{
+  #pragma omp atomic update
+  ++cnt2;
+}
+
+S::~S ()
+{
+  #pragma omp atomic
+  cnt3 = cnt3 + 1;
+  if (t < 3 || t > 9 || (t & 1) == 0)
+    abort ();
+}
+
+void
+bar (S *p, S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+baz (S *o, S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: S : omp_out.s += omp_in.s) initializer (omp_priv (0, 3))
+#pragma omp declare reduction (*: S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
+
+S a = { 0, 7 };
+S b (1, 5);
+
+void
+foo ()
+{
+  int i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (*: b) in_reduction (+: a)
+    {
+      a.s += 7;
+      b.s *= 2;
+      if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9))
+       abort ();
+    }
+}
+
+void
+test ()
+{
+  S c = { 0, 7 };
+  int t;
+  #pragma omp parallel num_threads (1)
+  {
+    S d (1, 5);
+    int r = 0;
+    #pragma omp parallel reduction (task, +: a, c) reduction (task, *: b, d) \
+                        reduction (+: r)
+    {
+      int i;
+      #pragma omp master
+      t = omp_get_num_threads ();
+      r++;
+      a.s += 3;
+      c.s += 4;
+      #pragma omp for
+      for (i = 0; i < 4; i++)
+       #pragma omp task in_reduction (*: b, d) in_reduction (+: a, c)
+       {
+         int j;
+         a.s += 7;
+         b.s *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a) in_reduction (*: b) \
+                            in_reduction (+: c) in_reduction (*: d)
+           {
+             a.s += 7;
+             b.s *= 2;
+             c.s += 9;
+             d.s *= 3;
+             foo ();
+             if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
+                 || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
+               abort ();
+           }
+         c.s += 9;
+         d.s *= 3;
+         if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
+             || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
+           abort ();
+       }
+    }
+#define THREEP4 (3L * 3L * 3L * 3L)
+    if (d.s != (THREEP4 * THREEP4 * THREEP4) || d.t != 5 || r != t)
+      abort ();
+  }
+  if (a.s != 28 * 7 + 3 * t || a.t != 7 || b.s != (1L << 28) || b.t != 5
+      || c.s != 12 * 9 + 4 * t || c.t != 7)
+    abort ();
+}
+
+int
+main ()
+{
+  int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
+  test ();
+  if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
+    abort ();
+}
diff --git a/libgomp/testsuite/libgomp.c++/taskloop-reduction-1.C b/libgomp/testsuite/libgomp.c++/taskloop-reduction-1.C
new file mode 100644 (file)
index 0000000..f7fb9ca
--- /dev/null
@@ -0,0 +1,153 @@
+extern "C" void abort ();
+
+struct S { S (); S (unsigned long long int, int); ~S (); static int cnt1, cnt2, cnt3; unsigned long long int s; int t; };
+
+int S::cnt1;
+int S::cnt2;
+int S::cnt3;
+
+S::S ()
+{
+  #pragma omp atomic
+  cnt1++;
+}
+
+S::S (unsigned long long int x, int y) : s (x), t (y)
+{
+  #pragma omp atomic update
+  ++cnt2;
+}
+
+S::~S ()
+{
+  #pragma omp atomic
+  cnt3 = cnt3 + 1;
+  if (t < 3 || t > 9 || (t & 1) == 0)
+    abort ();
+}
+
+void
+rbar (S *p, S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+rbaz (S *o, S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: S : omp_out.s += omp_in.s) \
+  initializer (omp_priv (0, 3))
+#pragma omp declare reduction (*: S : rbaz (&omp_out, &omp_in)) \
+  initializer (rbar (&omp_priv, &omp_orig))
+
+S gs = { 0, 7 };
+S &g = gs;
+S hs (1, 5);
+S &h = hs;
+
+int
+foo (int *a, int &b)
+{
+  int xs = 0;
+  int &x = xs;
+  #pragma omp taskloop reduction (+:x) in_reduction (+:b)
+  for (int i = 0; i < 64; i++)
+    {
+      x += a[i];
+      b += a[i] * 2;
+    }
+  return x;
+}
+
+unsigned long long int
+bar (int *a, unsigned long long int &b)
+{
+  unsigned long long int xs = 1;
+  unsigned long long int &x = xs;
+  #pragma omp taskloop reduction (*:x) in_reduction (*:b)
+  for (int i = 0; i < 64; i++)
+    {
+      #pragma omp task in_reduction (*:x)
+      x *= a[i];
+      #pragma omp task in_reduction (*:b)
+      b *= (3 - a[i]);
+    }
+  return x;
+}
+
+void
+baz (int i, int *a, int *c)
+{
+  #pragma omp task in_reduction (*:h) in_reduction (+:g)
+  {
+    g.s += 7 * a[i];
+    h.s *= (3 - c[i]);
+    if ((g.t != 7 && g.t != 3) || (h.t != 5 && h.t != 9))
+      abort ();
+  }
+}
+
+void
+test ()
+{
+  int i, j, a[64], b = 0, c[64];
+  unsigned long long int d = 1, e;
+  S ms (0, 7);
+  for (i = 0; i < 64; i++)
+    {
+      a[i] = 2 * i;
+      c[i] = 1 + ((i % 3) != 1);
+    }
+  #pragma omp parallel
+  #pragma omp master
+  {
+    S ns = { 1, 5 };
+    S &m = ms;
+    S &n = ns;
+    #pragma omp taskgroup task_reduction (+:b)
+      j = foo (a, b);
+    #pragma omp taskgroup task_reduction (*:d)
+      e = bar (c, d);
+    #pragma omp taskloop reduction (+: g, m) reduction (*: h, n)
+    for (i = 0; i < 64; ++i)
+      {
+       g.s += 3 * a[i];
+       h.s *= (3 - c[i]);
+       m.s += 4 * a[i];
+       n.s *= c[i];
+       if ((g.t != 7 && g.t != 3) || (h.t != 5 && h.t != 9)
+           || (m.t != 7 && m.t != 3) || (n.t != 5 && n.t != 9))
+         abort ();
+       baz (i, a, c);
+      }
+    if (n.s != (1ULL << 43) || n.t != 5)
+      abort ();
+  }
+  if (j != 63 * 64 || b != 63 * 64 * 2)
+    abort ();
+  if (e != (1ULL << 43) || d != (1ULL << 21))
+    abort ();
+  if (g.s != 63 * 64 * 10 || g.t != 7)
+    abort ();
+  if (h.s != (1ULL << 42) || h.t != 5)
+    abort ();
+  if (ms.s != 63 * 64 * 4 || ms.t != 7)
+    abort ();
+}
+
+int
+main ()
+{
+  int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
+  test ();
+  if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
+    abort ();
+}
diff --git a/libgomp/testsuite/libgomp.c++/taskloop-reduction-2.C b/libgomp/testsuite/libgomp.c++/taskloop-reduction-2.C
new file mode 100644 (file)
index 0000000..f1de5da
--- /dev/null
@@ -0,0 +1,253 @@
+extern "C" void abort ();
+
+int as[2];
+int (&a)[2] = as;
+long long int bs[7] = { 9, 11, 1, 1, 1, 13, 15 };
+long long int (&b)[7] = bs;
+int es[3] = { 5, 0, 5 };
+int (&e)[3] = es;
+int fs[5] = { 6, 7, 0, 0, 9 };
+int (&f)[5] = fs;
+int gs[4] = { 1, 0, 0, 2 };
+int (&g)[4] = gs;
+int hs[3] = { 0, 1, 4 };
+int (&h)[3] = hs;
+int ks[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+int (&k)[4][2] = ks;
+long long *ss;
+long long *&s = ss;
+long long (*ts)[2];
+long long (*&t)[2] = ts;
+struct U { U (); ~U () {}; U (const U &); int u[4]; };
+
+U::U
+()
+{
+  u[0] = 0; u[1] = 1; u[2] = 2; u[3] = 3;
+}
+
+U::U
+(const U &r)
+{
+  u[0] = r.u[0]; u[1] = r.u[1]; u[2] = r.u[2]; u[3] = r.u[3];
+}
+
+void
+foo (int &n, int *&c, long long int *&d, int (&m)[3], int *&r, int (&o)[4], int *&p, int (&q)[4][2])
+{
+  int i;
+  U u;
+  u.u[2] = 8;
+  #pragma omp taskloop in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                      in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
+                      in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
+                      in_reduction (*: s[1:2], t[2:2][:]) firstprivate (u) nogroup
+  for (i = 0; i < 2; i++)
+    {
+      a[0] += 7;
+      a[1] += 17;
+      b[2] *= 2;
+      b[4] *= 2;
+      c[0] += 6;
+      d[1] *= 2;
+      e[1] += 19;
+      f[2] += 21;
+      f[3] += 23;
+      g[1] += 25;
+      g[2] += 27;
+      h[0] += 29;
+      k[1][0] += 31;
+      k[2][1] += 33;
+      m[1] += 19;
+      r[2] += 21;
+      r[3] += 23;
+      o[1] += 25;
+      o[2] += 27;
+      p[0] += 29;
+      q[1][0] += 31;
+      q[2][1] += 33;
+      s[1] *= 2;
+      t[2][0] *= 2;
+      t[3][1] *= 2;
+      if (u.u[2] != 8)
+       abort ();
+    }
+}
+
+void
+test (int &n)
+{
+  int cs[2] = { 0, 0 };
+  int (&c)[2] = cs;
+  int ps[3] = { 0, 1, 4 };
+  int (&p)[3] = ps;
+  int qs[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+  int (&q)[4][2] = qs;
+  long long sb[4] = { 5, 1, 1, 6 };
+  long long tb[5][2] = { { 9, 10 }, { 11, 12 }, { 1, 1 }, { 1, 1 }, { 13, 14 } };
+  int ms[3] = { 5, 0, 5 };
+  int os[4] = { 1, 0, 0, 2 };
+  s = sb;
+  t = tb;
+  U u;
+  u.u[2] = 10;
+  #pragma omp parallel
+  #pragma omp single
+  {
+    long long int ds[] = { 1, 1 };
+    long long int (&d)[2] = ds;
+    int (&m)[3] = ms;
+    int rs[5] = { 6, 7, 0, 0, 9 };
+    int (&r)[5] = rs;
+    int (&o)[4] = os;
+    int i;
+    #pragma omp taskloop reduction (+: a, c) reduction (*: b[2 * n:3 * n], d) \
+                        reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                        reduction (+: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                        reduction (*: t[2:2][:], s[1:n + 1]) firstprivate (u)
+    for (i = 0; i < 4; i++)
+      {
+       int j;
+       a[0] += 2;
+       a[1] += 3;
+       b[2] *= 2;
+       f[3] += 8;
+       g[1] += 9;
+       g[2] += 10;
+       h[0] += 11;
+       k[1][1] += 13;
+       k[2][1] += 15;
+       m[1] += 16;
+       r[2] += 8;
+       s[1] *= 2;
+       t[2][1] *= 2;
+       t[3][1] *= 2;
+       if (u.u[2] != 10)
+         abort ();
+       for (j = 0; j < 2; j++)
+         #pragma omp task in_reduction (+: a, c[:2]) \
+                          in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                          in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                          in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                          in_reduction (*: s[n:2], t[2:2][:]) firstprivate (u)
+         {
+           m[1] += 6;
+           r[2] += 7;
+           q[1][0] += 17;
+           q[2][0] += 19;
+           a[0] += 4;
+           a[1] += 5;
+           b[3] *= 2;
+           b[4] *= 2;
+           f[3] += 18;
+           g[1] += 29;
+           g[2] += 18;
+           h[0] += 19;
+           s[2] *= 2;
+           t[2][0] *= 2;
+           t[3][0] *= 2;
+           int *cp = c;
+           long long int *dp = d;
+           int *rp = r;
+           int *pp = p;
+           foo (n, cp, dp, m, rp, o, pp, q);
+           if (u.u[2] != 10)
+             abort ();
+           r[3] += 18;
+           o[1] += 29;
+           o[2] += 18;
+           p[0] += 19;
+           c[0] += 4;
+           c[1] += 5;
+           d[0] *= 2;
+           e[1] += 6;
+           f[2] += 7;
+           k[1][0] += 17;
+           k[2][0] += 19;
+         }
+       r[3] += 8;
+       o[1] += 9;
+       o[2] += 10;
+       p[0] += 11;
+       q[1][1] += 13;
+       q[2][1] += 15;
+       b[3] *= 2;
+       c[0] += 4;
+       c[1] += 9;
+       d[0] *= 2;
+       e[1] += 16;
+       f[2] += 8;
+      }
+    if (d[0] != 1LL << (8 + 4)
+       || d[1] != 1LL << 16
+       || m[0] != 5
+       || m[1] != 19 * 16 + 6 * 8 + 16 * 4
+       || m[2] != 5
+       || r[0] != 6
+       || r[1] != 7
+       || r[2] != 21 * 16 + 7 * 8 + 8 * 4
+       || r[3] != 23 * 16 + 18 * 8 + 8 * 4
+       || r[4] != 9
+       || o[0] != 1
+       || o[1] != 25 * 16 + 29 * 8 + 9 * 4
+       || o[2] != 27 * 16 + 18 * 8 + 10 * 4
+       || o[3] != 2)
+      abort ();
+  }
+  if (a[0] != 7 * 16 + 4 * 8 + 2 * 4
+      || a[1] != 17 * 16 + 5 * 8 + 3 * 4
+      || b[0] != 9 || b[1] != 11
+      || b[2] != 1LL << (16 + 4)
+      || b[3] != 1LL << (8 + 4)
+      || b[4] != 1LL << (16 + 8)
+      || b[5] != 13 || b[6] != 15
+      || c[0] != 6 * 16 + 4 * 8 + 4 * 4
+      || c[1] != 5 * 8 + 9 * 4
+      || e[0] != 5
+      || e[1] != 19 * 16 + 6 * 8 + 16 * 4
+      || e[2] != 5
+      || f[0] != 6
+      || f[1] != 7
+      || f[2] != 21 * 16 + 7 * 8 + 8 * 4
+      || f[3] != 23 * 16 + 18 * 8 + 8 * 4
+      || f[4] != 9
+      || g[0] != 1
+      || g[1] != 25 * 16 + 29 * 8 + 9 * 4
+      || g[2] != 27 * 16 + 18 * 8 + 10 * 4
+      || g[3] != 2
+      || h[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || h[1] != 1 || h[2] != 4
+      || k[0][0] != 5 || k[0][1] != 6
+      || k[1][0] != 31 * 16 + 17 * 8
+      || k[1][1] != 13 * 4
+      || k[2][0] != 19 * 8
+      || k[2][1] != 33 * 16 + 15 * 4
+      || k[3][0] != 7 || k[3][1] != 8
+      || p[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || p[1] != 1 || p[2] != 4
+      || q[0][0] != 5 || q[0][1] != 6
+      || q[1][0] != 31 * 16 + 17 * 8
+      || q[1][1] != 13 * 4
+      || q[2][0] != 19 * 8
+      || q[2][1] != 33 * 16 + 15 * 4
+      || q[3][0] != 7 || q[3][1] != 8
+      || sb[0] != 5
+      || sb[1] != 1LL << (16 + 4)
+      || sb[2] != 1LL << 8
+      || sb[3] != 6
+      || tb[0][0] != 9 || tb[0][1] != 10 || tb[1][0] != 11 || tb[1][1] != 12
+      || tb[2][0] != 1LL << (16 + 8)
+      || tb[2][1] != 1LL << 4
+      || tb[3][0] != 1LL << 8
+      || tb[3][1] != 1LL << (16 + 4)
+      || tb[4][0] != 13 || tb[4][1] != 14)
+    abort ();
+}
+
+int
+main ()
+{
+  int n = 1;
+  test (n);
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/taskloop-reduction-3.C b/libgomp/testsuite/libgomp.c++/taskloop-reduction-3.C
new file mode 100644 (file)
index 0000000..0588e47
--- /dev/null
@@ -0,0 +1,314 @@
+extern "C" void abort ();
+
+struct S { S (); S (long int, long int); ~S (); static int cnt1, cnt2, cnt3; long int s, t; };
+
+int S::cnt1;
+int S::cnt2;
+int S::cnt3;
+
+S::S ()
+{
+  #pragma omp atomic
+  cnt1++;
+}
+
+S::S (long int x, long int y) : s (x), t (y)
+{
+  #pragma omp atomic update
+  ++cnt2;
+}
+
+S::~S ()
+{
+  #pragma omp atomic
+  cnt3 = cnt3 + 1;
+  if (t < 3 || t > 9 || (t & 1) == 0)
+    abort ();
+}
+
+void
+bar (S *p, S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+baz (S *o, S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: S : omp_out.s += omp_in.s) initializer (omp_priv (0, 3))
+#pragma omp declare reduction (*: S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
+
+S a[2] = { { 0, 7 }, { 0, 7 } };
+S b[7] = { { 9, 5 }, { 11, 5 }, { 1, 5 }, { 1, 5 }, { 1, 5 }, { 13, 5 }, { 15, 5 } };
+S e[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+S f[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+S g[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+S h[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+S k[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+S *s;
+S (*t)[2];
+
+void
+foo (int n, S *c, S *d, S m[3], S *r, S o[4], S *p, S q[4][2])
+{
+  int i;
+  #pragma omp taskloop in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                      in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
+                      in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
+                      in_reduction (*: s[1:2], t[2:2][:]) nogroup
+  for (i = 0; i < 2; i++)
+    {
+      a[0].s += 7;
+      a[1].s += 17;
+      b[2].s *= 2;
+      b[4].s *= 2;
+      c[0].s += 6;
+      d[1].s *= 2;
+      e[1].s += 19;
+      f[2].s += 21;
+      f[3].s += 23;
+      g[1].s += 25;
+      g[2].s += 27;
+      h[0].s += 29;
+      k[1][0].s += 31;
+      k[2][1].s += 33;
+      m[1].s += 19;
+      r[2].s += 21;
+      r[3].s += 23;
+      o[1].s += 25;
+      o[2].s += 27;
+      p[0].s += 29;
+      q[1][0].s += 31;
+      q[2][1].s += 33;
+      s[1].s *= 2;
+      t[2][0].s *= 2;
+      t[3][1].s *= 2;
+      if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+         || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+       abort ();
+      for (int z = 0; z < 2; z++)
+       if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+           || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+           || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+           || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+           || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+           || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+           || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+         abort ();
+      for (int z = 0; z < 3; z++)
+       if (b[z + 2].t != 5 && b[z + 2].t != 9)
+         abort ();
+    }
+}
+
+void
+test (int n)
+{
+  S c[2] = { { 0, 7 }, { 0, 7 } };
+  S p[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+  S q[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+  S ss[4] = { { 5, 5 }, { 1, 5 }, { 1, 5 }, { 6, 5 } };
+  S tt[5][2] = { { { 9, 5 }, { 10, 5 } }, { { 11, 5 }, { 12, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 13, 5 }, { 14, 5 } } };
+  s = ss;
+  t = tt;
+  #pragma omp parallel
+  #pragma omp single
+  {
+    S d[] = { { 1, 5 }, { 1, 5 } };
+    S m[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+    S r[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+    S o[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+    int i;
+    #pragma omp taskloop reduction (+: a, c) reduction (*: b[2 * n:3 * n], d) \
+                        reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                        reduction (+: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                        reduction (*: t[2:2][:], s[1:n + 1])
+    for (i = 0; i < 4; i++)
+      {
+       int j;
+       a[0].s += 2;
+       a[1].s += 3;
+       b[2].s *= 2;
+       f[3].s += 8;
+       g[1].s += 9;
+       g[2].s += 10;
+       h[0].s += 11;
+       k[1][1].s += 13;
+       k[2][1].s += 15;
+       m[1].s += 16;
+       r[2].s += 8;
+       s[1].s *= 2;
+       t[2][1].s *= 2;
+       t[3][1].s *= 2;
+       if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+            || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+         abort ();
+       for (int z = 0; z < 2; z++)
+         if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+              || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+              || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+              || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+              || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+              || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+              || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+           abort ();
+       for (int z = 0; z < 3; z++)
+         if (b[z + 2].t != 5 && b[z + 2].t != 9)
+           abort ();
+       #pragma omp taskloop in_reduction (+: a, c[:2]) \
+                            in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                            in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                            in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                            in_reduction (*: s[n:2], t[2:2][:]) nogroup
+       for (j = 0; j < 2; j++)
+         {
+           m[1].s += 6;
+           r[2].s += 7;
+           q[1][0].s += 17;
+           q[2][0].s += 19;
+           a[0].s += 4;
+           a[1].s += 5;
+           b[3].s *= 2;
+           b[4].s *= 2;
+           f[3].s += 18;
+           g[1].s += 29;
+           g[2].s += 18;
+           h[0].s += 19;
+           s[2].s *= 2;
+           t[2][0].s *= 2;
+           t[3][0].s *= 2;
+           foo (n, c, d, m, r, o, p, q);
+           if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+                || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+             abort ();
+           for (int z = 0; z < 2; z++)
+             if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+                  || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+                  || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+                  || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+                  || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+                  || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+                  || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+               abort ();
+           for (int z = 0; z < 3; z++)
+             if (b[z + 2].t != 5 && b[z + 2].t != 9)
+               abort ();
+           r[3].s += 18;
+           o[1].s += 29;
+           o[2].s += 18;
+           p[0].s += 19;
+           c[0].s += 4;
+           c[1].s += 5;
+           d[0].s *= 2;
+           e[1].s += 6;
+           f[2].s += 7;
+           k[1][0].s += 17;
+           k[2][0].s += 19;
+         }
+       r[3].s += 8;
+       o[1].s += 9;
+       o[2].s += 10;
+       p[0].s += 11;
+       q[1][1].s += 13;
+       q[2][1].s += 15;
+       b[3].s *= 2;
+       c[0].s += 4;
+       c[1].s += 9;
+       d[0].s *= 2;
+       e[1].s += 16;
+       f[2].s += 8;
+      }
+    if (d[0].s != 1LL << (8 + 4)
+       || d[1].s != 1LL << 16
+       || m[0].s != 5
+       || m[1].s != 19 * 16 + 6 * 8 + 16 * 4
+       || m[2].s != 5
+       || r[0].s != 6
+       || r[1].s != 7
+       || r[2].s != 21 * 16 + 7 * 8 + 8 * 4
+       || r[3].s != 23 * 16 + 18 * 8 + 8 * 4
+       || r[4].s != 9
+       || o[0].s != 1
+       || o[1].s != 25 * 16 + 29 * 8 + 9 * 4
+       || o[2].s != 27 * 16 + 18 * 8 + 10 * 4
+       || o[3].s != 2)
+      abort ();
+    if (e[1].t != 7 || h[0].t != 7 || m[1].t != 7 || p[0].t != 7)
+      abort ();
+    for (int z = 0; z < 2; z++)
+      if (a[z].t != 7 || c[z].t != 7 || d[z].t != 5 || f[z + 2].t != 7
+         || g[z + 1].t != 7 || r[z + 2].t != 7 || s[z + 1].t != 5 || o[z + 1].t != 7
+         || k[z + 1][0].t != 7 || k[z + 1][1].t != 7 || q[z + 1][0].t != 7 || q[z + 1][1].t != 7
+         || t[z + 2][0].t != 5 || t[z + 2][1].t != 5)
+       abort ();
+    for (int z = 0; z < 3; z++)
+      if (b[z + 2].t != 5)
+       abort ();
+  }
+  if (a[0].s != 7 * 16 + 4 * 8 + 2 * 4
+      || a[1].s != 17 * 16 + 5 * 8 + 3 * 4
+      || b[0].s != 9 || b[1].s != 11
+      || b[2].s != 1LL << (16 + 4)
+      || b[3].s != 1LL << (8 + 4)
+      || b[4].s != 1LL << (16 + 8)
+      || b[5].s != 13 || b[6].s != 15
+      || c[0].s != 6 * 16 + 4 * 8 + 4 * 4
+      || c[1].s != 5 * 8 + 9 * 4
+      || e[0].s != 5
+      || e[1].s != 19 * 16 + 6 * 8 + 16 * 4
+      || e[2].s != 5
+      || f[0].s != 6
+      || f[1].s != 7
+      || f[2].s != 21 * 16 + 7 * 8 + 8 * 4
+      || f[3].s != 23 * 16 + 18 * 8 + 8 * 4
+      || f[4].s != 9
+      || g[0].s != 1
+      || g[1].s != 25 * 16 + 29 * 8 + 9 * 4
+      || g[2].s != 27 * 16 + 18 * 8 + 10 * 4
+      || g[3].s != 2
+      || h[0].s != 29 * 16 + 19 * 8 + 11 * 4
+      || h[1].s != 1 || h[2].s != 4
+      || k[0][0].s != 5 || k[0][1].s != 6
+      || k[1][0].s != 31 * 16 + 17 * 8
+      || k[1][1].s != 13 * 4
+      || k[2][0].s != 19 * 8
+      || k[2][1].s != 33 * 16 + 15 * 4
+      || k[3][0].s != 7 || k[3][1].s != 8
+      || p[0].s != 29 * 16 + 19 * 8 + 11 * 4
+      || p[1].s != 1 || p[2].s != 4
+      || q[0][0].s != 5 || q[0][1].s != 6
+      || q[1][0].s != 31 * 16 + 17 * 8
+      || q[1][1].s != 13 * 4
+      || q[2][0].s != 19 * 8
+      || q[2][1].s != 33 * 16 + 15 * 4
+      || q[3][0].s != 7 || q[3][1].s != 8
+      || ss[0].s != 5
+      || ss[1].s != 1LL << (16 + 4)
+      || ss[2].s != 1LL << 8
+      || ss[3].s != 6
+      || tt[0][0].s != 9 || tt[0][1].s != 10 || tt[1][0].s != 11 || tt[1][1].s != 12
+      || tt[2][0].s != 1LL << (16 + 8)
+      || tt[2][1].s != 1LL << 4
+      || tt[3][0].s != 1LL << 8
+      || tt[3][1].s != 1LL << (16 + 4)
+      || tt[4][0].s != 13 || tt[4][1].s != 14)
+    abort ();
+}
+
+int
+main ()
+{
+  int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
+  test (1);
+  if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/taskloop-reduction-4.C b/libgomp/testsuite/libgomp.c++/taskloop-reduction-4.C
new file mode 100644 (file)
index 0000000..41c7040
--- /dev/null
@@ -0,0 +1,315 @@
+extern "C" void abort ();
+
+struct S { S (); S (long int, long int); ~S (); static int cnt1, cnt2, cnt3; long int s, t; };
+
+int S::cnt1;
+int S::cnt2;
+int S::cnt3;
+
+S::S ()
+{
+  #pragma omp atomic
+  cnt1++;
+}
+
+S::S (long int x, long int y) : s (x), t (y)
+{
+  #pragma omp atomic update
+  ++cnt2;
+}
+
+S::~S ()
+{
+  #pragma omp atomic
+  cnt3 = cnt3 + 1;
+  if (t < 3 || t > 9 || (t & 1) == 0)
+    abort ();
+}
+
+void
+bar (S *p, S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+baz (S *o, S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: S : omp_out.s += omp_in.s) initializer (omp_priv (0, 3))
+#pragma omp declare reduction (*: S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
+
+S a[2] = { { 0, 7 }, { 0, 7 } };
+S b[7] = { { 9, 5 }, { 11, 5 }, { 1, 5 }, { 1, 5 }, { 1, 5 }, { 13, 5 }, { 15, 5 } };
+S e[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+S f[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+S g[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+S h[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+S k[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+S *s;
+S (*t)[2];
+
+template <int N>
+void
+foo (int n, S *c, S *d, S m[3], S *r, S o[4], S *p, S q[4][2])
+{
+  int i;
+  #pragma omp taskloop in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                      reduction (default, +: o[n:n*2], m[1], p[0]) in_reduction (+: k[1:2][:], f[2:2]) \
+                      reduction (+: q[1:2][:], r[2:2]) in_reduction (+: g[n:n*2], e[1], h[0]) \
+                      in_reduction (*: s[1:2], t[2:2][:])
+  for (i = 0; i < 2; i++)
+    {
+      a[0].s += 7;
+      a[1].s += 17;
+      b[2].s *= 2;
+      b[4].s *= 2;
+      c[0].s += 6;
+      d[1].s *= 2;
+      e[1].s += 19;
+      f[2].s += 21;
+      f[3].s += 23;
+      g[1].s += 25;
+      g[2].s += 27;
+      h[0].s += 29;
+      k[1][0].s += 31;
+      k[2][1].s += 33;
+      m[1].s += 19;
+      r[2].s += 21;
+      r[3].s += 23;
+      o[1].s += 25;
+      o[2].s += 27;
+      p[0].s += 29;
+      q[1][0].s += 31;
+      q[2][1].s += 33;
+      s[1].s *= 2;
+      t[2][0].s *= 2;
+      t[3][1].s *= 2;
+      if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+         || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+       abort ();
+      for (int z = 0; z < 2; z++)
+       if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+           || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+           || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+           || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+           || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+           || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+           || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+         abort ();
+      for (int z = 0; z < 3; z++)
+       if (b[z + 2].t != 5 && b[z + 2].t != 9)
+         abort ();
+    }
+}
+
+template <typename T>
+void
+test (int n)
+{
+  T c[2] = { { 0, 7 }, { 0, 7 } };
+  T p[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
+  T q[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
+  T ss[4] = { { 5, 5 }, { 1, 5 }, { 1, 5 }, { 6, 5 } };
+  T tt[5][2] = { { { 9, 5 }, { 10, 5 } }, { { 11, 5 }, { 12, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 13, 5 }, { 14, 5 } } };
+  s = ss;
+  t = tt;
+  #pragma omp parallel
+  #pragma omp single
+  {
+    T d[] = { { 1, 5 }, { 1, 5 } };
+    T m[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
+    T r[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
+    T o[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
+    int i;
+    #pragma omp taskloop reduction (+: a, c) reduction (default, *: b[2 * n:3 * n], d) \
+                        reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                        reduction (+: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                        reduction (*: t[2:2][:], s[1:n + 1])
+    for (i = 0; i < 4; i++)
+      {
+       int j;
+       a[0].s += 2;
+       a[1].s += 3;
+       b[2].s *= 2;
+       f[3].s += 8;
+       g[1].s += 9;
+       g[2].s += 10;
+       h[0].s += 11;
+       k[1][1].s += 13;
+       k[2][1].s += 15;
+       m[1].s += 16;
+       r[2].s += 8;
+       s[1].s *= 2;
+       t[2][1].s *= 2;
+       t[3][1].s *= 2;
+       if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+            || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+         abort ();
+       for (int z = 0; z < 2; z++)
+         if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+              || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+              || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+              || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+              || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+              || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+              || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+           abort ();
+       for (int z = 0; z < 3; z++)
+         if (b[z + 2].t != 5 && b[z + 2].t != 9)
+           abort ();
+       #pragma omp taskloop in_reduction (+: a, c[:2]) \
+                            in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                            in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                            in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                            in_reduction (*: s[n:2], t[2:2][:]) nogroup
+       for (j = 0; j < 2; j++)
+         {
+           m[1].s += 6;
+           r[2].s += 7;
+           q[1][0].s += 17;
+           q[2][0].s += 19;
+           a[0].s += 4;
+           a[1].s += 5;
+           b[3].s *= 2;
+           b[4].s *= 2;
+           f[3].s += 18;
+           g[1].s += 29;
+           g[2].s += 18;
+           h[0].s += 19;
+           s[2].s *= 2;
+           t[2][0].s *= 2;
+           t[3][0].s *= 2;
+           foo<0> (n, c, d, m, r, o, p, q);
+           if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
+                || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
+             abort ();
+           for (int z = 0; z < 2; z++)
+             if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
+                  || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
+                  || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
+                  || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
+                  || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
+                  || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
+                  || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
+               abort ();
+           for (int z = 0; z < 3; z++)
+             if (b[z + 2].t != 5 && b[z + 2].t != 9)
+               abort ();
+           r[3].s += 18;
+           o[1].s += 29;
+           o[2].s += 18;
+           p[0].s += 19;
+           c[0].s += 4;
+           c[1].s += 5;
+           d[0].s *= 2;
+           e[1].s += 6;
+           f[2].s += 7;
+           k[1][0].s += 17;
+           k[2][0].s += 19;
+         }
+       r[3].s += 8;
+       o[1].s += 9;
+       o[2].s += 10;
+       p[0].s += 11;
+       q[1][1].s += 13;
+       q[2][1].s += 15;
+       b[3].s *= 2;
+       c[0].s += 4;
+       c[1].s += 9;
+       d[0].s *= 2;
+       e[1].s += 16;
+       f[2].s += 8;
+      }
+    if (d[0].s != 1LL << (8 + 4)
+       || d[1].s != 1LL << 16
+       || m[0].s != 5
+       || m[1].s != 19 * 16 + 6 * 8 + 16 * 4
+       || m[2].s != 5
+       || r[0].s != 6
+       || r[1].s != 7
+       || r[2].s != 21 * 16 + 7 * 8 + 8 * 4
+       || r[3].s != 23 * 16 + 18 * 8 + 8 * 4
+       || r[4].s != 9
+       || o[0].s != 1
+       || o[1].s != 25 * 16 + 29 * 8 + 9 * 4
+       || o[2].s != 27 * 16 + 18 * 8 + 10 * 4
+       || o[3].s != 2)
+      abort ();
+    if (e[1].t != 7 || h[0].t != 7 || m[1].t != 7 || p[0].t != 7)
+      abort ();
+    for (int z = 0; z < 2; z++)
+      if (a[z].t != 7 || c[z].t != 7 || d[z].t != 5 || f[z + 2].t != 7
+         || g[z + 1].t != 7 || r[z + 2].t != 7 || s[z + 1].t != 5 || o[z + 1].t != 7
+         || k[z + 1][0].t != 7 || k[z + 1][1].t != 7 || q[z + 1][0].t != 7 || q[z + 1][1].t != 7
+         || t[z + 2][0].t != 5 || t[z + 2][1].t != 5)
+       abort ();
+    for (int z = 0; z < 3; z++)
+      if (b[z + 2].t != 5)
+       abort ();
+  }
+  if (a[0].s != 7 * 16 + 4 * 8 + 2 * 4
+      || a[1].s != 17 * 16 + 5 * 8 + 3 * 4
+      || b[0].s != 9 || b[1].s != 11
+      || b[2].s != 1LL << (16 + 4)
+      || b[3].s != 1LL << (8 + 4)
+      || b[4].s != 1LL << (16 + 8)
+      || b[5].s != 13 || b[6].s != 15
+      || c[0].s != 6 * 16 + 4 * 8 + 4 * 4
+      || c[1].s != 5 * 8 + 9 * 4
+      || e[0].s != 5
+      || e[1].s != 19 * 16 + 6 * 8 + 16 * 4
+      || e[2].s != 5
+      || f[0].s != 6
+      || f[1].s != 7
+      || f[2].s != 21 * 16 + 7 * 8 + 8 * 4
+      || f[3].s != 23 * 16 + 18 * 8 + 8 * 4
+      || f[4].s != 9
+      || g[0].s != 1
+      || g[1].s != 25 * 16 + 29 * 8 + 9 * 4
+      || g[2].s != 27 * 16 + 18 * 8 + 10 * 4
+      || g[3].s != 2
+      || h[0].s != 29 * 16 + 19 * 8 + 11 * 4
+      || h[1].s != 1 || h[2].s != 4
+      || k[0][0].s != 5 || k[0][1].s != 6
+      || k[1][0].s != 31 * 16 + 17 * 8
+      || k[1][1].s != 13 * 4
+      || k[2][0].s != 19 * 8
+      || k[2][1].s != 33 * 16 + 15 * 4
+      || k[3][0].s != 7 || k[3][1].s != 8
+      || p[0].s != 29 * 16 + 19 * 8 + 11 * 4
+      || p[1].s != 1 || p[2].s != 4
+      || q[0][0].s != 5 || q[0][1].s != 6
+      || q[1][0].s != 31 * 16 + 17 * 8
+      || q[1][1].s != 13 * 4
+      || q[2][0].s != 19 * 8
+      || q[2][1].s != 33 * 16 + 15 * 4
+      || q[3][0].s != 7 || q[3][1].s != 8
+      || ss[0].s != 5
+      || ss[1].s != 1LL << (16 + 4)
+      || ss[2].s != 1LL << 8
+      || ss[3].s != 6
+      || tt[0][0].s != 9 || tt[0][1].s != 10 || tt[1][0].s != 11 || tt[1][1].s != 12
+      || tt[2][0].s != 1LL << (16 + 8)
+      || tt[2][1].s != 1LL << 4
+      || tt[3][0].s != 1LL << 8
+      || tt[3][1].s != 1LL << (16 + 4)
+      || tt[4][0].s != 13 || tt[4][1].s != 14)
+    abort ();
+}
+
+int
+main ()
+{
+  int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
+  test<S> (1);
+  if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
+    abort ();
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/cancel-parallel-1.c b/libgomp/testsuite/libgomp.c-c++-common/cancel-parallel-1.c
new file mode 100644 (file)
index 0000000..77395e2
--- /dev/null
@@ -0,0 +1,42 @@
+/* { dg-do run } */
+/* { dg-set-target-env-var OMP_CANCELLATION "true" } */
+
+#include <stdlib.h>
+#include <omp.h>
+
+int
+main ()
+{
+  int a[64];
+  #pragma omp parallel
+  {
+    #pragma omp barrier
+    if (omp_get_thread_num () == 0)
+      {
+       #pragma omp cancel parallel
+      }
+    #pragma omp for
+    for (int i = 0; i < 64; i++)
+      a[i] = i;
+    if (omp_get_cancellation ())
+      abort ();
+  }
+  #pragma omp parallel
+  {
+    #pragma omp barrier
+    if (omp_get_thread_num () == 0)
+      {
+       #pragma omp cancel parallel
+      }
+    #pragma omp taskgroup
+    {
+      #pragma omp for
+      for (int i = 0; i < 64; i++)
+       #pragma omp task
+       a[i] += i;
+      if (omp_get_cancellation ())
+       abort ();
+    }
+  }
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/cancel-taskgroup-3.c b/libgomp/testsuite/libgomp.c-c++-common/cancel-taskgroup-3.c
new file mode 100644 (file)
index 0000000..b9af835
--- /dev/null
@@ -0,0 +1,68 @@
+/* { dg-do run } */
+/* { dg-set-target-env-var OMP_CANCELLATION "true" } */
+
+#include <stdlib.h>
+#include <omp.h>
+
+int
+main ()
+{
+  int a = 0, i;
+  #pragma omp parallel
+  #pragma omp taskgroup
+  {
+    #pragma omp task
+    {
+      #pragma omp cancel taskgroup
+      if (omp_get_cancellation ())
+       abort ();
+    }
+    #pragma omp taskwait
+    #pragma omp for reduction (task, +: a)
+    for (i = 0; i < 64; ++i)
+      {
+       a++;
+       #pragma omp task in_reduction (+: a)
+       {
+         volatile int zero = 0;
+         a += zero;
+         if (omp_get_cancellation ())
+           abort ();
+       }
+      }
+    if (a != 64)
+      abort ();
+    #pragma omp task
+    {
+      if (omp_get_cancellation ())
+       abort ();
+    }
+  }
+  a = 0;
+  #pragma omp parallel
+  #pragma omp taskgroup
+  {
+    #pragma omp taskwait
+    #pragma omp for reduction (task, +: a)
+    for (i = 0; i < 64; ++i)
+      {
+       a++;
+       #pragma omp task in_reduction (+: a)
+       {
+         volatile int zero = 0;
+         a += zero;
+         #pragma omp cancel taskgroup
+         if (omp_get_cancellation ())
+           abort ();
+       }
+      }
+    if (a != 64)
+      abort ();
+    #pragma omp task
+    {
+      if (omp_get_cancellation ())
+       abort ();
+    }
+  }
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/depend-iterator-1.c b/libgomp/testsuite/libgomp.c-c++-common/depend-iterator-1.c
new file mode 100644 (file)
index 0000000..03cded4
--- /dev/null
@@ -0,0 +1,115 @@
+#ifdef __cplusplus
+extern "C"
+#endif
+void abort (void);
+int arr[64], arr2[64], arr3[64];
+
+int *
+foo (int x, int y, long z)
+{
+  int v;
+  switch (x)
+    {
+    case 1:
+      if (z != 0 || y < 0 || y >= 64)
+       abort ();
+      #pragma omp atomic capture
+      {
+       v = arr2[y];
+       arr2[y]++;
+      }
+      if (v != 0) abort ();
+      return &arr[y];
+    case 2:
+      if (y < 0 || y > 60 || (y & 3) || z < 0 || z >= 4)
+       abort ();
+      #pragma omp atomic
+      arr2[y + z] = arr2[y + z] + 4;
+      return &arr[y + z];
+    case 3:
+      if (z < 0 || z > 60 || (z & 3) || y < 0 || y >= 4)
+       abort ();
+      #pragma omp atomic
+      arr2[y + z] = arr2[y + z] + 16;
+      return &arr[y + z];
+    case 4:
+      if (y != 0 || z > 64 || z <= 0)
+       abort ();
+      #pragma omp atomic
+      arr2[z - 1] = arr2[z - 1] + 64;
+      return &arr[z - 1];
+    case 5:
+      if ((y & 3) != 0 || y < 64 || y >= 96
+         || (z & 127) != 0 || z < 512 || z >= 1024)
+       abort ();
+      y = (y - 64) + (z - 512) / 128;
+      #pragma omp atomic
+      arr2[y] = arr2[y] + 256;
+      return &arr[y];
+    case 6:
+      if ((y & 3) != 0 || y <= 64 || y > 96
+         || (z & 127) != 1 || z <= 513 || z > 1025)
+       abort ();
+      y = (y - 68) + (z - 641) / 128;
+      #pragma omp atomic
+      arr2[y] = arr2[y] + 1024;
+      return &arr[y];
+    default:
+      abort ();
+    }
+}
+
+volatile int beg, end, step, step2;
+volatile unsigned int begu, endu;
+
+int
+main ()
+{
+  int m;
+  beg = 60;
+  end = -4;
+  step = -4;
+  step2 = 4;
+  begu = -64U;
+  endu = -32U;
+  #pragma omp parallel
+  #pragma omp master
+  {
+    int i;
+    for (i = 0; i < 64; i++)
+      #pragma omp task depend (iterator (j=i:i+1) , out : foo (1, j, 0)[0])
+       arr[i] = i;
+    #pragma omp task depend (iterator (int k=beg:end:step,long int l=0:4:1) , inout : \
+                            foo (2, k, l)[0], foo (3, l, k)[0]) private (i)
+    for (i = 0; i < 64; i++)
+      if (arr[i] != i)
+       abort ();
+      else
+       arr[i] = arr[i] + 1;
+    #pragma omp task depend (iterator (int *p=&arr3[64]:&arr3[0]:-1) , inout : \
+                            foo (4, 0, p - &arr3[0])[0]) depend (in : beg)
+    for (i = 0; i < 64; i++)
+      if (arr[i] != i + 1)
+       abort ();
+      else
+       arr[i] = arr[i] + 2;
+    #pragma omp task depend (iterator (unsigned n=begu:endu:step2, unsigned int o = 512: 1024U: (unsigned char) 128), inout : \
+                            foo (5, n + 128, o)[0])
+    for (i = 0; i < 64; i++)
+      if (arr[i] != i + 3)
+       abort ();
+      else
+       arr[i] = arr[i] + 4;
+    #pragma omp task depend (iterator (int unsigned p=endu:begu:step,unsigned q= 1025U:513U:(signed char) -128), in : \
+                            foo (6, p + 128, q)[0])
+    for (i = 0; i < 64; i++)
+      if (arr[i] != i + 7)
+       abort ();
+      else
+       arr[i] = arr[i] + 8;
+  }
+  for (m = 0; m < 64; m++)
+    if (arr[m] != m + 15 || arr2[m] != (m < 32 ? 1365 : 85))
+      abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/depend-iterator-2.c b/libgomp/testsuite/libgomp.c-c++-common/depend-iterator-2.c
new file mode 100644 (file)
index 0000000..d9cbfdc
--- /dev/null
@@ -0,0 +1,63 @@
+volatile int v;
+
+__attribute__((noipa)) void
+foo (int *p, int i)
+{
+  #pragma omp task depend (out: p[0])
+  v++;
+  #pragma omp task depend (in: p[0])
+  v++;
+  #pragma omp task depend (inout: p[0])
+  v++;
+  #pragma omp task depend (mutexinoutset: p[0])
+  v++;
+  #pragma omp task depend (out: p[0]) depend (in: p[1])
+  v++;
+  #pragma omp task depend (in: p[0]) depend (inout: p[1])
+  v++;
+  #pragma omp task depend (inout: p[0]) depend (mutexinoutset: p[1])
+  v++;
+  #pragma omp task depend (mutexinoutset: p[0]) depend (out: p[1])
+  v++;
+  #pragma omp task depend (iterator (j=0:2) , out : p[j])
+  v++;
+  #pragma omp task depend (iterator (j=0:2) , in : p[j])
+  v++;
+  #pragma omp task depend (iterator (j=0:2) , inout : p[j])
+  v++;
+  #pragma omp task depend (iterator (j=0:2) , mutexinoutset : p[j])
+  v++;
+  #pragma omp task depend (iterator (j=0:2) , out : p[j]) depend (iterator (j=0:2) , in : p[j + 2])
+  v++;
+  #pragma omp task depend (iterator (j=0:2) , in : p[j]) depend (iterator (j=0:2) , inout : p[j + 2])
+  v++;
+  #pragma omp task depend (iterator (j=0:2) , inout : p[j]) depend (iterator (j=0:2) , mutexinoutset : p[j + 2])
+  v++;
+  #pragma omp task depend (iterator (j=0:2) , mutexinoutset : p[j]) depend (iterator (j=0:2) , out : p[j + 2])
+  v++;
+  #pragma omp task depend (iterator (j=0:i) , out : p[j])
+  v++;
+  #pragma omp task depend (iterator (j=0:i) , in : p[j])
+  v++;
+  #pragma omp task depend (iterator (j=0:i) , inout : p[j])
+  v++;
+  #pragma omp task depend (iterator (j=0:i) , mutexinoutset : p[j])
+  v++;
+  #pragma omp task depend (iterator (j=0:i) , out : p[j]) depend (iterator (j=0:i) , in : p[j + 2])
+  v++;
+  #pragma omp task depend (iterator (j=0:i) , in : p[j]) depend (iterator (j=0:i) , inout : p[j + 2])
+  v++;
+  #pragma omp task depend (iterator (j=0:i) , inout : p[j]) depend (iterator (j=0:i) , mutexinoutset : p[j + 2])
+  v++;
+  #pragma omp task depend (iterator (j=0:i) , mutexinoutset : p[j]) depend (iterator (j=0:i) , out : p[j + 2])
+  v++;
+}
+
+int
+main ()
+{
+  int p[4];
+  foo (p, 2);
+  foo (p, -1);
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/depend-mutexinout-1.c b/libgomp/testsuite/libgomp.c-c++-common/depend-mutexinout-1.c
new file mode 100644 (file)
index 0000000..86322ed
--- /dev/null
@@ -0,0 +1,28 @@
+int
+main ()
+{
+  int a, b, c, d;
+  #pragma omp parallel num_threads (6)
+  #pragma omp single
+  {
+    #pragma omp task depend(out: c)
+      c = 1;
+    #pragma omp task depend(out: a)
+      a = 2;
+    #pragma omp task depend(out: b)
+      b = 3;
+    /* The above 3 tasks can be scheduled in any order.  */
+    #pragma omp task depend(in: a) depend(mutexinoutset: c)
+      c += a;
+    #pragma omp task depend(in: b) depend(mutexinoutset: c)
+      c += b;
+    /* The above 2 tasks are mutually exclusive and need to wait
+       for the first and second or first and third tasks respectively.  */
+    #pragma omp task depend(in: c)
+      d = c;
+    /* The above task needs to wait for the mutexinoutset tasks.  */
+  }
+  if (d != 6)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/depend-mutexinout-2.c b/libgomp/testsuite/libgomp.c-c++-common/depend-mutexinout-2.c
new file mode 100644 (file)
index 0000000..ed92063
--- /dev/null
@@ -0,0 +1,59 @@
+int
+main ()
+{
+  int a, b, c = 0;
+  #pragma omp parallel num_threads(2)
+  {
+    #pragma omp barrier
+    #pragma omp single
+    {
+      #pragma omp task depend(out: a)
+      {
+       int i;
+       a = 0;
+       for (i = 0; i < 524288; ++i)
+         {
+           asm volatile ("" : "+g" (a));
+           a++;
+         }
+      }
+      #pragma omp task depend(out: b)
+      {
+       int i;
+       b = 0;
+       for (i = 0; i < 64; ++i)
+         {
+           asm volatile ("" : "+g" (b));
+           b++;
+         }
+      }
+      #pragma omp task depend(in: a) depend(mutexinoutset: c)
+      {
+       int i;
+       int d = c;
+       for (i = 0; i < 524288 + 64 - a; ++i)
+         {
+           asm volatile ("" : "+g" (d) : "g" (&a) : "memory");
+           d++;
+         }
+       asm volatile ("" : "+g" (d), "+g" (c));
+       c = d;
+      }
+      #pragma omp task depend(in: b) depend(mutexinoutset: c)
+      {
+       int i;
+       int d = c;
+       for (i = 0; i < 524288 + 64 - b; ++i)
+         {
+           asm volatile ("" : "+g" (d) : "g" (&b) : "memory");
+           d++;
+         }
+       asm volatile ("" : "+g" (d), "+g" (c));
+       c = d;
+      }
+    }
+  }
+  if (c != 524288 + 64)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/depobj-1.c b/libgomp/testsuite/libgomp.c-c++-common/depobj-1.c
new file mode 100644 (file)
index 0000000..a07a0c8
--- /dev/null
@@ -0,0 +1,99 @@
+#include <stdlib.h>
+#include <omp.h>
+
+void
+dep (void)
+{
+  int x = 1;
+  omp_depend_t d1, d2;
+  #pragma omp depobj (d1) depend(in: x)
+  #pragma omp depobj (d2) depend(in: x)
+  #pragma omp depobj (d2) update(out)
+  #pragma omp parallel
+  #pragma omp single
+  {
+    #pragma omp task shared (x) depend(depobj: d2)
+    x = 2;
+    #pragma omp task shared (x) depend(depobj: d1)
+    if (x != 2)
+      abort ();
+  }
+  #pragma omp depobj (d2) destroy
+  #pragma omp depobj (d1) destroy
+}
+
+void
+dep2 (void)
+{
+  #pragma omp parallel
+  #pragma omp single
+  {
+    int x = 1;
+    omp_depend_t d1, d2;
+    #pragma omp depobj (d1) depend(out: x)
+    #pragma omp depobj (*&d2) depend (in:x)
+    #pragma omp depobj(d2)update(in)
+    #pragma omp task shared (x) depend(depobj:d1)
+    x = 2;
+    #pragma omp task shared (x) depend(depobj : d2)
+    if (x != 2)
+      abort ();
+    #pragma omp taskwait
+    #pragma omp depobj(d1)destroy
+    #pragma omp depobj((&d2)[0]) destroy
+  }
+}
+
+void
+dep3 (void)
+{
+  omp_depend_t d[2];
+  #pragma omp parallel
+  {
+    int x = 1;
+    #pragma omp single
+    {
+      #pragma omp depobj(d[0]) depend(out:x)
+      #pragma omp depobj(d[1]) depend(in: x)
+      #pragma omp task shared (x) depend(depobj: *d)
+      x = 2;
+      #pragma omp task shared (x) depend(depobj: *(d + 1))
+      if (x != 2)
+       abort ();
+    }
+  }
+  #pragma omp depobj(d[0]) destroy
+  #pragma omp depobj(d[1]) destroy
+}
+
+int xx;
+omp_depend_t dd1, dd2;
+
+void
+antidep (void)
+{
+  xx = 1;
+  #pragma omp parallel
+  #pragma omp single
+  {
+    #pragma omp task shared(xx) depend(depobj:dd2)
+    if (xx != 1)
+      abort ();
+    #pragma omp task shared(xx) depend(depobj:dd1)
+    xx = 2;
+  }
+}
+
+int
+main ()
+{
+  dep ();
+  dep2 ();
+  dep3 ();
+  #pragma omp depobj (dd1) depend (inout: xx)
+  #pragma omp depobj (dd2) depend (in : xx)
+  antidep ();
+  #pragma omp depobj (dd2) destroy
+  #pragma omp depobj (dd1) destroy
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/display-affinity-1.c b/libgomp/testsuite/libgomp.c-c++-common/display-affinity-1.c
new file mode 100644 (file)
index 0000000..a67bb37
--- /dev/null
@@ -0,0 +1,91 @@
+/* { dg-set-target-env-var OMP_PROC_BIND "spread,close" } */
+/* { dg-set-target-env-var OMP_PLACES "cores" } */
+/* { dg-set-target-env-var OMP_NUM_THREADS "4" } */
+/* { dg-set-target-env-var OMP_AFFINITY_FORMAT "hello" } */
+
+#include <omp.h>
+#include <string.h>
+#include <stdlib.h>
+
+int
+main ()
+{
+#define FMT "L:%0.5L%%%n>%32H<!%.33{host}!%.6P_%i_%0.18i_%0.7{ancestor_tnum} %18A"
+  char buf[] = FMT, hostname[256], buf2[512 + 32], *q;
+  size_t l, l2, l3;
+  char *r = getenv ("OMP_AFFINITY_FORMAT");
+  if (r && strcmp (r, "hello") == 0)
+    {
+      if (omp_get_affinity_format (NULL, 0) != 5)
+       abort ();
+      if (omp_get_affinity_format (buf2, 3) != 5
+         || strcmp (buf2, "he") != 0)
+       abort ();
+      if (omp_get_affinity_format (buf2, 6) != 5
+         || strcmp (buf2, "hello") != 0)
+       abort ();
+    }
+  omp_set_affinity_format (buf);
+  memset (buf, '^', sizeof (buf));
+  if (omp_get_affinity_format (NULL, 0) != sizeof (buf) - 1)
+    abort ();
+  if (omp_get_affinity_format (buf, 3) != sizeof (buf) - 1
+      || buf[0] != FMT[0] || buf[1] != FMT[1] || buf[2] != '\0')
+    abort ();
+  memset (buf, ' ', sizeof (buf));
+  if (omp_get_affinity_format (buf, sizeof (buf) - 1) != sizeof (buf) - 1
+      || strncmp (buf, FMT, sizeof (buf) - 2) != 0
+      || buf[sizeof (buf) - 2] != '\0')
+    abort ();
+  memset (buf, '-', sizeof (buf));
+  if (omp_get_affinity_format (buf, sizeof (buf)) != sizeof (buf) - 1
+      || strcmp (buf, FMT) != 0)
+    abort ();
+  memset (buf, '0', sizeof (buf));
+  omp_display_affinity (NULL);
+  omp_display_affinity ("");
+  omp_display_affinity ("%%%0.9N");
+  omp_set_affinity_format ("%{host}");
+  l = omp_capture_affinity (hostname, sizeof hostname, NULL);
+  if (l < sizeof (hostname))
+    {
+      if (strlen (hostname) != l)
+       abort ();
+      l2 = omp_capture_affinity (NULL, 0,
+                                "%0.5{nesting_level}%%%32{host}|||%.33H"
+                                "%0.7a%3N!%N!");
+      if (l2 != (5 + 1 + (l > 32 ? l : 32) + 3 + (l > 33 ? l : 33)
+                + 7 + 3 + 1 + 1 + 1))
+       abort ();
+      omp_set_affinity_format ("%.5L%%%32H|||%.33{host}%0.7{ancestor_tnum}"
+                              "%3{num_threads}!%{num_threads}!");
+      l3 = omp_capture_affinity (buf2, sizeof buf2, "");
+      if (l3 != l2)
+       abort ();
+      if (memcmp (buf2, "    0%", 5 + 1) != 0)
+       abort ();
+      q = buf2 + 6;
+      if (memcmp (q, hostname, l) != 0)
+       abort ();
+      q += l;
+      if (l < 32)
+       for (l3 = 32 - l; l3; l3--)
+         if (*q++ != ' ')
+           abort ();
+      if (memcmp (q, "|||", 3) != 0)
+       abort ();
+      q += 3;
+      if (l < 33)
+       for (l3 = 33 - l; l3; l3--)
+         if (*q++ != ' ')
+           abort ();
+      if (memcmp (q, hostname, l) != 0)
+       abort ();
+      q += l;
+      if (strcmp (q, "-0000011  !1!") != 0)
+       abort ();
+    }
+  #pragma omp parallel num_threads (4) proc_bind(spread)
+  omp_display_affinity ("%0.2a!%n!%.4L!%N;%.2t;%0.2T;%{team_num};%{num_teams};%A");
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/for-10.c b/libgomp/testsuite/libgomp.c-c++-common/for-10.c
new file mode 100644 (file)
index 0000000..2b339a5
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-additional-options "-std=gnu99" {target c } } */
+
+#define CONDNE
+#include "for-4.c"
diff --git a/libgomp/testsuite/libgomp.c-c++-common/for-11.c b/libgomp/testsuite/libgomp.c-c++-common/for-11.c
new file mode 100644 (file)
index 0000000..e46b4dd
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-additional-options "-std=gnu99" {target c } } */
+
+#define CONDNE
+#include "for-5.c"
diff --git a/libgomp/testsuite/libgomp.c-c++-common/for-12.c b/libgomp/testsuite/libgomp.c-c++-common/for-12.c
new file mode 100644 (file)
index 0000000..e28ba93
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-additional-options "-std=gnu99" {target c } } */
+
+#define CONDNE
+#include "for-6.c"
diff --git a/libgomp/testsuite/libgomp.c-c++-common/for-13.c b/libgomp/testsuite/libgomp.c-c++-common/for-13.c
new file mode 100644 (file)
index 0000000..a476727
--- /dev/null
@@ -0,0 +1,99 @@
+unsigned short a[256];
+
+__attribute__((noinline, noclone)) void
+bar (void *x, unsigned short z)
+{
+  unsigned short *y = (unsigned short *) x;
+  if (y < &a[5] || y > &a[222] || y == &a[124])
+    __builtin_abort ();
+  *y += z;
+}
+
+__attribute__((noinline, noclone)) void
+foo (void *qx, void *rx, void *sx, int n)
+{
+  unsigned short (*q)[n], (*r)[n], (*s)[n], (*p)[n];
+  q = (typeof (q)) qx;
+  r = (typeof (r)) rx;
+  s = (typeof (s)) sx;
+  #pragma omp for
+  for (p = q; p != r; p++)
+    bar (p, 1);
+  #pragma omp for
+  for (p = s; p != r; p--)
+    bar (p, 2);
+  #pragma omp for
+  for (p = q; p != r; p = p + 1)
+    bar (p, 4);
+  #pragma omp for
+  for (p = s; p != r; p = p - 1)
+    bar (p, 8);
+  #pragma omp for
+  for (p = q; p != r; p = 1 + p)
+    bar (p, 16);
+  #pragma omp for
+  for (p = s; p != r; p = -1 + p)
+    bar (p, 32);
+  #pragma omp for
+  for (p = q; p != r; p += 1)
+    bar (p, 64);
+  #pragma omp for
+  for (p = s; p != r; p -= 1)
+    bar (p, 128);
+}
+
+__attribute__((noinline, noclone)) void
+baz (void *qx, void *rx, void *sx, int n)
+{
+  unsigned short (*q)[n], (*r)[n], (*s)[n], (*p)[n];
+  q = (typeof (q)) qx;
+  r = (typeof (r)) rx;
+  s = (typeof (s)) sx;
+  #pragma omp for
+  for (p = q; p < r; p++)
+    bar (p, 256);
+  #pragma omp for
+  for (p = s; p > r; p--)
+    bar (p, 512);
+  #pragma omp for
+  for (p = q; p < r; p = p + 1)
+    bar (p, 1024);
+  #pragma omp for
+  for (p = s; p > r; p = p - 1)
+    bar (p, 2048);
+  #pragma omp for
+  for (p = q; p < r; p = 1 + p)
+    bar (p, 4096);
+  #pragma omp for
+  for (p = s; p > r; p = -1 + p)
+    bar (p, 8192);
+  #pragma omp for
+  for (p = q; p < r; p += 1)
+    bar (p, 16384);
+  #pragma omp for
+  for (p = s; p > r; p -= 1)
+    bar (p, 32768U);
+}
+
+int
+main ()
+{
+  int i;
+  volatile int j = 7;
+#pragma omp parallel
+  {
+    foo (&a[5 + (j - 7)], &a[124 + (j - 7)], &a[222 + (j - 7)], j);
+    baz (&a[5 + (j - 7)], &a[124 + (j - 7)], &a[222 + (j - 7)], j);
+  }
+  for (i = 0; i < 256; i++)
+    if (i < 5 || i > 222 || i == 124 || ((i - 5) % 7) != 0)
+      {
+       if (a[i])
+         __builtin_abort ();
+      }
+    else if (i < 124 && a[i] != 1 + 4 + 16 + 64 + 256 + 1024 + 4096 + 16384)
+      __builtin_abort ();
+    else if (i > 124 && a[i] != 2 + 8 + 32 + 128 + 512 + 2048 + 8192 + 32768U)
+      __builtin_abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/for-14.c b/libgomp/testsuite/libgomp.c-c++-common/for-14.c
new file mode 100644 (file)
index 0000000..56440ab
--- /dev/null
@@ -0,0 +1,110 @@
+/* { dg-additional-options "-std=gnu99" { target c } } */
+
+extern
+#ifdef __cplusplus
+"C"
+#endif
+void abort ();
+
+#define M(x, y, z) O(x, y, z)
+#define O(x, y, z) x ## _ ## y ## _ ## z
+
+#define F distribute
+#define G d
+#define S
+#define N(x) M(x, G, normal)
+#include "for-2.h"
+#undef S
+#undef N
+#undef F
+#undef G
+
+#define F distribute
+#define G d_ds128
+#define S dist_schedule(static, 128)
+#define N(x) M(x, G, normal)
+#include "for-2.h"
+#undef S
+#undef N
+#undef F
+#undef G
+
+#define F distribute simd
+#define G ds
+#define S
+#define N(x) M(x, G, normal)
+#include "for-2.h"
+#undef S
+#undef N
+#undef F
+#undef G
+
+#define F distribute simd
+#define G ds_ds128
+#define S dist_schedule(static, 128)
+#define N(x) M(x, G, normal)
+#include "for-2.h"
+#undef S
+#undef N
+#undef F
+#undef G
+
+#define F distribute parallel for
+#define G dpf
+#include "for-1.h"
+#undef F
+#undef G
+
+#define F distribute parallel for dist_schedule(static, 128)
+#define G dpf_ds128
+#include "for-1.h"
+#undef F
+#undef G
+
+#define F distribute parallel for simd
+#define G dpfs
+#include "for-1.h"
+#undef F
+#undef G
+
+#define F distribute parallel for simd dist_schedule(static, 128)
+#define G dpfs_ds128
+#include "for-1.h"
+#undef F
+#undef G
+
+int
+main ()
+{
+  int err = 0;
+  #pragma omp teams reduction(|:err)
+    {
+      err |= test_d_normal ();
+      err |= test_d_ds128_normal ();
+      err |= test_ds_normal ();
+      err |= test_ds_ds128_normal ();
+      err |= test_dpf_static ();
+      err |= test_dpf_static32 ();
+      err |= test_dpf_auto ();
+      err |= test_dpf_guided32 ();
+      err |= test_dpf_runtime ();
+      err |= test_dpf_ds128_static ();
+      err |= test_dpf_ds128_static32 ();
+      err |= test_dpf_ds128_auto ();
+      err |= test_dpf_ds128_guided32 ();
+      err |= test_dpf_ds128_runtime ();
+      err |= test_dpfs_static ();
+      err |= test_dpfs_static32 ();
+      err |= test_dpfs_auto ();
+      err |= test_dpfs_guided32 ();
+      err |= test_dpfs_runtime ();
+      err |= test_dpfs_ds128_static ();
+      err |= test_dpfs_ds128_static32 ();
+      err |= test_dpfs_ds128_auto ();
+      err |= test_dpfs_ds128_guided32 ();
+      err |= test_dpfs_ds128_runtime ();
+    }
+  if (err)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/for-15.c b/libgomp/testsuite/libgomp.c-c++-common/for-15.c
new file mode 100644 (file)
index 0000000..512b972
--- /dev/null
@@ -0,0 +1,115 @@
+/* { dg-additional-options "-std=gnu99" { target c } } */
+
+extern
+#ifdef __cplusplus
+"C"
+#endif
+void abort ();
+
+#define M(x, y, z) O(x, y, z)
+#define O(x, y, z) x ## _ ## y ## _ ## z
+
+#define F for
+#define G f
+#define S
+#define N(x) M(x, G, normal)
+#include "for-2.h"
+#undef S
+#undef N
+#undef F
+#undef G
+
+#define F teams distribute
+#define G td
+#define S
+#define N(x) M(x, G, normal)
+#include "for-2.h"
+#undef S
+#undef N
+#undef F
+#undef G
+
+#define F teams distribute
+#define G td_ds128
+#define S dist_schedule(static, 128)
+#define N(x) M(x, G, normal)
+#include "for-2.h"
+#undef S
+#undef N
+#undef F
+#undef G
+
+#define F teams distribute simd
+#define G tds
+#define S
+#define N(x) M(x, G, normal)
+#include "for-2.h"
+#undef S
+#undef N
+#undef F
+#undef G
+
+#define F teams distribute simd
+#define G tds_ds128
+#define S dist_schedule(static, 128)
+#define N(x) M(x, G, normal)
+#include "for-2.h"
+#undef S
+#undef N
+#undef F
+#undef G
+
+#define F teams distribute parallel for
+#define G tdpf
+#include "for-1.h"
+#undef F
+#undef G
+
+#define F teams distribute parallel for dist_schedule(static, 128)
+#define G tdpf_ds128
+#include "for-1.h"
+#undef F
+#undef G
+
+#define F teams distribute parallel for simd
+#define G tdpfs
+#include "for-1.h"
+#undef F
+#undef G
+
+#define F teams distribute parallel for simd dist_schedule(static, 128)
+#define G tdpfs_ds128
+#include "for-1.h"
+#undef F
+#undef G
+
+int
+main ()
+{
+  if (test_td_normal ()
+      || test_td_ds128_normal ()
+      || test_tds_normal ()
+      || test_tds_ds128_normal ()
+      || test_tdpf_static ()
+      || test_tdpf_static32 ()
+      || test_tdpf_auto ()
+      || test_tdpf_guided32 ()
+      || test_tdpf_runtime ()
+      || test_tdpf_ds128_static ()
+      || test_tdpf_ds128_static32 ()
+      || test_tdpf_ds128_auto ()
+      || test_tdpf_ds128_guided32 ()
+      || test_tdpf_ds128_runtime ()
+      || test_tdpfs_static ()
+      || test_tdpfs_static32 ()
+      || test_tdpfs_auto ()
+      || test_tdpfs_guided32 ()
+      || test_tdpfs_runtime ()
+      || test_tdpfs_ds128_static ()
+      || test_tdpfs_ds128_static32 ()
+      || test_tdpfs_ds128_auto ()
+      || test_tdpfs_ds128_guided32 ()
+      || test_tdpfs_ds128_runtime ())
+    abort ();
+  return 0;
+}
index 0bd116c5aec1a488b1a0cfaf7d8f8b66e5d14ab2..91a604a6c25ee23a3f4d10d06870a9bdcbbebfb4 100644 (file)
@@ -21,6 +21,7 @@ noreturn (void)
 #define OMPFROM(v) do {} while (0)
 #endif
 
+#ifndef CONDNE
 __attribute__((noinline, noclone)) void
 N(f0) (void)
 {
@@ -311,3 +312,292 @@ N(test) (void)
          return 1;
   return 0;
 }
+
+#else
+
+__attribute__((noinline, noclone)) void
+N(f20) (void)
+{
+  int i;
+  OMPTGT
+#pragma omp F S
+  for (i = 0; i != 1500; i++)
+    a[i] += 2;
+}
+
+__attribute__((noinline, noclone)) void
+N(f21) (void)
+{
+  OMPTGT
+#pragma omp F S
+  for (unsigned int i = __INT_MAX__; i < 1500U + __INT_MAX__; i += 2 - 1)
+    a[(i - __INT_MAX__)] -= 2;
+}
+
+__attribute__((noinline, noclone)) void
+N(f22) (void)
+{
+  unsigned long long i;
+  OMPTGT
+#pragma omp F S
+  for (i = __LONG_LONG_MAX__ + 1500ULL - 27;
+       i != __LONG_LONG_MAX__ - 27ULL; i -= 3 - 2)
+    a[i + 26LL - __LONG_LONG_MAX__] -= 4;
+}
+
+__attribute__((noinline, noclone)) void
+N(f23) (long long n1, long long n2)
+{
+  OMPTGT
+#pragma omp F S
+  for (long long i = n1 + 23; i != n2 - 25; --i)
+    a[i + 48] += 7;
+}
+
+__attribute__((noinline, noclone)) void
+N(f24) (void)
+{
+  unsigned int i;
+  OMPTGT
+#pragma omp F S
+  for (i = 30; i != 30; i += 1)
+    a[i] += 10;
+}
+
+__attribute__((noinline, noclone)) void
+N(f25) (int n11, int n12, int n21, int n22, int n31, int n32,
+       int s2)
+{
+  SC int v1, v2, v3;
+  OMPTGT
+#pragma omp F S collapse(3)
+  for (v1 = n11; v1 != n12; v1 += 17 - 19 + 3)
+    for (v2 = n21; v2 < n22; v2 += s2)
+      for (v3 = n31; v3 != n32; ++v3)
+       b[v1][v2][v3] += 2.5;
+}
+
+__attribute__((noinline, noclone)) void
+N(f26) (int n11, int n12, int n21, int n22, long long n31, long long n32,
+       int s2)
+{
+  SC int v1, v2;
+  SC long long v3;
+  OMPTGT
+#pragma omp F S collapse(3)
+  for (v1 = n11; v1 != n12; v1 += -1)
+    for (v2 = n21; v2 > n22; v2 += s2)
+      for (v3 = n31; v3 != n32; v3 --)
+       b[v1][v2 / 2][v3] -= 4.5;
+}
+
+__attribute__((noinline, noclone)) void
+N(f27) (void)
+{
+  SC unsigned int v1, v3;
+  SC unsigned long long v2;
+  OMPTGT
+#pragma omp F S collapse(3)
+  for (v1 = 0; v1 < 20; v1 += 2)
+    for (v2 = __LONG_LONG_MAX__ + 11ULL;
+        v2 != __LONG_LONG_MAX__ - 4ULL; -- v2)
+      for (v3 = 10; v3 != 0; v3--)
+       b[v1 >> 1][v2 - __LONG_LONG_MAX__ + 3][v3 - 1] += 5.5;
+}
+
+__attribute__((noinline, noclone)) void
+N(f28) (void)
+{
+  SC long long v1, v2, v3;
+  OMPTGT
+#pragma omp F S collapse(3)
+  for (v1 = 0; v1 != 20; v1 -= 17 - 18)
+    for (v2 = 30; v2 < 20; v2++)
+      for (v3 = 10; v3 < 0; v3--)
+       b[v1][v2][v3] += 5.5;
+}
+
+__attribute__((noinline, noclone)) void
+N(f29) (void)
+{
+  int i;
+  OMPTGT
+#pragma omp F S
+  for (i = 20; i != 20; i++)
+    {
+      a[i] += 2;
+      noreturn ();
+      a[i] -= 4;
+    }
+}
+
+__attribute__((noinline, noclone)) void
+N(f30) (void)
+{
+  SC int i;
+  OMPTGT
+#pragma omp F S collapse(3)
+  for (i = 0; i != 10; i++)
+    for (int j = 10; j < 8; j++)
+      for (long k = -10; k != 10; k++)
+       {
+         b[i][j][k] += 4;
+         noreturn ();
+         b[i][j][k] -= 8;
+       }
+}
+
+__attribute__((noinline, noclone)) void
+N(f31) (int n)
+{
+  int i;
+  OMPTGT
+#pragma omp F S
+  for (i = 20; i != n; i++)
+    {
+      a[i] += 8;
+      noreturn ();
+      a[i] -= 16;
+    }
+}
+
+__attribute__((noinline, noclone)) void
+N(f32) (int n)
+{
+  SC int i;
+  OMPTGT
+#pragma omp F S collapse(3)
+  for (i = 0; i != 10; i++)
+    for (int j = n; j != 12; j++)
+      for (long k = -10; k != 10; k++)
+       {
+         b[i][j][k] += 16;
+         noreturn ();
+         b[i][j][k] -= 32;
+       }
+}
+
+__attribute__((noinline, noclone)) void
+N(f33) (void)
+{
+  int *i;
+  OMPTGT
+#pragma omp F S
+  for (i = a; i != &a[1500]; i++)
+    i[0] += 2;
+}
+
+__attribute__((noinline, noclone)) void
+N(f34) (void)
+{
+  SC float *i;
+  OMPTGT
+#pragma omp F S collapse(3)
+  for (i = &b[0][0][0]; i != &b[0][0][10]; i++)
+    for (float *j = &b[0][15][0]; j > &b[0][0][0]; j -= 10)
+      for (float *k = &b[0][0][10]; k != &b[0][0][0]; --k)
+       b[i - &b[0][0][0]][(j - &b[0][0][0]) / 10 - 1][(k - &b[0][0][0]) - 1]
+         -= 3.5;
+}
+
+__attribute__((noinline, noclone)) int
+N(test) (void)
+{
+  int i, j, k;
+  for (i = 0; i < 1500; i++)
+    a[i] = i - 25;
+  OMPTO (a);
+  N(f20) ();
+  OMPFROM (a);
+  for (i = 0; i < 1500; i++)
+    if (a[i] != i - 23)
+      return 1;
+  N(f21) ();
+  OMPFROM (a);
+  for (i = 0; i < 1500; i++)
+    if (a[i] != i - 25)
+      return 1;
+  N(f22) ();
+  OMPFROM (a);
+  for (i = 0; i < 1500; i++)
+    if (a[i] != i - 29)
+      return 1;
+  N(f23) (1500LL - 1 - 23 - 48, -1LL + 25 - 48);
+  OMPFROM (a);
+  for (i = 0; i < 1500; i++)
+    if (a[i] != i - 22)
+      return 1;
+  N(f24) ();
+  OMPFROM (a);
+  for (i = 0; i < 1500; i++)
+    if (a[i] != i - 22)
+      return 1;
+  for (i = 0; i < 10; i++)
+    for (j = 0; j < 15; j++)
+      for (k = 0; k < 10; k++)
+       b[i][j][k] = i - 2.5 + 1.5 * j - 1.5 * k;
+  OMPTO (b);
+  N(f25) (0, 10, 0, 15, 0, 10, 1);
+  OMPFROM (b);
+  for (i = 0; i < 10; i++)
+    for (j = 0; j < 15; j++)
+      for (k = 0; k < 10; k++)
+       if (b[i][j][k] != i + 1.5 * j - 1.5 * k)
+         return 1;
+  N(f25) (0, 10, 30, 15, 0, 10, 5);
+  OMPFROM (b);
+  for (i = 0; i < 10; i++)
+    for (j = 0; j < 15; j++)
+      for (k = 0; k < 10; k++)
+       if (b[i][j][k] != i + 1.5 * j - 1.5 * k)
+         return 1;
+  N(f26) (9, -1, 29, 0, 9, -1, -2);
+  OMPFROM (b);
+  for (i = 0; i < 10; i++)
+    for (j = 0; j < 15; j++)
+      for (k = 0; k < 10; k++)
+       if (b[i][j][k] != i - 4.5 + 1.5 * j - 1.5 * k)
+         return 1;
+  N(f27) ();
+  OMPFROM (b);
+  for (i = 0; i < 10; i++)
+    for (j = 0; j < 15; j++)
+      for (k = 0; k < 10; k++)
+       if (b[i][j][k] != i + 1.0 + 1.5 * j - 1.5 * k)
+         return 1;
+  N(f28) ();
+  OMPFROM (b);
+  for (i = 0; i < 10; i++)
+    for (j = 0; j < 15; j++)
+      for (k = 0; k < 10; k++)
+       if (b[i][j][k] != i + 1.0 + 1.5 * j - 1.5 * k)
+         return 1;
+  N(f29) ();
+  N(f30) ();
+  N(f31) (20);
+  N(f32) (12);
+  OMPFROM (a);
+  OMPFROM (b);
+  for (i = 0; i < 1500; i++)
+    if (a[i] != i - 22)
+      return 1;
+  for (i = 0; i < 10; i++)
+    for (j = 0; j < 15; j++)
+      for (k = 0; k < 10; k++)
+       if (b[i][j][k] != i + 1.0 + 1.5 * j - 1.5 * k)
+         return 1;
+  N(f33) ();
+  N(f34) ();
+  OMPFROM (a);
+  OMPFROM (b);
+  for (i = 0; i < 1500; i++)
+    if (a[i] != i - 20)
+      return 1;
+  for (i = 0; i < 10; i++)
+    for (j = 0; j < 15; j++)
+      for (k = 0; k < 10; k++)
+       if (b[i][j][k] != i - 2.5 + 1.5 * j - 1.5 * k)
+         return 1;
+  return 0;
+}
+#endif
diff --git a/libgomp/testsuite/libgomp.c-c++-common/for-7.c b/libgomp/testsuite/libgomp.c-c++-common/for-7.c
new file mode 100644 (file)
index 0000000..43461bb
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-additional-options "-std=gnu99" {target c } } */
+
+#define CONDNE
+#include "for-1.c"
diff --git a/libgomp/testsuite/libgomp.c-c++-common/for-8.c b/libgomp/testsuite/libgomp.c-c++-common/for-8.c
new file mode 100644 (file)
index 0000000..ed6bf71
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-additional-options "-std=gnu99" {target c } } */
+
+#define CONDNE
+#include "for-2.c"
diff --git a/libgomp/testsuite/libgomp.c-c++-common/for-9.c b/libgomp/testsuite/libgomp.c-c++-common/for-9.c
new file mode 100644 (file)
index 0000000..dfd674f
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-additional-options "-std=gnu99" {target c } } */
+
+#define CONDNE
+#include "for-3.c"
diff --git a/libgomp/testsuite/libgomp.c-c++-common/master-combined-1.c b/libgomp/testsuite/libgomp.c-c++-common/master-combined-1.c
new file mode 100644 (file)
index 0000000..3e6da09
--- /dev/null
@@ -0,0 +1,66 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+/* { dg-additional-options "-std=c99" { target c } } */
+/* { dg-additional-options "-msse2" { target sse2_runtime } } */
+/* { dg-additional-options "-mavx" { target avx_runtime } } */
+
+#include <omp.h>
+#include <stdlib.h>
+
+#define N 64
+
+int
+main ()
+{
+  int p, *q, i, l;
+  int a[N];
+  q = a;
+  #pragma omp parallel master num_threads(4) private (p) shared(a)
+  {
+    int i;
+    p = omp_get_thread_num ();
+    if (p != 0)
+      abort ();
+    #pragma omp taskloop nogroup
+    for (i = 0; i < N; ++i)
+      {
+       if (omp_get_thread_num () >= 4)
+         abort ();
+       a[i] = i;
+      }
+  }
+  #pragma omp parallel num_threads(4)
+  {
+    #pragma omp master taskloop lastprivate (i, l) firstprivate (q)
+    for (i = 0; i != N; i = i + 1)
+      l = q[i];
+  }
+  if (i != N || l != N - 1)
+    abort ();
+  #pragma omp parallel master taskloop num_threads(4) \
+                      lastprivate (i, l) firstprivate (q)
+  for (i = 0; i < N - 5; i += 2)
+    if (q[i] != i)
+      abort ();
+    else
+      l = q[i];
+  if (i != N - 4 || l != N - 6)
+    abort ();
+  #pragma omp parallel master taskloop simd num_threads(4)
+  for (i = 0; i < N; i++)
+    a[i] = 2 * a[i];
+  if (i != N)
+    abort ();
+  #pragma omp parallel num_threads(4)
+  {
+    int j;
+    #pragma omp master taskloop simd collapse(2)
+    for (i = 0; i < 2; i += 2)
+      for (j = 0; j < N; j++)
+       a[j] = a[j] + 1;
+  }
+  for (i = 0; i < N; i++)
+    if (a[i] != 2 * i + 1)
+      abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/pause-1.c b/libgomp/testsuite/libgomp.c-c++-common/pause-1.c
new file mode 100644 (file)
index 0000000..5367a72
--- /dev/null
@@ -0,0 +1,23 @@
+#include <omp.h>
+#include <stdlib.h>
+
+int a[64];
+
+int
+main ()
+{
+  int i;
+  #pragma omp parallel for
+  for (i = 0; i < 64; i++)
+    a[i] = i;
+  omp_pause_resource (omp_pause_soft, omp_get_initial_device ());
+  #pragma omp parallel for
+  for (i = 0; i < 64; i++)
+    a[i] += i;
+  omp_pause_resource_all (omp_pause_hard);
+  #pragma omp parallel for
+  for (i = 0; i < 64; i++)
+    if (a[i] != 2 * i)
+      abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/pause-2.c b/libgomp/testsuite/libgomp.c-c++-common/pause-2.c
new file mode 100644 (file)
index 0000000..e4781cd
--- /dev/null
@@ -0,0 +1,41 @@
+/* { dg-do run } */
+/* { dg-require-effective-target tls_runtime } */
+
+#include <omp.h>
+#include <stdlib.h>
+
+int t = 128;
+#pragma omp threadprivate (t)
+
+int
+main ()
+{
+  #pragma omp parallel
+  t = omp_get_thread_num () + 256;
+  #pragma omp parallel
+  if (t != omp_get_thread_num () + 256)
+    abort ();
+  omp_pause_resource (omp_pause_soft, omp_get_initial_device ());
+  /* This goes beyond what is required by the standard, we actually
+     check if the threads other than the initial one have been destroyed.  */
+  #pragma omp parallel
+  {
+    if (omp_get_thread_num () != 0 && t != 128)
+      abort ();
+    t = omp_get_thread_num () + 384;
+  }
+  #pragma omp parallel
+  if (t != omp_get_thread_num () + 384)
+    abort ();
+  omp_pause_resource_all (omp_pause_hard);
+  #pragma omp parallel
+  {
+    if (omp_get_thread_num () != 0 && t != 128)
+      abort ();
+    t = omp_get_thread_num () + 512;
+  }
+  #pragma omp parallel
+  if (t != omp_get_thread_num () + 512)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/pr66199-10.c b/libgomp/testsuite/libgomp.c-c++-common/pr66199-10.c
new file mode 100644 (file)
index 0000000..301fa6c
--- /dev/null
@@ -0,0 +1,60 @@
+/* PR middle-end/66199 */
+/* { dg-do run } */
+
+int u[1024], v[1024], w[1024];
+
+__attribute__((noinline, noclone)) long
+f1 (long a, long b)
+{
+  long d;
+  #pragma omp teams distribute parallel for simd default(none) firstprivate (a, b) shared(u, v, w)
+  for (d = a; d < b; d++)
+    u[d] = v[d] + w[d];
+  return d;
+}
+
+__attribute__((noinline, noclone)) long
+f2 (long a, long b, long c)
+{
+  long d, e;
+  #pragma omp teams distribute parallel for simd default(none) firstprivate (a, b, c) shared(u, v, w) linear(d) lastprivate(e)
+  for (d = a; d < b; d++)
+    {
+      u[d] = v[d] + w[d];
+      e = c + d * 5;
+    }
+  return d + e;
+}
+
+__attribute__((noinline, noclone)) long
+f3 (long a1, long b1, long a2, long b2)
+{
+  long d1, d2;
+  #pragma omp teams distribute parallel for simd default(none) firstprivate (a1, b1, a2, b2) shared(u, v, w) lastprivate(d1, d2) collapse(2)
+  for (d1 = a1; d1 < b1; d1++)
+    for (d2 = a2; d2 < b2; d2++)
+      u[d1 * 32 + d2] = v[d1 * 32 + d2] + w[d1 * 32 + d2];
+  return d1 + d2;
+}
+
+__attribute__((noinline, noclone)) long
+f4 (long a1, long b1, long a2, long b2)
+{
+  long d1, d2;
+  #pragma omp teams distribute parallel for simd default(none) firstprivate (a1, b1, a2, b2) shared(u, v, w) collapse(2)
+  for (d1 = a1; d1 < b1; d1++)
+    for (d2 = a2; d2 < b2; d2++)
+      u[d1 * 32 + d2] = v[d1 * 32 + d2] + w[d1 * 32 + d2];
+  return d1 + d2;
+}
+
+int
+main ()
+{
+  if (f1 (0, 1024) != 1024
+      || f2 (0, 1024, 17) != 1024 + (17 + 5 * 1023)
+      || f3 (0, 32, 0, 32) != 64
+      || f4 (0, 32, 0, 32) != 64)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/pr66199-11.c b/libgomp/testsuite/libgomp.c-c++-common/pr66199-11.c
new file mode 100644 (file)
index 0000000..bcb596e
--- /dev/null
@@ -0,0 +1,38 @@
+/* PR middle-end/66199 */
+/* { dg-do run } */
+/* { dg-options "-O2" { target c } } */
+
+int u[1024], v[1024], w[1024];
+
+__attribute__((noinline, noclone)) long
+f2 (long a, long b, long c)
+{
+  long d, e;
+  #pragma omp teams distribute parallel for default(none) firstprivate (a, b, c) shared(u, v, w) lastprivate(d, e)
+  for (d = a; d < b; d++)
+    {
+      u[d] = v[d] + w[d];
+      e = c + d * 5;
+    }
+  return d + e;
+}
+
+__attribute__((noinline, noclone)) long
+f3 (long a1, long b1, long a2, long b2)
+{
+  long d1, d2;
+  #pragma omp teams distribute parallel for default(none) firstprivate (a1, b1, a2, b2) shared(u, v, w) lastprivate(d1, d2) collapse(2)
+  for (d1 = a1; d1 < b1; d1++)
+    for (d2 = a2; d2 < b2; d2++)
+      u[d1 * 32 + d2] = v[d1 * 32 + d2] + w[d1 * 32 + d2];
+  return d1 + d2;
+}
+
+int
+main ()
+{
+  if (f2 (0, 1024, 17) != 1024 + (17 + 5 * 1023)
+      || f3 (0, 32, 0, 32) != 64)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/pr66199-12.c b/libgomp/testsuite/libgomp.c-c++-common/pr66199-12.c
new file mode 100644 (file)
index 0000000..78eb12a
--- /dev/null
@@ -0,0 +1,60 @@
+/* PR middle-end/66199 */
+/* { dg-do run } */
+
+int u[1024], v[1024], w[1024];
+
+__attribute__((noinline, noclone)) long
+f1 (long a, long b)
+{
+  long d;
+  #pragma omp teams distribute simd default(none) firstprivate (a, b) shared(u, v, w)
+  for (d = a; d < b; d++)
+    u[d] = v[d] + w[d];
+  return d;
+}
+
+__attribute__((noinline, noclone)) long
+f2 (long a, long b, long c)
+{
+  long d, e;
+  #pragma omp teams distribute simd default(none) firstprivate (a, b, c) shared(u, v, w) linear(d) lastprivate(e)
+  for (d = a; d < b; d++)
+    {
+      u[d] = v[d] + w[d];
+      e = c + d * 5;
+    }
+  return d + e;
+}
+
+__attribute__((noinline, noclone)) long
+f3 (long a1, long b1, long a2, long b2)
+{
+  long d1, d2;
+  #pragma omp teams distribute simd default(none) firstprivate (a1, b1, a2, b2) shared(u, v, w) lastprivate(d1, d2) collapse(2)
+  for (d1 = a1; d1 < b1; d1++)
+    for (d2 = a2; d2 < b2; d2++)
+      u[d1 * 32 + d2] = v[d1 * 32 + d2] + w[d1 * 32 + d2];
+  return d1 + d2;
+}
+
+__attribute__((noinline, noclone)) long
+f4 (long a1, long b1, long a2, long b2)
+{
+  long d1, d2;
+  #pragma omp teams distribute simd default(none) firstprivate (a1, b1, a2, b2) shared(u, v, w) collapse(2)
+  for (d1 = a1; d1 < b1; d1++)
+    for (d2 = a2; d2 < b2; d2++)
+      u[d1 * 32 + d2] = v[d1 * 32 + d2] + w[d1 * 32 + d2];
+  return d1 + d2;
+}
+
+int
+main ()
+{
+  if (f1 (0, 1024) != 1024
+      || f2 (0, 1024, 17) != 1024 + (17 + 5 * 1023)
+      || f3 (0, 32, 0, 32) != 64
+      || f4 (0, 32, 0, 32) != 64)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/pr66199-13.c b/libgomp/testsuite/libgomp.c-c++-common/pr66199-13.c
new file mode 100644 (file)
index 0000000..2f41a38
--- /dev/null
@@ -0,0 +1,64 @@
+/* PR middle-end/66199 */
+/* { dg-do run } */
+
+int u[1024], v[1024], w[1024];
+
+__attribute__((noinline, noclone)) long
+f1 (long a, long b)
+{
+  long d;
+  #pragma omp teams default(none) shared(a, b, d, u, v, w)
+  #pragma omp distribute simd firstprivate (a, b)
+  for (d = a; d < b; d++)
+    u[d] = v[d] + w[d];
+  return d;
+}
+
+__attribute__((noinline, noclone)) long
+f2 (long a, long b, long c)
+{
+  long d, e;
+  #pragma omp teams default(none) firstprivate (a, b, c) shared(d, e, u, v, w)
+  #pragma omp distribute simd linear(d) lastprivate(e)
+  for (d = a; d < b; d++)
+    {
+      u[d] = v[d] + w[d];
+      e = c + d * 5;
+    }
+  return d + e;
+}
+
+__attribute__((noinline, noclone)) long
+f3 (long a1, long b1, long a2, long b2)
+{
+  long d1, d2;
+  #pragma omp teams default(none) shared(a1, b1, a2, b2, d1, d2, u, v, w)
+  #pragma omp distribute simd firstprivate (a1, b1, a2, b2) lastprivate(d1, d2) collapse(2)
+  for (d1 = a1; d1 < b1; d1++)
+    for (d2 = a2; d2 < b2; d2++)
+      u[d1 * 32 + d2] = v[d1 * 32 + d2] + w[d1 * 32 + d2];
+  return d1 + d2;
+}
+
+__attribute__((noinline, noclone)) long
+f4 (long a1, long b1, long a2, long b2)
+{
+  long d1, d2;
+  #pragma omp teams default(none) firstprivate (a1, b1, a2, b2) shared(d1, d2, u, v, w)
+  #pragma omp distribute simd collapse(2)
+  for (d1 = a1; d1 < b1; d1++)
+    for (d2 = a2; d2 < b2; d2++)
+      u[d1 * 32 + d2] = v[d1 * 32 + d2] + w[d1 * 32 + d2];
+  return d1 + d2;
+}
+
+int
+main ()
+{
+  if (f1 (0, 1024) != 1024
+      || f2 (0, 1024, 17) != 1024 + (17 + 5 * 1023)
+      || f3 (0, 32, 0, 32) != 64
+      || f4 (0, 32, 0, 32) != 64)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/pr66199-14.c b/libgomp/testsuite/libgomp.c-c++-common/pr66199-14.c
new file mode 100644 (file)
index 0000000..21936bf
--- /dev/null
@@ -0,0 +1,39 @@
+/* PR middle-end/66199 */
+/* { dg-do run } */
+
+int u[1024], v[1024], w[1024];
+
+__attribute__((noinline, noclone)) long
+f2 (long a, long b, long c)
+{
+  long d, e;
+  #pragma omp teams default(none) firstprivate (a, b, c) shared(d, e, u, v, w)
+  #pragma omp distribute lastprivate(d, e)
+  for (d = a; d < b; d++)
+    {
+      u[d] = v[d] + w[d];
+      e = c + d * 5;
+    }
+  return d + e;
+}
+
+__attribute__((noinline, noclone)) long
+f3 (long a1, long b1, long a2, long b2)
+{
+  long d1, d2;
+  #pragma omp teams default(none) shared(a1, b1, a2, b2, d1, d2, u, v, w)
+  #pragma omp distribute firstprivate (a1, b1, a2, b2) lastprivate(d1, d2) collapse(2)
+  for (d1 = a1; d1 < b1; d1++)
+    for (d2 = a2; d2 < b2; d2++)
+      u[d1 * 32 + d2] = v[d1 * 32 + d2] + w[d1 * 32 + d2];
+  return d1 + d2;
+}
+
+int
+main ()
+{
+  if (f2 (0, 1024, 17) != 1024 + (17 + 5 * 1023)
+      || f3 (0, 32, 0, 32) != 64)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/simd-1.c b/libgomp/testsuite/libgomp.c-c++-common/simd-1.c
new file mode 100644 (file)
index 0000000..cce234d
--- /dev/null
@@ -0,0 +1,71 @@
+// { dg-do run }
+// { dg-additional-options "-msse2" { target sse2_runtime } }
+// { dg-additional-options "-mavx" { target avx_runtime } }
+
+#define N 1024
+int a[N], b[N];
+
+int
+f1 (void)
+{
+  int i;
+  #pragma omp simd private (i)
+  for (i = 0; i < N; i++)
+    a[i] = b[i] * 2;
+  #pragma omp simd lastprivate (i)
+  for (i = 0; i < N; i++)
+    a[i] += b[i] * 2;
+  return i;
+}
+
+int
+f2 (void)
+{
+  int i, j;
+  #pragma omp simd private (i), collapse (2), lastprivate (j)
+  for (i = 0; i < 32; i++)
+    for (j = 0; j < 32; ++j)
+      a[i * 32 + j] += b[i * 32 + j] * 2;
+  return j;
+}
+
+int
+f3 (void)
+{
+  static int i;
+  #pragma omp for simd private (i)
+  for (i = 0; i < N; ++i)
+    a[i] = b[i] * 2;
+  #pragma omp for simd lastprivate (i)
+  for (i = 0; i < N; ++i)
+    a[i] += b[i] * 2;
+  return i;
+}
+
+int
+f4 (void)
+{
+  static int i, j;
+  #pragma omp for simd private (i)collapse (2)lastprivate (j)
+  for (i = 0; i < 32; ++i)
+    for (j = 0; j < 32; j++)
+      a[i * 32 + j] += b[i * 32 + j] * 2;
+  return j;
+}
+
+int
+main ()
+{
+  int i;
+  for (i = 0; i < N; ++i)
+    a[i] = b[i] = i;
+  if (f1 () != 1024 || f2 () != 32)
+    __builtin_abort ();
+  #pragma omp parallel num_threads(4)
+  if (f3 () != 1024 || f4 () != 32)
+    __builtin_abort ();
+  for (i = 0; i < N; ++i)
+    if (a[i] != 6 * i || b[i] != i)
+      __builtin_abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-reduction-1.c b/libgomp/testsuite/libgomp.c-c++-common/task-reduction-1.c
new file mode 100644 (file)
index 0000000..6c6191d
--- /dev/null
@@ -0,0 +1,58 @@
+#ifdef __cplusplus
+extern "C"
+#endif
+void abort (void);
+
+int a;
+long int b = 1;
+
+void
+foo (void)
+{
+  int i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: a) in_reduction (*: b)
+    {
+      a += 7;
+      b *= 2;
+    }
+}
+
+int
+main ()
+{
+  int c = 0;
+  #pragma omp parallel
+  #pragma omp single
+  {
+    long int d = 1;
+    #pragma omp taskgroup task_reduction (+: a, c) task_reduction (*: b, d)
+    {
+      int i;
+      for (i = 0; i < 4; i++)
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b, d)
+       {
+         int j;
+         a += 7;
+         b *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c) in_reduction (*: b, d)
+           {
+             a += 7;
+             b *= 2;
+             c += 9;
+             d *= 3;
+             foo ();
+           }
+         c += 9;
+         d *= 3;
+       }
+    }
+#define THREEP4 (3L * 3L * 3L * 3L)
+    if (d != (THREEP4 * THREEP4 * THREEP4))
+      abort ();
+  }
+  if (a != 28 * 7 || b != (1L << 28) || c != 12 * 9)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-reduction-11.c b/libgomp/testsuite/libgomp.c-c++-common/task-reduction-11.c
new file mode 100644 (file)
index 0000000..038b0e2
--- /dev/null
@@ -0,0 +1,56 @@
+extern
+#ifdef __cplusplus
+"C"
+#endif
+void abort (void);
+int a, b[3] = { 1, 1, 1 };
+unsigned long int c[2] = { ~0UL, ~0UL };
+
+void
+bar (int i)
+{
+  #pragma omp task in_reduction (*: b[:3]) in_reduction (&: c[1:]) \
+             in_reduction (+: a)
+  {
+    a += 4;
+    b[1] *= 4;
+    c[1] &= ~(1UL << (i + 16));
+  }
+}
+
+void
+foo (unsigned long long int x, unsigned long long int y, unsigned long long int z)
+{
+  unsigned long long int i;
+  #pragma omp for schedule(runtime) reduction (task, +: a) \
+                 reduction (task, *: b) reduction (task, &: c[1:1])
+  for (i = x; i < y; i += z)
+    {
+      a++;
+      b[0] *= 2;
+      bar (i);
+      b[2] *= 3;
+      c[1] &= ~(1UL << i);
+    }
+}
+
+int
+main ()
+{
+  volatile int two = 2;
+  foo (two, 7 * two, two);
+  if (a != 30 || b[0] != 64 || b[1] != (1 << 12) || b[2] != 3 * 3 * 3 * 3 * 3 * 3
+      || c[0] != ~0UL || c[1] != ~0x15541554UL)
+    abort ();
+  a = 0;
+  b[0] = 1;
+  b[1] = 1;
+  b[2] = 1;
+  c[1] = ~0UL;
+  #pragma omp parallel
+  foo (two, 8 * two, two);
+  if (a != 35 || b[0] != 128 || b[1] != (1 << 14) || b[2] != 3 * 3 * 3 * 3 * 3 * 3 * 3
+      || c[0] != ~0UL || c[1] != ~0x55545554UL)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-reduction-12.c b/libgomp/testsuite/libgomp.c-c++-common/task-reduction-12.c
new file mode 100644 (file)
index 0000000..0ad9273
--- /dev/null
@@ -0,0 +1,67 @@
+extern
+#ifdef __cplusplus
+"C"
+#endif
+void abort (void);
+int a, b[3] = { 1, 1, 1 };
+unsigned long int c[2] = { ~0UL, ~0UL };
+
+void
+bar (int i)
+{
+  #pragma omp task in_reduction (*: b[:3]) in_reduction (&: c[1:]) \
+             in_reduction (+: a)
+  {
+    a += 4;
+    b[1] *= 4;
+    c[1] &= ~(1UL << (i + 16));
+  }
+}
+
+void
+foo (int x)
+{
+  #pragma omp sections reduction (task, +: a) reduction (task, *: b) \
+                      reduction (task, &: c[1:1])
+  {
+    {
+      a++; b[0] *= 2; bar (2); b[2] *= 3; c[1] &= ~(1UL << 2);
+    }
+    #pragma omp section
+    { b[0] *= 2; bar (4); b[2] *= 3; c[1] &= ~(1UL << 4); a++; }
+    #pragma omp section
+    { bar (6); b[2] *= 3; c[1] &= ~(1UL << 6); a++; b[0] *= 2; }
+    #pragma omp section
+    { b[2] *= 3; c[1] &= ~(1UL << 8); a++; b[0] *= 2; bar (8); }
+    #pragma omp section
+    { c[1] &= ~(1UL << 10); a++; b[0] *= 2; bar (10); b[2] *= 3; }
+    #pragma omp section
+    { a++; b[0] *= 2; b[2] *= 3; c[1] &= ~(1UL << 12); bar (12); }
+    #pragma omp section
+    if (x)
+      {
+       a++; b[0] *= 2; b[2] *= 3; bar (14); c[1] &= ~(1UL << 14);
+      }
+  }
+}
+
+int
+main ()
+{
+  volatile int one = 1;
+  foo (!one);
+  if (a != 30 || b[0] != 64 || b[1] != (1 << 12) || b[2] != 3 * 3 * 3 * 3 * 3 * 3
+      || c[0] != ~0UL || c[1] != ~0x15541554UL)
+    abort ();
+  a = 0;
+  b[0] = 1;
+  b[1] = 1;
+  b[2] = 1;
+  c[1] = ~0UL;
+  #pragma omp parallel
+  foo (one);
+  if (a != 35 || b[0] != 128 || b[1] != (1 << 14) || b[2] != 3 * 3 * 3 * 3 * 3 * 3 * 3
+      || c[0] != ~0UL || c[1] != ~0x55545554UL)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-reduction-2.c b/libgomp/testsuite/libgomp.c-c++-common/task-reduction-2.c
new file mode 100644 (file)
index 0000000..aad725c
--- /dev/null
@@ -0,0 +1,90 @@
+#ifdef __cplusplus
+extern "C"
+#endif
+void abort (void);
+
+struct S { long int s, t; };
+
+void
+bar (struct S *p, struct S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+baz (struct S *o, struct S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: struct S : omp_out.s += omp_in.s) initializer (omp_priv = { 0, 3 })
+#pragma omp declare reduction (*: struct S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
+
+struct S a = { 0, 7 };
+struct S b = { 1, 5 };
+
+void
+foo (void)
+{
+  int i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (*: b) in_reduction (+: a)
+    {
+      a.s += 7;
+      b.s *= 2;
+      if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9))
+       abort ();
+    }
+}
+
+int
+main ()
+{
+  struct S c = { 0, 7 };
+  #pragma omp parallel
+  #pragma omp single
+  {
+    struct S d = { 1, 5 };
+    #pragma omp taskgroup task_reduction (+: a, c) task_reduction (*: b, d)
+    {
+      int i;
+      for (i = 0; i < 4; i++)
+       #pragma omp task in_reduction (*: b, d) in_reduction (+: a, c)
+       {
+         int j;
+         a.s += 7;
+         b.s *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a) in_reduction (*: b) \
+                            in_reduction (+: c) in_reduction (*: d)
+           {
+             a.s += 7;
+             b.s *= 2;
+             c.s += 9;
+             d.s *= 3;
+             foo ();
+             if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
+                 || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
+               abort ();
+           }
+         c.s += 9;
+         d.s *= 3;
+         if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
+             || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
+           abort ();
+       }
+    }
+#define THREEP4 (3L * 3L * 3L * 3L)
+    if (d.s != (THREEP4 * THREEP4 * THREEP4) || d.t != 5)
+      abort ();
+  }
+  if (a.s != 28 * 7 || a.t != 7 || b.s != (1L << 28) || b.t != 5
+      || c.s != 12 * 9 || c.t != 7)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-reduction-3.c b/libgomp/testsuite/libgomp.c-c++-common/task-reduction-3.c
new file mode 100644 (file)
index 0000000..8a90e86
--- /dev/null
@@ -0,0 +1,218 @@
+#ifdef __cplusplus
+extern "C"
+#endif
+void abort (void);
+
+int a[2];
+long long int b[7] = { 9, 11, 1, 1, 1, 13, 15 };
+int e[3] = { 5, 0, 5 };
+int f[5] = { 6, 7, 0, 0, 9 };
+int g[4] = { 1, 0, 0, 2 };
+int h[3] = { 0, 1, 4 };
+int k[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+long long *s;
+long long (*t)[2];
+
+void
+foo (int n, int *c, long long int *d, int m[3], int *r, int o[4], int *p, int q[4][2])
+{
+  int i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                    in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
+                    in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
+                    in_reduction (*: s[1:2], t[2:2][:])
+    {
+      a[0] += 7;
+      a[1] += 17;
+      b[2] *= 2;
+      b[4] *= 2;
+      c[0] += 6;
+      d[1] *= 2;
+      e[1] += 19;
+      f[2] += 21;
+      f[3] += 23;
+      g[1] += 25;
+      g[2] += 27;
+      h[0] += 29;
+      k[1][0] += 31;
+      k[2][1] += 33;
+      m[1] += 19;
+      r[2] += 21;
+      r[3] += 23;
+      o[1] += 25;
+      o[2] += 27;
+      p[0] += 29;
+      q[1][0] += 31;
+      q[2][1] += 33;
+      s[1] *= 2;
+      t[2][0] *= 2;
+      t[3][1] *= 2;
+    }
+}
+
+void
+test (int n)
+{
+  int c[2] = { 0, 0 };
+  int p[3] = { 0, 1, 4 };
+  int q[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+  long long ss[4] = { 5, 1, 1, 6 };
+  long long tt[5][2] = { { 9, 10 }, { 11, 12 }, { 1, 1 }, { 1, 1 }, { 13, 14 } };
+  s = ss;
+  t = tt;
+  #pragma omp parallel
+  #pragma omp single
+  {
+    long long int d[] = { 1, 1 };
+    int m[3] = { 5, 0, 5 };
+    int r[5] = { 6, 7, 0, 0, 9 };
+    int o[4] = { 1, 0, 0, 2 };
+    #pragma omp taskgroup task_reduction (+: a, c) task_reduction (*: b[2 * n:3 * n], d) \
+                         task_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                         task_reduction (+: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                         task_reduction (*: t[2:2][:], s[1:n + 1])
+    {
+      int i;
+      for (i = 0; i < 4; i++)
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b[2 * n:3 * n], d) \
+                        in_reduction (+: o[n:n*2], q[1:2][:], p[0], m[1], r[2:2]) \
+                        in_reduction (+: g[n:n * 2], e[1], k[1:2][:], h[0], f[2:2]) \
+                        in_reduction (*: s[1:2], t[2:2][:])
+       {
+         int j;
+         a[0] += 2;
+         a[1] += 3;
+         b[2] *= 2;
+         f[3] += 8;
+         g[1] += 9;
+         g[2] += 10;
+         h[0] += 11;
+         k[1][1] += 13;
+         k[2][1] += 15;
+         m[1] += 16;
+         r[2] += 8;
+         s[1] *= 2;
+         t[2][1] *= 2;
+         t[3][1] *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c[:2]) \
+                            in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                            in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                            in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                            in_reduction (*: s[n:2], t[2:2][:])
+           {
+             m[1] += 6;
+             r[2] += 7;
+             q[1][0] += 17;
+             q[2][0] += 19;
+             a[0] += 4;
+             a[1] += 5;
+             b[3] *= 2;
+             b[4] *= 2;
+             f[3] += 18;
+             g[1] += 29;
+             g[2] += 18;
+             h[0] += 19;
+             s[2] *= 2;
+             t[2][0] *= 2;
+             t[3][0] *= 2;
+             foo (n, c, d, m, r, o, p, q);
+             r[3] += 18;
+             o[1] += 29;
+             o[2] += 18;
+             p[0] += 19;
+             c[0] += 4;
+             c[1] += 5;
+             d[0] *= 2;
+             e[1] += 6;
+             f[2] += 7;
+             k[1][0] += 17;
+             k[2][0] += 19;
+           }
+         r[3] += 8;
+         o[1] += 9;
+         o[2] += 10;
+         p[0] += 11;
+         q[1][1] += 13;
+         q[2][1] += 15;
+         b[3] *= 2;
+         c[0] += 4;
+         c[1] += 9;
+         d[0] *= 2;
+         e[1] += 16;
+         f[2] += 8;
+       }
+    }
+    if (d[0] != 1LL << (8 + 4)
+       || d[1] != 1LL << 16
+       || m[0] != 5
+       || m[1] != 19 * 16 + 6 * 8 + 16 * 4
+       || m[2] != 5
+       || r[0] != 6
+       || r[1] != 7
+       || r[2] != 21 * 16 + 7 * 8 + 8 * 4
+       || r[3] != 23 * 16 + 18 * 8 + 8 * 4
+       || r[4] != 9
+       || o[0] != 1
+       || o[1] != 25 * 16 + 29 * 8 + 9 * 4
+       || o[2] != 27 * 16 + 18 * 8 + 10 * 4
+       || o[3] != 2)
+      abort ();
+  }
+  if (a[0] != 7 * 16 + 4 * 8 + 2 * 4
+      || a[1] != 17 * 16 + 5 * 8 + 3 * 4
+      || b[0] != 9 || b[1] != 11
+      || b[2] != 1LL << (16 + 4)
+      || b[3] != 1LL << (8 + 4)
+      || b[4] != 1LL << (16 + 8)
+      || b[5] != 13 || b[6] != 15
+      || c[0] != 6 * 16 + 4 * 8 + 4 * 4
+      || c[1] != 5 * 8 + 9 * 4
+      || e[0] != 5
+      || e[1] != 19 * 16 + 6 * 8 + 16 * 4
+      || e[2] != 5
+      || f[0] != 6
+      || f[1] != 7
+      || f[2] != 21 * 16 + 7 * 8 + 8 * 4
+      || f[3] != 23 * 16 + 18 * 8 + 8 * 4
+      || f[4] != 9
+      || g[0] != 1
+      || g[1] != 25 * 16 + 29 * 8 + 9 * 4
+      || g[2] != 27 * 16 + 18 * 8 + 10 * 4
+      || g[3] != 2
+      || h[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || h[1] != 1 || h[2] != 4
+      || k[0][0] != 5 || k[0][1] != 6
+      || k[1][0] != 31 * 16 + 17 * 8
+      || k[1][1] != 13 * 4
+      || k[2][0] != 19 * 8
+      || k[2][1] != 33 * 16 + 15 * 4
+      || k[3][0] != 7 || k[3][1] != 8
+      || p[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || p[1] != 1 || p[2] != 4
+      || q[0][0] != 5 || q[0][1] != 6
+      || q[1][0] != 31 * 16 + 17 * 8
+      || q[1][1] != 13 * 4
+      || q[2][0] != 19 * 8
+      || q[2][1] != 33 * 16 + 15 * 4
+      || q[3][0] != 7 || q[3][1] != 8
+      || ss[0] != 5
+      || ss[1] != 1LL << (16 + 4)
+      || ss[2] != 1LL << 8
+      || ss[3] != 6
+      || tt[0][0] != 9 || tt[0][1] != 10 || tt[1][0] != 11 || tt[1][1] != 12
+      || tt[2][0] != 1LL << (16 + 8)
+      || tt[2][1] != 1LL << 4
+      || tt[3][0] != 1LL << 8
+      || tt[3][1] != 1LL << (16 + 4)
+      || tt[4][0] != 13 || tt[4][1] != 14)
+    abort ();
+}
+
+int
+main ()
+{
+  test (1);
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-reduction-4.c b/libgomp/testsuite/libgomp.c-c++-common/task-reduction-4.c
new file mode 100644 (file)
index 0000000..b0e5197
--- /dev/null
@@ -0,0 +1,70 @@
+extern
+#ifdef __cplusplus
+"C"
+#endif
+void abort (void);
+
+void
+bar (long long int *p)
+{
+  p[0] *= 2;
+  #pragma omp task in_reduction (*: p[0])
+  p[0] *= 3;
+}
+
+void
+foo (long long int *p, long long int *q)
+{
+  #pragma omp taskgroup task_reduction (*: p[0])
+  {
+    #pragma omp task in_reduction (*: p[0])
+    bar (p);
+    #pragma omp task in_reduction (*: p[0])
+    bar (p);
+    bar (p);
+    #pragma omp taskgroup task_reduction (*: q[0])
+    {
+      #pragma omp task in_reduction (*: q[0])
+      bar (q);
+      #pragma omp task in_reduction (*: q[0])
+      bar (q);
+      #pragma omp task in_reduction (*: q[0])
+      bar (q);
+      bar (q);
+      #pragma omp task in_reduction (*: p[0])
+      {
+       #pragma omp taskgroup task_reduction (*: p[0])
+       {
+         #pragma omp task in_reduction (*: p[0])
+         bar (p);
+         p[0] *= 2;
+         #pragma omp task in_reduction (*: p[0])
+         bar (p);
+       }
+      }
+    }
+  }
+}
+
+int
+main ()
+{
+  long long int p = 1LL, q = 1LL;
+  foo (&p, &q);
+  if (p != 6LL * 6LL * 6LL * 6LL * 6LL * 2LL || q != 6LL * 6LL * 6LL * 6LL)
+    abort ();
+  p = 1LL;
+  q = 1LL;
+  #pragma omp taskgroup
+  foo (&p, &q);
+  if (p != 6LL * 6LL * 6LL * 6LL * 6LL * 2LL || q != 6LL * 6LL * 6LL * 6LL)
+    abort ();
+  p = 1LL;
+  q = 1LL;
+  #pragma omp parallel
+  #pragma omp single
+  foo (&p, &q);
+  if (p != 6LL * 6LL * 6LL * 6LL * 6LL * 2LL || q != 6LL * 6LL * 6LL * 6LL)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-reduction-5.c b/libgomp/testsuite/libgomp.c-c++-common/task-reduction-5.c
new file mode 100644 (file)
index 0000000..018dc4f
--- /dev/null
@@ -0,0 +1,65 @@
+typedef __SIZE_TYPE__ size_t;
+extern
+#ifdef __cplusplus
+"C"
+#endif
+void abort (void);
+
+int *q;
+
+void
+bar (int *p, int *r, int *t, int s, size_t u)
+{
+  #pragma omp task in_reduction (*: p[0], q[0], r[s - 1], t[0:u + 1])
+  {
+    *p *= 4;
+    *q *= 5;
+    r[s - 1] *= 6;
+    t[0] *= 8;
+    t[1] *= 9;
+  }
+}
+
+void
+foo (int *p, int *r, int *t, int s, size_t u)
+{
+  int *p2 = p;
+  #pragma omp taskgroup task_reduction (*: p[0], q[0], r[s], t[0:u + 1])
+  {
+    p = (int *) 0;
+    s++;
+    bar (p2, r, t, s, u);
+    r++;
+    #pragma omp taskwait
+    #pragma omp task in_reduction (*: p2[0], q[0], r[s - 2], t[0:u + 1])
+    {
+      *p2 *= 2;
+      *q *= 3;
+      r[s - 2] *= 7;
+      t[0] *= 10;
+      t[1] *= 11;
+    }
+    u = (~(size_t) 0) / 4;
+    s++;
+    p2 = (int *) 0;
+    q = (int *) 0;
+    r = (int *) 0;
+    t = (int *) 0;
+  }
+}
+
+int
+main ()
+{
+  int a = 1, b = 1, c[2] = { 1, 0 }, d[3] = { 1, 1, -1 };
+  volatile int zero;
+  zero = 0;
+  q = &b;
+  #pragma omp parallel num_threads (2)
+  #pragma omp master
+  foo (&a, &c[0], &d[0], zero, zero + 1);
+  if (a != 8 || b != 15 || c[0] != 42 || c[1] != 0
+      || d[0] != 80 || d[1] != 99 || d[2] != -1)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-reduction-6.c b/libgomp/testsuite/libgomp.c-c++-common/task-reduction-6.c
new file mode 100644 (file)
index 0000000..09cbea6
--- /dev/null
@@ -0,0 +1,125 @@
+#include <omp.h>
+#include <stdlib.h>
+
+struct S { unsigned long long int s, t; };
+
+void
+rbar (struct S *p, struct S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+rbaz (struct S *o, struct S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: struct S : omp_out.s += omp_in.s) \
+  initializer (omp_priv = { 0, 3 })
+#pragma omp declare reduction (*: struct S : rbaz (&omp_out, &omp_in)) \
+  initializer (rbar (&omp_priv, &omp_orig))
+
+struct S g = { 0, 7 };
+struct S h = { 1, 5 };
+
+int
+foo (int *a, int *b)
+{
+  int x = 0;
+  #pragma omp taskloop reduction (+:x) in_reduction (+:b[0])
+  for (int i = 0; i < 64; i++)
+    {
+      x += a[i];
+      *b += a[i] * 2;
+    }
+  return x;
+}
+
+unsigned long long int
+bar (int *a, unsigned long long int *b)
+{
+  unsigned long long int x = 1;
+  #pragma omp taskloop reduction (*:x) in_reduction (*:b[0])
+  for (int i = 0; i < 64; i++)
+    {
+      #pragma omp task in_reduction (*:x)
+      x *= a[i];
+      #pragma omp task in_reduction (*:b[0])
+      *b *= (3 - a[i]);
+    }
+  return x;
+}
+
+void
+baz (int i, int *a, int *c)
+{
+  #pragma omp task in_reduction (*:h) in_reduction (+:g)
+  {
+    g.s += 7 * a[i];
+    h.s *= (3 - c[i]);
+    if ((g.t != 7 && g.t != 3) || (h.t != 5 && h.t != 9))
+      abort ();
+  }
+}
+
+int
+main ()
+{
+  int i, j, a[64], b = 0, c[64];
+  unsigned long long int d = 1, e;
+  int r = 0, t;
+  struct S m = { 0, 7 };
+  struct S n = { 1, 5 };
+  for (i = 0; i < 64; i++)
+    {
+      a[i] = 2 * i;
+      c[i] = 1 + ((i % 3) != 1);
+    }
+  #pragma omp parallel reduction (task, +:b) reduction(+:r) \
+                      reduction(task,*:d) reduction (task, +: g, m) \
+                      reduction (task, *: h, n) shared(t)
+  {
+    #pragma omp master
+    {
+      j = foo (a, &b);
+      t = omp_get_num_threads ();
+    }
+    r++;
+    #pragma omp single nowait
+      e = bar (c, &d);
+    #pragma omp master
+    #pragma omp taskloop in_reduction (+: g, m) in_reduction (*: h, n)
+    for (i = 0; i < 64; ++i)
+      {
+       g.s += 3 * a[i];
+       h.s *= (3 - c[i]);
+       m.s += 4 * a[i];
+       n.s *= c[i];
+       if ((g.t != 7 && g.t != 3) || (h.t != 5 && h.t != 9)
+           || (m.t != 7 && m.t != 3) || (n.t != 5 && n.t != 9))
+         abort ();
+       baz (i, a, c);
+      }
+  }
+  if (n.s != (1ULL << 43) || n.t != 5)
+    abort ();
+  if (j != 63 * 64 || b != 63 * 64 * 2)
+    abort ();
+  if (e != (1ULL << 43) || d != (1ULL << 21))
+    abort ();
+  if (g.s != 63 * 64 * 10 || g.t != 7)
+    abort ();
+  if (h.s != (1ULL << 42) || h.t != 5)
+    abort ();
+  if (m.s != 63 * 64 * 4 || m.t != 7)
+    abort ();
+  if (r != t)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-reduction-7.c b/libgomp/testsuite/libgomp.c-c++-common/task-reduction-7.c
new file mode 100644 (file)
index 0000000..c656f5f
--- /dev/null
@@ -0,0 +1,216 @@
+#ifdef __cplusplus
+extern "C"
+#endif
+void abort (void);
+
+int a[2];
+long long int b[7] = { 9, 11, 1, 1, 1, 13, 15 };
+int e[3] = { 5, 0, 5 };
+int f[5] = { 6, 7, 0, 0, 9 };
+int g[4] = { 1, 0, 0, 2 };
+int h[3] = { 0, 1, 4 };
+int k[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+long long *s;
+long long (*t)[2];
+
+void
+foo (int n, int *c, long long int *d, int m[3], int *r, int o[4], int *p, int q[4][2])
+{
+  int i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                    in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
+                    in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
+                    in_reduction (*: s[1:2], t[2:2][:])
+    {
+      a[0] += 7;
+      a[1] += 17;
+      b[2] *= 2;
+      b[4] *= 2;
+      c[0] += 6;
+      d[1] *= 2;
+      e[1] += 19;
+      f[2] += 21;
+      f[3] += 23;
+      g[1] += 25;
+      g[2] += 27;
+      h[0] += 29;
+      k[1][0] += 31;
+      k[2][1] += 33;
+      m[1] += 19;
+      r[2] += 21;
+      r[3] += 23;
+      o[1] += 25;
+      o[2] += 27;
+      p[0] += 29;
+      q[1][0] += 31;
+      q[2][1] += 33;
+      s[1] *= 2;
+      t[2][0] *= 2;
+      t[3][1] *= 2;
+    }
+}
+
+void
+test (int n)
+{
+  int c[2] = { 0, 0 };
+  int p[3] = { 0, 1, 4 };
+  int q[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+  long long ss[4] = { 5, 1, 1, 6 };
+  long long tt[5][2] = { { 9, 10 }, { 11, 12 }, { 1, 1 }, { 1, 1 }, { 13, 14 } };
+  long long int d[] = { 1, 1 };
+  int m[3] = { 5, 0, 5 };
+  int r[5] = { 6, 7, 0, 0, 9 };
+  int o[4] = { 1, 0, 0, 2 };
+  s = ss;
+  t = tt;
+  #pragma omp parallel reduction (task, +: a, c) reduction (task, *: b[2 * n:3 * n], d) \
+                      reduction (task, +: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                      reduction (task, +: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                      reduction (task, *: t[2:2][:], s[1:n + 1]) num_threads(4)
+  {
+    int i;
+    #pragma omp for
+    for (i = 0; i < 4; i++)
+      {
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b[2 * n:3 * n], d) \
+                        in_reduction (+: o[n:n*2], q[1:2][:], p[0], m[1], r[2:2]) \
+                        in_reduction (+: g[n:n * 2], e[1], k[1:2][:], h[0], f[2:2]) \
+                        in_reduction (*: s[1:2], t[2:2][:])
+       {
+         int j;
+         a[0] += 2;
+         a[1] += 3;
+         b[2] *= 2;
+         f[3] += 8;
+         g[1] += 9;
+         g[2] += 10;
+         h[0] += 11;
+         k[1][1] += 13;
+         k[2][1] += 15;
+         m[1] += 16;
+         r[2] += 8;
+         s[1] *= 2;
+         t[2][1] *= 2;
+         t[3][1] *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c[:2]) \
+                            in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                            in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                            in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                            in_reduction (*: s[n:2], t[2:2][:])
+           {
+             m[1] += 6;
+             r[2] += 7;
+             q[1][0] += 17;
+             q[2][0] += 19;
+             a[0] += 4;
+             a[1] += 5;
+             b[3] *= 2;
+             b[4] *= 2;
+             f[3] += 18;
+             g[1] += 29;
+             g[2] += 18;
+             h[0] += 19;
+             s[2] *= 2;
+             t[2][0] *= 2;
+             t[3][0] *= 2;
+             foo (n, c, d, m, r, o, p, q);
+             r[3] += 18;
+             o[1] += 29;
+             o[2] += 18;
+             p[0] += 19;
+             c[0] += 4;
+             c[1] += 5;
+             d[0] *= 2;
+             e[1] += 6;
+             f[2] += 7;
+             k[1][0] += 17;
+             k[2][0] += 19;
+           }
+         r[3] += 8;
+         o[1] += 9;
+         o[2] += 10;
+         p[0] += 11;
+         q[1][1] += 13;
+         q[2][1] += 15;
+         b[3] *= 2;
+         c[0] += 4;
+         c[1] += 9;
+         d[0] *= 2;
+         e[1] += 16;
+         f[2] += 8;
+       }
+      }
+  }
+  if (a[0] != 7 * 16 + 4 * 8 + 2 * 4
+      || a[1] != 17 * 16 + 5 * 8 + 3 * 4
+      || b[0] != 9 || b[1] != 11
+      || b[2] != 1LL << (16 + 4)
+      || b[3] != 1LL << (8 + 4)
+      || b[4] != 1LL << (16 + 8)
+      || b[5] != 13 || b[6] != 15
+      || c[0] != 6 * 16 + 4 * 8 + 4 * 4
+      || c[1] != 5 * 8 + 9 * 4
+      || d[0] != 1LL << (8 + 4)
+      || d[1] != 1LL << 16
+      || e[0] != 5
+      || e[1] != 19 * 16 + 6 * 8 + 16 * 4
+      || e[2] != 5
+      || f[0] != 6
+      || f[1] != 7
+      || f[2] != 21 * 16 + 7 * 8 + 8 * 4
+      || f[3] != 23 * 16 + 18 * 8 + 8 * 4
+      || f[4] != 9
+      || g[0] != 1
+      || g[1] != 25 * 16 + 29 * 8 + 9 * 4
+      || g[2] != 27 * 16 + 18 * 8 + 10 * 4
+      || g[3] != 2
+      || h[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || h[1] != 1 || h[2] != 4
+      || k[0][0] != 5 || k[0][1] != 6
+      || k[1][0] != 31 * 16 + 17 * 8
+      || k[1][1] != 13 * 4
+      || k[2][0] != 19 * 8
+      || k[2][1] != 33 * 16 + 15 * 4
+      || k[3][0] != 7 || k[3][1] != 8
+      || m[0] != 5
+      || m[1] != 19 * 16 + 6 * 8 + 16 * 4
+      || m[2] != 5
+      || o[0] != 1
+      || o[1] != 25 * 16 + 29 * 8 + 9 * 4
+      || o[2] != 27 * 16 + 18 * 8 + 10 * 4
+      || o[3] != 2
+      || p[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || p[1] != 1 || p[2] != 4
+      || q[0][0] != 5 || q[0][1] != 6
+      || q[1][0] != 31 * 16 + 17 * 8
+      || q[1][1] != 13 * 4
+      || q[2][0] != 19 * 8
+      || q[2][1] != 33 * 16 + 15 * 4
+      || q[3][0] != 7 || q[3][1] != 8
+      || r[0] != 6
+      || r[1] != 7
+      || r[2] != 21 * 16 + 7 * 8 + 8 * 4
+      || r[3] != 23 * 16 + 18 * 8 + 8 * 4
+      || r[4] != 9
+      || ss[0] != 5
+      || ss[1] != 1LL << (16 + 4)
+      || ss[2] != 1LL << 8
+      || ss[3] != 6
+      || tt[0][0] != 9 || tt[0][1] != 10 || tt[1][0] != 11 || tt[1][1] != 12
+      || tt[2][0] != 1LL << (16 + 8)
+      || tt[2][1] != 1LL << 4
+      || tt[3][0] != 1LL << 8
+      || tt[3][1] != 1LL << (16 + 4)
+      || tt[4][0] != 13 || tt[4][1] != 14)
+    abort ();
+}
+
+int
+main ()
+{
+  test (1);
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-reduction-8.c b/libgomp/testsuite/libgomp.c-c++-common/task-reduction-8.c
new file mode 100644 (file)
index 0000000..7b0859d
--- /dev/null
@@ -0,0 +1,141 @@
+#include <omp.h>
+#include <stdlib.h>
+
+struct S { unsigned long long int s, t; };
+
+void
+rbar (struct S *p, struct S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+rbaz (struct S *o, struct S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: struct S : omp_out.s += omp_in.s) \
+  initializer (omp_priv = { 0, 3 })
+#pragma omp declare reduction (*: struct S : rbaz (&omp_out, &omp_in)) \
+  initializer (rbar (&omp_priv, &omp_orig))
+
+struct S g = { 0, 7 };
+struct S h = { 1, 5 };
+
+int
+foo (int z, int *a, int *b)
+{
+  int x = 0;
+  #pragma omp taskloop reduction (+:x) in_reduction (+:b[0])
+  for (int i = z; i < z + 8; i++)
+    {
+      x += a[i];
+      *b += a[i] * 2;
+    }
+  return x;
+}
+
+unsigned long long int
+bar (int z, int *a, unsigned long long int *b, int *s)
+{
+  unsigned long long int x = 1;
+  #pragma omp taskloop reduction (*:x) in_reduction (*:b[0])
+  for (int i = z; i < z + 8; i++)
+    {
+      #pragma omp task in_reduction (*:x)
+      x *= a[i];
+      #pragma omp task in_reduction (*:b[0])
+      *b *= (3 - a[i]);
+      s[0]++;
+    }
+  return x;
+}
+
+void
+baz (int i, int *a, int *c)
+{
+  #pragma omp task in_reduction (*:h) in_reduction (+:g)
+  {
+    g.s += 7 * a[i];
+    h.s *= (3 - c[i]);
+    if ((g.t != 7 && g.t != 3) || (h.t != 5 && h.t != 9))
+      abort ();
+  }
+}
+
+int
+main ()
+{
+  int i, j = 0, a[64], b = 0, c[64], f = 0;
+  unsigned long long int d = 1, e = 1;
+  volatile int one = 1;
+  int r = 0, s = 0, t;
+  struct S m = { 0, 7 };
+  struct S n = { 1, 5 };
+  for (i = 0; i < 64; i++)
+    {
+      a[i] = 2 * i;
+      c[i] = 1 + ((i % 3) != 1);
+    }
+  #pragma omp parallel reduction (task, +:b) shared(t) reduction(+:r, s)
+  {
+    int z, q1, q2, q3;
+    #pragma omp master
+    t = omp_get_num_threads ();
+    #pragma omp for schedule(static) reduction (task, +: f) reduction (+: j)
+    for (z = 0; z < 64; z += 8)
+      {
+       f++;
+       j += foo (z, a, &b);
+       j += foo (z, a, &f);
+      }
+    if (j != 63 * 64 * 2 || f != 63 * 64 * 2 + 8)
+      abort ();
+    r++;
+    #pragma omp taskgroup task_reduction (+: s)
+    {
+      #pragma omp for schedule(static, 1) reduction(task, *: d) reduction (*: e)
+      for (z = 0; z < 64; z += 8)
+       e *= bar (z, c, &d, &s);
+    }
+    if (e != (1ULL << 43) || d != (1ULL << 21))
+      abort ();
+    #pragma omp for schedule(monotonic: dynamic, 1) reduction (task, +: g, m) \
+                   reduction (task, *: h, n) collapse(3)
+    for (q1 = 0; q1 < one; q1++)
+      for (q2 = 0; q2 < 64; q2 += 8)
+       for (q3 = 0; q3 < one; ++q3)
+         #pragma omp taskloop in_reduction (+: g, m) in_reduction (*: h, n) \
+                              nogroup
+         for (i = q2; i < q2 + 8; ++i)
+           {
+             g.s += 3 * a[i];
+             h.s *= (3 - c[i]);
+             m.s += 4 * a[i];
+             n.s *= c[i];
+             if ((g.t != 7 && g.t != 3) || (h.t != 5 && h.t != 9)
+                 || (m.t != 7 && m.t != 3) || (n.t != 5 && n.t != 9))
+               abort ();
+             baz (i, a, c);
+           }
+    if (n.s != (1ULL << 43) || n.t != 5)
+      abort ();
+    if (g.s != 63 * 64 * 10 || g.t != 7)
+      abort ();
+    if (h.s != (1ULL << 42) || h.t != 5)
+      abort ();
+    if (m.s != 63 * 64 * 4 || m.t != 7)
+      abort ();
+  }
+  if (b != 63 * 64 * 2)
+    abort ();
+  if (r != t || s != 64)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-reduction-9.c b/libgomp/testsuite/libgomp.c-c++-common/task-reduction-9.c
new file mode 100644 (file)
index 0000000..3d71fef
--- /dev/null
@@ -0,0 +1,217 @@
+#ifdef __cplusplus
+extern "C"
+#endif
+void abort (void);
+
+int a[2];
+long long int b[7] = { 9, 11, 1, 1, 1, 13, 15 };
+int e[3] = { 5, 0, 5 };
+int f[5] = { 6, 7, 0, 0, 9 };
+int g[4] = { 1, 0, 0, 2 };
+int h[3] = { 0, 1, 4 };
+int k[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+long long *s;
+long long (*t)[2];
+
+void
+foo (int n, int *c, long long int *d, int m[3], int *r, int o[4], int *p, int q[4][2])
+{
+  int i;
+  for (i = 0; i < 2; i++)
+    #pragma omp task in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                    in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
+                    in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
+                    in_reduction (*: s[1:2], t[2:2][:])
+    {
+      a[0] += 7;
+      a[1] += 17;
+      b[2] *= 2;
+      b[4] *= 2;
+      c[0] += 6;
+      d[1] *= 2;
+      e[1] += 19;
+      f[2] += 21;
+      f[3] += 23;
+      g[1] += 25;
+      g[2] += 27;
+      h[0] += 29;
+      k[1][0] += 31;
+      k[2][1] += 33;
+      m[1] += 19;
+      r[2] += 21;
+      r[3] += 23;
+      o[1] += 25;
+      o[2] += 27;
+      p[0] += 29;
+      q[1][0] += 31;
+      q[2][1] += 33;
+      s[1] *= 2;
+      t[2][0] *= 2;
+      t[3][1] *= 2;
+    }
+}
+
+void
+test (int n)
+{
+  int c[2] = { 0, 0 };
+  int p[3] = { 0, 1, 4 };
+  int q[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+  long long ss[4] = { 5, 1, 1, 6 };
+  long long tt[5][2] = { { 9, 10 }, { 11, 12 }, { 1, 1 }, { 1, 1 }, { 13, 14 } };
+  long long int d[] = { 1, 1 };
+  int m[3] = { 5, 0, 5 };
+  int r[5] = { 6, 7, 0, 0, 9 };
+  int o[4] = { 1, 0, 0, 2 };
+  s = ss;
+  t = tt;
+  #pragma omp parallel num_threads(4)
+  {
+    int i;
+    #pragma omp for reduction (task, +: a, c) reduction (task, *: b[2 * n:3 * n], d) \
+                   reduction (task, +: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                   reduction (task, +: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                   reduction (task, *: t[2:2][:], s[1:n + 1]) \
+                   schedule(nonmonotonic: runtime)
+    for (i = 0; i < 4; i++)
+      {
+       #pragma omp task in_reduction (+: a, c) in_reduction (*: b[2 * n:3 * n], d) \
+                        in_reduction (+: o[n:n*2], q[1:2][:], p[0], m[1], r[2:2]) \
+                        in_reduction (+: g[n:n * 2], e[1], k[1:2][:], h[0], f[2:2]) \
+                        in_reduction (*: s[1:2], t[2:2][:])
+       {
+         int j;
+         a[0] += 2;
+         a[1] += 3;
+         b[2] *= 2;
+         f[3] += 8;
+         g[1] += 9;
+         g[2] += 10;
+         h[0] += 11;
+         k[1][1] += 13;
+         k[2][1] += 15;
+         m[1] += 16;
+         r[2] += 8;
+         s[1] *= 2;
+         t[2][1] *= 2;
+         t[3][1] *= 2;
+         for (j = 0; j < 2; j++)
+           #pragma omp task in_reduction (+: a, c[:2]) \
+                            in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                            in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                            in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                            in_reduction (*: s[n:2], t[2:2][:])
+           {
+             m[1] += 6;
+             r[2] += 7;
+             q[1][0] += 17;
+             q[2][0] += 19;
+             a[0] += 4;
+             a[1] += 5;
+             b[3] *= 2;
+             b[4] *= 2;
+             f[3] += 18;
+             g[1] += 29;
+             g[2] += 18;
+             h[0] += 19;
+             s[2] *= 2;
+             t[2][0] *= 2;
+             t[3][0] *= 2;
+             foo (n, c, d, m, r, o, p, q);
+             r[3] += 18;
+             o[1] += 29;
+             o[2] += 18;
+             p[0] += 19;
+             c[0] += 4;
+             c[1] += 5;
+             d[0] *= 2;
+             e[1] += 6;
+             f[2] += 7;
+             k[1][0] += 17;
+             k[2][0] += 19;
+           }
+         r[3] += 8;
+         o[1] += 9;
+         o[2] += 10;
+         p[0] += 11;
+         q[1][1] += 13;
+         q[2][1] += 15;
+         b[3] *= 2;
+         c[0] += 4;
+         c[1] += 9;
+         d[0] *= 2;
+         e[1] += 16;
+         f[2] += 8;
+       }
+      }
+  }
+  if (a[0] != 7 * 16 + 4 * 8 + 2 * 4
+      || a[1] != 17 * 16 + 5 * 8 + 3 * 4
+      || b[0] != 9 || b[1] != 11
+      || b[2] != 1LL << (16 + 4)
+      || b[3] != 1LL << (8 + 4)
+      || b[4] != 1LL << (16 + 8)
+      || b[5] != 13 || b[6] != 15
+      || c[0] != 6 * 16 + 4 * 8 + 4 * 4
+      || c[1] != 5 * 8 + 9 * 4
+      || d[0] != 1LL << (8 + 4)
+      || d[1] != 1LL << 16
+      || e[0] != 5
+      || e[1] != 19 * 16 + 6 * 8 + 16 * 4
+      || e[2] != 5
+      || f[0] != 6
+      || f[1] != 7
+      || f[2] != 21 * 16 + 7 * 8 + 8 * 4
+      || f[3] != 23 * 16 + 18 * 8 + 8 * 4
+      || f[4] != 9
+      || g[0] != 1
+      || g[1] != 25 * 16 + 29 * 8 + 9 * 4
+      || g[2] != 27 * 16 + 18 * 8 + 10 * 4
+      || g[3] != 2
+      || h[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || h[1] != 1 || h[2] != 4
+      || k[0][0] != 5 || k[0][1] != 6
+      || k[1][0] != 31 * 16 + 17 * 8
+      || k[1][1] != 13 * 4
+      || k[2][0] != 19 * 8
+      || k[2][1] != 33 * 16 + 15 * 4
+      || k[3][0] != 7 || k[3][1] != 8
+      || m[0] != 5
+      || m[1] != 19 * 16 + 6 * 8 + 16 * 4
+      || m[2] != 5
+      || o[0] != 1
+      || o[1] != 25 * 16 + 29 * 8 + 9 * 4
+      || o[2] != 27 * 16 + 18 * 8 + 10 * 4
+      || o[3] != 2
+      || p[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || p[1] != 1 || p[2] != 4
+      || q[0][0] != 5 || q[0][1] != 6
+      || q[1][0] != 31 * 16 + 17 * 8
+      || q[1][1] != 13 * 4
+      || q[2][0] != 19 * 8
+      || q[2][1] != 33 * 16 + 15 * 4
+      || q[3][0] != 7 || q[3][1] != 8
+      || r[0] != 6
+      || r[1] != 7
+      || r[2] != 21 * 16 + 7 * 8 + 8 * 4
+      || r[3] != 23 * 16 + 18 * 8 + 8 * 4
+      || r[4] != 9
+      || ss[0] != 5
+      || ss[1] != 1LL << (16 + 4)
+      || ss[2] != 1LL << 8
+      || ss[3] != 6
+      || tt[0][0] != 9 || tt[0][1] != 10 || tt[1][0] != 11 || tt[1][1] != 12
+      || tt[2][0] != 1LL << (16 + 8)
+      || tt[2][1] != 1LL << 4
+      || tt[3][0] != 1LL << 8
+      || tt[3][1] != 1LL << (16 + 4)
+      || tt[4][0] != 13 || tt[4][1] != 14)
+    abort ();
+}
+
+int
+main ()
+{
+  test (1);
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/taskloop-reduction-1.c b/libgomp/testsuite/libgomp.c-c++-common/taskloop-reduction-1.c
new file mode 100644 (file)
index 0000000..d44b471
--- /dev/null
@@ -0,0 +1,119 @@
+extern
+#ifdef __cplusplus
+"C"
+#endif
+void abort (void);
+
+struct S { unsigned long long int s, t; };
+
+void
+rbar (struct S *p, struct S *o)
+{
+  p->s = 1;
+  if (o->t != 5)
+    abort ();
+  p->t = 9;
+}
+
+static inline void
+rbaz (struct S *o, struct S *i)
+{
+  if (o->t != 5 || i->t != 9)
+    abort ();
+  o->s *= i->s;
+}
+
+#pragma omp declare reduction (+: struct S : omp_out.s += omp_in.s) \
+  initializer (omp_priv = { 0, 3 })
+#pragma omp declare reduction (*: struct S : rbaz (&omp_out, &omp_in)) \
+  initializer (rbar (&omp_priv, &omp_orig))
+
+struct S g = { 0, 7 };
+struct S h = { 1, 5 };
+
+int
+foo (int *a, int *b)
+{
+  int x = 0;
+  #pragma omp taskloop reduction (+:x) in_reduction (+:b[0])
+  for (int i = 0; i < 64; i++)
+    {
+      x += a[i];
+      *b += a[i] * 2;
+    }
+  return x;
+}
+
+unsigned long long int
+bar (int *a, unsigned long long int *b)
+{
+  unsigned long long int x = 1;
+  #pragma omp taskloop reduction (*:x) in_reduction (*:b[0])
+  for (int i = 0; i < 64; i++)
+    {
+      #pragma omp task in_reduction (*:x)
+      x *= a[i];
+      #pragma omp task in_reduction (*:b[0])
+      *b *= (3 - a[i]);
+    }
+  return x;
+}
+
+void
+baz (int i, int *a, int *c)
+{
+  #pragma omp task in_reduction (*:h) in_reduction (+:g)
+  {
+    g.s += 7 * a[i];
+    h.s *= (3 - c[i]);
+    if ((g.t != 7 && g.t != 3) || (h.t != 5 && h.t != 9))
+      abort ();
+  }
+}
+
+int
+main ()
+{
+  int i, j, a[64], b = 0, c[64];
+  unsigned long long int d = 1, e;
+  struct S m = { 0, 7 };
+  for (i = 0; i < 64; i++)
+    {
+      a[i] = 2 * i;
+      c[i] = 1 + ((i % 3) != 1);
+    }
+  #pragma omp parallel
+  #pragma omp master
+  {
+    struct S n = { 1, 5 };
+    #pragma omp taskgroup task_reduction (+:b)
+      j = foo (a, &b);
+    #pragma omp taskgroup task_reduction (*:d)
+      e = bar (c, &d);
+    #pragma omp taskloop reduction (+: g, m) reduction (*: h, n)
+    for (i = 0; i < 64; ++i)
+      {
+       g.s += 3 * a[i];
+       h.s *= (3 - c[i]);
+       m.s += 4 * a[i];
+       n.s *= c[i];
+       if ((g.t != 7 && g.t != 3) || (h.t != 5 && h.t != 9)
+           || (m.t != 7 && m.t != 3) || (n.t != 5 && n.t != 9))
+         abort ();
+       baz (i, a, c);
+      }
+    if (n.s != (1ULL << 43) || n.t != 5)
+      abort ();
+  }
+  if (j != 63 * 64 || b != 63 * 64 * 2)
+    abort ();
+  if (e != (1ULL << 43) || d != (1ULL << 21))
+    abort ();
+  if (g.s != 63 * 64 * 10 || g.t != 7)
+    abort ();
+  if (h.s != (1ULL << 42) || h.t != 5)
+    abort ();
+  if (m.s != 63 * 64 * 4 || m.t != 7)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/taskloop-reduction-2.c b/libgomp/testsuite/libgomp.c-c++-common/taskloop-reduction-2.c
new file mode 100644 (file)
index 0000000..8fc05dc
--- /dev/null
@@ -0,0 +1,212 @@
+#ifdef __cplusplus
+extern "C"
+#endif
+void abort (void);
+
+int a[2];
+long long int b[7] = { 9, 11, 1, 1, 1, 13, 15 };
+int e[3] = { 5, 0, 5 };
+int f[5] = { 6, 7, 0, 0, 9 };
+int g[4] = { 1, 0, 0, 2 };
+int h[3] = { 0, 1, 4 };
+int k[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+long long *s;
+long long (*t)[2];
+
+void
+foo (int n, int *c, long long int *d, int m[3], int *r, int o[4], int *p, int q[4][2])
+{
+  int i;
+  #pragma omp taskloop in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
+                      in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
+                      in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
+                      in_reduction (*: s[1:2], t[2:2][:]) nogroup
+  for (i = 0; i < 2; i++)
+    {
+      a[0] += 7;
+      a[1] += 17;
+      b[2] *= 2;
+      b[4] *= 2;
+      c[0] += 6;
+      d[1] *= 2;
+      e[1] += 19;
+      f[2] += 21;
+      f[3] += 23;
+      g[1] += 25;
+      g[2] += 27;
+      h[0] += 29;
+      k[1][0] += 31;
+      k[2][1] += 33;
+      m[1] += 19;
+      r[2] += 21;
+      r[3] += 23;
+      o[1] += 25;
+      o[2] += 27;
+      p[0] += 29;
+      q[1][0] += 31;
+      q[2][1] += 33;
+      s[1] *= 2;
+      t[2][0] *= 2;
+      t[3][1] *= 2;
+    }
+}
+
+void
+test (int n)
+{
+  int c[2] = { 0, 0 };
+  int p[3] = { 0, 1, 4 };
+  int q[4][2] = { { 5, 6 }, { 0, 0 }, { 0, 0 }, { 7, 8 } };
+  long long ss[4] = { 5, 1, 1, 6 };
+  long long tt[5][2] = { { 9, 10 }, { 11, 12 }, { 1, 1 }, { 1, 1 }, { 13, 14 } };
+  s = ss;
+  t = tt;
+  #pragma omp parallel
+  #pragma omp single
+  {
+    long long int d[] = { 1, 1 };
+    int m[3] = { 5, 0, 5 };
+    int r[5] = { 6, 7, 0, 0, 9 };
+    int o[4] = { 1, 0, 0, 2 };
+    int i;
+    #pragma omp taskloop reduction (+: a, c) reduction (default, *: b[2 * n:3 * n], d) \
+                        reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
+                        reduction (default, +: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
+                        reduction (*: t[2:2][:], s[1:n + 1])
+    for (i = 0; i < 4; i++)
+      {
+       int j;
+       a[0] += 2;
+       a[1] += 3;
+       b[2] *= 2;
+       f[3] += 8;
+       g[1] += 9;
+       g[2] += 10;
+       h[0] += 11;
+       k[1][1] += 13;
+       k[2][1] += 15;
+       m[1] += 16;
+       r[2] += 8;
+       s[1] *= 2;
+       t[2][1] *= 2;
+       t[3][1] *= 2;
+       #pragma omp taskloop in_reduction (+: a, c[:2]) \
+                            in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
+                            in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
+                            in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
+                            in_reduction (*: s[n:2], t[2:2][:]) nogroup
+       for (j = 0; j < 2; j++)
+         {
+           m[1] += 6;
+           r[2] += 7;
+           q[1][0] += 17;
+           q[2][0] += 19;
+           a[0] += 4;
+           a[1] += 5;
+           b[3] *= 2;
+           b[4] *= 2;
+           f[3] += 18;
+           g[1] += 29;
+           g[2] += 18;
+           h[0] += 19;
+           s[2] *= 2;
+           t[2][0] *= 2;
+           t[3][0] *= 2;
+           foo (n, c, d, m, r, o, p, q);
+           r[3] += 18;
+           o[1] += 29;
+           o[2] += 18;
+           p[0] += 19;
+           c[0] += 4;
+           c[1] += 5;
+           d[0] *= 2;
+           e[1] += 6;
+           f[2] += 7;
+           k[1][0] += 17;
+           k[2][0] += 19;
+         }
+       r[3] += 8;
+       o[1] += 9;
+       o[2] += 10;
+       p[0] += 11;
+       q[1][1] += 13;
+       q[2][1] += 15;
+       b[3] *= 2;
+       c[0] += 4;
+       c[1] += 9;
+       d[0] *= 2;
+       e[1] += 16;
+       f[2] += 8;
+      }
+    if (d[0] != 1LL << (8 + 4)
+       || d[1] != 1LL << 16
+       || m[0] != 5
+       || m[1] != 19 * 16 + 6 * 8 + 16 * 4
+       || m[2] != 5
+       || r[0] != 6
+       || r[1] != 7
+       || r[2] != 21 * 16 + 7 * 8 + 8 * 4
+       || r[3] != 23 * 16 + 18 * 8 + 8 * 4
+       || r[4] != 9
+       || o[0] != 1
+       || o[1] != 25 * 16 + 29 * 8 + 9 * 4
+       || o[2] != 27 * 16 + 18 * 8 + 10 * 4
+       || o[3] != 2)
+      abort ();
+  }
+  if (a[0] != 7 * 16 + 4 * 8 + 2 * 4
+      || a[1] != 17 * 16 + 5 * 8 + 3 * 4
+      || b[0] != 9 || b[1] != 11
+      || b[2] != 1LL << (16 + 4)
+      || b[3] != 1LL << (8 + 4)
+      || b[4] != 1LL << (16 + 8)
+      || b[5] != 13 || b[6] != 15
+      || c[0] != 6 * 16 + 4 * 8 + 4 * 4
+      || c[1] != 5 * 8 + 9 * 4
+      || e[0] != 5
+      || e[1] != 19 * 16 + 6 * 8 + 16 * 4
+      || e[2] != 5
+      || f[0] != 6
+      || f[1] != 7
+      || f[2] != 21 * 16 + 7 * 8 + 8 * 4
+      || f[3] != 23 * 16 + 18 * 8 + 8 * 4
+      || f[4] != 9
+      || g[0] != 1
+      || g[1] != 25 * 16 + 29 * 8 + 9 * 4
+      || g[2] != 27 * 16 + 18 * 8 + 10 * 4
+      || g[3] != 2
+      || h[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || h[1] != 1 || h[2] != 4
+      || k[0][0] != 5 || k[0][1] != 6
+      || k[1][0] != 31 * 16 + 17 * 8
+      || k[1][1] != 13 * 4
+      || k[2][0] != 19 * 8
+      || k[2][1] != 33 * 16 + 15 * 4
+      || k[3][0] != 7 || k[3][1] != 8
+      || p[0] != 29 * 16 + 19 * 8 + 11 * 4
+      || p[1] != 1 || p[2] != 4
+      || q[0][0] != 5 || q[0][1] != 6
+      || q[1][0] != 31 * 16 + 17 * 8
+      || q[1][1] != 13 * 4
+      || q[2][0] != 19 * 8
+      || q[2][1] != 33 * 16 + 15 * 4
+      || q[3][0] != 7 || q[3][1] != 8
+      || ss[0] != 5
+      || ss[1] != 1LL << (16 + 4)
+      || ss[2] != 1LL << 8
+      || ss[3] != 6
+      || tt[0][0] != 9 || tt[0][1] != 10 || tt[1][0] != 11 || tt[1][1] != 12
+      || tt[2][0] != 1LL << (16 + 8)
+      || tt[2][1] != 1LL << 4
+      || tt[3][0] != 1LL << 8
+      || tt[3][1] != 1LL << (16 + 4)
+      || tt[4][0] != 13 || tt[4][1] != 14)
+    abort ();
+}
+
+int
+main ()
+{
+  test (1);
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/taskloop-reduction-3.c b/libgomp/testsuite/libgomp.c-c++-common/taskloop-reduction-3.c
new file mode 100644 (file)
index 0000000..30a8324
--- /dev/null
@@ -0,0 +1,45 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+/* { dg-additional-options "-std=c99" { target c } } */
+/* { dg-additional-options "-msse2" { target sse2_runtime } } */
+/* { dg-additional-options "-mavx" { target avx_runtime } } */
+
+#define N 1024
+long int u[N], m, n;
+
+__attribute__((noipa)) void
+foo (void)
+{
+  int i;
+  #pragma omp taskloop simd reduction (+:m) grainsize (64)
+  for (i = 0; i < N; ++i)
+    m += u[i];
+}
+
+__attribute__((noipa)) void
+bar (int x)
+{
+  #pragma omp taskloop simd in_reduction (+:n) grainsize (64) nogroup
+  for (int i = (x & 1) * (N / 2); i < (x & 1) * (N / 2) + (N / 2); i++)
+    n += 2 * u[i];
+}
+
+int
+main ()
+{
+  int i;
+  for (i = 0; i < N; ++i)
+    u[i] = i;
+  #pragma omp parallel master
+  {
+    foo ();
+    #pragma omp taskgroup task_reduction (+:n)
+    {
+      bar (0);
+      bar (1);
+    }
+  }
+  if (m != (long)(N - 1) * (N / 2) || n != (long)(N - 1) * N)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/taskloop-reduction-4.c b/libgomp/testsuite/libgomp.c-c++-common/taskloop-reduction-4.c
new file mode 100644 (file)
index 0000000..c1c29b3
--- /dev/null
@@ -0,0 +1,65 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+/* { dg-additional-options "-std=c99" { target c } } */
+/* { dg-additional-options "-msse2" { target sse2_runtime } } */
+/* { dg-additional-options "-mavx" { target avx_runtime } } */
+
+#include <omp.h>
+#include <stdlib.h>
+
+#define N 1024
+long int u[N], m, n, o;
+
+__attribute__((noipa)) void
+foo (void)
+{
+  int i = -1;
+  #pragma omp master taskloop simd reduction (+:m) grainsize (64)
+  for (i = 0; i < N; ++i)
+    m += u[i];
+  if (i != (omp_get_thread_num () ? -1 : N))
+    abort ();
+}
+
+__attribute__((noipa)) void
+bar (int x)
+{
+  int i = -1;
+  #pragma omp master taskloop simd in_reduction (+:n) grainsize (64)
+  for (i = (x & 1) * (N / 2); i < (x & 1) * (N / 2) + (N / 2); i++)
+    n += 2 * u[i];
+  if (i != (omp_get_thread_num () ? -1 : (x & 1) * (N / 2) + (N / 2)))
+    abort ();
+}
+
+__attribute__((noipa)) void
+baz (void)
+{
+  int i;
+  #pragma omp parallel master taskloop simd reduction (+:o) grainsize (64)
+  for (i = 0; i < N; ++i)
+    o += u[i];
+  if (i != N)
+    abort ();
+}
+
+int
+main ()
+{
+  int i;
+  for (i = 0; i < N; ++i)
+    u[i] = i;
+  #pragma omp parallel
+  {
+    foo ();
+    #pragma omp taskgroup task_reduction (+:n)
+    {
+      bar (0);
+      bar (1);
+    }
+  }
+  baz ();
+  if (m != (long)(N - 1) * (N / 2) || n != (long)(N - 1) * N || o != m)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/taskwait-depend-1.c b/libgomp/testsuite/libgomp.c-c++-common/taskwait-depend-1.c
new file mode 100644 (file)
index 0000000..094b4b3
--- /dev/null
@@ -0,0 +1,29 @@
+#ifdef __cplusplus
+extern "C"
+#endif
+void abort (void);
+
+int
+main ()
+{
+  int a, b, c, d;
+  #pragma omp parallel num_threads (4)
+  #pragma omp single
+  {
+    #pragma omp task depend(out : a)
+    a = 6;
+    #pragma omp task depend(out : b)
+    b = 7;
+    #pragma omp task depend(out : c)
+    c = 8;
+    #pragma omp taskwait depend(in : a, c)
+    d = a + c;
+    #pragma omp task depend(out : a)
+    a = 9;
+    #pragma omp task depend(out : c)
+    c = 10;
+  }
+  if (a != 9 || b != 7 || c != 10 || d != 6 + 8)
+    abort ();
+  return 0;
+}
index 30cfbb1c502bff11c0aa65e2ec9e90bf7c04b29a..d1d6f86733d9368224e22281f76545c61e4fb477 100644 (file)
@@ -20,7 +20,7 @@ foo (int *x)
     #pragma omp for
     for (i = 0; i < 1000; ++i)
       {
-       #pragma omp cancel for if (x[1])
+       #pragma omp cancel for if (cancel: x[1])
        #pragma omp atomic
        v++;
       }
@@ -34,7 +34,7 @@ foo (int *x)
     #pragma omp for
     for (i = 0; i < 1000; ++i)
       {
-       #pragma omp cancel for if (x[3])
+       #pragma omp cancel for if ( cancel : x[3])
        #pragma omp atomic
        v += 2;
       }
@@ -54,7 +54,7 @@ foo (int *x)
        #pragma omp cancel for if (x[0])
        abort ();
       }
-    #pragma omp cancel parallel if (omp_get_thread_num () == 2 && x[4])
+    #pragma omp cancel parallel if (cancel:omp_get_thread_num () == 2 && x[4])
     #pragma omp for
     for (i = 0; i < 1000; ++i)
       {
diff --git a/libgomp/testsuite/libgomp.c/task-reduction-1.c b/libgomp/testsuite/libgomp.c/task-reduction-1.c
new file mode 100644 (file)
index 0000000..224d995
--- /dev/null
@@ -0,0 +1,137 @@
+typedef __SIZE_TYPE__ size_t;
+extern void abort (void);
+
+void
+bar (int *a, int *b, int *c, int (*d)[2], int (*e)[4], size_t n, int f[1][n], int g[1][n * 2])
+{
+  #pragma omp task in_reduction (*: a[:n], b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+  {
+    a[0] *= 12;
+    a[1] *= 13;
+    b[3] *= 14;
+    b[4] *= 15;
+    c[n] *= 16;
+    c[n + 1] *= 17;
+    d[0][0] *= 18;
+    d[0][1] *= 19;
+    e[0][1] *= 20;
+    e[0][2] *= 21;
+    f[0][0] *= 22;
+    f[0][1] *= 23;
+    g[0][1] *= 24;
+    g[0][2] *= 25;
+  }
+}
+
+void
+foo (size_t n, void *x, void *y, int f[1][n], int g[1][n * 2])
+{
+  int a[n], b[n + 3], c[2 * n];
+  int (*d)[n] = (int (*)[n]) x;
+  int (*e)[n * 2] = (int (*)[n * 2]) y;
+  int i;
+  for (i = 0; i < n; i++)
+    {
+      a[i] = 1;
+      b[i + 3] = 1;
+      c[i + n] = 1;
+      d[0][i] = 1;
+      e[0][i + 1] = 1;
+      f[0][i] = 1;
+      g[0][i + 1] = 1;
+    }
+  #pragma omp taskgroup task_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+  {
+    bar (a, b, c, (int (*)[2]) d, (int (*)[4]) e, n, f, g);
+    #pragma omp task in_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+    {
+      a[0] *= 2;
+      a[1] *= 3;
+      b[3] *= 4;
+      b[4] *= 5;
+      c[n] *= 6;
+      c[n + 1] *= 7;
+      d[0][0] *= 8;
+      d[0][1] *= 9;
+      e[0][1] *= 10;
+      e[0][2] *= 11;
+      f[0][0] *= 12;
+      f[0][1] *= 13;
+      g[0][1] *= 14;
+      g[0][2] *= 15;
+    }
+    n = 0;
+  }
+  if (a[0] != 24 || a[1] != 39 || b[3] != 56 || b[4] != 75)
+    abort ();
+  if (c[2] != 96 || c[3] != 119 || d[0][0] != 144 || d[0][1] != 171)
+    abort ();
+  if (e[0][1] != 200 || e[0][2] != 231 || f[0][0] != 264 || f[0][1] != 299)
+    abort ();
+  if (g[0][1] != 336 || g[0][2] != 375)
+    abort ();
+}
+
+void
+baz (size_t n, void *x, void *y, int f[1][n], int g[1][n * 2])
+{
+  int a[n], b[n + 3], c[2 * n];
+  int (*d)[n] = (int (*)[n]) x;
+  int (*e)[n * 2] = (int (*)[n * 2]) y;
+  int i;
+  for (i = 0; i < n; i++)
+    {
+      a[i] = 1;
+      b[i + 3] = 1;
+      c[i + n] = 1;
+      d[0][i] = 1;
+      e[0][i + 1] = 1;
+      f[0][i] = 1;
+      g[0][i + 1] = 1;
+    }
+  #pragma omp parallel num_threads(2)
+  #pragma omp master
+  #pragma omp taskgroup task_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+  {
+    bar (a, b, c, (int (*)[2]) d, (int (*)[4]) e, n, f, g);
+    #pragma omp task in_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+    {
+      a[0] *= 2;
+      a[1] *= 3;
+      b[3] *= 4;
+      b[4] *= 5;
+      c[n] *= 6;
+      c[n + 1] *= 7;
+      d[0][0] *= 8;
+      d[0][1] *= 9;
+      e[0][1] *= 10;
+      e[0][2] *= 11;
+      f[0][0] *= 12;
+      f[0][1] *= 13;
+      g[0][1] *= 14;
+      g[0][2] *= 15;
+    }
+    n = 0;
+  }
+  if (a[0] != 24 || a[1] != 39 || b[3] != 56 || b[4] != 75)
+    abort ();
+  if (c[2] != 96 || c[3] != 119 || d[0][0] != 144 || d[0][1] != 171)
+    abort ();
+  if (e[0][1] != 200 || e[0][2] != 231 || f[0][0] != 264 || f[0][1] != 299)
+    abort ();
+  if (g[0][1] != 336 || g[0][2] != 375)
+    abort ();
+}
+
+int
+main ()
+{
+  int d[1][2], e[1][4], f[1][2], g[1][4];
+  volatile int two;
+  two = 2;
+  #pragma omp parallel num_threads (2)
+  #pragma omp master
+  foo (two, (void *) d, (void *) e, f, g);
+  baz (two, (void *) d, (void *) e, f, g);
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/task-reduction-2.c b/libgomp/testsuite/libgomp.c/task-reduction-2.c
new file mode 100644 (file)
index 0000000..f5d48c3
--- /dev/null
@@ -0,0 +1,86 @@
+typedef __SIZE_TYPE__ size_t;
+extern void abort (void);
+
+void
+bar (int *a, int *b, int *c, int (*d)[2], int (*e)[4], size_t n, int f[1][n], int g[1][n * 2])
+{
+  #pragma omp task in_reduction (*: a[:n], b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+  {
+    a[0] *= 12;
+    a[1] *= 13;
+    b[3] *= 14;
+    b[4] *= 15;
+    c[n] *= 16;
+    c[n + 1] *= 17;
+    d[0][0] *= 18;
+    d[0][1] *= 19;
+    e[0][1] *= 20;
+    e[0][2] *= 21;
+    f[0][0] *= 22;
+    f[0][1] *= 23;
+    g[0][1] *= 24;
+    g[0][2] *= 25;
+  }
+}
+
+void
+baz (size_t n, void *x, void *y, int f[1][n], int g[1][n * 2])
+{
+  int a[n], b[n + 3], c[2 * n];
+  int (*d)[n] = (int (*)[n]) x;
+  int (*e)[n * 2] = (int (*)[n * 2]) y;
+  int i;
+  for (i = 0; i < n; i++)
+    {
+      a[i] = 1;
+      b[i + 3] = 1;
+      c[i + n] = 1;
+      d[0][i] = 1;
+      e[0][i + 1] = 1;
+      f[0][i] = 1;
+      g[0][i + 1] = 1;
+    }
+  #pragma omp parallel num_threads(2) firstprivate (n) \
+                      reduction (task, *: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+  {
+    #pragma omp master
+    bar (a, b, c, (int (*)[2]) d, (int (*)[4]) e, n, f, g);
+    #pragma omp master
+    #pragma omp task in_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+    {
+      a[0] *= 2;
+      a[1] *= 3;
+      b[3] *= 4;
+      b[4] *= 5;
+      c[n] *= 6;
+      c[n + 1] *= 7;
+      d[0][0] *= 8;
+      d[0][1] *= 9;
+      e[0][1] *= 10;
+      e[0][2] *= 11;
+      f[0][0] *= 12;
+      f[0][1] *= 13;
+      g[0][1] *= 14;
+      g[0][2] *= 15;
+    }
+    n = 0;
+  }
+  if (a[0] != 24 || a[1] != 39 || b[3] != 56 || b[4] != 75)
+    abort ();
+  if (c[2] != 96 || c[3] != 119 || d[0][0] != 144 || d[0][1] != 171)
+    abort ();
+  if (e[0][1] != 200 || e[0][2] != 231 || f[0][0] != 264 || f[0][1] != 299)
+    abort ();
+  if (g[0][1] != 336 || g[0][2] != 375)
+    abort ();
+}
+
+int
+main ()
+{
+  int d[1][2], e[1][4], f[1][2], g[1][4];
+  volatile int two;
+  two = 2;
+  baz (two, (void *) d, (void *) e, f, g);
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/teams-1.c b/libgomp/testsuite/libgomp.c/teams-1.c
new file mode 100644 (file)
index 0000000..c5df837
--- /dev/null
@@ -0,0 +1,27 @@
+#include <omp.h>
+#include <stdlib.h>
+
+int
+main ()
+{
+  #pragma omp teams thread_limit (2)
+  {
+    if (omp_in_parallel ()
+       || omp_get_level () != 0
+       || omp_get_ancestor_thread_num (0) != 0
+       || omp_get_ancestor_thread_num (1) != -1)
+      abort ();
+    omp_set_dynamic (0);
+    omp_set_nested (1);
+    #pragma omp parallel num_threads (2)
+    {
+      if (!omp_in_parallel ()
+         || omp_get_level () != 1
+         || omp_get_ancestor_thread_num (0) != 0
+         || omp_get_ancestor_thread_num (1) != omp_get_thread_num ()
+         || omp_get_ancestor_thread_num (2) != -1)
+       abort ();
+    }
+  }
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/teams-2.c b/libgomp/testsuite/libgomp.c/teams-2.c
new file mode 100644 (file)
index 0000000..2ddf508
--- /dev/null
@@ -0,0 +1,123 @@
+#include <omp.h>
+#include <stdlib.h>
+
+__attribute__((noinline))
+void
+foo (int x, int y, int z, int *a, int *b)
+{
+  if (x == 0)
+    {
+      int i, j;
+      for (i = 0; i < 64; i++)
+       #pragma omp parallel for shared (a, b)
+       for (j = 0; j < 32; j++)
+         foo (3, i, j, a, b);
+    }
+  else if (x == 1)
+    {
+      int i, j;
+      #pragma omp distribute dist_schedule (static, 1)
+      for (i = 0; i < 64; i++)
+       #pragma omp parallel for shared (a, b)
+       for (j = 0; j < 32; j++)
+         foo (3, i, j, a, b);
+    }
+  else if (x == 2)
+    {
+      int j;
+      #pragma omp parallel for shared (a, b)
+      for (j = 0; j < 32; j++)
+       foo (3, y, j, a, b);
+    }
+  else
+    {
+      #pragma omp atomic
+      b[y] += z;
+      #pragma omp atomic
+      *a += 1;
+    }
+}
+
+__attribute__((noinline))
+int
+bar (int x, int y, int z)
+{
+  int a, b[64], i;
+  a = 8;
+  for (i = 0; i < 64; i++)
+    b[i] = i;
+  foo (x, y, z, &a, b);
+  if (x == 0)
+    {
+      if (a != 8 + 64 * 32)
+       return 1;
+      for (i = 0; i < 64; i++)
+       if (b[i] != i + 31 * 32 / 2)
+         return 1;
+    }
+  else if (x == 1)
+    {
+      int c = omp_get_num_teams ();
+      int d = omp_get_team_num ();
+      int e = d;
+      int f = 0;
+      for (i = 0; i < 64; i++)
+       if (i == e)
+         {
+           if (b[i] != i + 31 * 32 / 2)
+             return 1;
+           f++;
+           e = e + c;
+         }
+       else if (b[i] != i)
+         return 1;
+      if (a < 8 || a > 8 + f * 32)
+       return 1;
+    }
+  else if (x == 2)
+    {
+      if (a != 8 + 32)
+       return 1;
+      for (i = 0; i < 64; i++)
+       if (b[i] != i + (i == y ? 31 * 32 / 2 : 0))
+         return 1;
+    }
+  else if (x == 3)
+    {
+      if (a != 8 + 1)
+       return 1;
+      for (i = 0; i < 64; i++)
+       if (b[i] != i + (i == y ? z : 0))
+         return 1;
+    }
+  return 0;
+}
+
+int
+main ()
+{
+  int i, j, err = 0;
+  #pragma omp teams reduction(+:err)
+  err += bar (0, 0, 0);
+  if (err)
+    abort ();
+  #pragma omp teams reduction(+:err)
+  err += bar (1, 0, 0);
+  if (err)
+    abort ();
+  #pragma omp teams reduction(+:err)
+  #pragma omp distribute
+  for (i = 0; i < 64; i++)
+    err += bar (2, i, 0);
+  if (err)
+    abort ();
+  #pragma omp teams reduction(+:err)
+  #pragma omp distribute
+  for (i = 0; i < 64; i++)
+  #pragma omp parallel for reduction(+:err)
+    for (j = 0; j < 32; j++)
+      err += bar (3, i, j);
+  if (err)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/thread-limit-4.c b/libgomp/testsuite/libgomp.c/thread-limit-4.c
new file mode 100644 (file)
index 0000000..5642e6a
--- /dev/null
@@ -0,0 +1,57 @@
+/* { dg-do run } */
+/* { dg-set-target-env-var OMP_THREAD_LIMIT "9" } */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <omp.h>
+
+int
+main ()
+{
+  if (omp_get_thread_limit () != 9)
+    return 0;
+  omp_set_dynamic (0);
+  #pragma omp parallel num_threads (8)
+  if (omp_get_num_threads () != 8)
+    abort ();
+  #pragma omp parallel num_threads (16)
+  if (omp_get_num_threads () > 9)
+    abort ();
+  #pragma omp teams thread_limit (6)
+  {
+    if (omp_get_thread_limit () > 6)
+      abort ();
+    if (omp_get_thread_limit () == 6)
+      {
+       omp_set_dynamic (0);
+       omp_set_nested (1);
+       #pragma omp parallel num_threads (3)
+       if (omp_get_num_threads () != 3)
+         abort ();
+       #pragma omp parallel num_threads (3)
+       if (omp_get_num_threads () != 3)
+         abort ();
+       #pragma omp parallel num_threads (8)
+       if (omp_get_num_threads () > 6)
+         abort ();
+       #pragma omp parallel num_threads (6)
+       if (omp_get_num_threads () != 6)
+         abort ();
+       int cnt = 0;
+       #pragma omp parallel num_threads (5)
+       #pragma omp parallel num_threads (5)
+       #pragma omp parallel num_threads (2)
+       {
+         int v;
+         #pragma omp atomic capture
+         v = ++cnt;
+         if (v > 6)
+           abort ();
+         usleep (10000);
+         #pragma omp atomic
+         --cnt;
+       }
+      }
+  }
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/thread-limit-5.c b/libgomp/testsuite/libgomp.c/thread-limit-5.c
new file mode 100644 (file)
index 0000000..d3d22b1
--- /dev/null
@@ -0,0 +1,11 @@
+#include <stdlib.h>
+#include <omp.h>
+
+int
+main ()
+{
+  #pragma omp teams thread_limit (1)
+  if (omp_get_thread_limit () != 1)
+    abort ();
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.fortran/display-affinity-1.f90 b/libgomp/testsuite/libgomp.fortran/display-affinity-1.f90
new file mode 100644 (file)
index 0000000..4811b6f
--- /dev/null
@@ -0,0 +1,34 @@
+! { dg-set-target-env-var OMP_PROC_BIND "spread,close" }
+! { dg-set-target-env-var OMP_PLACES "cores" }
+! { dg-set-target-env-var OMP_NUM_THREADS "4" }
+! { dg-set-target-env-var OMP_AFFINITY_FORMAT "hello" }
+
+  use omp_lib
+  character(len=68) :: buf, buf2
+  character(len=8) :: buf3
+  character(len=1) :: buf4
+  integer :: l1, l2
+
+  buf = 'L:%0.5L%%%n>%32H<!%.33{host}!%.6P_%i_%0.18i_%0.7{ancestor_tnum} %18A'
+  call omp_set_affinity_format (format = buf)
+  if (omp_get_affinity_format (buf4) /= 68) stop 1
+  if (buf4 /= 'L') stop 2
+  if (omp_get_affinity_format (buf2) /= 68) stop 3
+  if (buf2 /= buf) stop 4
+  if (omp_get_affinity_format (buf3) /= 68) stop 5
+  if (buf3 /= 'L:%0.5L%') stop 6
+  call omp_display_affinity ('')
+  call omp_display_affinity ('%%%0.9N')
+  l1 = omp_capture_affinity (buf4, '%0.5{nesting_level}%%|||%0.7a%3N!%N!')
+  buf = '%.5L%%|||%0.7{ancestor_tnum}%3{num_threads}!%{num_threads}!'
+  call omp_set_affinity_format (trim (buf))
+  l2 = omp_capture_affinity (buf2, '')
+  if (l1 /= l2) stop 7
+  if (l1 /= 22) stop 8
+  if (buf2 /= '    0%|||-0000011  !1!') stop 9
+  if (buf4 /= '0') stop 10
+!$omp parallel num_threads (4) proc_bind(spread)
+  call omp_display_affinity ('%0.2a!%n!%.4L!%N;%.2t;%0.2T;&
+                             &%{team_num};%{num_teams};%A')
+!$omp end parallel
+end
index b2b341452892d093e4fe3a9cb957d06b802d82e5..16fc7076eddf8d6a69024bcc1e4a163c4ec6eee0 100644 (file)
@@ -76,7 +76,15 @@ alloc_work_share (struct gomp_team *team)
 #endif
 
   team->work_share_chunk *= 2;
+  /* Allocating gomp_work_share structures aligned is just an
+     optimization, don't do it when using the fallback method.  */
+#ifdef GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC
+  ws = gomp_aligned_alloc (__alignof (struct gomp_work_share),
+                          team->work_share_chunk
+                          * sizeof (struct gomp_work_share));
+#else
   ws = gomp_malloc (team->work_share_chunk * sizeof (struct gomp_work_share));
+#endif
   ws->next_alloc = team->work_shares[0].next_alloc;
   team->work_shares[0].next_alloc = ws;
   team->work_share_list_alloc = &ws[1];
@@ -90,30 +98,35 @@ alloc_work_share (struct gomp_team *team)
    This shouldn't touch the next_alloc field.  */
 
 void
-gomp_init_work_share (struct gomp_work_share *ws, bool ordered,
+gomp_init_work_share (struct gomp_work_share *ws, size_t ordered,
                      unsigned nthreads)
 {
   gomp_mutex_init (&ws->lock);
   if (__builtin_expect (ordered, 0))
     {
-#define INLINE_ORDERED_TEAM_IDS_CNT \
-  ((sizeof (struct gomp_work_share) \
-    - offsetof (struct gomp_work_share, inline_ordered_team_ids)) \
-   / sizeof (((struct gomp_work_share *) 0)->inline_ordered_team_ids[0]))
-
-      if (nthreads > INLINE_ORDERED_TEAM_IDS_CNT)
-       ws->ordered_team_ids
-         = gomp_malloc (nthreads * sizeof (*ws->ordered_team_ids));
+#define INLINE_ORDERED_TEAM_IDS_SIZE \
+  (sizeof (struct gomp_work_share) \
+   - offsetof (struct gomp_work_share, inline_ordered_team_ids))
+
+      if (__builtin_expect (ordered != 1, 0))
+       {
+         ordered += nthreads * sizeof (*ws->ordered_team_ids) - 1;
+         ordered = ordered + __alignof__ (long long) - 1;
+         ordered &= ~(__alignof__ (long long) - 1);
+       }
+      else
+       ordered = nthreads * sizeof (*ws->ordered_team_ids);
+      if (ordered > INLINE_ORDERED_TEAM_IDS_SIZE)
+       ws->ordered_team_ids = gomp_malloc (ordered);
       else
        ws->ordered_team_ids = ws->inline_ordered_team_ids;
-      memset (ws->ordered_team_ids, '\0',
-             nthreads * sizeof (*ws->ordered_team_ids));
+      memset (ws->ordered_team_ids, '\0', ordered);
       ws->ordered_num_used = 0;
       ws->ordered_owner = -1;
       ws->ordered_cur = 0;
     }
   else
-    ws->ordered_team_ids = NULL;
+    ws->ordered_team_ids = ws->inline_ordered_team_ids;
   gomp_ptrlock_init (&ws->next_ws, NULL);
   ws->threads_completed = 0;
 }
@@ -166,7 +179,7 @@ free_work_share (struct gomp_team *team, struct gomp_work_share *ws)
    if this was the first thread to reach this point.  */
 
 bool
-gomp_work_share_start (bool ordered)
+gomp_work_share_start (size_t ordered)
 {
   struct gomp_thread *thr = gomp_thread ();
   struct gomp_team *team = thr->ts.team;
@@ -178,7 +191,7 @@ gomp_work_share_start (bool ordered)
       ws = gomp_malloc (sizeof (*ws));
       gomp_init_work_share (ws, ordered, 1);
       thr->ts.work_share = ws;
-      return ws;
+      return true;
     }
 
   ws = thr->ts.work_share;