public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Hafiz Abid Qadeer <abidh@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/omp/gcc-11] Add a restriction on allocate clause (OpenMP 5.0)
Date: Wed,  9 Mar 2022 10:02:17 +0000 (GMT)	[thread overview]
Message-ID: <20220309100217.E87C33858031@sourceware.org> (raw)

https://gcc.gnu.org/g:68115abc85880f7202b5e3952e8c407a0f4e0f56

commit 68115abc85880f7202b5e3952e8c407a0f4e0f56
Author: Hafiz Abid Qadeer <abidh@codesourcery.com>
Date:   Fri Feb 18 21:28:08 2022 +0000

    Add a restriction on allocate clause (OpenMP 5.0)
    
    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.

Diff:
---
 gcc/ChangeLog.omp                             |  5 +++++
 gcc/omp-low.c                                 | 10 ++++++++++
 gcc/testsuite/ChangeLog.omp                   |  7 +++++++
 gcc/testsuite/c-c++-common/gomp/allocate-2.c  | 15 +++++++++++++++
 gcc/testsuite/c-c++-common/gomp/allocate-8.c  | 18 ++++++++++++++++++
 gcc/testsuite/gfortran.dg/gomp/allocate-3.f90 | 14 ++++++++++++++
 6 files changed, 69 insertions(+)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index a8e810ee746..77c8f392928 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -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:
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index eea258952ad..5e1649f3cb2 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -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;
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 6d8e5abcfac..202de55b7e9 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -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:
diff --git a/gcc/testsuite/c-c++-common/gomp/allocate-2.c b/gcc/testsuite/c-c++-common/gomp/allocate-2.c
index cc77efc8ffe..6bb4a8af2e7 100644
--- a/gcc/testsuite/c-c++-common/gomp/allocate-2.c
+++ b/gcc/testsuite/c-c++-common/gomp/allocate-2.c
@@ -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
index 00000000000..bacefafc6fc
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/allocate-8.c
@@ -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;
+  }
+}
+
diff --git a/gcc/testsuite/gfortran.dg/gomp/allocate-3.f90 b/gcc/testsuite/gfortran.dg/gomp/allocate-3.f90
index 7b57be980cb..0bee99d2d0c 100644
--- a/gcc/testsuite/gfortran.dg/gomp/allocate-3.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/allocate-3.f90
@@ -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


                 reply	other threads:[~2022-03-09 10:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220309100217.E87C33858031@sourceware.org \
    --to=abidh@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).