]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Diagnose using grainsize+num_tasks clauses together [PR115103]
authorJakub Jelinek <jakub@redhat.com>
Wed, 15 May 2024 16:34:44 +0000 (18:34 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 15 May 2024 16:34:44 +0000 (18:34 +0200)
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  <jakub@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.

gcc/c/c-typeck.cc
gcc/cp/semantics.cc
gcc/fortran/openmp.cc
gcc/testsuite/c-c++-common/gomp/clause-dups-1.c
gcc/testsuite/gfortran.dg/gomp/pr115103.f90 [new file with mode: 0644]

index 4567b114734b711df054b4502b522007e6563fd1..7ecca9f58c684aeaca5e7276fb1fc297eff78eaf 100644 (file)
@@ -14722,6 +14722,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;
@@ -16021,8 +16023,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:
@@ -16048,6 +16048,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);
@@ -16333,6 +16343,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 (detach_seen)
     {
       if (mergeable_seen)
index df62e2d80dbd3016d1f7dee919abd1f36150f2cf..f90c304a65b7709e2ab1447b94b8dd3a551a279a 100644 (file)
@@ -7098,6 +7098,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
   bool mergeable_seen = false;
   bool implicit_moved = false;
   bool target_in_reduction_seen = false;
+  bool num_tasks_seen = false;
 
   bitmap_obstack_initialize (NULL);
   bitmap_initialize (&generic_head, &bitmap_default_obstack);
@@ -7656,6 +7657,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:
@@ -9246,6 +9251,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),
index 315ec68f259d12c150119d8127f4c3948427bd09..5246647e6f87ebd8ce5688fc52d48628a1826fed 100644 (file)
@@ -9175,6 +9175,13 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
     resolve_positive_int_expr (omp_clauses->grainsize, "GRAINSIZE");
   if (omp_clauses->num_tasks)
     resolve_positive_int_expr (omp_clauses->num_tasks, "NUM_TASKS");
+  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");
index a17f68dfb6b293bf16d1fc1aff5d9f4a0f7f4b1f..6fc53e83f0101c04cbd77c334d50075bf3a71557 100644 (file)
@@ -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 (file)
index 0000000..9fb4979
--- /dev/null
@@ -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