From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11691 invoked by alias); 4 May 2013 19:23:16 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 11631 invoked by uid 48); 4 May 2013 19:23:09 -0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/57160] short-circuit IF only with -ffrontend-optimize Date: Sat, 04 May 2013 19:23:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: CC Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 X-SW-Source: 2013-05/txt/msg00290.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57160 Tobias Burnus changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |burnus at gcc dot gnu.org --- Comment #1 from Tobias Burnus 2013-05-04 19:23:08 UTC --- GCC (the middle end) has TRUTH_AND_EXPR (matching Fortran's .AND.) and TRUTH_ANDIF_EXPR (matching C's &&) - besides the IAND/& which is BIT_AND_EXPR. Currently, the code generation directly translates all .AND. into TRUTH_AND_EXPR. Hence, the middle end/target-code generation might decide to evaluate "A.AND.B" as "A andif B", "B andif A" or both as "A and B". That's really outside the scope of the Fortran front end. What you would like is that both A and B are /always/ evaluated with .AND. That's quite some work with little gain. As I know for experience, the current TRUTH_AND_EXPR does no short-circuit evaluation in the given order - I already had segfaults for code similar to your's. * * * As a side note, see http://www.j3-fortran.org/doc/year/13/13-234.txt for a proposal for the next Fortran standard which allows to explicitly require short-circuit evaluation, using: if ( IF (ASSOCIATED(m)) THEN (m%T) ELSE (.false.) ) then write (6,*) s1(m) end if Or even as: write (6,*) IF (ASSOCIATED(m)) THEN ( IF(m%T)then("X")ELSE("") ) ELSE ("")