From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 222E33858429; Thu, 10 Mar 2022 09:00:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 222E33858429 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.90,169,1643702400"; d="scan'208";a="75552767" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 10 Mar 2022 01:00:30 -0800 IronPort-SDR: ZfCgRSZg3ZdQvfL4avKxqs8b7cR55Q9h2dd+jiNNPMVwL+TBit95mcVJL0CClA0fEpZHuPtygh FyfgFkOSMTb+ZKqxdQFVC24u9NFNl/AUqF0Pv7ITn92fNCNn8eLvZ6OrmDUZp24ffDR19id+p6 67IDKT8KsTp1trs/FtQvVyeTP9nQ431TqaKDHMyqTpQ0mtBomPRgH942O7sVDn9+qSishjP9Na JBWjsIKCyRbljijvBwyjqrBgIAxBkhkoYgj1Bq2XFXqBglbRxvv7fW0ESCo/6r5DhxGY/UEK6h FiM= From: Thomas Schwinge To: Tobias Burnus CC: , , Jakub Jelinek Subject: Re: [Patch] Fortran: OpenMP/OpenACC avoid uninit access in size calc for mapping In-Reply-To: References: User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/27.1 (x86_64-pc-linux-gnu) Date: Thu, 10 Mar 2022 10:00:09 +0100 Message-ID: <877d92mbc6.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-15.mgc.mentorg.com (139.181.222.15) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Mar 2022 09:00:33 -0000 Hi Tobias! On 2022-03-08T15:25:07+0100, Tobias Burnus wrote: > found when working on the deep-mapping patch* with OpenMP code > (and part of that patch) but it already shows up in an existing > OpenACC testcase. I think it makes sense to fix it already for GCC 12. > > Problem: Also for unallocated allocatables, their size was > calculated - the 'if(desc.data =3D=3D NULL)' check was only added > for pointers. > > Result after the patch: When compiling with -O (which is the default > for goacc.exp), the warning now disappears. Thus, I now use '-O0' > and the previous "is uninitialized" is now "may be uninitialized". I recently added that checking in commit 4bd8b1e881f0c26a5103cd1919809b3d63b60ef2 "Document current '-Wuninitialized'/'-Wmaybe-uninitialized' diagnostics for OpenACC test cases", to document the status quo. I'll leave it to you to decide what is more appropriate: (1), as you have proposed, add '-O0' (but with source code comment, please); something like: ! { dg-additional-options -Wuninitialized } +! Trigger "may be used uninitialized". +! { dg-additional-options -O0 } ..., or (2): update the test cases to simply reflect diagnostics that are now (no longer) seen with (default) '-O' (rationale: the test cases haven't originally been written for the '-Wuninitialized' diagnostics; that's just tested additionally, and using '-O0' instead of '-O' may be disturbing what they originally meant to test?), or (3): duplicate the test cases to account for both (1) and (2) (in other words: write dedicated test cases for your GCC/Fortran front end changes (for example, based on the ones you've modified here), and for the existing test cases apply (2)). The latter, (3), would be my approach. > Unrelated to the patch and the testcase, I added some > 'allocate'**/'if(allocated())' to the testcase - as otherwise > uninit vars would be accessed. (Not relevant for the warning > or the patch - but I prefer no invalid code in testcases, > if it can be avoided.) Agreed in principle, but again: I don't know what these test cases originally have been testing? > OK for mainline? I can't comment on the GCC/Fortran front end changes -- so unless somebody else speaks up, that's an implicit approval for those, I suppose. ;-) > Tobias > * https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591144.html > ** I am actually not sure whether 'acc update(b)' will/should map a > previous allocated variable - or whether it should. (Are the typos here: in "will/should map": 's%map%update', and in "or whether it should": 's%should%shouldn't'?) > But that's > unrelated to this bug fix. See also: https://gcc.gnu.org/PR96668 > for the re-mapping in OpenMP (works for arrays but not scalars). I don't quickly dig that, sorry. Do we need to first clarify that with OpenACC Technical Committee, or is this just a GCC/OpenACC implementation issue? Gr=C3=BC=C3=9Fe Thomas > Fortran: OpenMP/OpenACC avoid uninit access in size calc for mapping > > gcc/fortran/ChangeLog: > > * trans-openmp.cc (gfc_trans_omp_clauses, gfc_omp_finish_clause): > Obtain size for mapping only if allocatable array is allocated. > > gcc/testsuite/ChangeLog: > > * gfortran.dg/goacc/array-with-dt-1.f90: Run with -O0 and > update dg-warning. > * gfortran.dg/goacc/pr93464.f90: Likewise. > > gcc/fortran/trans-openmp.cc | 6 ++++-- > gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 | 12 +++++++++--- > gcc/testsuite/gfortran.dg/goacc/pr93464.f90 | 8 ++++---- > 3 files changed, 17 insertions(+), 9 deletions(-) > > diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc > index 4d56a771349..fad76a4791f 100644 > --- a/gcc/fortran/trans-openmp.cc > +++ b/gcc/fortran/trans-openmp.cc > @@ -1597,7 +1597,8 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p, b= ool openacc) > tree size =3D create_tmp_var (gfc_array_index_type); > tree elemsz =3D TYPE_SIZE_UNIT (gfc_get_element_type (type)); > elemsz =3D fold_convert (gfc_array_index_type, elemsz); > - if (GFC_TYPE_ARRAY_AKIND (type) =3D=3D GFC_ARRAY_POINTER > + if (GFC_TYPE_ARRAY_AKIND (type) =3D=3D GFC_ARRAY_ALLOCATABLE > + || GFC_TYPE_ARRAY_AKIND (type) =3D=3D GFC_ARRAY_POINTER > || GFC_TYPE_ARRAY_AKIND (type) =3D=3D GFC_ARRAY_POINTER_CONT) > { > stmtblock_t cond_block; > @@ -3208,7 +3209,8 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_= clauses *clauses, > > /* We have to check for n->sym->attr.dimension becaus= e > of scalar coarrays. */ > - if (n->sym->attr.pointer && n->sym->attr.dimension) > + if ((n->sym->attr.pointer || n->sym->attr.allocatable= ) > + && n->sym->attr.dimension) > { > stmtblock_t cond_block; > tree size > diff --git a/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 b/gcc/te= stsuite/gfortran.dg/goacc/array-with-dt-1.f90 > index 136e42acd59..f6880238c89 100644 > --- a/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 > +++ b/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 > @@ -1,4 +1,4 @@ > -! { dg-additional-options -Wuninitialized } > +! { dg-additional-options "-Wuninitialized -O0" } > > type t > integer, allocatable :: A(:,:) > @@ -8,9 +8,15 @@ type(t), allocatable :: b(:) > ! { dg-note {'b' declared here} {} { target *-*-* } .-1 } > > !$acc update host(b) > -! { dg-warning {'b\.dim\[0\]\.ubound' is used uninitialized} {} { target= *-*-* } .-1 } > -! { dg-warning {'b\.dim\[0\]\.lbound' is used uninitialized} {} { target= *-*-* } .-2 } > +! { dg-warning {'b\.dim\[0\]\.ubound' may be used uninitialized} {} { ta= rget *-*-* } .-1 } > +! { dg-warning {'b\.dim\[0\]\.lbound' may be used uninitialized} {} { ta= rget *-*-* } .-2 } > + > +allocate(b(1)) > +!$acc update host(b) > !$acc update host(b(:)) > + > +!$acc update host(b(1)%A) > +allocate(b(1)%A(1,1)) > !$acc update host(b(1)%A) > !$acc update host(b(1)%A(:,:)) > end > diff --git a/gcc/testsuite/gfortran.dg/goacc/pr93464.f90 b/gcc/testsuite/= gfortran.dg/goacc/pr93464.f90 > index c92f1d3d8b2..18531abdf77 100644 > --- a/gcc/testsuite/gfortran.dg/goacc/pr93464.f90 > +++ b/gcc/testsuite/gfortran.dg/goacc/pr93464.f90 > @@ -2,17 +2,17 @@ > ! > ! Contributed by G. Steinmetz > > -! { dg-additional-options -Wuninitialized } > +! { dg-additional-options "-Wuninitialized -O0" } > > program p > character :: c(2) =3D 'a' > character, allocatable :: z(:) > ! { dg-note {'z' declared here} {} { target *-*-* } .-1 } > !$acc parallel > - ! { dg-warning {'z\.dim\[0\]\.ubound' is used uninitialized} {} { tar= get *-*-* } .-1 } > - ! { dg-warning {'z\.dim\[0\]\.lbound' is used uninitialized} {} { tar= get *-*-* } .-2 } > + ! { dg-warning {'z\.dim\[0\]\.ubound' may be used uninitialized} {} {= target *-*-* } .-1 } > + ! { dg-warning {'z\.dim\[0\]\.lbound' may be used uninitialized} {} {= target *-*-* } .-2 } > !$omp target > - z =3D c > + if (allocated(z)) z =3D c > !$acc end parallel > !$omp end target > print *, z ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstra=C3=9Fe 201= , 80634 M=C3=BCnchen; Gesellschaft mit beschr=C3=A4nkter Haftung; Gesch=C3= =A4ftsf=C3=BChrer: Thomas Heurung, Frank Th=C3=BCrauf; Sitz der Gesellschaf= t: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955