From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1729) id BFE4A3850203; Wed, 29 Jun 2022 14:44:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BFE4A3850203 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Kwok Yeung To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-12] Add a restriction on allocate clause (OpenMP 5.0) X-Act-Checkin: gcc X-Git-Author: Hafiz Abid Qadeer X-Git-Refname: refs/heads/devel/omp/gcc-12 X-Git-Oldrev: a6c1eccffb161130351d891dc87f5afe54f8075c X-Git-Newrev: df47c25110474565f521508a1545232550052a75 Message-Id: <20220629144439.BFE4A3850203@sourceware.org> Date: Wed, 29 Jun 2022 14:44:39 +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: Wed, 29 Jun 2022 14:44:39 -0000 https://gcc.gnu.org/g:df47c25110474565f521508a1545232550052a75 commit df47c25110474565f521508a1545232550052a75 Author: Hafiz Abid Qadeer 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.cc (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.cc | 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 4765deaac24..c9645410b4b 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,8 @@ +2022-03-08 Abid Qadeer + + * omp-low.cc (omp_maybe_offloaded_ctx): New prototype. + (scan_sharing_clauses): Check a restriction on allocate clause. + 2022-03-01 Tobias Burnus * langhooks-def.h (lhd_omp_deep_mapping_p, diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc index 8c2f3c0dd23..4d50d87b1ac 100644 --- a/gcc/omp-low.cc +++ b/gcc/omp-low.cc @@ -205,6 +205,7 @@ static vec task_cpyfns; 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: \ @@ -1400,6 +1401,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), "% clause must" + " specify an allocator here"); if (ctx->allocate_map == NULL) ctx->allocate_map = new hash_map; tree val = integer_zero_node; diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp index d9cbad5236c..978e183a7f4 100644 --- a/gcc/testsuite/ChangeLog.omp +++ b/gcc/testsuite/ChangeLog.omp @@ -1,3 +1,10 @@ +2022-03-08 Abid Qadeer + + * 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-01 Tobias Burnus * gfortran.dg/c_loc_test_22.f90: Update scan-tree. 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