From patchwork Sat Sep 22 17:23:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 973597 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-486183-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=netcologne.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="g2T4mAYX"; dkim=pass (2048-bit key; unprotected) header.d=netcologne.de header.i=@netcologne.de header.b="fel7IJ1g"; 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 42Hckd1TFFz9sB4 for ; Sun, 23 Sep 2018 03:23:35 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=CPt8+iCO7yGe0Wn6d62gGpxZXl1oTyBm0d40bgnXZCOX3eMLx8 lPw61rzajw0KIPeCXOjYA4sUNP7R4alhzQIfyqD2ScH/VVth7wxjkNQLK9dltNim 7kQwa9BqtzxMqzomyWc/NXIUDW2BvKhwVY9zOBK9eYX0v7KMUE61DqyoQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=MIlRTncMVBB8me+J8V0Iiy+EN+k=; b=g2T4mAYX0mA7rNITlZ3K laI1P3n4rEQOZhV5TtQ8995SrFHh0YwdbR9q+KL7cnfTyIwai8vsbcUBHto+pUZK Cv4t2WSQKz/yfuN3T4kx7riv9T/AAPvjVeLm5XXLk+zpESXlRQ6mlnCl0SprJ3c6 JsQ3y9rSkysZVXKIo+M5Jm4= Received: (qmail 10422 invoked by alias); 22 Sep 2018 17:23:27 -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 10401 invoked by uid 89); 22 Sep 2018 17:23:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=expr_type, outlined, UD:netcologne.de X-HELO: cc-smtpout2.netcologne.de Received: from cc-smtpout2.netcologne.de (HELO cc-smtpout2.netcologne.de) (89.1.8.212) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 22 Sep 2018 17:23:24 +0000 Received: from cc-smtpin1.netcologne.de (cc-smtpin1.netcologne.de [89.1.8.201]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id 2E6CE12720; Sat, 22 Sep 2018 19:23:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=netcologne.de; s=nc1116a; t=1537637002; bh=1ihV1O10MJGO2WyzPhqbN04wuP2x1yGF68CD6C4/j0M=; h=To:From:Subject:Message-ID:Date:From; b=fel7IJ1g5mdPH8203bPSHzyiZEq9SynIjkbRfHyZ3SRSE0qqnXzKZQzUBiHoWiOIC bZqLqshIUI7N0p8lqnZgLwKhO26psbXZHZjviAEV606ORqzZeGtbeTKDIxIV92tOIO 4SLvx9zR28f0BO8mK5tX4UNaT3Dm7R8UKPiDinvHLS7f8YWRroedRzAlB+UAY5ZDM8 UeamyJIbOyfjMS9TNmMXhSSfBsSr8szhboSjZ3CMHC2oOJB5W129nWTHA/L8cSpS8Z Vn4AYB3r5bkDfcq2TDbHGItOdWoWeLQtNKhOKKAdlmFObDauvPnzbHLlBLZEzrBynB AkJiSBN/a6z6Q== Received: from localhost (localhost [127.0.0.1]) by cc-smtpin1.netcologne.de (Postfix) with ESMTP id 1BA0211D93; Sat, 22 Sep 2018 19:23:22 +0200 (CEST) Received: from [78.35.132.184] (helo=cc-smtpin1.netcologne.de) by localhost with ESMTP (eXpurgate 4.6.0) (envelope-from ) id 5ba67a8a-5f8a-7f0000012729-7f000001c088-1 for ; Sat, 22 Sep 2018 19:23:22 +0200 Received: from [192.168.178.68] (xdsl-78-35-132-184.netcologne.de [78.35.132.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by cc-smtpin1.netcologne.de (Postfix) with ESMTPSA; Sat, 22 Sep 2018 19:23:20 +0200 (CEST) To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, fortran] Clobber some intent(out) variables on call Message-ID: Date: Sat, 22 Sep 2018 19:23:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 Hello world, the attached patch lets the middle-end know that variables associated with intent(out) arguments become undefined, by issuing an assignment to a special value (a "clobber") before entering the procedure. Originally, I had also planned to do so on entry to the procedure, see https://gcc.gnu.org/ml/fortran/2018-09/msg00148.html . This turned out to cause regressions; some details are outlined in the PR. Regression-tested. OK for trunk? Regards Thomas 2018-09-22 Thomas Koenig PR fortran/41453 * trans.h (gfc_conv_expr_reference): Add optional argument add_clobber to prototype. (gfc_conv_procedure_call): Set add_clobber argument to gfc_conv_procedure_reference to true for scalar, INTENT(OUT), non-pointer, non-allocatable, non-dummy variables whose type is neither BT_CHARACTER, BT_DERIVED or BT_CLASS, but only if the procedure is not elemental. * trans-expr.c (gfc_conv_procedure_reference): Add clobber statement before call if add_clobber is set. 2018-09-22 Thomas Koenig PR fortran/41453 * gfortran.dg/intent_optimize_2.f90: New test. Index: trans-expr.c =================================================================== --- trans-expr.c (Revision 264487) +++ trans-expr.c (Arbeitskopie) @@ -5276,8 +5276,17 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * } } else - gfc_conv_expr_reference (&parmse, e); + { + bool add_clobber; + add_clobber = fsym && fsym->attr.intent == INTENT_OUT + && !fsym->attr.allocatable && !fsym->attr.pointer + && !e->symtree->n.sym->attr.pointer + && !e->symtree->n.sym->attr.dummy /* See PR 41453. */ + && e->ts.type != BT_CHARACTER && e->ts.type != BT_DERIVED + && e->ts.type != BT_CLASS && !sym->attr.elemental; + gfc_conv_expr_reference (&parmse, e, add_clobber); + } /* Catch base objects that are not variables. */ if (e->ts.type == BT_CLASS && e->expr_type != EXPR_VARIABLE @@ -8060,7 +8069,7 @@ gfc_conv_expr_type (gfc_se * se, gfc_expr * expr, values only. */ void -gfc_conv_expr_reference (gfc_se * se, gfc_expr * expr) +gfc_conv_expr_reference (gfc_se * se, gfc_expr * expr, bool add_clobber) { gfc_ss *ss; tree var; @@ -8100,6 +8109,16 @@ void gfc_add_block_to_block (&se->pre, &se->post); se->expr = var; } + else if (add_clobber) + { + tree clobber; + tree var; + /* FIXME: This fails if var is passed by reference, see PR + 41453. */ + var = expr->symtree->n.sym->backend_decl; + clobber = build_clobber (TREE_TYPE (var)); + gfc_add_modify (&se->pre, var, clobber); + } return; } Index: trans.h =================================================================== --- trans.h (Revision 264487) +++ trans.h (Arbeitskopie) @@ -485,7 +485,8 @@ tree gfc_build_compare_string (tree, tree, tree, t void gfc_conv_expr (gfc_se * se, gfc_expr * expr); void gfc_conv_expr_val (gfc_se * se, gfc_expr * expr); void gfc_conv_expr_lhs (gfc_se * se, gfc_expr * expr); -void gfc_conv_expr_reference (gfc_se * se, gfc_expr *); +void gfc_conv_expr_reference (gfc_se * se, gfc_expr * expr, + bool add_clobber = false); void gfc_conv_expr_type (gfc_se * se, gfc_expr *, tree);