From patchwork Sun Sep 18 20:15:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1282 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2302:b0:79:6ae5:3758 with SMTP id gv2csp1021962dyb; Sun, 18 Sep 2022 13:17:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7NBeqXDESutnoTxwkyLhAXPnO7BDGompzI/6gufOIVkyqI8wy34Tdcp3qKgwkmZn6vx7GI X-Received: by 2002:a17:907:2c44:b0:770:8623:66c4 with SMTP id hf4-20020a1709072c4400b00770862366c4mr10987697ejc.3.1663532249623; Sun, 18 Sep 2022 13:17:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663532249; cv=none; d=google.com; s=arc-20160816; b=n7HoU0M6t6vllN25UYP1LGvUr1oeAq+mvaMztipQJeRRevfgdHi6zY9spxsj6VflBK CsRzpqZ/33LA7ZYx6gUe0b5r3yGxRoGmyRLbEIKVKnIFDEbSbs3jB36fn+ujp3LAmCWc DRvf/BqL+S12afa3plD9+hZoZkgsueddUnG32/KuBTJxiteFkbwrWfGVZLPfxmHSWnWa PbhzD8XsZHqhKZ8UirBfPPAfQI7EfRoh/JdW+q0QWITDFgQVwJaLQ8cgB8hUcWRLVaCm pzEZHUlj/1b0POtt6wRgDPxfgjseueYiVovndO60STVOzK7TgNMvvHseIZKBo2RxNkz+ QRPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=MQ9qdOQjC0GrIXlNT772gwidUdQHGg83ed+nuSXlbsM=; b=EPKcf3Ija4HXnazppXggRyQc0E7aoZKedIkH6nfQ5xXYjRzRYrB4XM4Nbp0tik62sg mQKaXtOV8fvVoei89YC5neb8rOHwKR0agiQ8vcRffZBTig4kVy+QJl/be3l/H0fXGGsc xTQR0cgTdnLbDzO66xLmuyZXTdt8S/W9o3Zk1wumgkGXXJg1skpcaSkddHg98yWlch5c irQJmDEpu0uBVzKTPATjtQSNDYhB4L0rIRmgJk83Pore3SoFuzliSBsDsrQsx8dbUqXi mTuvsXphzsf2e2J3BkTsg8OSwLZ0JoDyW1ACpbe72K71OtE40YPXjZ9TfC/xpPF1baNl Cckw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=R8L28Myc; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f14-20020a50fe0e000000b00442296a8407si6675203edt.629.2022.09.18.13.17.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Sep 2022 13:17:29 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=R8L28Myc; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E2AFC38328E6 for ; Sun, 18 Sep 2022 20:16:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2AFC38328E6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663532201; bh=MQ9qdOQjC0GrIXlNT772gwidUdQHGg83ed+nuSXlbsM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=R8L28MycH0tzrYp7w1ALZHxFosMzMxCvwymOx0iJUNQaFBI98khuO4XagU9oZLbub yeuUIXAjirDQmb5cIcJF74uUODmFFNdnPnYXIwK+NbXJrjW3Bmjj/WPKwF3qbTX/Gc D+uNbvH/NCjUlkFn5R0+KMqqOr3o/uvH8xtTq1ck= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp07.smtpout.orange.fr [80.12.242.129]) by sourceware.org (Postfix) with ESMTPS id EC7D13858D39 for ; Sun, 18 Sep 2022 20:15:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EC7D13858D39 Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id a0hgorqvnjJi0a0hmokkEB; Sun, 18 Sep 2022 22:15:55 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Sun, 18 Sep 2022 22:15:55 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH v2 1/9] fortran: Move the clobber generation code Date: Sun, 18 Sep 2022 22:15:37 +0200 Message-Id: <20220918201545.453296-2-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220918201545.453296-1-mikael@gcc.gnu.org> References: <20220918201545.453296-1-mikael@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Mikael Morin via Gcc-patches From: Mikael Morin Reply-To: Mikael Morin Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744339992279682813?= X-GMAIL-MSGID: =?utf-8?q?1744339992279682813?= This change inlines the clobber generation code from gfc_conv_expr_reference to the single caller from where the add_clobber flag can be true, and removes the add_clobber argument. What motivates this is the standard making the procedure call a cause for a variable to become undefined, which translates to a clobber generation, so clobber generation should be closely related to procedure call generation, whereas it is rather orthogonal to variable reference generation. Thus the generation of the clobber feels more appropriate in gfc_conv_procedure_call than in gfc_conv_expr_reference. Behaviour remains unchanged. gcc/fortran/ChangeLog: * trans.h (gfc_conv_expr_reference): Remove add_clobber argument. * trans-expr.cc (gfc_conv_expr_reference): Ditto. Inline code depending on add_clobber and conditions controlling it ... (gfc_conv_procedure_call): ... to here. --- gcc/fortran/trans-expr.cc | 58 +++++++++++++++++++++------------------ gcc/fortran/trans.h | 3 +- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 850007fd2e1..7902b941c2d 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -6395,7 +6395,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, && e->symtree->n.sym->attr.pointer)) && fsym && fsym->attr.target) /* Make sure the function only gets called once. */ - gfc_conv_expr_reference (&parmse, e, false); + gfc_conv_expr_reference (&parmse, e); else if (e->expr_type == EXPR_FUNCTION && e->symtree->n.sym->result && e->symtree->n.sym->result != e->symtree->n.sym @@ -6502,22 +6502,36 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, } else { - bool add_clobber; - add_clobber = fsym && fsym->attr.intent == INTENT_OUT - && !fsym->attr.allocatable && !fsym->attr.pointer - && e->symtree && e->symtree->n.sym - && !e->symtree->n.sym->attr.dimension - && !e->symtree->n.sym->attr.pointer - && !e->symtree->n.sym->attr.allocatable - /* See PR 41453. */ - && !e->symtree->n.sym->attr.dummy - /* FIXME - PR 87395 and PR 41453 */ - && e->symtree->n.sym->attr.save == SAVE_NONE - && !e->symtree->n.sym->attr.associate_var - && e->ts.type != BT_CHARACTER && e->ts.type != BT_DERIVED - && e->ts.type != BT_CLASS && !sym->attr.elemental; + gfc_conv_expr_reference (&parmse, e); - gfc_conv_expr_reference (&parmse, e, add_clobber); + if (fsym + && fsym->attr.intent == INTENT_OUT + && !fsym->attr.allocatable + && !fsym->attr.pointer + && e->expr_type == EXPR_VARIABLE + && e->ref == NULL + && e->symtree + && e->symtree->n.sym + && !e->symtree->n.sym->attr.dimension + && !e->symtree->n.sym->attr.pointer + && !e->symtree->n.sym->attr.allocatable + /* See PR 41453. */ + && !e->symtree->n.sym->attr.dummy + /* FIXME - PR 87395 and PR 41453 */ + && e->symtree->n.sym->attr.save == SAVE_NONE + && !e->symtree->n.sym->attr.associate_var + && e->ts.type != BT_CHARACTER + && e->ts.type != BT_DERIVED + && e->ts.type != BT_CLASS + && !sym->attr.elemental) + { + tree var; + /* FIXME: This fails if var is passed by reference, see PR + 41453. */ + var = e->symtree->n.sym->backend_decl; + tree clobber = build_clobber (TREE_TYPE (var)); + gfc_add_modify (&se->pre, var, clobber); + } } /* Catch base objects that are not variables. */ if (e->ts.type == BT_CLASS @@ -9485,7 +9499,7 @@ gfc_conv_expr_type (gfc_se * se, gfc_expr * expr, tree type) values only. */ void -gfc_conv_expr_reference (gfc_se * se, gfc_expr * expr, bool add_clobber) +gfc_conv_expr_reference (gfc_se * se, gfc_expr * expr) { gfc_ss *ss; tree var; @@ -9525,16 +9539,6 @@ gfc_conv_expr_reference (gfc_se * se, gfc_expr * expr, bool add_clobber) gfc_add_block_to_block (&se->pre, &se->post); se->expr = var; } - else if (add_clobber && expr->ref == NULL) - { - 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; } diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h index 03d5288aad2..bc9035c1717 100644 --- a/gcc/fortran/trans.h +++ b/gcc/fortran/trans.h @@ -499,8 +499,7 @@ tree gfc_build_compare_string (tree, tree, tree, tree, int, enum tree_code); 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 * expr, - bool add_clobber = false); +void gfc_conv_expr_reference (gfc_se * se, gfc_expr * expr); void gfc_conv_expr_type (gfc_se * se, gfc_expr *, tree); From patchwork Sun Sep 18 20:15:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1285 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2302:b0:79:6ae5:3758 with SMTP id gv2csp1022635dyb; Sun, 18 Sep 2022 13:19:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5jJGbLEob8/ELcDel47sbEPSQQH8UThV+7g8x8S7metOqQMIgxIDsLx0onQ24K9qbcN+iY X-Received: by 2002:a17:907:97c2:b0:780:6a13:53 with SMTP id js2-20020a17090797c200b007806a130053mr10634996ejc.187.1663532378314; Sun, 18 Sep 2022 13:19:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663532378; cv=none; d=google.com; s=arc-20160816; b=SsZsQJ2xHPU5a6b5McxjJnzmX+NfjYATYhl+hMP+VYBUcAiqwsDg+GU2SVpiZhAJkW 0Ni0+JrK2TWmuMunzTxdTIIXPiGAZxjUHTnthEj2jZxB3MwtJtsfshY6pioGYh6qNAr0 Xw+EYLcw3oLscHrSoMoHXpaQWMxyjZuHCJ66/WLZnM/AUlrEY7+y60gbZKiwUxLLrh0X /CaDQk7k/X+RiNcB9v0H2Eri8XzIJRL3yv4OOQSNJXpQfdpVTxoeRVpfu/hQJjc9f0/U e94lVoKd6S+GqcNGy4401UVznTF+z4L5TBMEvv9LOnAPgeKTyd36Iav+pojhEK/CjV0O xlrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=4yfj8YB9+Ure3nyOmgnoeBQ8aVxepNcdq9AvQdtdR5U=; b=Db8oJfVmDo059mFJn+/2ECjMZnZejKzDGFImqPMlM3plJEkk9qXWZTnFF6RUEwLAO2 FNPpEcBOirAZHBThOthhJyWc4+jnHmUJeRUVbQNb9HPXSz/5BNDEdRnC8RaHntXmQspj ZDzJEwZ5+nEZYw9NaOHXZB2CC2N6mOtXTtUqgCNRm6b2BRuR7riMbFzSBcHIbELM8hxY J6iVD3Zh3QWC+qlijbiZwyLM1e0G5/VZ5xrzHQsTrkN/njKmjgbmzSflEYK561rGUeHz cyZeRi5TqS8/2BI1aEo2nNL/sS/ndGCEd1VTeR8cTg75MBVuTVwxw92ZNv3Yksova8mB DMiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ut9AWlwU; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id du21-20020a17090772d500b00780ec2af6e4si4756701ejc.67.2022.09.18.13.19.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Sep 2022 13:19:38 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ut9AWlwU; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C83263831DC5 for ; Sun, 18 Sep 2022 20:17:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C83263831DC5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663532259; bh=4yfj8YB9+Ure3nyOmgnoeBQ8aVxepNcdq9AvQdtdR5U=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ut9AWlwU2HWZ2vldJly+kL49SV4KJl0OsNxFnyNhNt9Ci9hdm5f4scujYR3oz9jEy d8FIstAmVKYIRQe9necS5RTISorCNO43TfPz+ngjnAFkgTQno/ItcfYp1+2IJr6dzj YX2mRoPcAG9E2Co06NxJ3E3c1engpK3BaKSCZ1n4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp08.smtpout.orange.fr [80.12.242.130]) by sourceware.org (Postfix) with ESMTPS id 3FD413858C53 for ; Sun, 18 Sep 2022 20:15:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3FD413858C53 Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id a0hgorqvnjJi0a0hnokkEE; Sun, 18 Sep 2022 22:15:55 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Sun, 18 Sep 2022 22:15:55 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH v2 2/9] fortran: Fix invalid function decl clobber ICE [PR105012] Date: Sun, 18 Sep 2022 22:15:38 +0200 Message-Id: <20220918201545.453296-3-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220918201545.453296-1-mikael@gcc.gnu.org> References: <20220918201545.453296-1-mikael@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Mikael Morin via Gcc-patches From: Mikael Morin Reply-To: Mikael Morin Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744340127088572750?= X-GMAIL-MSGID: =?utf-8?q?1744340127088572750?= The fortran frontend, as result symbol for a function without declared result symbol, uses the function symbol itself. This caused an invalid clobber of a function decl to be emitted, leading to an ICE, whereas the intended behaviour was to clobber the function result variable. This change fixes the problem by getting the decl from the just-retrieved variable reference after the call to gfc_conv_expr_reference, instead of copying it from the frontend symbol. PR fortran/105012 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_conv_procedure_call): Retrieve variable from the just calculated variable reference. gcc/testsuite/ChangeLog: * gfortran.dg/intent_out_15.f90: New test. --- gcc/fortran/trans-expr.cc | 3 ++- gcc/testsuite/gfortran.dg/intent_out_15.f90 | 27 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/intent_out_15.f90 diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 7902b941c2d..76c587e3d9f 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -6528,7 +6528,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, tree var; /* FIXME: This fails if var is passed by reference, see PR 41453. */ - var = e->symtree->n.sym->backend_decl; + var = build_fold_indirect_ref_loc (input_location, + parmse.expr); tree clobber = build_clobber (TREE_TYPE (var)); gfc_add_modify (&se->pre, var, clobber); } diff --git a/gcc/testsuite/gfortran.dg/intent_out_15.f90 b/gcc/testsuite/gfortran.dg/intent_out_15.f90 new file mode 100644 index 00000000000..64334e6f038 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/intent_out_15.f90 @@ -0,0 +1,27 @@ +! { dg-do compile } +! { dg-additional-options "-fdump-tree-original" } +! +! PR fortran/105012 +! The following case was triggering an ICE because of a clobber +! on the DERFC function decl instead of its result. + +module error_function +integer, parameter :: r8 = selected_real_kind(12) ! 8 byte real +contains +SUBROUTINE CALERF_r8(ARG, RESULT, JINT) + integer, parameter :: rk = r8 + real(rk), intent(in) :: arg + real(rk), intent(out) :: result + IF (Y .LE. THRESH) THEN + END IF +end SUBROUTINE CALERF_r8 +FUNCTION DERFC(X) + integer, parameter :: rk = r8 ! 8 byte real + real(rk), intent(in) :: X + real(rk) :: DERFC + CALL CALERF_r8(X, DERFC, JINT) +END FUNCTION DERFC +end module error_function + +! { dg-final { scan-tree-dump-times "CLOBBER" 1 "original" } } +! { dg-final { scan-tree-dump "__result_derfc = {CLOBBER};" "original" } } From patchwork Sun Sep 18 20:15:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1287 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2302:b0:79:6ae5:3758 with SMTP id gv2csp1023152dyb; Sun, 18 Sep 2022 13:21:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5xV73JudTXNVI6zGZAUgovN8sJsMcYq0T85A7hJ16vRmDtjv9ZoORlngksACSWsKI+vxWT X-Received: by 2002:a05:6402:10cc:b0:446:491f:d6dd with SMTP id p12-20020a05640210cc00b00446491fd6ddmr12744771edu.360.1663532477161; Sun, 18 Sep 2022 13:21:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663532477; cv=none; d=google.com; s=arc-20160816; b=ZA+QIulBBmel6vmDLDKl/qoR03nCpH3Mx2+codcbib00P4g4RyPOhTAqb6PDVBRwDY Cvx+r4QCqQ/CUlOETsjSBW0t11JNuGLevq4vwLSn3bLBn4N5HSe32vl1IC0PGza2NH7X 3zIMSEiJkI4D7dWXg9gDkIVQG0X4Mqmi/LpvB5+mXd+CF9KjTDCCYJZanSAFO8C/gbCI 52iPvWHueXHYm7Hv8ZVvcNgT8oDRw5WYaiIWllIYAPth9NEPJw2wdWh4G6PqAEVAPJ6E CARYqdbduuIlOdl4fdHpqFSy/AnU0hwQks/yFGq+P7GhEZF7sEiUjS8rN6FEzyavxj/V QqCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=N3QVz9rcBmAPJpp9jUH+Ops/FarkZ2bWd9L+brNWL4U=; b=MB2AEi1B0JkP1Bggz6O4sSkvbsU6o+dEw0xDPpBkjMHrBHgrxqcawbSsp7293Nxj9g 4/37/yLK0lBInAooPEmQqfz66Lh5MBebewe+9JHUi+N428ishLgXvbAUnB0jnKM1eaj+ CXOh2JN3Yvi8UQhzb+AkaFh+b1hGu1Dx/2d4mY3baohDE8hy2OLelCiz8NEa+VBehX49 dbnIJp7NZRZfLEUsgMnDuKnXDsR1r/AmxEMpSN1sBF7cWVXKetxDDiuj7EzOG20D9/vJ fptbnMGqOdx/V2CWRxJDehRpU5FzJGPZW9LUT0fQYPRsltLr6sq9eDed9iyznPqlTz2w MbeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NNE8ZgnK; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qq17-20020a17090720d100b0072b3cde0ce8si9626677ejb.471.2022.09.18.13.21.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Sep 2022 13:21:17 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NNE8ZgnK; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 87CA5382D434 for ; Sun, 18 Sep 2022 20:18:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 87CA5382D434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663532317; bh=N3QVz9rcBmAPJpp9jUH+Ops/FarkZ2bWd9L+brNWL4U=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=NNE8ZgnK8mS2AsIX395Sg2FwpLaWAR6dacOsaAn4UoJ4rhFF6doFxjTPHW5nPMoOl H8Budn1poZ2FlawWGHg8p40HJDd0J9yTls88y8zz6W9wiNBfeksnO2I+ItSsaLpODo HdgGVoFkUz5Hf1Sxfb4V0rEIbur7I97lOHEhJH+E= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp09.smtpout.orange.fr [80.12.242.131]) by sourceware.org (Postfix) with ESMTPS id 4D97F3858C39 for ; Sun, 18 Sep 2022 20:15:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4D97F3858C39 Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id a0hgorqvnjJi0a0hnokkEH; Sun, 18 Sep 2022 22:15:55 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Sun, 18 Sep 2022 22:15:55 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH v2 3/9] fortran: Move clobbers after evaluation of all arguments [PR106817] Date: Sun, 18 Sep 2022 22:15:39 +0200 Message-Id: <20220918201545.453296-4-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220918201545.453296-1-mikael@gcc.gnu.org> References: <20220918201545.453296-1-mikael@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Mikael Morin via Gcc-patches From: Mikael Morin Reply-To: Mikael Morin Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744340230819941261?= X-GMAIL-MSGID: =?utf-8?q?1744340230819941261?= For actual arguments whose dummy is INTENT(OUT), we used to generate clobbers on them at the same time we generated the argument reference for the function call. This was wrong if for an argument coming later, the value expression was depending on the value of the just- clobbered argument, and we passed an undefined value in that case. With this change, clobbers are collected separatedly and appended to the procedure call preliminary code after all the arguments have been evaluated. PR fortran/106817 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_conv_procedure_call): Collect all clobbers to their own separate block. Append the block of clobbers to the procedure preliminary block after the argument evaluation codes for all the arguments. gcc/testsuite/ChangeLog: * gfortran.dg/intent_optimize_4.f90: New test. --- gcc/fortran/trans-expr.cc | 6 ++- .../gfortran.dg/intent_optimize_4.f90 | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/intent_optimize_4.f90 diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 76c587e3d9f..a62a3bb642d 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -6018,7 +6018,6 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, gfc_charlen cl; gfc_expr *e; gfc_symbol *fsym; - stmtblock_t post; enum {MISSING = 0, ELEMENTAL, SCALAR, SCALAR_POINTER, ARRAY}; gfc_component *comp = NULL; int arglen; @@ -6062,7 +6061,9 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, else info = NULL; + stmtblock_t post, clobbers; gfc_init_block (&post); + gfc_init_block (&clobbers); gfc_init_interface_mapping (&mapping); if (!comp) { @@ -6531,7 +6532,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, var = build_fold_indirect_ref_loc (input_location, parmse.expr); tree clobber = build_clobber (TREE_TYPE (var)); - gfc_add_modify (&se->pre, var, clobber); + gfc_add_modify (&clobbers, var, clobber); } } /* Catch base objects that are not variables. */ @@ -7400,6 +7401,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, vec_safe_push (arglist, parmse.expr); } + gfc_add_block_to_block (&se->pre, &clobbers); gfc_finish_interface_mapping (&mapping, &se->pre, &se->post); if (comp) diff --git a/gcc/testsuite/gfortran.dg/intent_optimize_4.f90 b/gcc/testsuite/gfortran.dg/intent_optimize_4.f90 new file mode 100644 index 00000000000..effbaa12a2d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/intent_optimize_4.f90 @@ -0,0 +1,43 @@ +! { dg-do run } +! { dg-additional-options "-fdump-tree-original" } +! { dg-final { scan-tree-dump-times "CLOBBER" 2 "original" } } +! +! PR fortran/106817 +! Check that for an actual argument whose dummy is INTENT(OUT), +! the clobber that is emitted in the caller before a procedure call +! happens after any expression depending on the argument value has been +! evaluated. +! + +module m + implicit none +contains + subroutine copy1(out, in) + integer, intent(in) :: in + integer, intent(out) :: out + out = in + end subroutine copy1 + subroutine copy2(in, out) + integer, intent(in) :: in + integer, intent(out) :: out + out = in + end subroutine copy2 +end module m + +program p + use m + implicit none + integer :: a, b + + ! Clobbering of a should happen after a+1 has been evaluated. + a = 3 + call copy1(a, a+1) + if (a /= 4) stop 1 + + ! Clobbering order does not depend on the order of arguments. + ! It should also come last with reversed arguments. + b = 12 + call copy2(b+1, b) + if (b /= 13) stop 2 + +end program p From patchwork Sun Sep 18 20:15:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1289 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2302:b0:79:6ae5:3758 with SMTP id gv2csp1023533dyb; Sun, 18 Sep 2022 13:22:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6e2KlJuG4mX5h6gAYDNlj/iQlVXquiW5J9rYRPAquDxZqHdQs3lNoz0djW/GloYYVIii2C X-Received: by 2002:a17:907:2be4:b0:780:c46a:2b72 with SMTP id gv36-20020a1709072be400b00780c46a2b72mr7441127ejc.238.1663532553878; Sun, 18 Sep 2022 13:22:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663532553; cv=none; d=google.com; s=arc-20160816; b=dGP2X30kZT4XpUeIsATCF3HyCJcblQR5f2xI313K8hSQGu5LIINEiR6Hu3e2rBIdm7 SOIhF0bZiFwy9RiKdKDLRjGAgbhEr9aVCC7kUyTxXX0GD7Gj2b5BrEVn8w5TbU9t6Onm 6Gh0g/kyGaKkCFulrME8g8pAJauyO7KJS3INWeaVUI0Lsc3gNX2m7XJu8JJSv8ImR+pW pE1l89GlXr9h05BxFqRNm7r9R9/ZRxmLOq1rD+4Q7905IQCczQiIIXMjGl5F0X0xUngU //X+AjkKcOGgWYV4MUdlPYJDvTIsz3XmdzqkYbgErDPxGg2zlQlERX8/FahrbYiszsJc +ReQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=xFoY3sXsU15QmrV2/Q9M14H2kzE7PkUArqPTXav4KJg=; b=o6+aqv5doUzX/zf3M0W6ButLPINg9FukSGCddrgwW5RrrHYrmWC70cEyyqOl5SYNFI 7Nv8wyW1zC7Yxn+ysDaBqwdkMPvBLkreQ20rfzcsOAp0z9wGkRsRvdSA5v7uPMk7d6Jo A69dcYxO251CD9EE09a1DDeRIchNMD5YfVEWV+1RZXgO61uS9lwfiIHqUxsi1EOKC4xk 6+YyfZQxP5Zp4z8jbPEbFYtCY3gDHox/WapjHIssj34UdC+2nneacvXzmX79gOSL+g5F RJ0akYb1jdjocln48OsrC+kcIBcFA2DaH2k1ZYkexeySUgEPv0xqKnKnF0l+6dJ3lffv OTiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RRTXQk59; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gs37-20020a1709072d2500b00770d9e664f8si26357834ejc.152.2022.09.18.13.22.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Sep 2022 13:22:33 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RRTXQk59; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7CB5C381D4C3 for ; Sun, 18 Sep 2022 20:19:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CB5C381D4C3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663532374; bh=xFoY3sXsU15QmrV2/Q9M14H2kzE7PkUArqPTXav4KJg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=RRTXQk59vngpXaeq+nqBrrD0FdtGn4mS7M62kpAtM1SFJdURe/pbsZCxLovY/1IlW ZNCwL8Q2SamSdZZ4r3p6ZYu/XNNTXRXNpBepwfv511gqopTuY/buciN3AxQ2mogzHf r2SXPwUl238mWT3uHou/SEukemySsNXEvulfA6Us= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp07.smtpout.orange.fr [80.12.242.129]) by sourceware.org (Postfix) with ESMTPS id 8D12E3858406 for ; Sun, 18 Sep 2022 20:15:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D12E3858406 Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id a0hgorqvnjJi0a0hnokkEJ; Sun, 18 Sep 2022 22:15:55 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Sun, 18 Sep 2022 22:15:55 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH v2 4/9] fortran: Support clobbering with implicit interfaces [PR105012] Date: Sun, 18 Sep 2022 22:15:40 +0200 Message-Id: <20220918201545.453296-5-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220918201545.453296-1-mikael@gcc.gnu.org> References: <20220918201545.453296-1-mikael@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Mikael Morin via Gcc-patches From: Mikael Morin Reply-To: Mikael Morin Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744340311210185583?= X-GMAIL-MSGID: =?utf-8?q?1744340311210185583?= From: Harald Anlauf Before procedure calls, we clobber actual arguments whose associated dummy is INTENT(OUT). This only applies to procedures with explicit interfaces, as the knowledge of the interface is necessary to know whether an argument has the INTENT(OUT) attribute. This change also enables clobber generation for procedure calls without explicit interface, when the procedure has been defined in the same file because we can use the dummy arguments' characteristics from the procedure definition in that case. The knowledge of the dummy characteristics is directly available through gfc_actual_arglist’s associated_dummy pointers which have been populated as a side effect of calling gfc_check_externals. PR fortran/105012 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_conv_procedure_call): Use dummy information from associated_dummy if there is no information from the procedure interface. gcc/testsuite/ChangeLog: * gfortran.dg/intent_optimize_5.f90: New test. Co-Authored-By: Mikael Morin --- gcc/fortran/trans-expr.cc | 19 +++++++++++---- .../gfortran.dg/intent_optimize_5.f90 | 24 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/intent_optimize_5.f90 diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index a62a3bb642d..2301724729f 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -6505,10 +6505,21 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, { gfc_conv_expr_reference (&parmse, e); - if (fsym - && fsym->attr.intent == INTENT_OUT - && !fsym->attr.allocatable - && !fsym->attr.pointer + gfc_symbol *dsym = fsym; + gfc_dummy_arg *dummy; + + /* Use associated dummy as fallback for formal + argument if there is no explicit interface. */ + if (dsym == NULL + && (dummy = arg->associated_dummy) + && dummy->intrinsicness == GFC_NON_INTRINSIC_DUMMY_ARG + && dummy->u.non_intrinsic->sym) + dsym = dummy->u.non_intrinsic->sym; + + if (dsym + && dsym->attr.intent == INTENT_OUT + && !dsym->attr.allocatable + && !dsym->attr.pointer && e->expr_type == EXPR_VARIABLE && e->ref == NULL && e->symtree diff --git a/gcc/testsuite/gfortran.dg/intent_optimize_5.f90 b/gcc/testsuite/gfortran.dg/intent_optimize_5.f90 new file mode 100644 index 00000000000..2f184bf84a8 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/intent_optimize_5.f90 @@ -0,0 +1,24 @@ +! { dg-do run } +! { dg-additional-options "-fno-inline -fno-ipa-modref -fdump-tree-optimized -fdump-tree-original" } +! +! PR fortran/105012 +! Check that the INTENT(OUT) attribute causes one clobber to be emitted in +! the caller before the call to Y in the *.original dump, and the +! initialization constant to be optimized away in the *.optimized dump, +! despite the non-explicit interface if the subroutine with the INTENT(OUT) +! is declared in the same file. + +SUBROUTINE Y (Z) + integer, intent(out) :: Z + Z = 42 +END SUBROUTINE Y +PROGRAM TEST + integer :: X + X = 123456789 + CALL Y (X) + if (X.ne.42) STOP 1 +END PROGRAM + +! { dg-final { scan-tree-dump-times "CLOBBER" 1 "original" } } +! { dg-final { scan-tree-dump "x = {CLOBBER};" "original" } } +! { dg-final { scan-tree-dump-not "123456789" "optimized" { target __OPTIMIZE__ } } } From patchwork Sun Sep 18 20:15:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1284 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2302:b0:79:6ae5:3758 with SMTP id gv2csp1022198dyb; Sun, 18 Sep 2022 13:18:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM40DFBpVeTrgrZS748ERidlyZ9HV7dNbVP1LuV+CBXCiUe4hyPhQdE8FaCAMi/GCYJovW0Y X-Received: by 2002:a05:6402:5179:b0:44e:d177:3a21 with SMTP id d25-20020a056402517900b0044ed1773a21mr13150013ede.20.1663532294330; Sun, 18 Sep 2022 13:18:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663532294; cv=none; d=google.com; s=arc-20160816; b=C+qmhrEXWsoLiPYJghqp/pJh9rA9ZW2vqI0BjtsKkCsGXoPDZvuZqOKIzTh1kmBZ3C Le3cMwORYqY/0Tb19TNAcFRiuYC7FdDSH3YNreAsxgZ5uOcBwQ4vZFjKlWVF1Q6IMoyt Bu+7+Oc3rJ82Bl9c20E2eA9gUJKOlgqBEni4j0HpDMSl8ssBbUiLCN1rRS2FuiV7wKlP QKhudFtajlwTduZyME+FzLAETil11XKfxNSQtW50DrpP6H39/ELhdAerGR87af5P8YSM OgmycEx2VqgnkIQX5FIKvC2D22+TFchJGHJUGVefzL1+vvyeS1gpP6mJ8y5hV79Q/VQy hg3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=Uu40qydSDUdRGK5CVxlXI2M3BpupPc3ojTxvLqdyIF4=; b=Q9RR5oufT8b5F9Oa1OPsUQwNsFyoCfTZqpVbmt/eC3l1vtXa0oarAL/fvfEFFpea+v X5YskAUPjWOe1b6+hsnWgcNPeGpo73V83FrqPXsS93P0zY3QMyldt3sQrQQVEvLB/0Fr zMOTJ3DAvtZGubIzI2BvODPSiELTwe8dfjElzcHzTpGPTA8XmztMDOV6pw7Xn9RKDx0o kg4jeNss58r7aBIZK56mHNXZ6UHkwp54JvAIjlcCW1l+E5cePlrUXOJj6rD0qm7x5WHb 4pNGeDEqD999TG8GDvmzXKK9P5gJ6xZXdwiOStdsBi4NbMH8OF1hTHKprCKhmN89c6mT RF2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=i7mCF2j4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e6-20020a17090658c600b0072e6774827asi4608321ejs.915.2022.09.18.13.18.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Sep 2022 13:18:14 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=i7mCF2j4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B4E11382EA29 for ; Sun, 18 Sep 2022 20:16:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B4E11382EA29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663532219; bh=Uu40qydSDUdRGK5CVxlXI2M3BpupPc3ojTxvLqdyIF4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=i7mCF2j4c62oO/i9iozbjqro4Aiu9t844IdD+oJiTFSLzWQeX9A6GqZrQ8+8nputO LChNr+RCWv/7q2zHeP36/5akTNynEsNTNKJmHD4kiKQa8wz9H6MRaxRkjt05kpt1hZ s5/eSR/SE7auNJpJLBmLZ+ZcvwJaTLJnrHb3hsLA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp08.smtpout.orange.fr [80.12.242.130]) by sourceware.org (Postfix) with ESMTPS id 94E2C385840F for ; Sun, 18 Sep 2022 20:15:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 94E2C385840F Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id a0hgorqvnjJi0a0hnokkEL; Sun, 18 Sep 2022 22:15:55 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Sun, 18 Sep 2022 22:15:55 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH v2 5/9] fortran: Support clobbering of reference variables [PR41453] Date: Sun, 18 Sep 2022 22:15:41 +0200 Message-Id: <20220918201545.453296-6-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220918201545.453296-1-mikael@gcc.gnu.org> References: <20220918201545.453296-1-mikael@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Mikael Morin via Gcc-patches From: Mikael Morin Reply-To: Mikael Morin Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744340039018534711?= X-GMAIL-MSGID: =?utf-8?q?1744340039018534711?= This adds support for clobbering of variables passed by reference, when the reference is forwarded to a subroutine as actual argument whose associated dummy has the INTENT(OUT) attribute. This was explicitly disabled and enabling it seems to work, as demonstrated by the new testcase. PR fortran/41453 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_conv_procedure_call): Remove condition disabling clobber generation for dummy variables. Remove obsolete comment. gcc/testsuite/ChangeLog: * gfortran.dg/intent_optimize_6.f90: New test. --- gcc/fortran/trans-expr.cc | 4 --- .../gfortran.dg/intent_optimize_6.f90 | 34 +++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/intent_optimize_6.f90 diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 2301724729f..9b2832bdb26 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -6527,8 +6527,6 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, && !e->symtree->n.sym->attr.dimension && !e->symtree->n.sym->attr.pointer && !e->symtree->n.sym->attr.allocatable - /* See PR 41453. */ - && !e->symtree->n.sym->attr.dummy /* FIXME - PR 87395 and PR 41453 */ && e->symtree->n.sym->attr.save == SAVE_NONE && !e->symtree->n.sym->attr.associate_var @@ -6538,8 +6536,6 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, && !sym->attr.elemental) { tree var; - /* FIXME: This fails if var is passed by reference, see PR - 41453. */ var = build_fold_indirect_ref_loc (input_location, parmse.expr); tree clobber = build_clobber (TREE_TYPE (var)); diff --git a/gcc/testsuite/gfortran.dg/intent_optimize_6.f90 b/gcc/testsuite/gfortran.dg/intent_optimize_6.f90 new file mode 100644 index 00000000000..72fec3db583 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/intent_optimize_6.f90 @@ -0,0 +1,34 @@ +! { dg-do run } +! { dg-additional-options "-fno-inline -fno-ipa-modref -fdump-tree-optimized -fdump-tree-original" } +! +! PR fortran/41453 +! Check that the INTENT(OUT) attribute causes one clobber to be emitted in +! the caller before each call to FOO in the *.original dump, and the +! initialization constant to be optimized away in the *.optimized dump, +! in the case of an argument passed by reference to the caller. + +module x +implicit none +contains + subroutine foo(a) + integer(kind=4), intent(out) :: a + a = 42 + end subroutine foo + subroutine bar(b) + integer(kind=4) :: b + b = 123456789 + call foo(b) + end subroutine bar +end module x + +program main + use x + implicit none + integer(kind=4) :: c + call bar(c) + if (c /= 42) stop 1 +end program main + +! { dg-final { scan-tree-dump-times "CLOBBER" 1 "original" } } +! { dg-final { scan-tree-dump "\\*\\\(integer\\\(kind=4\\\) \\*\\\) b = {CLOBBER};" "original" } } +! { dg-final { scan-tree-dump-not "123456789" "optimized" { target __OPTIMIZE__ } } } From patchwork Sun Sep 18 20:15:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1290 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2302:b0:79:6ae5:3758 with SMTP id gv2csp1023944dyb; Sun, 18 Sep 2022 13:23:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6iLQxNkKrYdyF0UCcgz3wurGrjbzxIYap7YV3+TR8VxYd8D/gxtMAPR42zQ18CjhWvmVsw X-Received: by 2002:a17:907:86ab:b0:77f:f628:3ed7 with SMTP id qa43-20020a17090786ab00b0077ff6283ed7mr10572900ejc.71.1663532627212; Sun, 18 Sep 2022 13:23:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663532627; cv=none; d=google.com; s=arc-20160816; b=kPVyYWAW9TKJ1niLFZWv/w5GBTW/LLrZ/GLmd8c/7uuInMnucI6X8k7hcWbU7mzl7s zD+qAEmS3kUpNihrxh/MUOryVs/pbR/2kRv6BnVohgWE9feFurCAI6f3WaFCI6vjojkl /Cjz5FNRRpNGklQFoV1+cKb9ZC6/G7yTyPQ5ugAh1AcObg9JNb5BDJ7JE65oQdYLOnn5 3yqrFr4n1ygd71d8VPDRFNeDaOOkYLwxU8gg24HV5TQxYfgWUWP5CA51F2s3HK3AC9rE 8l4hX02r9czP9WQceaVpyujCItsiCwoI4Rs/5yBCi2qiH95EVfAYO6+3Styo2x5X2jnH iX4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=TY4tRe/YSalYcihOTimNrvjqZii699z4FtfL0Tze7ZQ=; b=tHIEvMBl6BsLOY8bx3m1b1EvoocEW7yF+6PNywpWJchH3kxeEWam4WAK1u4hAP4ljI Nh4Hi9zEc4Oi7DtuwMr2RvRKwpePM5H7jcfpaCvViDScELKeq58nHSxdvx+TLh0B0Zek 7ibmORgriF7O2+VpJSShEys1VgHSvOnJiSyqr2Epdi/yk+TcMWV2OySbND+C7RjvIS0G voPKfxYK+u1X5YK4BMsBiwwf8gXk/En6kOU6sEDy4xs5pnXwrQXoEeAWqphDjwIsXZUK 4bwdE+hROM5RlgfXrHjXCMYyB0LwUim/9RlnvN+A59WXlx5zoxuGjJWL/3U9QO4Fl95p z4Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PZo07Ajd; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id eb11-20020a0564020d0b00b00451f433ecd4si8214811edb.107.2022.09.18.13.23.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Sep 2022 13:23:47 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PZo07Ajd; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2D8DF38301A9 for ; Sun, 18 Sep 2022 20:20:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D8DF38301A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663532448; bh=TY4tRe/YSalYcihOTimNrvjqZii699z4FtfL0Tze7ZQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=PZo07AjdF9+pjycgbYjGeq4b/fQhga75w3K7G2UjBibn0qRQ7PM9vXFsw25cVPOkA mfs6JQsspUsbzouRdkGiWEAkPfqnE/Qw5u6ei/BOQgIUD418L4V4gU6Jmc8qF90p3t Rk2BlCli8K6stY8/BqvGhxD7qis2W45V4CyD1C0Q= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp07.smtpout.orange.fr [80.12.242.129]) by sourceware.org (Postfix) with ESMTPS id BD32B385843E for ; Sun, 18 Sep 2022 20:15:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BD32B385843E Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id a0hgorqvnjJi0a0hnokkEN; Sun, 18 Sep 2022 22:15:56 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Sun, 18 Sep 2022 22:15:56 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH v2 6/9] fortran: Support clobbering of SAVE variables [PR87395] Date: Sun, 18 Sep 2022 22:15:42 +0200 Message-Id: <20220918201545.453296-7-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220918201545.453296-1-mikael@gcc.gnu.org> References: <20220918201545.453296-1-mikael@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Mikael Morin via Gcc-patches From: Mikael Morin Reply-To: Mikael Morin Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744340388243225730?= X-GMAIL-MSGID: =?utf-8?q?1744340388243225730?= This is in spirit a revert of: r9-3032-gee7fb0588c6361b4d77337ab0f7527be64fcdde2 That commit added a condition to avoid generating ICE with clobbers of variables with the SAVE attribute. The test added at that point continues to pass if we remove that condition now. PR fortran/87395 PR fortran/41453 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_conv_procedure_call): Remove condition on SAVE attribute guarding clobber generation. --- gcc/fortran/trans-expr.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 9b2832bdb26..d169df44a71 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -6527,8 +6527,6 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, && !e->symtree->n.sym->attr.dimension && !e->symtree->n.sym->attr.pointer && !e->symtree->n.sym->attr.allocatable - /* FIXME - PR 87395 and PR 41453 */ - && e->symtree->n.sym->attr.save == SAVE_NONE && !e->symtree->n.sym->attr.associate_var && e->ts.type != BT_CHARACTER && e->ts.type != BT_DERIVED From patchwork Sun Sep 18 20:15:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1283 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2302:b0:79:6ae5:3758 with SMTP id gv2csp1022097dyb; Sun, 18 Sep 2022 13:17:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6L9qOxgccqDgvnE3Gzq+RUrf5uMKO5CFBbCJtXG2jS7ZW+xjiqzMGoDGOLMghO5dsCp/gm X-Received: by 2002:aa7:c74d:0:b0:44f:d34:affb with SMTP id c13-20020aa7c74d000000b0044f0d34affbmr12596971eds.143.1663532275738; Sun, 18 Sep 2022 13:17:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663532275; cv=none; d=google.com; s=arc-20160816; b=Rtv8E/janOdWmrHX3slDeYHgEFGlp6EGnnOa7reDne7HKJqKXjzos0VsAA6eTRWH/T 8zaobGzai6+t9gSSZiBVtL7WhEEjQDv2MvoG2xPkVoUtnmvfkhQE0S/VJVTgGqCk6kkA Uy1fvZK80pkznjmA/SpIOijGs+oGChW9flCRFuM7+Eea1lYnfgxjEF6ZibXYTo22NeZL PZg6J2FXfOUT6vokTi0cFrJAxQ4AtPF63TciamPcpicDNaVjk+YU0iiF17CtGefOdblP ciGWBifg4a40+/15eVCKNMQ7AJGsAQno0yaXHHZcsgQQSinVz9C6/wQ6JyiSaN3UnRmP zqSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=xRAyBfGLD+Kjs0HKVcFLkFN0uDocnd2gOt9ejxzXmKs=; b=QFvDaaTMSHeXAKZq28DNhkA4ebOTnoA3ONGZm43iHcPoK7RUdemMTiyw4o7gYvenhF C4E8QeAsiQoYW7nSy9PRRQgscGb5uIwWoK7xR9FHsgQb8YyPmO5AO96B9/dCbX7P7k+m 5lBU53hfj3YCqB+1zimSzf8ocEWtO9yaPhRFR4RTT80QXESWPzs8vl/KX4iw0X5fbGX4 nGbwkiVo21lwii+mo7eL64G/Ye4EAFslDh5a5s6XqcyqKWbgSL6K8T6g9ozs7w+SQQcf 2h6/3IpBDasZyEdoSkmAUGUYIRi4SPPezJ9tQBuJ7LOVXedANfdrKSUlUp1nvhfbqzpu FaAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="O/lPlyyl"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id nd27-20020a170907629b00b00779f84dbe5fsi27293555ejc.385.2022.09.18.13.17.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Sep 2022 13:17:55 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="O/lPlyyl"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 11E6A3860777 for ; Sun, 18 Sep 2022 20:16:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11E6A3860777 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663532214; bh=xRAyBfGLD+Kjs0HKVcFLkFN0uDocnd2gOt9ejxzXmKs=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=O/lPlyyldFYbm0M6lh8PBVuf/DFW/1dHukSEuqiHQ6PqBa5z6bRdKGShJxtYBl1of 1f2SChU8j6RcdeYZNNW7rVbs+FBAbbGsnWfmUmXq4q3TR2fApnUTDtLi134fVdRaZz K1EehlrFmx1Wlm47/Pt0s7wOlTHRQ3RH/2gL+1v4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp-27.smtpout.orange.fr [80.12.242.27]) by sourceware.org (Postfix) with ESMTPS id E258338582A4 for ; Sun, 18 Sep 2022 20:15:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E258338582A4 Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id a0hgorqvnjJi0a0hookkEP; Sun, 18 Sep 2022 22:15:56 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Sun, 18 Sep 2022 22:15:56 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH v2 7/9] fortran: Support clobbering of ASSOCIATE variables [PR87397] Date: Sun, 18 Sep 2022 22:15:43 +0200 Message-Id: <20220918201545.453296-8-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220918201545.453296-1-mikael@gcc.gnu.org> References: <20220918201545.453296-1-mikael@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Mikael Morin via Gcc-patches From: Mikael Morin Reply-To: Mikael Morin Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744340019677938531?= X-GMAIL-MSGID: =?utf-8?q?1744340019677938531?= This is in spirit a revert of: r9-3051-gc109362313623d83fe0a5194bceaf994cf0c6ce0 That commit added a condition to avoid generating ICE with clobbers of ASSOCIATE variables. The test added at that point continues to pass if we remove that condition now. PR fortran/87397 PR fortran/41453 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_conv_procedure_call): Remove condition disabling clobber generation for ASSOCIATE variables. --- gcc/fortran/trans-expr.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index d169df44a71..4491465c4d6 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -6527,7 +6527,6 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, && !e->symtree->n.sym->attr.dimension && !e->symtree->n.sym->attr.pointer && !e->symtree->n.sym->attr.allocatable - && !e->symtree->n.sym->attr.associate_var && e->ts.type != BT_CHARACTER && e->ts.type != BT_DERIVED && e->ts.type != BT_CLASS From patchwork Sun Sep 18 20:15:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1288 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2302:b0:79:6ae5:3758 with SMTP id gv2csp1023154dyb; Sun, 18 Sep 2022 13:21:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM70JKClAUyUxo4E/QSl2SagAehXs60Wdol3+7iI4IE1adfXlB+1rkVD0cj/Y/EoRmOw4Yms X-Received: by 2002:aa7:cdc8:0:b0:451:e570:882c with SMTP id h8-20020aa7cdc8000000b00451e570882cmr12724938edw.334.1663532477421; Sun, 18 Sep 2022 13:21:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663532477; cv=none; d=google.com; s=arc-20160816; b=kp6D9mSF6uzIghbkU5BxLL+clfqFiLAIsH51/pIVZYemY1nOmNkfOcM3MMmSVPZh72 8Fz6s1UXJGV88ADMYjac6uZLXky9TXxdsEtYGufz2hIKVJSrgvuzwMvRNG6f5R2CpBP+ IAu6gNeVWB9zVsPgccdCX8fFWeaOhd6GIbJzbTuPXAlipjO1RN9jFm+9PvuWnf+fe/3i LtKH7I7hHEc/baWPfMoinJmN/Vy/8aX6gXDlNep8o5uS/0n8TvaUWTZbAKt8l+zM86rJ 7NsrSahXNZJav1KPvuCVrKNSG8W8RQJGToU1R1kEy9fctAPuzpsxY3HG3O/I1+ZWAs9M R0IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=fTRvnNzUIhabWVbgpAScxZNNPGdETc/2/5T2g+mEqug=; b=TdA9kxEf9g/aNbUHh+KIEbVJBgIj8U8BSW5mzZZtwGVmv5s8sxAmbnxLP0cB9jPZiX sOhvi/WI9BAjpFp5EOQEg+yAI4yXS8OUVWR688US7n3mBTB8BHY1HT2Ge+R47xh3Yg5H GG8rsIMbG7inF1ZLnErDTSFSICbGbfG0Aw3dXpvmGxfO/DoSU8DNQG77CjKK+CKWnJbN VJROWH9ktaBiUoBARfWIEjOBUox1HjcqGOh9tPpFXHLh4I9kKndEze5/M+bUAoIWYcol 7UpiAs5ubtibcplo4azvwi/g7GgOL7xoA6LOUoKInhNzINujOGOots263X9gs3dQNp1i awsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DSJmuj35; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qa33-20020a17090786a100b00732fd5caf3fsi21823415ejc.227.2022.09.18.13.21.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Sep 2022 13:21:17 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DSJmuj35; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9CF653851177 for ; Sun, 18 Sep 2022 20:18:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9CF653851177 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663532317; bh=fTRvnNzUIhabWVbgpAScxZNNPGdETc/2/5T2g+mEqug=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=DSJmuj35UV32LbyJ7QJUWYaD9QLfeIsH69OMRqxKfHlE8ATuBg0RJcducYGA28hTj 5MrSBybzcLcOgruzXRHosyeXpgA7KhGT6GoQSwsXl4bpfS8PxPCC5PllC7L3wQcVuC lp4O5gUILZoBHjX968YleVGwZJcKtdN/qIAN2nNU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp-27.smtpout.orange.fr [80.12.242.27]) by sourceware.org (Postfix) with ESMTPS id 14321385800F for ; Sun, 18 Sep 2022 20:15:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 14321385800F Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id a0hgorqvnjJi0a0hookkES; Sun, 18 Sep 2022 22:15:56 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Sun, 18 Sep 2022 22:15:56 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH v2 8/9] fortran: Support clobbering of allocatables and pointers [PR41453] Date: Sun, 18 Sep 2022 22:15:44 +0200 Message-Id: <20220918201545.453296-9-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220918201545.453296-1-mikael@gcc.gnu.org> References: <20220918201545.453296-1-mikael@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Mikael Morin via Gcc-patches From: Mikael Morin Reply-To: Mikael Morin Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744340230705284285?= X-GMAIL-MSGID: =?utf-8?q?1744340230705284285?= This adds support for clobbering of allocatable and pointer scalar variables passed as actual argument to a subroutine when the associated dummy has the INTENT(OUT) attribute. Support was explicitly disabled, but the clobber generation code seems to support it well, as demonstrated by the newly added testcase. PR fortran/41453 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_conv_procedure_call): Remove conditions on ALLOCATABLE and POINTER attributes guarding clobber generation. gcc/testsuite/ChangeLog: * gfortran.dg/intent_optimize_7.f90: New test. --- gcc/fortran/trans-expr.cc | 2 - .../gfortran.dg/intent_optimize_7.f90 | 42 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/intent_optimize_7.f90 diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 4491465c4d6..ae685157e22 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -6525,8 +6525,6 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, && e->symtree && e->symtree->n.sym && !e->symtree->n.sym->attr.dimension - && !e->symtree->n.sym->attr.pointer - && !e->symtree->n.sym->attr.allocatable && e->ts.type != BT_CHARACTER && e->ts.type != BT_DERIVED && e->ts.type != BT_CLASS diff --git a/gcc/testsuite/gfortran.dg/intent_optimize_7.f90 b/gcc/testsuite/gfortran.dg/intent_optimize_7.f90 new file mode 100644 index 00000000000..0146dff4e20 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/intent_optimize_7.f90 @@ -0,0 +1,42 @@ +! { dg-do run } +! { dg-additional-options "-fno-inline -fno-ipa-modref -fdump-tree-optimized -fdump-tree-original" } +! +! PR fortran/41453 +! Check that the INTENT(OUT) attribute causes one clobber to be emitted in +! the caller before each call to FOO in the *.original dump, and the +! initialization constants to be optimized away in the *.optimized dump, +! in the case of scalar allocatables and pointers. + +module x +implicit none +contains + subroutine foo(a) + integer, intent(out) :: a + a = 42 + end subroutine foo +end module x + +program main + use x + implicit none + integer, allocatable :: ca + integer, target :: ct + integer, pointer :: cp + + allocate(ca) + ca = 123456789 + call foo(ca) + if (ca /= 42) stop 1 + deallocate(ca) + + ct = 987654321 + cp => ct + call foo(cp) + if (ct /= 42) stop 2 +end program main + +! { dg-final { scan-tree-dump-times "CLOBBER" 2 "original" } } +! { dg-final { scan-tree-dump "\\*ca = {CLOBBER};" "original" } } +! { dg-final { scan-tree-dump "\\*cp = {CLOBBER};" "original" } } +! { dg-final { scan-tree-dump-not "123456789" "optimized" { target __OPTIMIZE__ } } } +! { dg-final { scan-tree-dump-not "987654321" "optimized" { target __OPTIMIZE__ } } } From patchwork Sun Sep 18 20:15:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1286 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2302:b0:79:6ae5:3758 with SMTP id gv2csp1022791dyb; Sun, 18 Sep 2022 13:20:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5OzGMjzlQDdfBGZ1awTixFHwnZJt0yicv1pn8VQ7vWyn5J6rQCbqoLaJNcdmSJLPnMiYpq X-Received: by 2002:aa7:cdd2:0:b0:44e:be4d:3231 with SMTP id h18-20020aa7cdd2000000b0044ebe4d3231mr13065379edw.296.1663532405147; Sun, 18 Sep 2022 13:20:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663532405; cv=none; d=google.com; s=arc-20160816; b=uzG7X4Qkxm5k30Uwu1OnEEwTQTfJ32k9gIxKde50g9NTOi8tCgb4Rvqa/wqm0kSNRU kiRL3zX2G0EJQ+SZ/LblLQT2YFP1vkzUFBrXC1+uTmSq2ZWEUDtq/0kHqxw7EwyWfZeE Bich+SqAddcUA2rFErwE970tnbsjy6JjXN33wkJP1NsIW7e4dX8aabR5Ft8cX/7Eettg yWaK1tFH//pBKROXUtL1I47GEo6EP2BitI+fVYjwjxojxh570flw47LVonXJNbrtQJsh mu4YUawuTvwByDc0KdUTwe0RAWSFu+wKssaA7QjQW9DBRSCdzXSLDweiRvhJPujIjIOU +joQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=DMY1oAj1ErC4wctnlyAUFJLtmJ2nnaEOdkIYhdzS+5k=; b=PFlscI9XWGPJw6PNPXGw3o3Rw5GVTVlR6MYN9vcvNhiWRZjaGYty7Zu7xcIDhj/j0e 9i8LkvARIOzikP/DH31j8jv/Z6rpt8TT69ZLnaNV1+SctSbMWbuz/c1ox6JdvTMw4qZs wOh9h+esSGvqK9VY3yIs9Y+g5Nupg951ZLUxKsXv7/Nw4q/wZpheb7r9NHzUkFk+ZvSa WLL+djYfD0Mj9CljVQM8RFkvoXbBysZPjxsBBeZOD5m+cTpC13LFqhyYeBI8Q5mjcz6+ ioe44jyI3Tm6IUyhLapuufY656wZjz9YoPVhF5EgqIX1J35kTGOau/4a+5V2P8bkyLTG QV4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yRl8PEJZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id o3-20020a170906974300b0073d15dfd9b7si27196299ejy.472.2022.09.18.13.20.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Sep 2022 13:20:05 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yRl8PEJZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4C73E3948A7D for ; Sun, 18 Sep 2022 20:17:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C73E3948A7D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663532272; bh=DMY1oAj1ErC4wctnlyAUFJLtmJ2nnaEOdkIYhdzS+5k=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=yRl8PEJZQQ+gOSVcfC9aRYf92hI5WE8DVqXczgi0cOm1sQqdo+NTOwXg32lF0HGPw ct9WY0HySqHVlW/he7v9MyrihXmz+1nfdjMSmXJsEcyeD4XSzua//psElmFEPtOP5y yuKouCZaQGF0bwraXLDFcZTTJGVDszQr/DuCnyhM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp07.smtpout.orange.fr [80.12.242.129]) by sourceware.org (Postfix) with ESMTPS id 3A2303857C4D for ; Sun, 18 Sep 2022 20:15:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3A2303857C4D Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id a0hgorqvnjJi0a0hookkEU; Sun, 18 Sep 2022 22:15:56 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Sun, 18 Sep 2022 22:15:56 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH v2 9/9] fortran: Support clobbering of derived types [PR41453] Date: Sun, 18 Sep 2022 22:15:45 +0200 Message-Id: <20220918201545.453296-10-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220918201545.453296-1-mikael@gcc.gnu.org> References: <20220918201545.453296-1-mikael@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Mikael Morin via Gcc-patches From: Mikael Morin Reply-To: Mikael Morin Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744340155205621352?= X-GMAIL-MSGID: =?utf-8?q?1744340155205621352?= This is probably the most risky patch in the series. A previous version of this patch allowing all exactly matching derived types showed two regressions. One of them uncovered PR106817 for which I added a fix in this series, and for the other I have excluded types with allocatable components from clobbering. I have additionnally excluded finalizable types for similar reasons, and parameterized derived type because they may not be constant-sized. I hope we are safe for all the rest. -- >8 -- This adds support for clobbering of non-polymorphic derived type variables, when they are passed as actual argument whose associated dummy has the INTENT(OUT) attribute. We avoid to play with non-constant type sizes or class descriptors by requiring that the types are derived (not class) and strictly matching, and by excluding parameterized derived types. Types that are used in the callee are also excluded: they are types with allocatable components (the components will be deallocated), and finalizable types or types with finalizable components (they will be passed to finalization routines). PR fortran/41453 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_conv_procedure_call): Allow strictly matching derived types. gcc/testsuite/ChangeLog: * gfortran.dg/intent_optimize_8.f90: New test. --- gcc/fortran/trans-expr.cc | 18 ++++- .../gfortran.dg/intent_optimize_8.f90 | 66 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/intent_optimize_8.f90 diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index ae685157e22..16f14554db3 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -6526,8 +6526,24 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, && e->symtree->n.sym && !e->symtree->n.sym->attr.dimension && e->ts.type != BT_CHARACTER - && e->ts.type != BT_DERIVED && e->ts.type != BT_CLASS + && (e->ts.type != BT_DERIVED + || (dsym->ts.type == BT_DERIVED + && e->ts.u.derived == dsym->ts.u.derived + /* Types with allocatable components are + excluded from clobbering because we need + the unclobbered pointers to free the + allocatable components in the callee. + Same goes for finalizable types or types + with finalizable components, we need to + pass the unclobbered values to the + finalization routines. + For parameterized types, it's less clear + but they may not have a constant size + so better exclude them in any case. */ + && !e->ts.u.derived->attr.alloc_comp + && !e->ts.u.derived->attr.pdt_type + && !gfc_is_finalizable (e->ts.u.derived, NULL))) && !sym->attr.elemental) { tree var; diff --git a/gcc/testsuite/gfortran.dg/intent_optimize_8.f90 b/gcc/testsuite/gfortran.dg/intent_optimize_8.f90 new file mode 100644 index 00000000000..d8bc1bb3b7b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/intent_optimize_8.f90 @@ -0,0 +1,66 @@ +! { dg-do run } +! { dg-additional-options "-fno-inline -fno-ipa-modref -fdump-tree-optimized -fdump-tree-original" } +! +! PR fortran/41453 +! Check that the INTENT(OUT) attribute causes in the case of non-polymorphic derived type arguments: +! - one clobber to be emitted in the caller before calls to FOO in the *.original dump, +! - no clobber to be emitted in the caller before calls to BAR in the *.original dump, +! - the initialization constants to be optimized away in the *.optimized dump. + +module x + implicit none + type :: t + integer :: c + end type t + type, extends(t) :: u + integer :: d + end type u +contains + subroutine foo(a) + type(t), intent(out) :: a + a = t(42) + end subroutine foo + subroutine bar(b) + class(t), intent(out) :: b + b%c = 24 + end subroutine bar +end module x + +program main + use x + implicit none + type(t) :: tc + type(u) :: uc, ud + class(t), allocatable :: te, tf + + tc = t(123456789) + call foo(tc) + if (tc%c /= 42) stop 1 + + uc = u(987654321, 0) + call foo(uc%t) + if (uc%c /= 42) stop 2 + if (uc%d /= 0) stop 3 + + ud = u(11223344, 0) + call bar(ud) + if (ud%c /= 24) stop 4 + + te = t(55667788) + call foo(te) + if (te%c /= 42) stop 5 + + tf = t(99887766) + call bar(tf) + if (tf%c /= 24) stop 6 + +end program main + +! We don't support class descriptors, neither derived type components, so there is a clobber for tc only; +! no clobber for uc, ud, te, tf. +! { dg-final { scan-tree-dump-times "CLOBBER" 1 "original" } } +! { dg-final { scan-tree-dump "tc = {CLOBBER};" "original" } } + +! There is a clobber for tc, so we should manage to optimize away the associated initialization constant (but not other +! initialization constants). +! { dg-final { scan-tree-dump-not "123456789" "optimized" { target __OPTIMIZE__ } } }