From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ciao.gmane.io (ciao.gmane.io [116.202.254.214]) by sourceware.org (Postfix) with ESMTPS id 30616385841E for ; Sat, 24 Jun 2023 19:51:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30616385841E Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=m.gmane-mx.org Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1qD9Hg-0007gW-TQ for gcc-patches@gcc.gnu.org; Sat, 24 Jun 2023 21:51:00 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: gcc-patches@gcc.gnu.org From: Harald Anlauf Subject: Re: [Patch, fortran] PR49213 - [OOP] gfortran rejects structure constructor expression Date: Sat, 24 Jun 2023 21:50:53 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------ZUuwdq0Ua4rvfL56eioRw5QH" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Content-Language: en-US In-Reply-To: Cc: fortran@gcc.gnu.org X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Message-ID: <20230624195053.LnZOjCleRUDMCKpP9gsBwhdnosfJfsevcAOd7GYLvFo@z> This is a multi-part message in MIME format. --------------ZUuwdq0Ua4rvfL56eioRw5QH Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Paul! On 6/24/23 15:18, Paul Richard Thomas via Gcc-patches wrote: > I have included the adjustment to 'gfc_is_ptr_fcn' and eliminating the > extra blank line, introduced by my last patch. I played safe and went > exclusively for class functions with attr.class_pointer set on the > grounds that these have had all the accoutrements checked and built > (ie. class_ok). I am still not sure if this is necessary or not. maybe it is my fault, but I find the version in the patch confusing: @@ -816,7 +816,7 @@ bool gfc_is_ptr_fcn (gfc_expr *e) { return e != NULL && e->expr_type == EXPR_FUNCTION - && (gfc_expr_attr (e).pointer + && ((e->ts.type != BT_CLASS && gfc_expr_attr (e).pointer) || (e->ts.type == BT_CLASS && CLASS_DATA (e)->attr.class_pointer)); } The caller 'gfc_is_ptr_fcn' has e->expr_type == EXPR_FUNCTION, so gfc_expr_attr (e) boils down to: if (e->value.function.esym && e->value.function.esym->result) { gfc_symbol *sym = e->value.function.esym->result; attr = sym->attr; if (sym->ts.type == BT_CLASS && sym->attr.class_ok) { attr.dimension = CLASS_DATA (sym)->attr.dimension; attr.pointer = CLASS_DATA (sym)->attr.class_pointer; attr.allocatable = CLASS_DATA (sym)->attr.allocatable; } } ... else if (e->symtree) attr = gfc_variable_attr (e, NULL); So I thought this should already do what you want if you do gfc_is_ptr_fcn (gfc_expr *e) { return e != NULL && e->expr_type == EXPR_FUNCTION && gfc_expr_attr (e).pointer; } or what am I missing? The additional checks in gfc_expr_attr are there to avoid ICEs in case CLASS_DATA (sym) has issues, and we all know Gerhard who showed that he is an expert in exploiting this. To sum up, I'd prefer to use the safer form if it works. If it doesn't, I would expect a latent issue. The rest of the code looked good to me, but I was suspicious about the handling of CHARACTER. Nasty as I am, I modified the testcase to use character(kind=4) instead of kind=1 (see attached). This either fails here (stop 10), or if I activate the marked line ! cont = tContainer('hello!') ! ### ICE! ### I get an ICE. Can you have another look? Thanks, Harald > > OK for trunk? > > Paul > > Fortran: Enable class expressions in structure constructors [PR49213] > > 2023-06-24 Paul Thomas > > gcc/fortran > PR fortran/49213 > * expr.cc (gfc_is_ptr_fcn): Guard pointer attribute to exclude > class expressions. > * resolve.cc (resolve_assoc_var): Call gfc_is_ptr_fcn to allow > associate names with pointer function targets to be used in > variable definition context. > * trans-decl.cc (get_symbol_decl): Remove extraneous line. > * trans-expr.cc (alloc_scalar_allocatable_subcomponent): Obtain > size of intrinsic and character expressions. > (gfc_trans_subcomponent_assign): Expand assignment to class > components to include intrinsic and character expressions. > > gcc/testsuite/ > PR fortran/49213 > * gfortran.dg/pr49213.f90 : New test --------------ZUuwdq0Ua4rvfL56eioRw5QH Content-Type: text/x-fortran; charset=UTF-8; name="pr49213-kind4.f90" Content-Disposition: attachment; filename="pr49213-kind4.f90" Content-Transfer-Encoding: base64 ISB7IGRnLWRvIHJ1biB9CiEKISBDb250cmlidXRlZCBieSBOZWlsIENhcmxzb24gIDxuZWls Lm4uY2FybHNvbkBnbWFpbC5jb20+CiEKcHJvZ3JhbSBtYWluCiEgY2hhcmFjdGVyKDIpIDo6 IGMKICBjaGFyYWN0ZXIoMixraW5kPTQpIDo6IGMKCiAgdHlwZSA6OiBTCiAgICBpbnRlZ2Vy IDo6IG4KICBlbmQgdHlwZQogIHR5cGUoUykgOjogU29iagoKICB0eXBlLCBleHRlbmRzKFMp IDo6IFMyCiAgICBpbnRlZ2VyIDo6IG0KICBlbmQgdHlwZQogIHR5cGUoUzIpIDo6IFMyb2Jq CgogIHR5cGUgOjogVAogICAgY2xhc3MoUyksIGFsbG9jYXRhYmxlIDo6IHgKICBlbmQgdHlw ZQogIHR5cGUoVCkgOjogVG9iagoKICBTb2JqID0gUygxKQogIFRvYmogPSBUKFNvYmopCgog IFMyb2JqID0gUzIoMSwyKQogIFRvYmogPSBUKFMyb2JqKSAgICAgICAgICAgICEgRmFpbGVk IGhlcmUKICBzZWxlY3QgdHlwZSAoeCA9PiBUb2JqJXgpCiAgICB0eXBlIGlzIChTMikKICAg ICAgaWYgKCh4JW4gLm5lLiAxKSAub3IuICh4JW0gLm5lLiAyKSkgc3RvcCAxCiAgICBjbGFz cyBkZWZhdWx0CiAgICAgIHN0b3AgMgogIGVuZCBzZWxlY3Q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ISBG YWlsZWQgaGVyZQogICAgc2VsZWN0IHR5cGUgKHogPT4gY29udCV4KQogICAgICB0eXBlIGlz IChpbnRlZ2VyKQogICAgICAgIGlmICh6IC5uZS4gNDIpIHN0b3AgOAogICAgICBjbGFzcyBk ZWZhdWx0CiAgICAgICAgc3RvcCA5CiAgICBlbmQgc2VsZWN0CgohICAgIGNvbnQgPSB0Q29u dGFpbmVyKCdoZWxsbyEnKSAgICAgICAhICMjIyBJQ0UhICMjIwogICAgY29udCA9IHRDb250 YWluZXIoNF8naGVsbG8hJykKICAgIHNlbGVjdCB0eXBlICh6ID0+IGNvbnQleCkKICAgICAg dHlwZSBpcyAoY2hhcmFjdGVyKCosa2luZD00KSkKICAgICAgICBpZiAoeiAubmUuIDRfJ2hl bGxvIScpIHN0b3AgMTAKICAgICAgY2xhc3MgZGVmYXVsdAogICAgICAgIHN0b3AgMTEKICAg IGVuZCBzZWxlY3QKCiAgICBjb250ID0gdENvbnRhaW5lcihjaHIpCiAgICBzZWxlY3QgdHlw ZSAoeiA9PiBjb250JXgpCiAgICAgIHR5cGUgaXMgKGNoYXJhY3RlcigqLGtpbmQ9NCkpCiAg ICAgICAgaWYgKHogLm5lLiA0Xydnb29kYnllJykgc3RvcCAxMgogICAgICBjbGFzcyBkZWZh dWx0CiAgICAgICAgc3RvcCAxMwogICAgZW5kIHNlbGVjdAoKICBlbmQgc3Vicm91dGluZSBi YXIKZW5kIHByb2dyYW0K --------------ZUuwdq0Ua4rvfL56eioRw5QH--