From patchwork Fri Sep 16 20:24:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1262 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp915807wrt; Fri, 16 Sep 2022 13:26:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM56Xtns+bdc0X1U3S3LvO4bN4mC8NA2SVBIGUZdM813hOnXMPcCz5bjdQ2naUh+fnUj270q X-Received: by 2002:a17:907:7e9b:b0:780:3d91:9223 with SMTP id qb27-20020a1709077e9b00b007803d919223mr4733889ejc.157.1663359994129; Fri, 16 Sep 2022 13:26:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663359994; cv=none; d=google.com; s=arc-20160816; b=uBstEXn8valUThEPRvCsXIxBqBQnVsHoHjnQQVtbb3+3Qo1jZIa62uLmcXtVmxcOnh uvxrKmX83RF+eRYmMkV/ulWTuJvH+XxhgKiRsg/f3Y/TkNfmsZHXWBZUBNkE3JvuJo1Z JnEPubIoZB/oLpCOlOpkBNb0VwQ+6o1blhzfpwTfI1XVlz3mOFYhbO+hN4zjIu0C/6im Y71EMeSXk1WIKpdpH9itDAlN+xGbsF6hoEa+3rcO0FIMfkmPMglskNa8one5alEaKc8k 9kR4geVOP0DC2bisojKDYSK9eUK6o6ZrV3WdSLdkeWEZFqPnHjTkCevNoTthdVGBkgVz O+vQ== 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=aQz3SPdbailS3Likk0ZHhHIxx9GbgQ5DayXsy0YmAkjHRUE5CGnq9H9TXZENTMBTpT XWwLXoDZenzGpjoRMyPENi/wniC17rwUKiQA+ua52t5tHN3lul2q7em5Y/s/ArOSHMT5 el0+P7MfKoO+kRNXhA1cOhNzeC1AMyxPQNWukwgqLma5pEAeSqAN1Wan/eY8o92NTkaH rbVKc9BtQG9byW5UjhjC1UYXrbHTCHi4XZTiJ5q25OaiUBbIJsIuUbFMz2Eh2CO6Xs8l JrHx+epqc5/PrPJx1M1CyKJ9Mf6SU+JqmJe42Fv5X4J2d3OvI98rpn+EsQL71+AKrIlG ZhUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Q5ql0Yh8; 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 hr14-20020a1709073f8e00b0077b4a3c47d6si18048353ejc.679.2022.09.16.13.26.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 13:26:34 -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=Q5ql0Yh8; 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 8E4F23954C76 for ; Fri, 16 Sep 2022 20:25:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8E4F23954C76 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663359931; 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=Q5ql0Yh8XqvuW1LyUZMuBB5JVKQrZWvbn8sJfrjtFmveMzFfU6Q4dQ4mQk48DDBEc oWw0R3MS9gMD76Hgz7AjDeTFvTtbxtYHiIdTszPBCs5fZlExVV1AoZkDe6LY/ExIBq MnKIWFee27QB3YhZ4VHh/QklHZeH+RBwQ4pgp7IA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp03.smtpout.orange.fr [80.12.242.125]) by sourceware.org (Postfix) with ESMTPS id 71637385C420 for ; Fri, 16 Sep 2022 20:24:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 71637385C420 Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id ZHt9oWAI9LFqbZHtFowxzc; Fri, 16 Sep 2022 22:24:45 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Fri, 16 Sep 2022 22:24:45 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH 01/10] fortran: Move the clobber generation code Date: Fri, 16 Sep 2022 22:24:30 +0200 Message-Id: <20220916202439.549820-2-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220916202439.549820-1-mikael@gcc.gnu.org> References: <20220916202439.549820-1-mikael@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.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?1744159368925383525?= X-GMAIL-MSGID: =?utf-8?q?1744159368925383525?= 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 Fri Sep 16 20:24:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1260 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp915777wrt; Fri, 16 Sep 2022 13:26:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7LbreXVi9h0urwxsyiQZRitG78XSww3FoaYU+oKR3IFLzYpsFX9ameqYGLwwR2JdwGibWn X-Received: by 2002:a17:907:9718:b0:77b:45b6:b047 with SMTP id jg24-20020a170907971800b0077b45b6b047mr4706714ejc.479.1663359990038; Fri, 16 Sep 2022 13:26:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663359990; cv=none; d=google.com; s=arc-20160816; b=K9aJ9S5wkd+3SnujYDlPoj28ehDsQumuTguwBF6K5r2lbnC48xrVka2BxguQSkTxZK EWR5bKO4mY9Cv/nAv4oKr4/okrDDz9xN4EGqb6KSIqizoF7eAkk4K5bD6ImcVEo/kExC E4lKwJgV71pM6tY6EwktnwggUd+yJO8ye5wMWpyCpynBFFK2mJAntxMafOwEJDo7wwl7 7F2sL+AppAewZfZG6WFhkbo11WlRhMmXH+fjBfKcGvjr40v3ZbHc2oZme/Ypw5eyqdYX oHYNuTnqwMCUvbrH3evM2zzVAH5YwGT8UHiFjGoInT0kXkR8+FVYX1aC5SbSdkY/1TnR 7wIQ== 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=SYi40GFTbASyb4I1AaSvCohWsd7QAwEU724W/Z13vJE4qwQmwk27UBZqMTl3GqbK3v jhRcoWf9HbDVpMKvZp8E7fLz35vcr1banhflqWCEB7MDlJmchRpuEGZGUaR2ZFWuGbid qbFT7zUzTMqmGH3/Jqp9KzT94l3vCgy2SY25X+eMbbzijiURmPwnAcVRUIFo8QlObp44 B5L3HC6h3hNBtU0r2zYw8hQ3fPlGh/pZFxeevW1A5Tnt14aERIX1h6iqghpJPsE2m3h1 oN6/Ao+XZqbt01/Yeqe2iYYqqXJR55yQFt+XA9QAEnJ3CncfQxfAkbG8QGyOIm74/5JT skWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eLGu6o7G; 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 s5-20020a170906c30500b0073dced72063si14568270ejz.570.2022.09.16.13.26.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 13:26:30 -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=eLGu6o7G; 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 833FE395445F for ; Fri, 16 Sep 2022 20:25:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 833FE395445F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663359930; 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=eLGu6o7GrtRGNwtsYgcsu+0IXwLlcggmmJ5Ydsx23TrxBVV/VA0XjWNTZZp3Cakci vebN2ZyBI9xA7TGZ9DIltKYDvygbJE4pRyPEWAmSA3A5Gb70LmKEUeO+jFESVDC1Nd TdfRReMZWO6KOlpkMYvD7N/gixikJflMl21pb5Ho= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp01.smtpout.orange.fr [80.12.242.123]) by sourceware.org (Postfix) with ESMTPS id 73B013854161 for ; Fri, 16 Sep 2022 20:24:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 73B013854161 Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id ZHt9oWAI9LFqbZHtFowxze; Fri, 16 Sep 2022 22:24:45 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Fri, 16 Sep 2022 22:24:45 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH 02/10] fortran: Fix invalid function decl clobber ICE [PR105012] Date: Fri, 16 Sep 2022 22:24:31 +0200 Message-Id: <20220916202439.549820-3-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220916202439.549820-1-mikael@gcc.gnu.org> References: <20220916202439.549820-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?1744159364644559140?= X-GMAIL-MSGID: =?utf-8?q?1744159364644559140?= 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 Fri Sep 16 20:24:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1261 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp915784wrt; Fri, 16 Sep 2022 13:26:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ffkWFTcOnIY4L/Kwg8Mr2QvOYqKxPeHg7eTbpMRcZpZZ90AZleA95MHHjzfFIgCHmG/8q X-Received: by 2002:a17:906:846b:b0:770:82e5:1519 with SMTP id hx11-20020a170906846b00b0077082e51519mr4791079ejc.221.1663359991441; Fri, 16 Sep 2022 13:26:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663359991; cv=none; d=google.com; s=arc-20160816; b=c3kRsHMBRUP0rLtl991csRSfzjl8BNSNfzMIYaMr7x/xURchnsc9FFpybSx0P2zR13 3O9jTvAUax49RE22BLtAyA9YODmJRoGyr7oFzLvplzoyn9ZzmsL0flKvseKEDnax5rZu iiuU5YCPRsIBojX8yFMkK0qpSw7kqjz9Nmwakq19e8bNUwHU0VmHzHNUbPIYOVjVKYyW s3YUwz7+tOIFFsZvMZ4JfwwhhTX/u29ayJxZOPZS+pJ6SNexmnmZ5Lv2mGK7wffnaQLo 8GSTNaWfct4f+nT8IQW6pLwXhIvVlaMaX2JuMjblVmKgcTST4yK1HBYMnWqbmuWwHlpn JRNQ== 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=J7QW8S0qLCc9tTnsWlRTFADi/YmXFkBL8ipeNOdsRgA=; b=lWUwV1DMRkE62lfQW8iEzudUfOeupFg4A7KJv77+8N+d1tri7l3PxxG5uV9Xff8vA2 4rfr1uia8puQbTTiaseETrWXFHLvSEAKQQS/15GUAoQx45aVDCB+Mc3wpJU4PVdYvJ1t wAWTIn67SOq9H6AnX6nYyFvvatva0bt1k3PWZQAkfZH8vQg9kYCfaqt/06Bn1bwXn22J Csr1zBTzeyFAL5gxWwWnPZyNuykyv2ASLP2qgcOFP4ulIYbKVOE8c61CajnG5tS7cMze KSfpWtPld+q5nMrrGlBWSwV11Bs3wabGTBUwDVfq+E90YfjXR7y7+2/0kpKU7gTcoFNP JzwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yBz0SkiY; 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 fj4-20020a1709069c8400b0073d751c96adsi15959911ejc.1000.2022.09.16.13.26.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 13:26:31 -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=yBz0SkiY; 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 DE0743948821 for ; Fri, 16 Sep 2022 20:25:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE0743948821 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663359930; bh=J7QW8S0qLCc9tTnsWlRTFADi/YmXFkBL8ipeNOdsRgA=; 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=yBz0SkiY0I5wrrPbw+W73JwKo7/An74h347cbcIMDjIwCrPGgLKuccMHj+9iQr519 kGjb0EpU0BlCGAD14VblvnEZEDKlCCY26ekZC/7nO1wPE2KIeJ7aT+IfwER93SAF+m EnQwoiLUrdTO/GE1Q2nNAZApiRbJJ2R4ph4emgBE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp-12.smtpout.orange.fr [80.12.242.12]) by sourceware.org (Postfix) with ESMTPS id 6D0653857B9D for ; Fri, 16 Sep 2022 20:24:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6D0653857B9D Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id ZHt9oWAI9LFqbZHtFowxzg; Fri, 16 Sep 2022 22:24:45 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Fri, 16 Sep 2022 22:24:45 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH 03/10] fortran: Move clobbers after evaluation of all arguments [PR106817] Date: Fri, 16 Sep 2022 22:24:32 +0200 Message-Id: <20220916202439.549820-4-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220916202439.549820-1-mikael@gcc.gnu.org> References: <20220916202439.549820-1-mikael@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KHOP_HELO_FCRDNS, 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?1744159366609295592?= X-GMAIL-MSGID: =?utf-8?q?1744159366609295592?= 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_9.f90: New test. --- gcc/fortran/trans-expr.cc | 6 ++- .../gfortran.dg/intent_optimize_9.f90 | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/intent_optimize_9.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_9.f90 b/gcc/testsuite/gfortran.dg/intent_optimize_9.f90 new file mode 100644 index 00000000000..effbaa12a2d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/intent_optimize_9.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 Fri Sep 16 20:24:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1264 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp916828wrt; Fri, 16 Sep 2022 13:29:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7KGPG3gmR8JPV7uPl+Lj6yTADZR7idSH8j/XdBgNgzN+EboZfnKyvkhwiDhBEQw7xP7hWU X-Received: by 2002:a17:907:7e9b:b0:780:3d91:9223 with SMTP id qb27-20020a1709077e9b00b007803d919223mr4740206ejc.157.1663360182020; Fri, 16 Sep 2022 13:29:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663360182; cv=none; d=google.com; s=arc-20160816; b=Os/zPPR7VKHm2nMAuD/Y/aY11VL9ruF3FsOzgoVFyAB5f9ndgxwMRwqdthQKvVQQjf eYHesglnVBjFvKj1qcyS2vUtOwrXxZvlfP1bDVuvbvmzXKQQ6dF1YfGFWp/Rczy/G+WS qG+j51fpVswxpaFC/uJW45mxvEsKgQuK8Gfc1esg0uKAHVrqxkqb7vV/fPHOkZl4+sNS 7e7LJwFvS71ytct6O397K6lfcQraE80/EDzq/pyynkl1YgCe3Y9y3b3X6o9u7/cCR2sM a/V13L8+Rp7DIVRJfxT/Wh+MbnAR1U/omFpu0/QQ9lGrsm3nlwBxONYUUNDSBdw/QPRU QQCA== 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=ZXOiN/Bv6DpQuvv+KWPTFD0wFIrBZpkjNRqV571GdZs=; b=FTW0vst1rfYuFyvv0xehYacQgQRWzAv3yfiyRaCCQdGlVRgfI+PjtpuATVbJrQYveO wFOqP0yCDFOpIK7ooL+lzty1mxVsitc8QNGYhy5eLUd9baMfuZvSiqMgCwkrg1dTlcMy mmpWtbGoTlsYDP5ppLZA1Vy5A7iiUtmHbcqOM08VbYoG6MUclwaB95nSn2/RPoot2A4N vqhS+U/FALRoITtqwWTVj7/U5+r/HQunN9p9wLVRBlOs2duP+1WMSr8LGyRYrXQ2X0T4 ihVtlyh52iTVvuQeUHng60MCRgOwW4JXDH0zGXyPugQEFnTO28aPPB717kzNE3fy4gHS qpcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=M9aRijMC; 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 xe6-20020a170907318600b0077de0f381f1si14733329ejb.811.2022.09.16.13.29.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 13:29:42 -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=M9aRijMC; 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 1C3F33959CB1 for ; Fri, 16 Sep 2022 20:27:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C3F33959CB1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663360021; bh=ZXOiN/Bv6DpQuvv+KWPTFD0wFIrBZpkjNRqV571GdZs=; 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=M9aRijMCSrZJAVPm45Bejy5UGAp5XGYxXe+ZaMGGAM0jEVuLYW2zB2jr3g6MN14jO hDy8bhfybgkrziQclxg5ZRxZN5L41fvYYOXztnc1raQpRm72ZyJPlvmUS90AfM769O eRib4U1v6U3aEerIII+mCR0PFgd/2DSPqFXhc7/8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp02.smtpout.orange.fr [80.12.242.124]) by sourceware.org (Postfix) with ESMTPS id 8D71D3853821 for ; Fri, 16 Sep 2022 20:24:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D71D3853821 Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id ZHt9oWAI9LFqbZHtFowxzj; Fri, 16 Sep 2022 22:24:45 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Fri, 16 Sep 2022 22:24:45 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH 04/10] fortran: Support clobbering with implicit interfaces [PR105012] Date: Fri, 16 Sep 2022 22:24:33 +0200 Message-Id: <20220916202439.549820-5-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220916202439.549820-1-mikael@gcc.gnu.org> References: <20220916202439.549820-1-mikael@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 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?1744159566400516323?= X-GMAIL-MSGID: =?utf-8?q?1744159566400516323?= 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_4.f90: New test. Co-Authored-By: Mikael Morin --- gcc/fortran/trans-expr.cc | 19 +++++++++++---- .../gfortran.dg/intent_optimize_4.f90 | 24 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 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 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_4.f90 b/gcc/testsuite/gfortran.dg/intent_optimize_4.f90 new file mode 100644 index 00000000000..2f184bf84a8 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/intent_optimize_4.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 Fri Sep 16 20:24:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp917213wrt; Fri, 16 Sep 2022 13:30:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5qT4VQgQo2lMYkTFO4dCN3cl0cGUPKURFSjdrJdvZqKcC7VtJAjlGeXX95ARccA3+JnGTD X-Received: by 2002:a17:906:6dd3:b0:742:296d:15c8 with SMTP id j19-20020a1709066dd300b00742296d15c8mr4610117ejt.550.1663360248027; Fri, 16 Sep 2022 13:30:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663360248; cv=none; d=google.com; s=arc-20160816; b=sQ+hk2xhdVz7TOuRdJXMAOSlHXHs5L0+MSlYXUMK45L5NaPAHzaz4m1UKPnefa5S/I 3Q6oJ5TUlt845TEu+Ql6xSIEDu4qo4aowmk7GAD5Nrh2YyOFzWOdVuup6W/BpphINLua 3zQMXlgWtMxuHN7h8hYGGXZ5fO17meKJxd2vsOUxqaIcymJcpz9w+bK1vGEUmZo1ldrz 36S8TconlOTLvNQZglOnjo/WgzXmWt4DxZYmANERU3yRUAxZN3tzQE4pPmWzaaG6M/vF SzW+4U6iLiydPCP1LWpiVoU5D1BQsLx6Ssh2H9KBNfvTFM8yD7QTFzhzk0m4f+jUj6/4 swFw== 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=WU70xemW24723QxBkjxUnOH/xWCj54vbulXHJdCuXfY=; b=u/2PNv9sH8WjuntYykB+IWxE2LFkB7QzcCnzpbDycqyUyIbz9UHadrtsI0iyQy9Dyt AaXC42p9/wYFVqOQz/qlSBOLiGWwCABTRsKuSMimymGgbig7MJLa4WkzcAwSiIa0feHw 0/wYGDI9xkgnV1bqGEIKFvscVmwxzb9aCLuqqMkjutWRMZpLtYbMrZNUw2eB5HICyImU dg7IV1zSUoMVU5FFekdXYbzsnTFf6s+MfEOP9DnlthT8q62fAQ1694kbw+fHnTEWmBBe jyiTFWrxXtPNT5+tuiO5qLYQcqdYHQww98SvKioaPsmFHYRDKl5ltxeEbvBLjZfbsvt+ nBQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qxy1suoZ; 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 b13-20020a056402278d00b0045174ca49fesi3442364ede.67.2022.09.16.13.30.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 13:30:48 -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=qxy1suoZ; 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 6D32939540B7 for ; Fri, 16 Sep 2022 20:27:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D32939540B7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663360078; bh=WU70xemW24723QxBkjxUnOH/xWCj54vbulXHJdCuXfY=; 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=qxy1suoZrK2GQmkvMnsRoKXtU6Cpxzz9WFHQMfwWn01W+Fedeq+a0P5FAVu4pD9Vd SFDyuBHpiVPgIXhTGWdVzBS4qYhF2WRrqkf6g4y3W+3NcE6/1PqcBMH9DHR3ZLOPf4 fbESt0bu6SKQ8DuupBebvPWZp+FUEKDVXouC/Qco= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp-12.smtpout.orange.fr [80.12.242.12]) by sourceware.org (Postfix) with ESMTPS id B31A83853837 for ; Fri, 16 Sep 2022 20:24:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B31A83853837 Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id ZHt9oWAI9LFqbZHtFowxzm; Fri, 16 Sep 2022 22:24:45 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Fri, 16 Sep 2022 22:24:45 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH 05/10] fortran: Support clobbering of reference variables [PR41453] Date: Fri, 16 Sep 2022 22:24:34 +0200 Message-Id: <20220916202439.549820-6-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220916202439.549820-1-mikael@gcc.gnu.org> References: <20220916202439.549820-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, KHOP_HELO_FCRDNS, 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?1744159635559755779?= X-GMAIL-MSGID: =?utf-8?q?1744159635559755779?= 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_5.f90: New test. --- gcc/fortran/trans-expr.cc | 4 --- .../gfortran.dg/intent_optimize_5.f90 | 34 +++++++++++++++++++ 2 files changed, 34 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 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_5.f90 b/gcc/testsuite/gfortran.dg/intent_optimize_5.f90 new file mode 100644 index 00000000000..1633b681fc3 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/intent_optimize_5.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, intent(out) :: a + a = 42 + end subroutine foo + subroutine bar(b) + integer :: b + b = 123456789 + call foo(b) + end subroutine bar +end module x + +program main + use x + implicit none + integer :: 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 Fri Sep 16 20:24:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1263 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp916504wrt; Fri, 16 Sep 2022 13:28:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4HmM3hLiuEIyYGWfkJ7MOF0bsKqnLyWZNl6fLCUn8Leke+0AAqKkACUqjqw7GJerU479rp X-Received: by 2002:a05:6402:5409:b0:44f:1e05:1e8 with SMTP id ev9-20020a056402540900b0044f1e0501e8mr5274656edb.373.1663360126634; Fri, 16 Sep 2022 13:28:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663360126; cv=none; d=google.com; s=arc-20160816; b=eGcY3114nOHgmp6C4+giiz6NJXzMwYmWb5Td0ZC00QOwqUHeX3G9SP+oXxwLHULSYa 2Kr9HVAFw5/Rt0rS21JH4cxr7GNnDvbs+o5UOgPMbH1SQLkOkDfs5GDHiSm8KxAtqt6n AezbX6kpSaH9GnuCr+GbMjJwa+WKX7Ah1XegJAAF2YzstxZrVxcKaujoDT6O0uSMTPT/ 0Fk1LI15de9glFQs9ZgXETrB/fIQrrqlsPtia4syrfKEBrBYgYN6d8OCIPGsPvQk0I36 qSSn9yF24mQeZUO9POwRr+g6FQEE5eT++Z3yd+8p0x3hEa0caCRcSL7oZK4tAmZ05/DC pZeQ== 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=O6KzCT+pGbnTKY/8ZeWz+Z7W3MnO0b2CBQnCZG7XotGfsTMC5DQQcGfW3yDVlkjHNU oslbAGhROn6PufbreFq2ksSeCQS267SS8BeUD0MoY5tgL1Zg2wRX+5DM8D/6wdCfweCz ywiMb6vW4cOjdtlvN+qY5Pq+4ON7+Z4yLZT793JFS4S6+wvDy322ObV3+hX1x1UYRO9g 3wlJ8rnEra/KO5DZQiZ6wk3YAsMdat/WFZmiPXkmiOnUYZMsIMvXWgazrELgAe4Fgild ikfOj7At0+08b/uXvJuPOf+FGQnrlyaaMdXRaydTDb+iN74ka0Wu0FNdyzyWjPx0k5IS kE2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="O/yBODsz"; 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 c11-20020a05640227cb00b0044eb8a65cd0si3446255ede.398.2022.09.16.13.28.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 13:28:46 -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="O/yBODsz"; 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 45D2D395BC12 for ; Fri, 16 Sep 2022 20:26:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45D2D395BC12 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663359988; 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=O/yBODszrxPLUZ5v03DG7s7xEB0wlYClme4WPhLjyfngddBvT4CELzjJFIe8nYjdZ 2U8i14fD+NWd4ZRekk+nHXCJxXm52nuT/ETUSfO1P274FV9Zb0SLsFxjOcP96h0Qk9 Bl2IyCIA1oGu+yno+G0TiW9QFUmdGfV5vk4p6AQc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp-12.smtpout.orange.fr [80.12.242.12]) by sourceware.org (Postfix) with ESMTPS id C6B813853542 for ; Fri, 16 Sep 2022 20:24:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C6B813853542 Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id ZHt9oWAI9LFqbZHtFowxzo; Fri, 16 Sep 2022 22:24:46 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Fri, 16 Sep 2022 22:24:46 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH 06/10] fortran: Support clobbering of SAVE variables [PR87395] Date: Fri, 16 Sep 2022 22:24:35 +0200 Message-Id: <20220916202439.549820-7-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220916202439.549820-1-mikael@gcc.gnu.org> References: <20220916202439.549820-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, KHOP_HELO_FCRDNS, 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?1744159508094739721?= X-GMAIL-MSGID: =?utf-8?q?1744159508094739721?= 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 Fri Sep 16 20:24:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1268 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp917636wrt; Fri, 16 Sep 2022 13:31:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7eohdnq9ZPV5OxmXDXnyvMVLo4+ynFhAeXli/FGhEL43+jbeiQHZeIj5qbSHCzv2LOs6a1 X-Received: by 2002:a17:907:2da1:b0:773:dc01:877a with SMTP id gt33-20020a1709072da100b00773dc01877amr4651021ejc.567.1663360310508; Fri, 16 Sep 2022 13:31:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663360310; cv=none; d=google.com; s=arc-20160816; b=rXdUJmpLAr/SvRcd45RMA5OgrW7DO5YrDF53wBKQEt2bj8aeUYALBKYoDrNhtizuH3 pBNVbk5n1Aa5UQkRX4Jv567uXFK2daJHN0CM1h9OH4LA3BzbAe4/eQ6waemxBorL3CEI cEGW5lW6AEPYSMYN/3lvuWm6J2xi8XG0t8pyS796MIMrCcveoKmTGpGhvjKZho6Rm3nJ Ez7AmiBwjX/eOnr1i+NDw9Af9PpB7lScVsAHARnqec32dT/5CQcAe2BDL+kwj8b7cpG4 +qmhGVQ3ZRiRu94KhRGLjLQXPtUPUnTDXcnOJsjTihEAg5LJAWOSUnX2/ng+bYK7z/bI NJAw== 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=Ksm1r5SS4iYhPO/1KsrFpVEEwCfVXq/vu3btbCqIYtjYTaH0L3a29EqOo+8wJrhw0q DrV6Ij9bvBc1XdcS3OJmmBheVBttiYRq9DH8n3mau7CCeDm2wV1ClBc/LBNN2PZUebXW 8ek8VBRuyMZY0zYvSNf+WkBkyUTkuo/gMLtzo2Tq5YL+rVxUJudFOr3uATAnJXZ8KoV1 +KMC0BJV4CfbSsAYYDiK6y93/dSQfWkBnyN0zzKb1mDRLlSdFbDWJdhpYqnDtV5DtUJe WLTV/eIXq5GgVP/k6hlVP0p5QlB5JB9fnexgEq/RvTDnx3JeYuhFTCBw5GZ+wfrgSHyE VIwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="cEpZ/fyo"; 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 s12-20020a056402520c00b0045166660c66si3575850edd.41.2022.09.16.13.31.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 13:31:50 -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="cEpZ/fyo"; 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 B1FDA3954452 for ; Fri, 16 Sep 2022 20:28:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1FDA3954452 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663360137; 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=cEpZ/fyoXylz6f/yGex5DxkBbdUBbwPV0RXT51WWNIN+0L3b6yLvqs8J+7HmltDsG fAw7ICQEVBAstl0oRdjHKUYZgzK/7nVwIXIfSEMj2LQo77KcNlPUbebfUKUpbt1Uzu RIU1UuAkt9OrQnCJOSmAQorN9+8Ryr81A/Kt54rA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp01.smtpout.orange.fr [80.12.242.123]) by sourceware.org (Postfix) with ESMTPS id DB41A3851C1A for ; Fri, 16 Sep 2022 20:24:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DB41A3851C1A Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id ZHt9oWAI9LFqbZHtGowxzq; Fri, 16 Sep 2022 22:24:46 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Fri, 16 Sep 2022 22:24:46 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH 07/10] fortran: Support clobbering of ASSOCIATE variables [PR87397] Date: Fri, 16 Sep 2022 22:24:36 +0200 Message-Id: <20220916202439.549820-8-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220916202439.549820-1-mikael@gcc.gnu.org> References: <20220916202439.549820-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?1744159701063023511?= X-GMAIL-MSGID: =?utf-8?q?1744159701063023511?= 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 Fri Sep 16 20:24: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: 1265 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp916978wrt; Fri, 16 Sep 2022 13:30:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5cPPehE2NmWyQRRSzXLj40V/92qE4Fl1dJbh33TO3OTYNpG1LO8G3Ce2Et9gjyqwg4VE1h X-Received: by 2002:a17:906:d550:b0:780:cec2:aae1 with SMTP id cr16-20020a170906d55000b00780cec2aae1mr749389ejc.477.1663360210667; Fri, 16 Sep 2022 13:30:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663360210; cv=none; d=google.com; s=arc-20160816; b=EfuwV//ta+dDgJZmbaqQneQKNVY8JBEYgS2cjCK7aJHXNVcszW6zha029ZBJ6NEjmp IB/McfMmhdbv5qxrOlkrA8MpCimrALYHQOp76OSCFB7/hpFP+u/lMhWr9ipPxyeK758e zXFZ9s+O0Hd31jaJVPbm42x1Xi65auizKKFVzVfEYppwU7TCocwKK8Funiql5o07dJ7z bNw/+h3+PJmGC4lENBlNGUJfW3vkPtS2SHWfR7JtfECF1tQ051bkn/3PlaF2/zgftHhw R8SizDgMkSey9vfwa1N6e2sooTk7CU6kFH1s+ETzHKW1+owpdKQPttyvJmsYS6+75+Nm zLVQ== 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=gHHteFKj1KMGDuw2pUz5Eju/KioVrWvT9ReJNYN5Bkc=; b=nFGgnrEv/jwpoWEUwd1isyIJm0KBuB+tKLBFNZwiSgNS83swquQTrCDHtzPKGOM3VL S2eWf9j052/ULn9wu2OVigxgOl3welPmN6NekzbKM7vWQLKx6gtNvFXDScef1mcFbH6Y J+MTdp6BHhdJuFun7tD8Jz7TccssLKoQO5oCK2WSokuTOXU+QxJH/TIeKp9Az6986bHG 1hpxevS3vF4I0T7cAfOKtRsF4w2SMCYIp8QNOAt86gXZdtTEN2mBu/UQLB5h+JndNwED zPrOm9e9myAFpjRhOWCklOBuLir4COJ15mml4jjeAVqPG0f00LiW/5lan3SMAf8v4vm7 x8vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=h2+Dhhfo; 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 hd42-20020a17090796aa00b0072f1c8d0e62si21988395ejc.95.2022.09.16.13.30.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 13:30:10 -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=h2+Dhhfo; 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 09CBE395A404 for ; Fri, 16 Sep 2022 20:27:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09CBE395A404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663360046; bh=gHHteFKj1KMGDuw2pUz5Eju/KioVrWvT9ReJNYN5Bkc=; 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=h2+Dhhforyh0qUvN61yXWuFmpdvUd34DX7ND/NvuSJ45rrHg6M71aGNv/PwHmPUso FjXoaT9hn7hmcWs8y0DPo71TJBlksSf4Qkuo9ScpwgAXjhEKZ5KA9nEC1ssZc74Zjc lB5snGspo2fTVgvFXzhy97hRFGWIBi3BTkS4TlyU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp02.smtpout.orange.fr [80.12.242.124]) by sourceware.org (Postfix) with ESMTPS id 0A47E384BC0E for ; Fri, 16 Sep 2022 20:24:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0A47E384BC0E Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id ZHt9oWAI9LFqbZHtGowxzs; Fri, 16 Sep 2022 22:24:46 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Fri, 16 Sep 2022 22:24:46 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH 08/10] fortran: Support clobbering of allocatables and pointers [PR41453] Date: Fri, 16 Sep 2022 22:24:37 +0200 Message-Id: <20220916202439.549820-9-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220916202439.549820-1-mikael@gcc.gnu.org> References: <20220916202439.549820-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?1744159596485445495?= X-GMAIL-MSGID: =?utf-8?q?1744159596485445495?= 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_6.f90: New test. --- gcc/fortran/trans-expr.cc | 2 - .../gfortran.dg/intent_optimize_6.f90 | 42 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 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 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_6.f90 b/gcc/testsuite/gfortran.dg/intent_optimize_6.f90 new file mode 100644 index 00000000000..0146dff4e20 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/intent_optimize_6.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 Fri Sep 16 20:24:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1269 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp917861wrt; Fri, 16 Sep 2022 13:32:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6KA6D//Mg/vMp26RhqoV+5xON/H2YwlwvL+T9cx/HNUsS0KAhzSZp6tZ6yCRY4g3i01DOQ X-Received: by 2002:a17:907:2672:b0:780:8bb5:25a3 with SMTP id ci18-20020a170907267200b007808bb525a3mr4319101ejc.281.1663360345800; Fri, 16 Sep 2022 13:32:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663360345; cv=none; d=google.com; s=arc-20160816; b=xQMIjBjveH+S8/yf1Tl2c7FvW1K3j3GWLKqlTj+D3nallPBs4UerpAHt+oWdBDWzSU Exu9k0p03QXLaLthsu5Kk4JklkQeZuITr4p3aH9cq7MnoP30nwKDj0+nzTIdk7EQJ4Id JdVgg1TvKkvobofPfEbvY7EKQ5GSZkBRkG7FVQVSyb5nrLPCnkFTv0yr/tpYzGlmlcim Mcct04B9dS272ac/35NzSCbRsH3fHTeYMR69uBsZ6j3e8Kzcm1c74RwC3q62IZF5P2Nb 6D26snTR+uawmQk7FfmanlbAh817VK54c5rbL3AEvZMNn726dvtnwf1YB3dIBOCEs0nr elNQ== 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=k1F85oNTV0Ev2fUHk5tr0v15gG32TteqNb3SiGCJjjo=; b=F/Ehl2vK8wXglVkLNSRDAphgUeDjaE6qkzPckqgBhg7RV+jeLYeBBMoEROk+R8sIsG 9cwib0fH/WM/K+3SIplqBunpMYb+qD8vAouIcQSNvvYRVBjH6Rfk/LZPg+7tz6MZdhtq hNCaYfP8zB9ypnPR3SnPI7lln4oN7QSgEMgpTAoA6S0Ta4FBQ4Goz04mlqYvFyaoxgVx lM+k2LV7/l3wDC3R3wm5+rmUk5AYr6Rg1Du7XH03cj12f12rVjVsFxpoXas9ElQiVfkt zZeYH9rts6jyc6PjUtCtSUYXyPNasajyaCqa23nsxqlpOSq+gblhFKHJon1OlEb04Goa Q3Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bebYlruc; 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 v18-20020a170906859200b007707a47c3d5si12690645ejx.944.2022.09.16.13.32.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 13:32:25 -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=bebYlruc; 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 E26A4394C82B for ; Fri, 16 Sep 2022 20:29:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E26A4394C82B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663360194; bh=k1F85oNTV0Ev2fUHk5tr0v15gG32TteqNb3SiGCJjjo=; 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=bebYlrucu+ET/sFu0P+tiQIL7RT0BEjlAX4HzC80ywfMwFjYxDX8ep31hoczFZMhQ 7YnyxKcAxx/L/4VQWk42g8spDJ1U5xwoX8mQkp0m04JvEJBKfC0d2aoRD1CwHFE3GX 3t3c3cS8TaVfcbYKWJnD0feersO0Y5Bd2lGJH8Fk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp03.smtpout.orange.fr [80.12.242.125]) by sourceware.org (Postfix) with ESMTPS id 3E6FD384B82E for ; Fri, 16 Sep 2022 20:24:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3E6FD384B82E Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id ZHt9oWAI9LFqbZHtGowxzu; Fri, 16 Sep 2022 22:24:46 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Fri, 16 Sep 2022 22:24:46 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH 09/10] fortran: Support clobbering of variable subreferences [PR88364] Date: Fri, 16 Sep 2022 22:24:38 +0200 Message-Id: <20220916202439.549820-10-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220916202439.549820-1-mikael@gcc.gnu.org> References: <20220916202439.549820-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?1744159738178295221?= X-GMAIL-MSGID: =?utf-8?q?1744159738178295221?= This adds support for clobbering of partial variable references, when they are passed as actual argument and the associated dummy has the INTENT(OUT) attribute. Support includes array elements, derived type component references, and complex real or imaginary parts. This is done by removing the check for lack of subreferences, which is basically a revert of r9-4911-gbd810d637041dba49a5aca3d085504575374ac6f. This removal allows more expressions than just array elements, components and complex parts, but the other expressions are excluded by other conditions: substrings are excluded by the check on expression type (CHARACTER is excluded), KIND and LEN references are rejected by the compiler as not valid in a variable definition context. The check for scalarness is also updated as it was only valid when there was no subreference. PR fortran/88364 PR fortran/41453 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_conv_procedure_call): Don’t check for lack of subreference. Check the global expression rank instead of the root symbol dimension attribute. gcc/testsuite/ChangeLog: * gfortran.dg/intent_optimize_7.f90: New test. --- gcc/fortran/trans-expr.cc | 5 +- .../gfortran.dg/intent_optimize_7.f90 | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+), 4 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 ae685157e22..f1026d7f309 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -6521,10 +6521,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, && !dsym->attr.allocatable && !dsym->attr.pointer && e->expr_type == EXPR_VARIABLE - && e->ref == NULL - && e->symtree - && e->symtree->n.sym - && !e->symtree->n.sym->attr.dimension + && e->rank == 0 && 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..14dcfd9961b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/intent_optimize_7.f90 @@ -0,0 +1,65 @@ +! { 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 or BAR in the *.original dump, and the +! initialization constants to be optimized away in the *.optimized dump, +! in the case of scalar array elements, derived type components, +! and complex real and imaginary part. + +module x +implicit none +contains + subroutine foo(a) + integer, intent(out) :: a + a = 42 + end subroutine foo + subroutine bar(a) + real, intent(out) :: a + a = 24.0 + end subroutine bar +end module x + +program main + use x + implicit none + type :: t + integer :: c + end type t + type(t) :: dc + integer :: ac(3) + complex :: xc, xd + + dc = t(123456789) + call foo(dc%c) + if (dc%c /= 42) stop 1 + + ac = 100 + ac(2) = 987654321 + call foo(ac(2)) + if (any(ac /= [100, 42, 100])) stop 2 + + xc = (12345.0, 11.0) + call bar(xc%re) + if (xc /= (24.0, 11.0)) stop 3 + + xd = (17.0, 67890.0) + call bar(xd%im) + if (xd /= (17.0, 24.0)) stop 4 + +end program main + +! { dg-final { scan-tree-dump-times "CLOBBER" 4 "original" } } +! { dg-final { scan-tree-dump "dc\\.c = {CLOBBER};" "original" } } +! { dg-final { scan-tree-dump "ac\\\[1\\\] = {CLOBBER};" "original" } } +! { dg-final { scan-tree-dump "REALPART_EXPR = {CLOBBER};" "original" } } +! { dg-final { scan-tree-dump "IMAGPART_EXPR = {CLOBBER};" "original" } } +! { dg-final { scan-tree-dump "123456789" "original" } } +! { dg-final { scan-tree-dump-not "123456789" "optimized" { target __OPTIMIZE__ } } } +! { dg-final { scan-tree-dump "987654321" "original" } } +! { dg-final { scan-tree-dump-not "987654321" "optimized" { target __OPTIMIZE__ } } } +! { dg-final { scan-tree-dump "1\\.2345e\\+4" "original" } } +! { dg-final { scan-tree-dump-not "1\\.2345e\\+4" "optimized" { target __OPTIMIZE__ } } } +! { dg-final { scan-tree-dump "6\\.789e\\+4" "original" } } +! { dg-final { scan-tree-dump-not "6\\.789e\\+4" "optimized" { target __OPTIMIZE__ } } } From patchwork Fri Sep 16 20:24: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: 1267 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp917438wrt; Fri, 16 Sep 2022 13:31:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM64x+Y0s4aawn56d1e3mRz1jiHLXgOpAHy1ssO7hOM3beXSvn9XvZU9TYOr4SCYAvu+HIiM X-Received: by 2002:a05:6402:35d2:b0:450:be1b:d7cf with SMTP id z18-20020a05640235d200b00450be1bd7cfmr5419850edc.51.1663360282402; Fri, 16 Sep 2022 13:31:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663360282; cv=none; d=google.com; s=arc-20160816; b=zCCUNl5JapK1ZNzuo3G0jtv3YO50qKVVHQTyUVVyNVVulhLgjr+Rrb8T+xkXS66NR3 Vk24/2zU7sywkrtJv7gLTh1EQ2gaqQVw9FobAKtiL30ITM7w1s10nQCnHfGvpawBiI2X bDmZUlb5Zp35IG3yHpUkg5N7Q8Cdf4TC1A18L5fRUWArFvjb2dvIBUjz0jWIVo5uhyQr X058q/n8CtoT3/Z6jWbTFs5suZECRt+WjalzRI1LaBxQX5hem/efbfV6T6AzYQuX2gHg a+YN4/hdnEJvGFKsGvaXga618mITeZrCQ0HbZhPc7PN+77GQ74p+q5SsHDuhF9ijuI4p +cEQ== 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=DBQ38WFMoAaF0EMnqH29MjlywhJWZ0UEfyZ5sKGHYl0=; b=wHTHJ9UwGgnuI+iub4tIE+UWyt93BfUHYvpTFqZAy/X57C1uQAWvmw5eDEcWLWhP2x DyKVeZpdeWDXVd8dqUzthgKPLI8CO0wwl42+eo3EDzZTmbcdTknwErEYjIxZKEtGPNmk wCxRKSbKrX3zirBPC7C8n2t94hfSI59YqIbbFAtudTNW6JwSC7jixPbTC1SJO1nmWYYg gZTpIWZgZAF1w1/4s23trqH+lOSf2Oj6eha2D5XVahw8Mi1TuTjmaiiVJqeyLdagiY4p 6NWLNYLg0Q2GLtdcl+qsxHV18Sfl1HCKrRndyi07ZFNxdYBdsdkyxF7eWwtA7ZVt79Z1 1v1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SWxwAi2C; 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 l18-20020a056402255200b0045142ba98ffsi3371723edb.593.2022.09.16.13.31.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 13:31:22 -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=SWxwAi2C; 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 03D0D395BC51 for ; Fri, 16 Sep 2022 20:28:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03D0D395BC51 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663360112; bh=DBQ38WFMoAaF0EMnqH29MjlywhJWZ0UEfyZ5sKGHYl0=; 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=SWxwAi2CXzQi4VVKDWEh8W4ySdpECtVuSYnHhoiqSsTZMcKNIFNoibVWblEtRWjga PUg0nmcFh6Nu9Tq//zt71kngl7oogygnhLCAVMey8UxmcFI27uCqialBO3+R05y9rC yzv1+rLHjzxblhtzrppgYacqUpFyWdr3v377Qwps= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp01.smtpout.orange.fr [80.12.242.123]) by sourceware.org (Postfix) with ESMTPS id 54D9F382EA27 for ; Fri, 16 Sep 2022 20:24:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 54D9F382EA27 Received: from cyrano.home ([86.215.174.255]) by smtp.orange.fr with ESMTPA id ZHt9oWAI9LFqbZHtGowxzw; Fri, 16 Sep 2022 22:24:46 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Fri, 16 Sep 2022 22:24:46 +0200 X-ME-IP: 86.215.174.255 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH 10/10] fortran: Support clobbering of derived types [PR41453] Date: Fri, 16 Sep 2022 22:24:39 +0200 Message-Id: <20220916202439.549820-11-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220916202439.549820-1-mikael@gcc.gnu.org> References: <20220916202439.549820-1-mikael@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 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=unavailable 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?1744159671402405947?= X-GMAIL-MSGID: =?utf-8?q?1744159671402405947?= 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 | 67 +++++++++++++++++++ 2 files changed, 84 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 f1026d7f309..f8fcd2d97d9 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -6523,8 +6523,24 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, && e->expr_type == EXPR_VARIABLE && e->rank == 0 && 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..584592842e1 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/intent_optimize_8.f90 @@ -0,0 +1,67 @@ +! { 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, so there are clobbers for tc and uc only; no clobber for ud, te, tf. +! { dg-final { scan-tree-dump-times "CLOBBER" 2 "original" } } +! { dg-final { scan-tree-dump "tc = {CLOBBER};" "original" } } +! { dg-final { scan-tree-dump "uc\\.t = {CLOBBER};" "original" } } + +! There are clobbers for tc and uc, so we should manage to optimize away the associated initialization constants (but not other +! initialization constants). +! { dg-final { scan-tree-dump-not "123456789" "optimized" { target __OPTIMIZE__ } } } +! { dg-final { scan-tree-dump-not "987654321" "optimized" { target __OPTIMIZE__ } } }