From patchwork Sat Jan 4 02:25:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 1217475 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-516641-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="iRh0A1qF"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47qQcQ19CVz9s4Y for ; Sat, 4 Jan 2020 13:25:55 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; q=dns; s=default; b=Wt5 TH9Bc5CemGQE2Zu73LvLkPY+rHMbbZOeW5VSEmH8wuIraIGkbUkqzGvgFaYQBDVZ T1SmvaPC66ud+LCje2CJtqQYvR4blpDXZszMRXiBCWs0nTdxjJ9qj4wW/1LiP5Gx 6Al6a/KteqDYIcWW0hsO0uwwimnHLP4bJGwvTDMk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=default; bh=8xShmw59G R0irWeA20eY4YXqVYw=; b=iRh0A1qF/g10BKpIZPV3V55GtJv/XUGTC0I1Xiftg dw2nUR3swGR4AM06tC7DGVyO2sJ3/nSrYc5a9sI2UM50+0bHIXsHA7S2fWEFKiQ3 yLwBAxwuoT/qGAE1g326yqcijkh2gct+4rOYmNRHVpygCVceWTflgXgTmApjSHL/ B4= Received: (qmail 71981 invoked by alias); 4 Jan 2020 02:25:44 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 71964 invoked by uid 89); 4 Jan 2020 02:25:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.1 spammy=goacc, HContent-Transfer-Encoding:8bit X-HELO: esa3.mentor.iphmx.com Received: from esa3.mentor.iphmx.com (HELO esa3.mentor.iphmx.com) (68.232.137.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 04 Jan 2020 02:25:43 +0000 IronPort-SDR: FUddxJr+SxmZE4bLeGFUpYuU0RsUL9y+3Vl5Uku4nWSPguu4RwAW3fm9K/F5hGP3PnhXS3ow1+ 1oUrebr4Eik4tdnS+jZZeOkXNd0nq09GpsVQylrtX5KR5hq2kqR/XOLlSXJ/2p2M1uijgPRZUJ MDySMqKftyiwQKuWUbIDoVsLPpx7w/EfFqqGkf6SeRdIkHWdM2fWnfM6/Vn4zvrpTrZ9hAAsqT /NC8JLvRgw6u6sRIRug58yRixg0ah4lUxegtBXqVREVaUYdcks8aUcJDef7cGt2XoWELDHV5ay 7c8= Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 03 Jan 2020 18:25:41 -0800 IronPort-SDR: MaFyn8tokrqVB+87oxtDrWJHWPwKf4iT/35JC/YpwQZQM8Q8Pp0onRoPz+F9+GUuduIdBMjWG1 hDhdCja+B88uiwW728aAEQ/Dsbj0arJxKjSCQeLlimbGac00K2gezPEbT7sOSYx7hCsR2GvhLr Ld0E6ApKTjR8955PEks7U0rVHBL9VYrtk/r6BNOiaYMBJpw5ukykDBVeOEKH3khP+fdp0Dy6UN 7fUZ5mnuBpYkrc1QVgXEgsKofS34tnYJBpDnWh4QIorTvpnsNMOgK3sxJ61ns9fUOyIhyDGSk+ CFE= From: Julian Brown To: CC: , , Thomas Schwinge , Jakub Jelinek Subject: [PATCH 1/3] Add OpenACC test for sub-references being pointer or allocatable variables Date: Fri, 3 Jan 2020 18:25:12 -0800 Message-ID: <20200104022514.115942-1-julian@codesourcery.com> MIME-Version: 1.0 X-IsSubscribed: yes Hi, This test (by Tobias Burnus, mildly edited) adds a test to check whether the final component of a derived-type access has pointer or allocatable type for manual deep copy attach/detach operations. This is just checking existing behaviour. This arose from discussion of the manual deep copy patch here: https://gcc.gnu.org/ml/gcc-patches/2019-12/msg01439.html OK? Thanks, Julian ChangeLog 2020-01-04 Tobias Burnus gcc/testsuite/ * gfortran.dg/goacc/strided-alloc-ptr.f90: New test. --- .../gfortran.dg/goacc/strided-alloc-ptr.f90 | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/goacc/strided-alloc-ptr.f90 diff --git a/gcc/testsuite/gfortran.dg/goacc/strided-alloc-ptr.f90 b/gcc/testsuite/gfortran.dg/goacc/strided-alloc-ptr.f90 new file mode 100644 index 00000000000..755fd1c164b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/goacc/strided-alloc-ptr.f90 @@ -0,0 +1,34 @@ +implicit none +type t + integer, allocatable :: i, j(:) + integer, pointer :: k, ll(:) +end type t +type(t) :: x(2) + +!$acc enter data copyin(x) + +!$acc enter data copyin(x(:)%i) +! { dg-error "Component to the right of a part reference with nonzero rank must not have the ALLOCATABLE attribute" "" { target "*-*-*" } 10 } +! { dg-error ".x. in MAP clause at .1. is not a proper array section" "" { target "*-*-*" } 10 } + +!$acc enter data copyin(x(:)%j(3)) +! { dg-error "Component to the right of a part reference with nonzero rank must not have the ALLOCATABLE attribute" "" { target "*-*-*" } 14 } +! { dg-error ".x. in MAP clause at .1. is not a proper array section" "" { target "*-*-*" } 14 } + +!$acc enter data copyin(x(:)%j) +! { dg-error "Component to the right of a part reference with nonzero rank must not have the ALLOCATABLE attribute" "" { target "*-*-*" } 18 } +! { dg-error ".x. in MAP clause at .1. is not a proper array section" "" { target "*-*-*" } 18 } + + +!$acc enter data copyin(x(:)%k) +! { dg-error "Component to the right of a part reference with nonzero rank must not have the POINTER attribute" "" { target "*-*-*" } 23 } +! { dg-error ".x. in MAP clause at .1. is not a proper array section" "" { target "*-*-*" } 23 } + +!$acc enter data copyin(x(:)%ll(3)) +! { dg-error "Component to the right of a part reference with nonzero rank must not have the POINTER attribute" "" { target "*-*-*" } 27 } +! { dg-error ".x. in MAP clause at .1. is not a proper array section" "" { target "*-*-*" } 27 } + +!$acc enter data copyin(x(:)%ll) +! { dg-error "Component to the right of a part reference with nonzero rank must not have the POINTER attribute" "" { target "*-*-*" } 31 } +! { dg-error ".x. in MAP clause at .1. is not a proper array section" "" { target "*-*-*" } 31 } +end From patchwork Sat Jan 4 02:25:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 1217476 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-516642-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="G4UmJxmM"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47qQcg6JWFz9s4Y for ; Sat, 4 Jan 2020 13:26:11 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; q=dns; s= default; b=uD03qb5NchytVgIW/UjVU66vmbeRILTJYmWNmVwT/7DGXaw85l3+n a9LJr9eV65YT9H7j7HwEIjWtrCyqvjpPUTKX0FJtPnVvRykAKnZMQoueQXws70S7 EVMjoWofK1NoLIWHu/oKa9XdUHtFDt094Pq81ONYI8hdPyrIsGXBw0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=fAxP+9szCHXrc5jHBCXyfizfX/c=; b=G4UmJxmMXjl++q4oIRMPQgpXmQxQ asoLKqIN2AlPpJSqkowOzjv+5tchlmyKgRiZf/cLMpnPil1j6SvTFjoOL/Vee6qJ /hy16Km2z5IMqGMWzClcXfH/Juqf3fF0sxRlktVWqhkK/uLaE2jt18zdeCqRkZ7S /VEkyovqBu46JSA= Received: (qmail 73025 invoked by alias); 4 Jan 2020 02:25:52 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 72351 invoked by uid 89); 4 Jan 2020 02:25:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.1 spammy=1n, xi, UD:f95, expr_type X-HELO: esa3.mentor.iphmx.com Received: from esa3.mentor.iphmx.com (HELO esa3.mentor.iphmx.com) (68.232.137.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 04 Jan 2020 02:25:44 +0000 IronPort-SDR: NXUBXGpt2kqEUpS/diCdNm12Y6pMupwZ2Q0Yt/p4iThnbyb0iNZgS4AjJO6BlcWoKRcsrZJSvP 7ESow/I9OK0jrvPm8qp/sd0JB/tOJ6x+bmz0m7LRAH08ZXlI7vsbeISPIejwo6SOHld603xtW9 0XcrWRolI+oKPpks8igqN/9shLi7LMUq31ga0mfRF7XHFD4lqkVD5xsGaDiTRiHelqvVW8hw+V xdDXRFBoSl+whk3rlW9V7+swa13hbmVfG0wZY8S2txcWRqJaMvvwdM/ZwoedS0kB8PrNHJxuV/ CSg= Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 03 Jan 2020 18:25:44 -0800 IronPort-SDR: F4/46PAunr7lexe/fz31MGHEY25tXR2/tDesdBnvFKjiGA1JI1a702VerCEsg5fupY8q60JMaa txdldXRH+N7o+/rP6QTaRU6kDu+Znb9kHrE+9FBafTnZ4znPPi9ICrIgVxg5SaR+fPRldiZJd/ y3NLp+Jt3kT9OHPJ2ebhdYtZlp7OC5z5+GmUWB9HFqi+c8C+971kMzXu6RGydmpI1s+Hoks+Rk HVEK8w6DZNTIydFtUe9aWDK7BBsIqLlGa67oCGWrCa+K1tv+eLEFOEZj7af/SobjpKnXhwXeg1 dqE= From: Julian Brown To: CC: , , Thomas Schwinge , Jakub Jelinek Subject: [PATCH 2/3] Don't allow mixed component and non-component accesses for OpenACC/Fortran Date: Fri, 3 Jan 2020 18:25:13 -0800 Message-ID: <20200104022514.115942-2-julian@codesourcery.com> In-Reply-To: <20200104022514.115942-1-julian@codesourcery.com> References: <20200104022514.115942-1-julian@codesourcery.com> MIME-Version: 1.0 X-IsSubscribed: yes Hi, This patch arose from discussion of the manual deep copy patch here: https://gcc.gnu.org/ml/gcc-patches/2019-12/msg01439.html In C/C++, it's not permitted to mix full struct-type accesses and "attach/detach" accesses to the same struct's members within a single directive. This patch adds the same restriction to the Fortran front-end, and adjusts some existing tests to match. A test is also added for detection of duplicate derived-type member accesses within a directive. Tested with offloading to NVPTX. OK for mainline? Thanks, Julian ChangeLog 2020-01-04 Julian Brown gcc/fortran/ * gfortran.h (gfc_symbol): Add comp_mark bitfield. * openmp.c (resolve_omp_clauses): Disallow mixed component and full-derived-type accesses to the same variable within a single directive. libgomp/ * testsuite/libgomp.oacc-fortran/deep-copy-2.f90: Remove test from here. * testsuite/libgomp.oacc-fortran/deep-copy-3.f90: Don't use mixed component/non-component variable refs in a single directive. * testsuite/libgomp.oacc-fortran/classtypes-1.f95: Likewise. gcc/testsuite/ * gfortran.dg/goacc/deep-copy-2.f90: Add test here. Make a compilation test, and expect rejection of mixed component/non-component accesses. * gfortran.dg/goacc/mapping-tests-1.f90: New test. --- gcc/fortran/gfortran.h | 6 ++-- gcc/fortran/openmp.c | 31 ++++++++++--------- .../gfortran.dg/goacc}/deep-copy-2.f90 | 8 +++-- .../gfortran.dg/goacc/mapping-tests-1.f90 | 15 +++++++++ .../libgomp.oacc-fortran/classtypes-1.f95 | 6 ++-- .../libgomp.oacc-fortran/deep-copy-3.f90 | 4 ++- 6 files changed, 49 insertions(+), 21 deletions(-) rename {libgomp/testsuite/libgomp.oacc-fortran => gcc/testsuite/gfortran.dg/goacc}/deep-copy-2.f90 (63%) create mode 100644 gcc/testsuite/gfortran.dg/goacc/mapping-tests-1.f90 diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index df07eeed8e3..1de5f0d171e 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -1592,9 +1592,11 @@ typedef struct gfc_symbol current statement have the mark member nonzero. Of these symbols, symbols with old_symbol equal to NULL are symbols created within the current statement. Otherwise, old_symbol points to a copy of - the old symbol. gfc_new is used in symbol.c to flag new symbols. */ + the old symbol. gfc_new is used in symbol.c to flag new symbols. + comp_mark is used to indicate variables which have component accesses + in OpenACC directive clauses. */ struct gfc_symbol *old_symbol; - unsigned mark:1, gfc_new:1; + unsigned mark:1, comp_mark:1, gfc_new:1; /* The tlink field is used in the front end to carry the module declaration of separate module procedures so that the characteristics diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c index c105657a91b..78351b190f7 100644 --- a/gcc/fortran/openmp.c +++ b/gcc/fortran/openmp.c @@ -4245,6 +4245,7 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses, for (n = omp_clauses->lists[list]; n; n = n->next) { n->sym->mark = 0; + n->sym->comp_mark = 0; if (n->sym->attr.flavor == FL_VARIABLE || n->sym->attr.proc_pointer || (!code && (!n->sym->attr.dummy || n->sym->ns != ns))) @@ -4310,23 +4311,25 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses, && (list != OMP_LIST_REDUCTION || !openacc)) for (n = omp_clauses->lists[list]; n; n = n->next) { - bool array_only_p = true; - /* Disallow duplicate bare variable references and multiple - subarrays of the same array here, but allow multiple components of - the same (e.g. derived-type) variable. For the latter, duplicate - components are detected elsewhere. */ + bool component_ref_p = false; + + /* Allow multiple components of the same (e.g. derived-type) + variable here. Duplicate components are detected elsewhere. */ if (openacc && n->expr && n->expr->expr_type == EXPR_VARIABLE) for (gfc_ref *ref = n->expr->ref; ref; ref = ref->next) - if (ref->type != REF_ARRAY) - { - array_only_p = false; - break; - } - if (array_only_p) + if (ref->type == REF_COMPONENT) + component_ref_p = true; + if (openacc && ((!component_ref_p && n->sym->comp_mark) + || (component_ref_p && n->sym->mark))) + gfc_error ("Symbol %qs has mixed component and non-component " + "accesses at %L", n->sym->name, &n->where); + else if (n->sym->mark) + gfc_error ("Symbol %qs present on multiple clauses at %L", + n->sym->name, &n->where); + else { - if (n->sym->mark) - gfc_error ("Symbol %qs present on multiple clauses at %L", - n->sym->name, &n->where); + if (component_ref_p) + n->sym->comp_mark = 1; else n->sym->mark = 1; } diff --git a/libgomp/testsuite/libgomp.oacc-fortran/deep-copy-2.f90 b/gcc/testsuite/gfortran.dg/goacc/deep-copy-2.f90 similarity index 63% rename from libgomp/testsuite/libgomp.oacc-fortran/deep-copy-2.f90 rename to gcc/testsuite/gfortran.dg/goacc/deep-copy-2.f90 index 35936617b87..1e556b16b47 100644 --- a/libgomp/testsuite/libgomp.oacc-fortran/deep-copy-2.f90 +++ b/gcc/testsuite/gfortran.dg/goacc/deep-copy-2.f90 @@ -1,4 +1,4 @@ -! { dg-do run } +! { dg-do compile } ! Test of attach/detach with "acc data", two clauses at once. @@ -14,7 +14,9 @@ program dtype allocate(var%a(1:n)) -!$acc data copy(var) copy(var%a) +!$acc data copy(var) copy(var%a) ! { dg-error "Symbol .var. has mixed component and non-component accesses" } + +!$acc data copy(var%a) copy(var) ! { dg-error "Symbol .var. has mixed component and non-component accesses" } !$acc parallel loop do i = 1,n @@ -22,6 +24,8 @@ program dtype end do !$acc end parallel loop +!$acc end data + !$acc end data do i = 1,n diff --git a/gcc/testsuite/gfortran.dg/goacc/mapping-tests-1.f90 b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-1.f90 new file mode 100644 index 00000000000..c1bfe586842 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-1.f90 @@ -0,0 +1,15 @@ +! { dg-do compile } + +subroutine foo + type t + integer :: i, j + end type t + + type(t) x + + ! We should reject the duplicate reference here. +!$acc enter data copyin(x%i, x%i) +! { dg-error ".x.i. appears more than once in map clauses" "" { target "*-*-*" } 11 } + + +end diff --git a/libgomp/testsuite/libgomp.oacc-fortran/classtypes-1.f95 b/libgomp/testsuite/libgomp.oacc-fortran/classtypes-1.f95 index f16f42fc3af..c5f0ffffb02 100644 --- a/libgomp/testsuite/libgomp.oacc-fortran/classtypes-1.f95 +++ b/libgomp/testsuite/libgomp.oacc-fortran/classtypes-1.f95 @@ -31,7 +31,8 @@ program main myvar%p%p(i) = -1.0 end do -!$acc enter data copyin(myvar, myvar%p) create(myvar%p%p) +!$acc enter data copyin(myvar) +!$acc enter data copyin(myvar%p) create(myvar%p%p) !$acc parallel loop present(myvar%p%p) do i=1,100 @@ -39,7 +40,8 @@ program main end do !$acc end parallel loop -!$acc exit data copyout(myvar%p%p) delete(myvar, myvar%p) +!$acc exit data copyout(myvar%p%p) delete(myvar%p) +!$acc exit data delete(myvar) do i=1,100 if (myvar%p%p(i) .ne. i * 2) stop 1 diff --git a/libgomp/testsuite/libgomp.oacc-fortran/deep-copy-3.f90 b/libgomp/testsuite/libgomp.oacc-fortran/deep-copy-3.f90 index 667d944fecb..edb6b8d61a4 100644 --- a/libgomp/testsuite/libgomp.oacc-fortran/deep-copy-3.f90 +++ b/libgomp/testsuite/libgomp.oacc-fortran/deep-copy-3.f90 @@ -16,12 +16,14 @@ program dtype allocate(var%a(1:n)) allocate(var%b(1:n)) -!$acc parallel loop copy(var) copy(var%a(1:n)) copy(var%b(1:n)) +!$acc data copy(var) +!$acc parallel loop copy(var%a(1:n)) copy(var%b(1:n)) do i = 1,n var%a(i) = i var%b(i) = i end do !$acc end parallel loop +!$acc end data do i = 1,n if (i .ne. var%a(i)) stop 1 From patchwork Sat Jan 4 02:25:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 1217477 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-516643-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="PPgT1by+"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47qQcv617pz9s4Y for ; Sat, 4 Jan 2020 13:26:23 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; q=dns; s= default; b=Nvy13zKWJmsyLXHYaejeHrJCKkKpWL8pibNOqHzabRXEz6Jlmp7g9 CPfyoWtd15WPZWJjuskheQNSyxQHmQat0qCYtRcDj9sm69fAgjF37uIl2/LivNRR WRlFpup8SdymVaMkomIEFRLHM9FbfDzMWl7PeaAnWLIEbIfQhhKvO0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=RrkDPSv5cp8UvzJ+dTzx1hl1xi0=; b=PPgT1by++GuXcLy79qfd5DkuvGpu PKZfGJZIT8mTjBxxmV61+/wMyGBf/r8id0Aw/2nzns2aa7U4731ZBascLAzDqF5d 7MBwvKUYSkjxhbHVFicb0zL25b+AZJ70UkkhaA5/88WhHk8Yi8ZaIIXrX7sMIWJj FxPYoTyBxBA8u38= Received: (qmail 73050 invoked by alias); 4 Jan 2020 02:25:52 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 72934 invoked by uid 89); 4 Jan 2020 02:25:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.1 spammy=foot X-HELO: esa3.mentor.iphmx.com Received: from esa3.mentor.iphmx.com (HELO esa3.mentor.iphmx.com) (68.232.137.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 04 Jan 2020 02:25:48 +0000 IronPort-SDR: Fcbs7T3lKD2zeHiyAm1cN5v78eL1gTaG06t5yMqvNwmijaSmWlohKXAsHOnqZggdAm9Swpnn3T fKwvUgikQ0JGoeYuuMB8dGtvOvZGZb2lP7DRiTgtS/B8X4/EwEwtpgj3R6CifxnnEKTiv8PmlA B6wtVASMnPtfELUpCQgI/y/G/NGIyX+zEUl5wskEDMaKNG2KgRHshDwdnnr5BVYwfZfFK8Xd3R wpI3yiaDcjw+5UNKykVaQfGSP7crHZmkE+aNTvpFJqawoWSCcCo2JOBpQru3/JPug+C1ovg/Zb q3M= Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 03 Jan 2020 18:25:47 -0800 IronPort-SDR: 7DAVX7d5mE24K39NHW9+imCTvxO7XO8D2Yjt8GM3f0zzK9rb69JgyikyyZE4BK9QP0kIFfKQWi H/HQFlFFfcyrg6x6KgXGfEbXJZ56omexMl2fSwg8aSkyNjucBNPYVrhn6YBydnzQm5cQOHhmlK adGRGFzOU3jeGEm/vX8EkkEnJrZlMA+wHujFvfDQIdJ5gc8tsICqDier1OL7dh67tEkVGOGoMB 0pGAH+x7/9bB8+at7eR+t0rgH3Gie9Ki7ac3xdw+H7LO803GXjxjY6sTLt/ZYIFw4v56cczQyi dP4= From: Julian Brown To: CC: , , Thomas Schwinge , Jakub Jelinek Subject: [PATCH 3/3] Check array contiguity for OpenACC/Fortran Date: Fri, 3 Jan 2020 18:25:14 -0800 Message-ID: <20200104022514.115942-3-julian@codesourcery.com> In-Reply-To: <20200104022514.115942-1-julian@codesourcery.com> References: <20200104022514.115942-1-julian@codesourcery.com> MIME-Version: 1.0 X-IsSubscribed: yes Hi, This patch tightens up error checking for array references used in OpenACC clauses such that they must now be contiguous. I believe this matches up to the spec (as of 2.6). I've tried to make it so an error only triggers if the compiler is sure that a given array expression must be non-contiguous at compile time, although this errs on the side of potentially allowing the user to shoot themselves in the foot at runtime: at least one existing test in the testsuite appears to expect that behaviour. This hopefully addresses Tobias's concern in: https://gcc.gnu.org/ml/gcc-patches/2019-12/msg01439.html In particular, with the error checking, we no longer get an ICE for the example given in that message. The new check also catches a test case that appears to have been relying on undefined behaviour. Tested with offloading to NVPTX. OK for trunk? Thanks, Julian ChangeLog 2020-01-04 Julian Brown PR fortran/93025 gcc/fortran/ * openmp.c (resolve_omp_clauses): Check array references for contiguity. gcc/testsuite/ * gfortran.dg/goacc/mapping-tests-2.f90: New test. * gfortran.dg/goacc/subarrays.f95: Expect rejection of non-contiguous array. --- gcc/fortran/openmp.c | 29 +++++++++++++---- .../gfortran.dg/goacc/mapping-tests-2.f90 | 32 +++++++++++++++++++ gcc/testsuite/gfortran.dg/goacc/subarrays.f95 | 2 +- 3 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/goacc/mapping-tests-2.f90 diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c index 78351b190f7..71308c0235c 100644 --- a/gcc/fortran/openmp.c +++ b/gcc/fortran/openmp.c @@ -4533,13 +4533,28 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses, /* Look through component refs to find last array reference. */ if (openacc && resolved) - while (array_ref - && (array_ref->type == REF_COMPONENT - || (array_ref->type == REF_ARRAY - && array_ref->next - && (array_ref->next->type - == REF_COMPONENT)))) - array_ref = array_ref->next; + { + /* The "!$acc cache" directive allows rectangular + subarrays to be specified, with some restrictions + on the form of bounds (not implemented). + Only raise an error here if we're really sure the + array isn't contiguous. An expression such as + arr(-n:n,-n:n) could be contiguous even if it looks + like it may not be. */ + if (list != OMP_LIST_CACHE + && !gfc_is_simply_contiguous (n->expr, false, true) + && gfc_is_not_contiguous (n->expr)) + gfc_error ("Array is not contiguous at %L", + &n->where); + + while (array_ref + && (array_ref->type == REF_COMPONENT + || (array_ref->type == REF_ARRAY + && array_ref->next + && (array_ref->next->type + == REF_COMPONENT)))) + array_ref = array_ref->next; + } } if (array_ref || (n->expr diff --git a/gcc/testsuite/gfortran.dg/goacc/mapping-tests-2.f90 b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-2.f90 new file mode 100644 index 00000000000..1372f6af53e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-2.f90 @@ -0,0 +1,32 @@ +subroutine foo + type t + integer :: i, j + end type t + + type t2 + type(t) :: cc(3) + end type t2 + + type(t) x, y(3) + type(t2) :: z(3) + + ! OK - map whole aggregated variable +!$acc enter data copyin(x) + ! map(to:x [len: 8]) + + ! OK - map two components of the aggregated variable +!$acc enter data copyin(x%j, x%i) + + ! Bad - we cannot mix full-object and component accesses +!$acc enter data copyin(x, x%i) +! { dg-error "Symbol .x. has mixed component and non-component accesses" "" { target "*-*-*" } 21 } + + ! Bad - we cannot do a strided access of 'x' + ! No C/C++ equivalent +!$acc enter data copyin(y(:)%i) +! { dg-error "Array is not contiguous" "" { target "*-*-*" } 26 } + + ! Bad - again, a strided access +!$acc enter data copyin(z(1)%cc(:)%i) +! { dg-error "Array is not contiguous" "" { target "*-*-*" } 30 } +end diff --git a/gcc/testsuite/gfortran.dg/goacc/subarrays.f95 b/gcc/testsuite/gfortran.dg/goacc/subarrays.f95 index f6adde459f4..fa0378550e9 100644 --- a/gcc/testsuite/gfortran.dg/goacc/subarrays.f95 +++ b/gcc/testsuite/gfortran.dg/goacc/subarrays.f95 @@ -27,7 +27,7 @@ program test ! { dg-error "'a' in MAP clause" "" { target *-*-* } .-2 } !$acc end parallel - !$acc parallel copy (b(1:3,2:4)) + !$acc parallel copy (b(1:3,2:4)) ! { dg-error "Array is not contiguous" } !$acc end parallel !$acc parallel copy (b(2:3)) ! { dg-error "Rank mismatch" "" { target *-*-* } .-1 }