diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 5f322874423..be3f4f09f6e 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -14557,7 +14557,6 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) } break; - case OMP_CLAUSE_AFFINITY: case OMP_CLAUSE_DEPEND: t = OMP_CLAUSE_DECL (c); if (t == NULL_TREE) @@ -14566,8 +14565,7 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) == OMP_CLAUSE_DEPEND_SOURCE); break; } - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND - && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SINK) + if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SINK) { gcc_assert (TREE_CODE (t) == TREE_LIST); for (; t; t = TREE_CHAIN (t)) @@ -14595,6 +14593,9 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) } break; } + /* FALLTHRU */ + case OMP_CLAUSE_AFFINITY: + t = OMP_CLAUSE_DECL (c); if (TREE_CODE (t) == TREE_LIST && TREE_PURPOSE (t) && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 31302803c62..15ef4882875 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -17399,6 +17399,7 @@ tsubst_omp_clauses (tree clauses, enum c_omp_region_type ort, case OMP_CLAUSE_COPYPRIVATE: case OMP_CLAUSE_UNIFORM: case OMP_CLAUSE_DEPEND: + case OMP_CLAUSE_AFFINITY: case OMP_CLAUSE_FROM: case OMP_CLAUSE_TO: case OMP_CLAUSE_MAP: diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index e40462d192a..d08c1ddabf9 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -4968,7 +4968,11 @@ handle_omp_array_sections_1 (tree c, tree t, vec &types, if (REFERENCE_REF_P (t)) t = TREE_OPERAND (t, 0); } - if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) + if (TREE_CODE (t) == FIELD_DECL + && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)) + ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE); + else if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) { if (processing_template_decl && TREE_CODE (t) != OVERLOAD) return NULL_TREE; @@ -4985,7 +4989,9 @@ handle_omp_array_sections_1 (tree c, tree t, vec &types, else if (ort == C_ORT_OMP && TREE_CODE (t) == PARM_DECL && DECL_ARTIFICIAL (t) - && DECL_NAME (t) == this_identifier) + && DECL_NAME (t) == this_identifier + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND) { error_at (OMP_CLAUSE_LOCATION (c), "% allowed in OpenMP only in %" @@ -7468,7 +7474,6 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) } goto handle_field_decl; - case OMP_CLAUSE_AFFINITY: case OMP_CLAUSE_DEPEND: t = OMP_CLAUSE_DECL (c); if (t == NULL_TREE) @@ -7477,13 +7482,15 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) == OMP_CLAUSE_DEPEND_SOURCE); break; } - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND - && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SINK) + if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SINK) { if (cp_finish_omp_clause_depend_sink (c)) remove = true; break; } + /* FALLTHRU */ + case OMP_CLAUSE_AFFINITY: + t = OMP_CLAUSE_DECL (c); if (TREE_CODE (t) == TREE_LIST && TREE_PURPOSE (t) && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC) @@ -7516,13 +7523,6 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) } if (t == error_mark_node) remove = true; - else if (ort != C_ORT_ACC && t == current_class_ptr) - { - error_at (OMP_CLAUSE_LOCATION (c), - "% allowed in OpenMP only in %" - " clauses"); - remove = true; - } else if (processing_template_decl && TREE_CODE (t) != OVERLOAD) break; else if (!lvalue_p (t)) @@ -7543,11 +7543,9 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL && DECL_BIT_FIELD (TREE_OPERAND (t, 1))) { - gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND - || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY); error_at (OMP_CLAUSE_LOCATION (c), "bit-field %qE in %qs clause", t, - omp_clause_code_name[OMP_CLAUSE_CODE (c)]); + omp_clause_code_name[OMP_CLAUSE_CODE (c)]); remove = true; } else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND diff --git a/gcc/testsuite/g++.dg/gomp/depend-iterator-3.C b/gcc/testsuite/g++.dg/gomp/depend-iterator-3.C new file mode 100644 index 00000000000..1a7f29a3f0f --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/depend-iterator-3.C @@ -0,0 +1,43 @@ +// PR c++/100859 + +struct S { + S () {} +}; + +struct W { + S c[10]; + W () { +#pragma omp task affinity (iterator (i = 0 : 10 : 1): c[i]) + ; +#pragma omp task depend (iterator (i = 0 : 10 : 1), inout: c[i]) + ; +#pragma omp task affinity (this[0]) + ; +#pragma omp task depend (inout: this[0]) + ; +#pragma omp taskwait + } +}; + +template +struct U { + T c[10]; + U () { +#pragma omp task affinity (iterator (i = 0 : 10 : 1): c[i]) + ; +#pragma omp task depend (iterator (i = 0 : 10 : 1), inout: c[i]) + ; +#pragma omp task affinity (this[0]) + ; +#pragma omp task depend (inout: this[0]) + ; +#pragma omp taskwait + } +}; + +struct V : public U { + V () : U () {} +}; + +W w; +V v; diff --git a/gcc/testsuite/g++.dg/gomp/this-1.C b/gcc/testsuite/g++.dg/gomp/this-1.C index e7bd5831118..1bffc912c4a 100644 --- a/gcc/testsuite/g++.dg/gomp/this-1.C +++ b/gcc/testsuite/g++.dg/gomp/this-1.C @@ -21,9 +21,13 @@ S::bar () #pragma omp for linear (this) // { dg-error ".this. allowed in OpenMP only in .declare simd. clauses" } for (int i = 0; i < 10; i++) ; - #pragma omp task depend(inout: this) // { dg-error ".this. allowed in OpenMP only in .declare simd. clauses" } + #pragma omp task depend(inout: this) // { dg-error ".this. is not lvalue expression nor array section in .depend. clause" } ; - #pragma omp task depend(inout: this[0]) // { dg-error ".this. allowed in OpenMP only in .declare simd. clauses" } + #pragma omp task depend(inout: this[0]) + ; + #pragma omp task affinity(this) // { dg-error ".this. is not lvalue expression nor array section in .affinity. clause" } + ; + #pragma omp task affinity(this[0]) ; #pragma omp parallel private (this) // { dg-error ".this. allowed in OpenMP only in .declare simd. clauses" } { @@ -54,9 +58,13 @@ T::bar () #pragma omp for linear (this) // { dg-error ".this. allowed in OpenMP only in .declare simd. clauses" } for (int i = 0; i < 10; i++) ; - #pragma omp task depend(inout: this) // { dg-error ".this. allowed in OpenMP only in .declare simd. clauses" } + #pragma omp task depend(inout: this) // { dg-error ".this. is not lvalue expression nor array section in .depend. clause" } ; - #pragma omp task depend(inout: this[0]) // { dg-error ".this. allowed in OpenMP only in .declare simd. clauses" } + #pragma omp task depend(inout: this[0]) + ; + #pragma omp task affinity(this) // { dg-error ".this. is not lvalue expression nor array section in .affinity. clause" } + ; + #pragma omp task affinity(this[0]) ; #pragma omp parallel private (this) // { dg-error ".this. allowed in OpenMP only in .declare simd. clauses" } { diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index d38e8617e3d..5396131e176 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1453,6 +1453,27 @@ copy_tree_body_r (tree *tp, int *walk_subtrees, void *data) *walk_subtrees = 0; } + else if (TREE_CODE (*tp) == OMP_CLAUSE + && (OMP_CLAUSE_CODE (*tp) == OMP_CLAUSE_AFFINITY + || OMP_CLAUSE_CODE (*tp) == OMP_CLAUSE_DEPEND)) + { + tree t = OMP_CLAUSE_DECL (*tp); + if (TREE_CODE (t) == TREE_LIST + && TREE_PURPOSE (t) + && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC) + { + *walk_subtrees = 0; + OMP_CLAUSE_DECL (*tp) = copy_node (t); + t = OMP_CLAUSE_DECL (*tp); + TREE_PURPOSE (t) = copy_node (TREE_PURPOSE (t)); + for (int i = 0; i <= 4; i++) + walk_tree (&TREE_VEC_ELT (TREE_PURPOSE (t), i), + copy_tree_body_r, id, NULL); + if (TREE_VEC_ELT (TREE_PURPOSE (t), 5)) + remap_block (&TREE_VEC_ELT (TREE_PURPOSE (t), 5), id); + walk_tree (&TREE_VALUE (t), copy_tree_body_r, id, NULL); + } + } } /* Keep iterating. */