]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add a restriction on allocate clause (OpenMP 5.0)
authorHafiz Abid Qadeer <abidh@codesourcery.com>
Fri, 18 Feb 2022 21:28:08 +0000 (21:28 +0000)
committerHafiz Abid Qadeer <abidh@codesourcery.com>
Tue, 8 Mar 2022 19:17:51 +0000 (19:17 +0000)
This is backport of a patch posted in
https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590597.html

An allocate clause in target region must specify an allocator
unless the compilation unit has requires construct with
dynamic_allocators clause.  Current implementation of the allocate
clause did not check for this restriction. This patch fills that
gap.

gcc/ChangeLog:

* omp-low.c (omp_maybe_offloaded_ctx): New prototype.
(scan_sharing_clauses):  Check a restriction on allocate clause.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/allocate-2.c: Add tests.
* c-c++-common/gomp/allocate-8.c: New test.
* gfortran.dg/gomp/allocate-3.f90: Add tests.
* gcc.dg/gomp/pr104517.c: Update.

gcc/ChangeLog.omp
gcc/omp-low.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/c-c++-common/gomp/allocate-2.c
gcc/testsuite/c-c++-common/gomp/allocate-8.c [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/allocate-3.f90

index a8e810ee746ec80143fe847ad7551ba280ccbb91..77c8f3929284220064366e1aed8a44d9584e5cdb 100644 (file)
@@ -1,3 +1,8 @@
+2022-03-08  Abid Qadeer  <abidh@codesourcery.com>
+
+       * omp-low.c (omp_maybe_offloaded_ctx): New prototype.
+       (scan_sharing_clauses):  Check a restriction on allocate clause.
+
 2022-02-27  Tobias Burnus  <tobias@codesourcery.com>
 
        Backported from master:
index eea258952ad235eaab46be486bc00bf8f999cb30..5e1649f3cb2520c360b79af41c36a56c555b4774 100644 (file)
@@ -204,6 +204,7 @@ static vec<omp_context *> taskreg_contexts;
 
 static void scan_omp (gimple_seq *, omp_context *);
 static tree scan_omp_1_op (tree *, int *, void *);
+static bool omp_maybe_offloaded_ctx (omp_context *ctx);
 
 #define WALK_SUBSTMTS  \
     case GIMPLE_BIND: \
@@ -1416,6 +1417,15 @@ scan_sharing_clauses (tree clauses, omp_context *ctx,
            || !integer_onep (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c))
            || OMP_CLAUSE_ALLOCATE_ALIGN (c) != NULL_TREE))
       {
+       /* The allocate clauses that appear on a target construct or on
+          constructs in a target region must specify an allocator expression
+          unless a requires directive with the dynamic_allocators clause
+          is present in the same compilation unit.  */
+       if (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) == NULL_TREE
+           && ((omp_requires_mask & OMP_REQUIRES_DYNAMIC_ALLOCATORS) == 0)
+           && omp_maybe_offloaded_ctx (ctx))
+         error_at (OMP_CLAUSE_LOCATION (c), "%<allocate%> clause must"
+                   " specify an allocator here");
        if (ctx->allocate_map == NULL)
          ctx->allocate_map = new hash_map<tree, tree>;
        tree val = integer_zero_node;
index 6d8e5abcfacd23ab0897fa74662c2c2f445bed9d..202de55b7e96b09e1faafe7721e0891691fc0bf2 100644 (file)
@@ -1,3 +1,10 @@
+2022-03-08  Abid Qadeer  <abidh@codesourcery.com>
+
+       * c-c++-common/gomp/allocate-2.c: Add tests.
+       * c-c++-common/gomp/allocate-8.c: New test.
+       * gfortran.dg/gomp/allocate-3.f90: Add tests.
+       * gcc.dg/gomp/pr104517.c: Update.
+
 2022-03-08  Abid Qadeer  <abidh@codesourcery.com>
 
        Backported from master:
index cc77efc8ffead59eff2a9decb9c3eb33ec5f6e68..6bb4a8af2e7c8d35654e69f05dcf0e97e03806cf 100644 (file)
@@ -43,3 +43,18 @@ foo (int x, int z)
   #pragma omp parallel private (x) allocate (0 : x)    /* { dg-error "'allocate' clause allocator expression has type 'int' rather than 'omp_allocator_handle_t'" } */
   bar (x, &x, 0);
 }
+
+void
+foo1 ()
+{
+  int a = 10;
+#pragma omp target
+  {
+    #pragma omp parallel private (a) allocate(a) // { dg-error "'allocate' clause must specify an allocator here" }
+    a = 20;
+  }
+#pragma omp target private(a) allocate(a) // { dg-error "'allocate' clause must specify an allocator here" }
+  {
+    a = 30;
+  }
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/allocate-8.c b/gcc/testsuite/c-c++-common/gomp/allocate-8.c
new file mode 100644 (file)
index 0000000..bacefaf
--- /dev/null
@@ -0,0 +1,18 @@
+#pragma omp requires dynamic_allocators
+void
+foo ()
+{
+  int a = 10;
+#pragma omp parallel private (a) allocate(a)
+  a = 20;
+#pragma omp target
+  {
+    #pragma omp parallel private (a) allocate(a)
+    a = 30;
+  }
+#pragma omp target private(a) allocate(a)
+  {
+    a = 40;
+  }
+}
+
index 7b57be980cb3005552c12daee0e9671eb3f67fe8..0bee99d2d0c1964b0abe4866a3d79a30710288d7 100644 (file)
@@ -12,3 +12,17 @@ subroutine foo(x)
   !$omp end parallel do simd
 
 end subroutine
+
+subroutine bar(a)
+  implicit none
+  integer  :: a
+!$omp target
+  !$omp parallel private (a) allocate(a) ! { dg-error "'allocate' clause must specify an allocator here" }
+    a = 20
+  !$omp end parallel
+!$omp end target
+
+!$omp target private(a) allocate(a) ! { dg-error "'allocate' clause must specify an allocator here" }
+  a = 30;
+!$omp end target
+end subroutine