From patchwork Fri Jul 20 21:37:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janus Weil X-Patchwork-Id: 947217 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-482010-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="iudwfPAc"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41XPPz0SwWz9s4V for ; Sat, 21 Jul 2018 07:38:13 +1000 (AEST) Received: (qmail 92764 invoked by alias); 20 Jul 2018 21:38:04 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 92741 invoked by uid 89); 20 Jul 2018 21:38:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.3 required=5.0 tests=AWL, BAYES_40, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=impure, mandate, sk:ffronte, became X-HELO: mail-yb0-f172.google.com Received: from mail-yb0-f172.google.com (HELO mail-yb0-f172.google.com) (209.85.213.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Jul 2018 21:38:02 +0000 Received: by mail-yb0-f172.google.com with SMTP id y11-v6so5168306ybm.7; Fri, 20 Jul 2018 14:38:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:from:date:message-id:subject:to; bh=VFWzLtfL5Sm6YLbe/dGpQU7mP5zPv8Myln2aMFvLv4g=; b=iudwfPAccU+Z+8WYjxU/sEsEiD9FuzOD0kDkzMFfPbyL8vroCOJoHKbRJrGeWT5xLW 3xxTAjyd6Nw2mZkW7mdjp6Mzpc0as6Qi+i5bEGR5+QF9YxIpFuoYdc4/uUwsH88wcsd/ P03xNZ5pSnoCQjSlw73uQqgLXYGwjxQaZP0CDo5AYf+A09ZlFsB2t/YrNeoNWHSYhSa0 Qe/hFcdtuyiCwElU6R5J5ztl7pfRSgwTf3iBSfzc2J6jmuIwN6bBXfDxDxmItUdSmLuN +zFxwYJBdoRI8DkZEQwBK1V1GUgO9KNtMikTPkbQrd5vDtfB4WA1/TLxSjFQ5+9sDc3Y fz+g== MIME-Version: 1.0 Sender: jaydub66@gmail.com Received: by 2002:a0d:ea0c:0:0:0:0:0 with HTTP; Fri, 20 Jul 2018 14:37:59 -0700 (PDT) From: Janus Weil Date: Fri, 20 Jul 2018 23:37:59 +0200 Message-ID: Subject: [Patch, Fortran] PR 57160: short-circuit IF only with -ffrontend-optimize To: gfortran , gcc-patches 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 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. Index: gcc/fortran/trans-expr.c =================================================================== --- gcc/fortran/trans-expr.c (revision 262908) +++ gcc/fortran/trans-expr.c (working copy) @@ -3348,12 +3348,12 @@ gfc_conv_expr_op (gfc_se * se, gfc_expr * expr) return; case INTRINSIC_AND: - code = TRUTH_ANDIF_EXPR; + code = flag_frontend_optimize ? TRUTH_ANDIF_EXPR : TRUTH_AND_EXPR; lop = 1; break; case INTRINSIC_OR: - code = TRUTH_ORIF_EXPR; + code = flag_frontend_optimize ? TRUTH_ORIF_EXPR : TRUTH_OR_EXPR; lop = 1; break; Index: gcc/testsuite/gfortran.dg/actual_pointer_function_1.f90 =================================================================== --- gcc/testsuite/gfortran.dg/actual_pointer_function_1.f90 (revision 262908) +++ 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)