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: 1685377 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=lD1OquJR; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MgZlV2LLNz20cn for ; Mon, 3 Oct 2022 07:08:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A99A73857C61 for ; Sun, 2 Oct 2022 20:07:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A99A73857C61 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664741279; bh=8uB3YWwLMx7J03jl+bmTygwDBUKWKFqy2NaJKzo4PJ0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=lD1OquJR6HLAHKUdqcVHEan9fRms+qANBX5Ry8B+5j3DWncU9suBFlRX5ObnrU/nf /XE1Pm3aSIwDC7F/zU7EBFXuDKVGN6A/Q+DHo5fxJltxvmspLE2VWa3wUo9Ycc/K00 WNbHPcemFGmTwmJbkKXgnDVxX7tVRiRJrQCcXndw= 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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. */