From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.smtpout.orange.fr (smtp-18.smtpout.orange.fr [80.12.242.18]) by sourceware.org (Postfix) with ESMTPS id C99703858401 for ; Mon, 3 Oct 2022 09:05:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C99703858401 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orange.fr Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=orange.fr Received: from [192.168.1.17] ([86.215.174.255]) by smtp.orange.fr with ESMTPA id fHNso4jdyXaejfHNxooZY3; Mon, 03 Oct 2022 11:05:15 +0200 X-ME-Helo: [192.168.1.17] X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Mon, 03 Oct 2022 11:05:15 +0200 X-ME-IP: 86.215.174.255 Message-ID: Date: Mon, 3 Oct 2022 11:05:08 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: Re: [patch, RFC. Fortran] Some clobbering for INTENT(OUT) arrays To: Thomas Koenig , "fortran@gcc.gnu.org" , gcc-patches References: Content-Language: fr, en-US From: Mikael Morin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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 List-Id: Hello, Le 02/10/2022 à 22:07, Thomas Koenig via Fortran a écrit : > > 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? > I don't understand why you are trying to do this. According to Richi [1], array references are not allowed, so you can (and actually have to) pick the full variable decl directly. [1] https://gcc.gnu.org/pipermail/fortran/2022-September/058181.html A few comments about the rest... > 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. The canonical way is to look for GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (...)). Your way should work in most cases, but there are twisted cases for which I'm not sure (assumed shape arrays with the value attribute). > 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 > @@ -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)) The scalar case has a few more conditions this seems to miss. e->expr_type == EXPR_VARIABLE at least, but also e->ts.type != CHARACTER, alloc_comp and finalizable derived types, etc. > + clobber_array > + = gfc_build_array_ref (e->symtree->n.sym->backend_decl, > + build_int_cst (size_type_node, 0), > + NULL_TREE, true, NULL_TREE); This is picking the decl from the frontend data. This proved to be problematic in the scalar case, so maybe it would be better to pick the variable to be clobbered from parmse.expr. Admittedly I'm not too sure about this, arrays are much more difficult to work with (and to think about). > @@ -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. */ This can be moved to the preceding hunk.