From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 8D8733836009; Mon, 30 May 2022 07:33:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D8733836009 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.91,262,1647331200"; d="scan'208";a="76515344" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 29 May 2022 23:33:35 -0800 IronPort-SDR: dUz8i1RHpGj7EgMHnqbAm7EPoxLpdPOs3pR//XNxS3xL19oyGYXSWJv3NrD75RFhZnVwTU+0Ku 4XRI1gqV+0DH+G9SNqAl57kg2uCN703rKLaQwu6CwRidXtSkyd+BZn6kh8Cb/paTgPCkYYwD0K 4xb7WkgzLc6tjyRFiP4lFN7B01fJVVG+T3jchy5O0L1LrkXowtAhnKvoDHroG6ghXa28zQOkQ+ nZYHFpfGJhkJOBBKVX5TRtSvS2bBw3Dce8/f2qKKP/R2YXZt1DQV9sshZIBvdbvlus1Y+hKgFP xEA= Message-ID: <3480e229-b8af-905a-b33a-bc10751fc933@codesourcery.com> Date: Mon, 30 May 2022 09:33:29 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] PR fortran/91300 - runtime error message with allocate and errmsg= Content-Language: en-US To: Harald Anlauf , fortran , gcc-patches References: From: Tobias Burnus In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: quoted-printable X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Mon, 30 May 2022 07:33:40 -0000 On 28.05.22 22:25, Harald Anlauf via Fortran wrote: > the PR rightfully complained that we did not differentiate errors on > ALLOCATE(...,stat=3D,errmsg=3D) for failures from allocation of already > allocated objects or insufficient virtual memory. It is even worse: The error message states the wrong reason. > The attached patch introduces a new STAT value LIBERROR_NO_MEMORY > that is returned for insufficient virtual memory, and a corresponding > (simple and invariant) ERRMSG: "Insufficient virtual memory". I think the message is fine =E2=80=93 at least on Linux 'virtual memory' is what's used and it is clear what's meant, even if I stumble a bit about the wording. (But do not have a crisp short & comprehensive wording myself.= ) > (In the PR Janne mentions checking for errno, but since the standard > malloc(3) only mentions ENOMEM as possible error value, and the user > may replace malloc by a special library, I believe that won't be easy > to handle in a general way.) I con concur. Especially as POSIX and the Linux manpage only list ENOMEM as only value. > Most compilers I tried (Intel/NAG/Crayftn) behave similarly, except > for Nvidia/Flang, which try to return the size of the allocation in > the error message. > > I am not sure that this is worth the effort. I think it is not needed =E2=80=93 especially as we generate the message in= the FE and not in libgfortran. The advantage for the users is that they know what value has been requested =E2=80=93 but they cannot really do much with= the knowledge, either. > The testcase should be able to handle 32 and 64 bit systems. > At least that's what I think. I hope it is =E2=80=93 at least on 64bit, I currently expect it too fail somewhat reliably, with 32bit I think it won't =E2=80=93 but that's also ha= ndled. But you could add a -fdump-tree-original + '! { dg-final { scan-tree-dump*' to do some checking in addition (e.g. whether both strings appear in the dump; could be more complex, but that's probably not needed). > Regtested on x86_64-pc-linux-gnu. OK for mainline? Suggestions? LGTM =E2=80=93 with considering comments on the testcase. > Fortran: improve runtime error message with ALLOCATE and ERRMSG=3D Consider appending [PR91300] in that line =E2=80=93 and try to make the gcc-patches@ and fortran@ lines the same (Searching for the PR number or case-insignificantly for the string in the mailing list archive, will fine the message; thus, that's okay.) > ALLOCATE: generate different STAT,ERRMSG results for failures from > allocation of already allocated objects or insufficient virtual memory. > > gcc/fortran/ChangeLog: > > PR fortran/91300 > * libgfortran.h: Define new error code LIBERROR_NO_MEMORY. > * trans-stmt.cc (gfc_trans_allocate): Generate code for setting > ERRMSG depending on result of STAT result of ALLOCATE. > * trans.cc (gfc_allocate_using_malloc): Use STAT value of > LIBERROR_NO_MEMORY in case of failed malloc. > > gcc/testsuite/ChangeLog: > > PR fortran/91300 > * gfortran.dg/allocate_alloc_opt_15.f90: New test. > --- ... > + stat1 =3D -1 > + errmsg1 =3D "" > + allocate (array(1), stat=3Dstat1, errmsg=3Derrmsg1) > + if (stat1 /=3D 0) stop 1 > + if (errmsg1 /=3D "") stop 1 Consider to init the errmsg1 and then check that is has not been touched. (For completeness, I think we already have such tests). > + ! Obtain stat,errmsg for attempt to allocate an allocated object > + allocate (array(1), stat=3Dstat1, errmsg=3Derrmsg1) > + if (stat1 =3D=3D 0) stop 2 > + if (errmsg1 =3D=3D "") stop 2 Consider to check (either here or as a third test) for the gfortran-specific error message. > + stat2 =3D -1 > + errmsg2 =3D "" > + ! Try to allocate very large object > + allocate (bigarray(bignumber), stat=3Dstat2, errmsg=3Derrmsg2) > + if (stat2 /=3D 0) then > + print *, "stat =3D", stat1 > + print *, "errmsg: ", trim (errmsg1) > + print *, "stat =3D", stat2 > + print *, "errmsg: ", trim (errmsg2) > + ! Ensure different results for stat, errmsg variables > + if (stat2 =3D=3D stat1 ) stop 3 > + if (errmsg2 =3D=3D "" .or. errmsg2 =3D=3D errmsg1) stop 4 Likewise for errmsg2 Thanks, Tobias ----------------- 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