From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1534) id C3B1F3858CDB; Wed, 15 Feb 2023 10:48:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3B1F3858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676458125; bh=b45FrE6aTKCPF5341EUaajlDdwih33mRgEDYe/eAeCY=; h=From:To:Subject:Date:From; b=CbomUDmr99HEwAJftwD36CqbrFYOVZxYxL4Ru0GZEiaqLc+Mc18U9TynYXhCRk5HU 51WqgjSfdRljJdDSS9EtLqJ/d2Q9hEweXdvyDzZFKmImR+d1ABqv29Et4fPGm47fnW sQnWJBPJnXY7H5fZ430H91GWLZOhnqFp6MG6eobk= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Tobias Burnus To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-12] libgomp: Fix 'target enter data' with always pointer X-Act-Checkin: gcc X-Git-Author: Tobias Burnus X-Git-Refname: refs/heads/devel/omp/gcc-12 X-Git-Oldrev: e7279cc2eda2a0c50cff19ee4e02eea3d7808f68 X-Git-Newrev: ec6bf735cf752818b5fd5b53100552ee3d06f62e Message-Id: <20230215104845.C3B1F3858CDB@sourceware.org> Date: Wed, 15 Feb 2023 10:48:45 +0000 (GMT) List-Id: https://gcc.gnu.org/g:ec6bf735cf752818b5fd5b53100552ee3d06f62e commit ec6bf735cf752818b5fd5b53100552ee3d06f62e Author: Tobias Burnus Date: Wed Feb 15 11:40:21 2023 +0100 libgomp: Fix 'target enter data' with always pointer As GOMP_MAP_ALWAYS_POINTER operates on the previous map item, ensure that with 'target enter data' both are passed together to gomp_map_vars_internal. libgomp/ChangeLog: * target.c (gomp_map_vars_internal): Add 'i > 0' before doing a kind check. (GOMP_target_enter_exit_data): If the next map item is GOMP_MAP_ALWAYS_POINTER map it together with the current item. * testsuite/libgomp.fortran/target-enter-data-4.f90: New test. (cherry picked from commit c7a9655be60cb4f224d1e5906bfe8ae227b5a3a0) (Testfile added as target-enter-data-4.f90 as ...-3.f90 already existed.) Diff: --- libgomp/ChangeLog.omp | 11 +++++++++++ libgomp/target.c | 10 +++++++--- .../libgomp.fortran/target-enter-data-4.f90 | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp index 67065f59922..6216ea41b2e 100644 --- a/libgomp/ChangeLog.omp +++ b/libgomp/ChangeLog.omp @@ -1,3 +1,14 @@ +2023-02-15 Tobias Burnus + + Backported from master: + 2023-02-15 Tobias Burnus + + * target.c (gomp_map_vars_internal): Add 'i > 0' before doing a + kind check. + (GOMP_target_enter_exit_data): If the next map item is + GOMP_MAP_ALWAYS_POINTER map it together with the current item. + * testsuite/libgomp.fortran/target-enter-data-4.f90: New test. + 2023-02-14 Thomas Schwinge * target.c (gomp_target_rev): Address cast to pointer from integer diff --git a/libgomp/target.c b/libgomp/target.c index 6edfc9214e4..ea7a1c3c097 100644 --- a/libgomp/target.c +++ b/libgomp/target.c @@ -1561,8 +1561,9 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep, gomp_mutex_unlock (&devicep->lock); gomp_fatal ("always pointer not mapped"); } - if ((get_kind (short_mapkind, kinds, i - 1) & typemask) - != GOMP_MAP_ALWAYS_POINTER) + if (i > 0 + && ((get_kind (short_mapkind, kinds, i - 1) & typemask) + != GOMP_MAP_ALWAYS_POINTER)) cur_node.tgt_offset = gomp_map_val (tgt, hostaddrs, i - 1); if (cur_node.tgt_offset) cur_node.tgt_offset -= sizes[i]; @@ -4338,7 +4339,10 @@ GOMP_target_enter_exit_data (int device, size_t mapnum, void **hostaddrs, GOMP_MAP_VARS_ENTER_DATA); i += j - i - 1; } - else if (i + 1 < mapnum && (kinds[i + 1] & 0xff) == GOMP_MAP_ATTACH) + else if (i + 1 < mapnum + && ((kinds[i + 1] & 0xff) == GOMP_MAP_ATTACH + || ((kinds[i + 1] & 0xff) == GOMP_MAP_ALWAYS_POINTER + && (kinds[i] & 0xff) != GOMP_MAP_ALWAYS_POINTER))) { /* An attach operation must be processed together with the mapped base-pointer list item. */ diff --git a/libgomp/testsuite/libgomp.fortran/target-enter-data-4.f90 b/libgomp/testsuite/libgomp.fortran/target-enter-data-4.f90 new file mode 100644 index 00000000000..5d97566c66c --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/target-enter-data-4.f90 @@ -0,0 +1,22 @@ +implicit none +type t + integer :: dummy + integer, pointer :: p1(:), p2(:) + integer :: dummy2 +end type t +type(t) :: var +integer :: i +allocate(var%p1(5),var%p2(2:4)) +var%p1 = [22,53,28,6,4] +var%p2 = [46,679,54] + +!$omp target enter data map(to:var%p1, var%p2) +!$omp target + if (.not.associated(var%p1).or.lbound(var%p1,1)/=1.or.ubound(var%p1,1)/=5) stop 1 + if (.not.associated(var%p2).or.lbound(var%p2,1)/=2.or.ubound(var%p2,1)/=4) stop 2 + if (any (var%p1 /= [22,53,28,6,4])) stop 3 + if (any (var%p2 /= [46,679,54])) stop 4 +!$omp end target +!!$omp target exit data map(from:var%p1, var%p2) +end +