From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1534) id 61320385E017; Fri, 4 Jun 2021 09:23:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61320385E017 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Tobias Burnus To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-11] openmp: Assorted depend/affinity/iterator related fixes [PR100859] X-Act-Checkin: gcc X-Git-Author: Tobias Burnus X-Git-Refname: refs/heads/devel/omp/gcc-11 X-Git-Oldrev: 1f17d3af97e9be62449188a1985f5b7addd936f5 X-Git-Newrev: 2673ef51f0f4e73815a93d6993556090aa3c006e Message-Id: <20210604092324.61320385E017@sourceware.org> Date: Fri, 4 Jun 2021 09:23:24 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Jun 2021 09:23:24 -0000 https://gcc.gnu.org/g:2673ef51f0f4e73815a93d6993556090aa3c006e commit 2673ef51f0f4e73815a93d6993556090aa3c006e Author: Tobias Burnus Date: Fri Jun 4 11:19:55 2021 +0200 openmp: Assorted depend/affinity/iterator related fixes [PR100859] The depend-iterator-3.C testcases shows various bugs. 1) tsubst_omp_clauses didn't handle OMP_CLAUSE_AFFINITY (should be handled like OMP_CLAUSE_DEPEND) 2) because locators can be arbitrary lvalue expressions, we need to allow for C++ array section base (especially when array section is just an array reference) FIELD_DECLs, handle them as this->member, but don't need to privatize in any way 3) similarly for this as base 4) depend(inout: this) is invalid, but for different reason than the reported one, again this is an expression, but not lvalue expression, so that should be reported 5) the ctor/dtor cloning in the C++ FE (which is using walk_tree with copy_tree_body_r) didn't handle iterators correctly, walk_tree normally doesn't walk TREE_PURPOSE of TREE_LIST, and in the iterator case that TREE_VEC contains also a BLOCK that needs special handling during copy_tree_body_r 2021-06-03 Jakub Jelinek PR c++/100859 gcc/ * tree-inline.c (copy_tree_body_r): Handle iterators on OMP_CLAUSE_AFFINITY or OMP_CLAUSE_DEPEND. gcc/c/ * c-typeck.c (c_finish_omp_clauses): Move OMP_CLAUSE_AFFINITY after depend only cases. gcc/cp/ * semantics.c (handle_omp_array_sections_1): For OMP_CLAUSE_{AFFINITY,DEPEND} handle FIELD_DECL base using finish_non_static_data_member and allow this as base. (finish_omp_clauses): Move OMP_CLAUSE_AFFINITY after depend only cases. Let this be diagnosed by !lvalue_p case for OMP_CLAUSE_{AFFINITY,DEPEND} and remove useless assert. * pt.c (tsubst_omp_clauses): Handle OMP_CLAUSE_AFFINITY. gcc/testsuite/ * g++.dg/gomp/depend-iterator-3.C: New test. * g++.dg/gomp/this-1.C: Don't expect any diagnostics for this as base expression of depend array section, expect a different error wording for this as depend locator and add testcases for affinity clauses. (cherry picked from commit 098f4e989beb1a1be1157430c56ea4f158c1d538) Diff: --- gcc/ChangeLog.omp | 9 ++++++ gcc/c/ChangeLog.omp | 9 ++++++ gcc/c/c-typeck.c | 7 +++-- gcc/cp/ChangeLog.omp | 15 ++++++++++ gcc/cp/pt.c | 1 + gcc/cp/semantics.c | 28 ++++++++--------- gcc/testsuite/ChangeLog.omp | 12 ++++++++ gcc/testsuite/g++.dg/gomp/depend-iterator-3.C | 43 +++++++++++++++++++++++++++ gcc/testsuite/g++.dg/gomp/this-1.C | 16 +++++++--- gcc/tree-inline.c | 21 +++++++++++++ 10 files changed, 139 insertions(+), 22 deletions(-) diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index f4131ffc9cc..df5f83dd488 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,12 @@ +2021-06-04 Tobias Burnus + + Backported from master: + 2021-06-03 Jakub Jelinek + + PR c++/100859 + * tree-inline.c (copy_tree_body_r): Handle iterators on + OMP_CLAUSE_AFFINITY or OMP_CLAUSE_DEPEND. + 2021-05-31 Tobias Burnus Backported from master: diff --git a/gcc/c/ChangeLog.omp b/gcc/c/ChangeLog.omp index c42f0d8b114..2f9d98bca6f 100644 --- a/gcc/c/ChangeLog.omp +++ b/gcc/c/ChangeLog.omp @@ -1,3 +1,12 @@ +2021-06-04 Tobias Burnus + + Backported from master: + 2021-06-03 Jakub Jelinek + + PR c++/100859 + * c-typeck.c (c_finish_omp_clauses): Move OMP_CLAUSE_AFFINITY + after depend only cases. + 2021-05-28 Tobias Burnus Backported from master: diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index a84e14f087a..015144c24d8 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -14632,7 +14632,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) @@ -14641,8 +14640,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)) @@ -14670,6 +14668,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/ChangeLog.omp b/gcc/cp/ChangeLog.omp index 5e2685b3e60..d58fe1d926d 100644 --- a/gcc/cp/ChangeLog.omp +++ b/gcc/cp/ChangeLog.omp @@ -1,3 +1,18 @@ +2021-06-04 Tobias Burnus + + Backported from master: + 2021-06-03 Jakub Jelinek + + PR c++/100859 + * semantics.c (handle_omp_array_sections_1): For + OMP_CLAUSE_{AFFINITY,DEPEND} handle FIELD_DECL base using + finish_non_static_data_member and allow this as base. + (finish_omp_clauses): Move OMP_CLAUSE_AFFINITY + after depend only cases. Let this be diagnosed by !lvalue_p + case for OMP_CLAUSE_{AFFINITY,DEPEND} and remove useless + assert. + * pt.c (tsubst_omp_clauses): Handle OMP_CLAUSE_AFFINITY. + 2021-05-28 Tobias Burnus Backported from master: diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 59f5513fc79..f59850fccfa 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -17480,6 +17480,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 0f2c5621b82..cf23f9fbb45 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -4990,7 +4990,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; @@ -5010,7 +5014,9 @@ handle_omp_array_sections_1 (tree c, tree t, vec &types, && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FROM && 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 %" @@ -7579,7 +7585,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) @@ -7588,13 +7593,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) @@ -7627,13 +7634,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)) @@ -7654,11 +7654,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/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp index ccc44b3186f..171848f7085 100644 --- a/gcc/testsuite/ChangeLog.omp +++ b/gcc/testsuite/ChangeLog.omp @@ -1,3 +1,15 @@ +2021-06-04 Tobias Burnus + + Backported from master: + 2021-06-03 Jakub Jelinek + + PR c++/100859 + * g++.dg/gomp/depend-iterator-3.C: New test. + * g++.dg/gomp/this-1.C: Don't expect any diagnostics for + this as base expression of depend array section, expect a different + error wording for this as depend locator and add testcases + for affinity clauses. + 2021-06-01 Tobias Burnus Backported from master: 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]) + ; + #pragma omp task affinity(this) // { dg-error ".this. is not lvalue expression nor array section in .affinity. clause" } ; - #pragma omp task depend(inout: this[0]) // { dg-error ".this. allowed in OpenMP only in .declare simd. clauses" } + #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 1dcb31c0267..28f0cd6f219 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1477,6 +1477,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. */