https://gcc.gnu.org/g:d968c3f6f81a39e3041f7226431c94fe633b652a
commit d968c3f6f81a39e3041f7226431c94fe633b652a Author: Jakub Jelinek <ja...@redhat.com> Date: Wed May 15 18:34:44 2024 +0200 openmp: Diagnose using grainsize+num_tasks clauses together [PR115103] I've noticed that while we diagnose many other OpenMP exclusive clauses, we don't diagnose grainsize together with num_tasks on taskloop construct in all of C, C++ and Fortran (the implementation simply ignored grainsize in that case) and for Fortran also don't diagnose mixing nogroup clause with reduction clause(s). Fixed thusly. 2024-05-15 Jakub Jelinek <ja...@redhat.com> PR c/115103 gcc/c/ * c-typeck.cc (c_finish_omp_clauses): Diagnose grainsize used together with num_tasks. gcc/cp/ * semantics.cc (finish_omp_clauses): Diagnose grainsize used together with num_tasks. gcc/fortran/ * openmp.cc (resolve_omp_clauses): Diagnose grainsize used together with num_tasks or nogroup used together with reduction. gcc/testsuite/ * c-c++-common/gomp/clause-dups-1.c: Add 2 further expected errors. * gfortran.dg/gomp/pr115103.f90: New test. (cherry picked from commit 7fdbefc575c24881356b5f4091fa57b5f7166a90) Diff: --- gcc/c/ChangeLog.omp | 5 +++++ gcc/c/c-typeck.cc | 22 ++++++++++++++++++++-- gcc/cp/ChangeLog.omp | 5 +++++ gcc/cp/semantics.cc | 16 ++++++++++++++++ gcc/fortran/ChangeLog.omp | 6 ++++++ gcc/fortran/openmp.cc | 7 +++++++ gcc/testsuite/ChangeLog.omp | 5 +++++ gcc/testsuite/c-c++-common/gomp/clause-dups-1.c | 4 ++-- gcc/testsuite/gfortran.dg/gomp/pr115103.f90 | 14 ++++++++++++++ 9 files changed, 80 insertions(+), 4 deletions(-) diff --git a/gcc/c/ChangeLog.omp b/gcc/c/ChangeLog.omp index 5221390d138..99afa386844 100644 --- a/gcc/c/ChangeLog.omp +++ b/gcc/c/ChangeLog.omp @@ -1,3 +1,8 @@ +2024-05-15 Jakub Jelinek <ja...@redhat.com> + + * c-typeck.cc (c_finish_omp_clauses): Diagnose grainsize + used together with num_tasks. + 2024-05-04 Sandra Loosemore <sloosem...@baylibre.com> * c-decl.cc (c_decl_attributes): Don't add "omp declare target diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 68226c3c42b..55e8fdf57e7 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -14947,6 +14947,8 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) tree *detach_seen = NULL; bool linear_variable_step_check = false; tree *nowait_clause = NULL; + tree *grainsize_seen = NULL; + bool num_tasks_seen = false; tree ordered_clause = NULL_TREE; tree schedule_clause = NULL_TREE; bool oacc_async = false; @@ -16376,8 +16378,6 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) case OMP_CLAUSE_PROC_BIND: case OMP_CLAUSE_DEVICE_TYPE: case OMP_CLAUSE_PRIORITY: - case OMP_CLAUSE_GRAINSIZE: - case OMP_CLAUSE_NUM_TASKS: case OMP_CLAUSE_THREADS: case OMP_CLAUSE_SIMD: case OMP_CLAUSE_HINT: @@ -16403,6 +16403,16 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) pc = &OMP_CLAUSE_CHAIN (c); continue; + case OMP_CLAUSE_GRAINSIZE: + grainsize_seen = pc; + pc = &OMP_CLAUSE_CHAIN (c); + continue; + + case OMP_CLAUSE_NUM_TASKS: + num_tasks_seen = true; + pc = &OMP_CLAUSE_CHAIN (c); + continue; + case OMP_CLAUSE_MERGEABLE: mergeable_seen = true; pc = &OMP_CLAUSE_CHAIN (c); @@ -16702,6 +16712,14 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) *nogroup_seen = OMP_CLAUSE_CHAIN (*nogroup_seen); } + if (grainsize_seen && num_tasks_seen) + { + error_at (OMP_CLAUSE_LOCATION (*grainsize_seen), + "%<grainsize%> clause must not be used together with " + "%<num_tasks%> clause"); + *grainsize_seen = OMP_CLAUSE_CHAIN (*grainsize_seen); + } + if (full_seen && partial_seen) { error_at (OMP_CLAUSE_LOCATION (*full_seen), diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp index a8f9285a420..f0b50bea7f9 100644 --- a/gcc/cp/ChangeLog.omp +++ b/gcc/cp/ChangeLog.omp @@ -1,3 +1,8 @@ +2024-05-15 Jakub Jelinek <ja...@redhat.com> + + * semantics.cc (finish_omp_clauses): Diagnose grainsize + used together with num_tasks. + 2024-05-04 Sandra Loosemore <sloosem...@baylibre.com> * decl2.cc (cplus_decl_attributes): Don't add "omp declare target diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 0985b060ed1..eab75a12a88 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -7403,6 +7403,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) bool implicit_moved = false; bool target_in_reduction_seen = false; bool partial_seen = false; + bool num_tasks_seen = false; bitmap_obstack_initialize (NULL); bitmap_initialize (&generic_head, &bitmap_default_obstack); @@ -7961,6 +7962,10 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) /* FALLTHRU */ case OMP_CLAUSE_NUM_TASKS: + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TASKS) + num_tasks_seen = true; + /* FALLTHRU */ + case OMP_CLAUSE_NUM_TEAMS: case OMP_CLAUSE_NUM_THREADS: case OMP_CLAUSE_NUM_GANGS: @@ -9745,6 +9750,17 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) } pc = &OMP_CLAUSE_CHAIN (c); continue; + case OMP_CLAUSE_GRAINSIZE: + if (num_tasks_seen) + { + error_at (OMP_CLAUSE_LOCATION (c), + "%<grainsize%> clause must not be used together with " + "%<num_tasks%> clause"); + *pc = OMP_CLAUSE_CHAIN (c); + continue; + } + pc = &OMP_CLAUSE_CHAIN (c); + continue; case OMP_CLAUSE_ORDERED: if (reduction_seen == -2) error_at (OMP_CLAUSE_LOCATION (c), diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp index f62025fdef4..65b918f4ed7 100644 --- a/gcc/fortran/ChangeLog.omp +++ b/gcc/fortran/ChangeLog.omp @@ -1,3 +1,9 @@ +2024-05-15 Jakub Jelinek <ja...@redhat.com> + + * openmp.cc (resolve_omp_clauses): Diagnose grainsize + used together with num_tasks or nogroup used together with + reduction. + 2024-05-04 Sandra Loosemore <sloosem...@baylibre.com> * trans-openmp.cc (gfc_trans_omp_declare_variant): Adjust arguments diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index 714fb2e8646..e869146517a 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -9784,6 +9784,13 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses, if (omp_clauses->full && omp_clauses->partial) gfc_error ("%<FULL%> clause at %C must not be used together with " "%<PARTIAL%> clause"); + if (omp_clauses->grainsize && omp_clauses->num_tasks) + gfc_error ("%<GRAINSIZE%> clause at %L must not be used together with " + "%<NUM_TASKS%> clause", &omp_clauses->grainsize->where); + if (omp_clauses->lists[OMP_LIST_REDUCTION] && omp_clauses->nogroup) + gfc_error ("%<REDUCTION%> clause at %L must not be used together with " + "%<NOGROUP%> clause", + &omp_clauses->lists[OMP_LIST_REDUCTION]->where); if (omp_clauses->async) if (omp_clauses->async_expr) resolve_scalar_int_expr (omp_clauses->async_expr, "ASYNC"); diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp index cc947651296..d1440fbe908 100644 --- a/gcc/testsuite/ChangeLog.omp +++ b/gcc/testsuite/ChangeLog.omp @@ -1,3 +1,8 @@ +2024-05-15 Jakub Jelinek <ja...@redhat.com> + + * c-c++-common/gomp/clause-dups-1.c: Add 2 further expected errors. + * gfortran.dg/gomp/pr115103.f90: New test. + 2024-05-10 Sandra Loosemore <sloosem...@baylibre.com> * c-c++-common/gomp/declare-variant-13.c: Use optimized diff --git a/gcc/testsuite/c-c++-common/gomp/clause-dups-1.c b/gcc/testsuite/c-c++-common/gomp/clause-dups-1.c index a17f68dfb6b..6fc53e83f01 100644 --- a/gcc/testsuite/c-c++-common/gomp/clause-dups-1.c +++ b/gcc/testsuite/c-c++-common/gomp/clause-dups-1.c @@ -107,10 +107,10 @@ f1 (int *p) #pragma omp taskloop num_tasks (2) num_tasks (2) /* { dg-error "too many 'num_tasks' clauses" } */ for (i = 0; i < 8; ++i) f0 (); - #pragma omp taskloop num_tasks (1) grainsize (2) + #pragma omp taskloop num_tasks (1) grainsize (2) /* { dg-error "'grainsize' clause must not be used together with 'num_tasks' clause" } */ for (i = 0; i < 8; ++i) f0 (); - #pragma omp taskloop grainsize (2) num_tasks (2) + #pragma omp taskloop grainsize (2) num_tasks (2) /* { dg-error "'grainsize' clause must not be used together with 'num_tasks' clause" } */ for (i = 0; i < 8; ++i) f0 (); #pragma omp taskloop collapse (1) collapse (1) /* { dg-error "too many 'collapse' clauses" } */ diff --git a/gcc/testsuite/gfortran.dg/gomp/pr115103.f90 b/gcc/testsuite/gfortran.dg/gomp/pr115103.f90 new file mode 100644 index 00000000000..9fb4979f698 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/pr115103.f90 @@ -0,0 +1,14 @@ +subroutine nogroup_reduction + integer :: i, r + r = 0 +!$omp taskloop nogroup reduction(+:r) ! { dg-error "'REDUCTION' clause at .1. must not be used together with 'NOGROUP' clause" } + do i = 1, 32 + r = r + i + end do +end +subroutine grainsize_num_tasks + integer :: i +!$omp taskloop grainsize(2) num_tasks(2) ! { dg-error "'GRAINSIZE' clause at .1. must not be used together with 'NUM_TASKS' clause" } + do i = 1, 32 + end do +end