From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 108125 invoked by alias); 23 Jul 2018 07:40:31 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@gcc.gnu.org Received: (qmail 108116 invoked by uid 89); 23 Jul 2018 07:40:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=BAYES_00,KAM_COUK,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=mandate, H*Ad:D*co.uk, inhibit, H*Ad:U*adam X-HELO: smtpout.karoo.kcom.com Received: from smtpout.karoo.kcom.com (HELO smtpout.karoo.kcom.com) (212.50.160.34) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Jul 2018 07:40:28 +0000 Received: from adsl-178-78-64-188.karoo.kcom.com (HELO [192.168.0.5]) ([178.78.64.188]) by smtpout.karoo.kcom.com with ESMTP; 23 Jul 2018 08:40:52 +0100 Subject: Re: [Patch, Fortran] PR 57160: short-circuit IF only with -ffrontend-optimize To: fortran@gcc.gnu.org References: From: Adam Hirst Openpgp: preference=signencrypt Message-ID: <64b6a3bb-eabd-f65b-7bed-6af7cbf9a8bb@aphirst.karoo.co.uk> Date: Mon, 23 Jul 2018 07:40:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="pLViiNtLzi1ONhkumHNOulVZLzAmeVH0U" X-IsSubscribed: yes X-SW-Source: 2018-07/txt/msg00090.txt.bz2 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --pLViiNtLzi1ONhkumHNOulVZLzAmeVH0U Content-Type: multipart/mixed; boundary="WtSph8J1Cjg5NtvB7SmHNE6bv4pHr6PxM"; protected-headers="v1" From: Adam Hirst To: fortran@gcc.gnu.org Message-ID: <64b6a3bb-eabd-f65b-7bed-6af7cbf9a8bb@aphirst.karoo.co.uk> Subject: Re: [Patch, Fortran] PR 57160: short-circuit IF only with -ffrontend-optimize References: In-Reply-To: --WtSph8J1Cjg5NtvB7SmHNE6bv4pHr6PxM Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Language: en-GB Content-length: 2389 On 20/07/18 22:37, Janus Weil wrote: > Hi all, > > here is a follow-up patch to my recent commit for PR 85599, also > dealing with the short-circuiting of logical operators. In the course > of the extensive discussion of that PR it became clear that the > Fortran standard allows the short-circuiting of .AND. and .OR. > operators, but does not mandate it. > > gfortran currently does short-circuiting, and after my patch for PR > 85599 warns about cases where this might remove an impure function > call (which potentially can change results). > > Now, this PR (57160) is about code which relies on the > short-circuiting behavior. Since short-circuiting is not guaranteed by > the standard, such code is invalid. Generating a warning or an error > at compile-time is a bit harder here, though, since there are multiple > variations of such a situation, e.g.: > * ASSOCIATED(p) .AND. p%T > * ALLOCATED(a) .AND. a%T > * i * ... > > The suggestion in the PR was to do short-circuiting only with > optimization flags, but inhibit it with -O0, so that the faulty code > will run into a segfault (or runtime error) at least when > optimizations are disabled, and the problem can be identified. > > I find this suggestion very reasonable. It makes it possible to detect > invalid code at -O0, while keeping good performance for valid code at > -O{1,2,3}. Also it is technically very simple to implement, and it > immediately identified a faulty test case that has lived in the > testsuite for eleven years without being detected. One thing I'm not seeing in the original discussion was whether or not this should also count for -Og, which certainly in my experience is (paired with -g) a common debug setting. I would err towards -Og here being paired with -O0, but I could see it being argued both ways - either way, I thought it might at least be worth making explicit? > The attached patch regtests cleanly on x86_64-linux-gnu. Ok for trunk? > > Cheers, > Janus > > > 2018-07-20 Janus Weil > > PR fortran/57160 > * trans-expr.c (gfc_conv_expr_op): Use short-circuiting operators only > with -ffrontend-optimize. Without that flag, make sure that both > operands are evaluated. > > > 2018-07-20 Janus Weil > > PR fortran/57160 > * gfortran.dg/actual_pointer_function_1.f90: Fix invalid test case. --WtSph8J1Cjg5NtvB7SmHNE6bv4pHr6PxM-- --pLViiNtLzi1ONhkumHNOulVZLzAmeVH0U Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" Content-length: 833 -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEOmWvSRzZZF3Y1lD8c04TXaTmZJcFAltVhmkACgkQc04TXaTm ZJflCQ/9F8TlkV2MhGnRgPUOt73t5DK3+gza99oteYRhKaVntMgDiakf1Osi7/bu aMDPDb5d1G46J79iIYiaWq3uNx4gpsstNoEISPeWBop9UDHtalratAJaL4Xy7G8z 1MCw1/e7RgBFN3qNFuJ16Z8NMhbI8ynv1yQNO3lp1aRF/dUWidZKPlLUiQrs8X5p syCMNMyMINZ9aKBq0/2p1Up2eyl4syrct0fNp13UHNmF9ZaPmEwUwYQXdo08c29t RezVF17vNqPsBT8gTqqCpljMXUwbANDQ7W1zxR7yd4DU2Vlz01JCen5g1VI9cqBH JQjNK0gRtjzLI6PkFiI0TxcLXOY1dY6PUfQ7gctWCSeKPS1NyJPUlOuToG7AhkPe XqQzbiessZoH2iV99TSWlMWbeD5E1pegom4w2BkuGYoCQQqSluxzzEFOn5ha+TIc DV0JMWpO/JQKk1f6hwQfK96AvfjkrDbJYuyQWVuzFkfFPpipG0eZ3EhUp/wDn9Ik UrFuT2C8vvLEEGoZ9zWdusMUxygLxOR3LQ1GvKTCoJL78jEzFLtdOdInxZt/EziY srcEspDLxapPPn8LUJU35s4RCNPtE+bDRWll7oypdYFdekGXlJYVQn0TdgCPNzms o/SNTog/d0xTYG/57TZ8aTRahv/dxzT4jbYtxLS1zVhXT1fEdMY= =+SW0 -----END PGP SIGNATURE----- --pLViiNtLzi1ONhkumHNOulVZLzAmeVH0U--