http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57160
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |burnus at gcc dot gnu.org
--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 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 ("")