https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57160
janus at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |janus at gcc dot gnu.org --- Comment #9 from janus at gcc dot gnu.org --- (In reply to Thomas Koenig from comment #6) > The problem there is what we should consider for a warning. I think getting the warnings right for all possible cases is pretty tough. OTOH, following Joost's original suggestion to do short-circuiting only with -ffrontend-optimize is almost trivial, so I'd vote to go with that. Here's the patch: Index: gcc/fortran/trans-expr.c =================================================================== --- gcc/fortran/trans-expr.c (revision 262859) +++ gcc/fortran/trans-expr.c (working copy) @@ -3348,12 +3348,18 @@ gfc_conv_expr_op (gfc_se * se, gfc_expr * expr) return; case INTRINSIC_AND: - code = TRUTH_ANDIF_EXPR; + if (flag_frontend_optimize) + code = TRUTH_ANDIF_EXPR; + else + code = TRUTH_AND_EXPR; lop = 1; break; case INTRINSIC_OR: - code = TRUTH_ORIF_EXPR; + if (flag_frontend_optimize) + code = TRUTH_ORIF_EXPR; + else + code = TRUTH_OR_EXPR; lop = 1; break; As noted already somewhere in the discussion of PR85599 on the mailing list, this breaks actual_pointer_function_1.f90 in the testsuite, which is very similar to comment 0 (and apparently also contributed by Joost). Both are invalid code. The former is fixed by: Index: gcc/testsuite/gfortran.dg/actual_pointer_function_1.f90 =================================================================== --- gcc/testsuite/gfortran.dg/actual_pointer_function_1.f90 (revision 262859) +++ gcc/testsuite/gfortran.dg/actual_pointer_function_1.f90 (working copy) @@ -17,7 +17,11 @@ CONTAINS logical function cp_logger_log(logger) TYPE(cp_logger_type), POINTER ::logger - cp_logger_log = associated (logger) .and. (logger%a .eq. 42) + if (associated (logger)) then + cp_logger_log = (logger%a .eq. 42) + else + cp_logger_log = .false. + end if END function FUNCTION cp_get_default_logger(v) RESULT(res)