From patchwork Sun Oct 2 20:07:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 1636 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp685209wrs; Sun, 2 Oct 2022 13:08:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM42y8I/ui6Cwo2WIZl2/HIaeU55IVFEcWXGAlfPIHgcdvI8p7SfWT0X1WCQo9kvIjAOkH54 X-Received: by 2002:a17:907:94c1:b0:783:59a:da2d with SMTP id dn1-20020a17090794c100b00783059ada2dmr12982757ejc.136.1664741304176; Sun, 02 Oct 2022 13:08:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664741304; cv=none; d=google.com; s=arc-20160816; b=LHnFfyMhqwXSMR6MSZbXkfR9VpK9MfFdKu/j+QkwdqzCAoanbyIc8L7UqjMTYUDQHW caNFa6GXnhApJPbBsLYgo2gl0Tlt3II+pk4mlAw2Wg1Inhk4+JkAvCMeyoF7XJr8hJ5K VQ4n8/uZTENttuJYpdDy05h/0vYTyyPCfG7mkbL9x2i3WpW7XRp3n8F2XCzjhMs9K1o9 tCkp2narXx6EXdJFwXZtdTSLwnW6OCLYfLMlzlnNTxiHxWov4AxZ1cvHjBHum6PObSP7 Y1vbJjlppuTZU1srRMXA9A11eqw+yY4ipxgutUZymgfuwa1erPHIw4J4hy/AJK0ri/Lr CElQ== 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:subject:to :content-language:user-agent:mime-version:date:message-id :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=8uB3YWwLMx7J03jl+bmTygwDBUKWKFqy2NaJKzo4PJ0=; b=XMaonYRabDmSXg3cLzKZCrtjFndl6jmIE4KGRPBPErDKM4yUIP/FZ2aLSzt0hEhZ4J I/WXuMy9vlXpvCULAwy74sCyaaWeYoHcgl2NJtg+jxpfJh9tDrB3qTOBTZvIwffMSHTo 2x+Z9sS0P+rob+jLGQHuHfuzvLEEeY1LGrfmxKU+oaxJllrMG2B5G6xfxrQTgyQuWKue XDxR/nfc0GKNi4H48lO+KhtP4/i3LugYpLHTgiG1pzfjby5bKbG2J06yJcJJ4wfUY3qM 2GM4Tti3qAHN4HNO6hrb4g9JIeEgQTAE4NjQscsVbqwrTJ//EskZy0dKx9TqX83Tn9DJ i8ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XFKMZjMr; 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 a19-20020a170906275300b007878144285csi5998551ejd.314.2022.10.02.13.08.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Oct 2022 13:08:24 -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=XFKMZjMr; 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 AD52738582B0 for ; Sun, 2 Oct 2022 20:08:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD52738582B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664741302; bh=8uB3YWwLMx7J03jl+bmTygwDBUKWKFqy2NaJKzo4PJ0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=XFKMZjMrA0o9NI1yct86SeytcOiEiJAhebOACiWAr7BL5yvFwneogbMh75D/Wr+l4 hjeuxmzTRFUHaNN6AC2JPTsllaD+oHMCnb/JoJkb14IS1WrpomeiedEjbawqaDbSVa Gw152Qgz02GxQj2N0leteySLW/GR+6yJh5OJSYt8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cc-smtpout2.netcologne.de (cc-smtpout2.netcologne.de [IPv6:2001:4dd0:100:1062:25:2:0:2]) by sourceware.org (Postfix) with ESMTPS id 3F4553858D32; Sun, 2 Oct 2022 20:07:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3F4553858D32 Received: from cc-smtpin1.netcologne.de (cc-smtpin1.netcologne.de [89.1.8.201]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id 0E09A1268B; Sun, 2 Oct 2022 22:07:37 +0200 (CEST) Received: from [IPV6:2a0a:a540:3831:0:7285:c2ff:fe6c:992d] (2a0a-a540-3831-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de [IPv6:2a0a:a540:3831:0:7285:c2ff:fe6c:992d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by cc-smtpin1.netcologne.de (Postfix) with ESMTPSA id 8C80111D70; Sun, 2 Oct 2022 22:07:35 +0200 (CEST) Message-ID: Date: Sun, 2 Oct 2022 22:07:34 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, RFC. Fortran] Some clobbering for INTENT(OUT) arrays X-NetCologne-Spam: L X-Rspamd-Queue-Id: 8C80111D70 X-Spamd-Bar: / X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, 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: Thomas Koenig via Gcc-patches From: Thomas Koenig Reply-To: Thomas Koenig 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?1745607777692064763?= X-GMAIL-MSGID: =?utf-8?q?1745607777692064763?= Hi, following Mikael's recent patch series, here is a first idea of what extending clobbering to arrays wold look like. The attached patch works for a subset of cases, for example program main implicit none interface subroutine foo(a) integer, intent(out) :: a(*) end subroutine foo end interface integer, dimension(10) :: a call foo(a) end program main and program main implicit none interface subroutine foo(a) integer, intent(out) :: a(:) end subroutine foo end interface integer, dimension(10) :: a a(1) = 32 a(2) = 32 call foo(a) end program main but it does not cover cases like an assumed-size array being handed down to an INTENT(OUT) argument. What happens if the + if (!sym->attr.allocatable && !sym->attr.pointer + && !POINTER_TYPE_P (TREE_TYPE (sym->backend_decl))) part is taken out is that the whole descriptor can be clobbered in such a case, which is of course not what is wanted. I am a bit stuck of how to generate a reference to the first element of the array (really, just dereferencing the data pointer) in the most elegant way. I am currently leaning towards building a gfc_expr, which should work, but would be less than elegant. So, anything more elegant at hand? Best regards Thomas diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 4f3ae82d39c..bbb00f90a77 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see #include "gimplify.h" #include "tm.h" /* For CHAR_TYPE_SIZE. */ +#include "debug.h" /* Calculate the number of characters in a string. */ @@ -5981,7 +5982,6 @@ post_call: gfc_add_block_to_block (&parmse->post, &block); } - /* Generate code for a procedure call. Note can return se->post != NULL. If se->direct_byref is set then se->expr contains the return parameter. Return nonzero, if the call has alternate specifiers. @@ -6099,6 +6099,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, { bool finalized = false; tree derived_array = NULL_TREE; + tree clobber_array = NULL_TREE; e = arg->expr; fsym = formal ? formal->sym : NULL; @@ -6896,10 +6897,23 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, fsym->attr.pointer); } else - /* This is where we introduce a temporary to store the - result of a non-lvalue array expression. */ - gfc_conv_array_parameter (&parmse, e, nodesc_arg, fsym, - sym->name, NULL); + { + /* This is where we introduce a temporary to store the + result of a non-lvalue array expression. */ + gfc_conv_array_parameter (&parmse, e, nodesc_arg, fsym, + sym->name, NULL); + if (fsym && fsym->attr.intent == INTENT_OUT + && gfc_full_array_ref_p (e->ref, NULL)) + { + gfc_symbol *sym = e->symtree->n.sym; + if (!sym->attr.allocatable && !sym->attr.pointer + && !POINTER_TYPE_P (TREE_TYPE (sym->backend_decl))) + clobber_array + = gfc_build_array_ref (e->symtree->n.sym->backend_decl, + build_int_cst (size_type_node, 0), + NULL_TREE, true, NULL_TREE); + } + } /* If an ALLOCATABLE dummy argument has INTENT(OUT) and is allocated on entry, it must be deallocated. @@ -6952,6 +6966,13 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, tmp, build_empty_stmt (input_location)); gfc_add_expr_to_block (&se->pre, tmp); } + + if (clobber_array != NULL_TREE) + { + tree clobber; + clobber = build_clobber (TREE_TYPE(clobber_array)); + gfc_add_modify (&clobbers, clobber_array, clobber); + } } } /* Special case for an assumed-rank dummy argument. */