From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc32.google.com (mail-oo1-xc32.google.com [IPv6:2607:f8b0:4864:20::c32]) by sourceware.org (Postfix) with ESMTPS id DEFC73858D39; Wed, 28 Jun 2023 09:47:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DEFC73858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-560c617c820so3888241eaf.3; Wed, 28 Jun 2023 02:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687945672; x=1690537672; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=HBKJ1cRfgAJQXF3k7OTpX7CyIYjRRG2XpHR60o0t4ns=; b=NQ+OQDeN5QpKSpLd04K3rc+o6dx+1ZiCEeCslds5lHVz/q02MqCr/Lvs1QBFB4y4Fw UkkDI2MLwcUJX43DSOZ+9UP+JSrjRygxtcA3fxtyZLbHvby6hjj0bW8CXq02L70+iipn 53rcu9T5WNUwDBH6Ea7XKrIFcTdCAm8gHtNj/DsPXXXEuiZ9HrNUxO4ZvwBiNUKiALrw 6U+WX2NsG8Ki42OqjhgKzMEOEurXgWWvGKqoXilzjQa/OdeQGUz22yQZW8cMz6+Jx4dz 6I/QI8XG2O6RCHHOLAi05JBXa2Y2b1fgyIZVgZu9Rh612IcrnfN1pxo+VkACUOL7PwXj HLXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687945672; x=1690537672; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HBKJ1cRfgAJQXF3k7OTpX7CyIYjRRG2XpHR60o0t4ns=; b=gPzCt9CRPOOEfau6pNL+n45HiZOR8tq1TSjLfSaagJA+pwyDQWrPNeAghGAFY6xfDk AynEjIp1c6DIGMToMcyrt3YyRKx3W0I06q1qvG/jcmXCFelGCnPqJqMOfgSmW5Qo2V1V RjkTWE6bt7cXsSdWfaGOyugIh7vFSqF+B2mMBSVcma+BqCJ6Cl9haWEpZW7ZAsAPgNTe kr8VcEYPZ0XyNEOa2y1c4O4XKc9GhnxUxRmB6Zai08gkGt6A/Hgj1v3HgLyCXGriQVQP 4pPX8TuhT7QC1oeFiuYxfkeG9h1O8xBDMSfORR1CdOXUaLWkCdw9UAnXsirsBjtUa7Sh SuhA== X-Gm-Message-State: AC+VfDzh+EVHAJNpl69FExQhqFLtCyrdFKxEuUk2VJQ1SpeQeOSR/tX4 dviAaqcPE3YJ08I89o02HOAFXifUOT7VfWlyrXVtuOd3 X-Google-Smtp-Source: ACHHUZ61pntd1KS7/s9Y6rePIblMyHOZQ58xEKkMpUwiML5DRs4Zbj98nKwiicI/LPovQM2gAVQFIvWkOKK1Dehq7Fw= X-Received: by 2002:a05:6808:1248:b0:3a0:5cc1:3204 with SMTP id o8-20020a056808124800b003a05cc13204mr21389883oiv.16.1687945671975; Wed, 28 Jun 2023 02:47:51 -0700 (PDT) MIME-Version: 1.0 References: <152f9e8b-6998-e505-7875-14dc14268382@gmx.de> In-Reply-To: <152f9e8b-6998-e505-7875-14dc14268382@gmx.de> From: Paul Richard Thomas Date: Wed, 28 Jun 2023 10:47:40 +0100 Message-ID: Subject: Re: [Patch, fortran] PR49213 - [OOP] gfortran rejects structure constructor expression To: Harald Anlauf Cc: "fortran@gcc.gnu.org" , gcc-patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: Hi Harald, I'll change to gfc_charlen_type_node. Thanks for your patience in reviewing this patch :-) Cheers Paul On Tue, 27 Jun 2023 at 20:27, Harald Anlauf wrote: > > Hi Paul, > > this is much better now. > > I have only a minor comment left: in the calculation of the > size of a character string you are using an intermediate > gfc_array_index_type, whereas I have learned to use > gfc_charlen_type_node now, which seems like the natural > type here. > > OK for trunk, and thanks for your patience! > > Harald > > > On 6/27/23 12:30, Paul Richard Thomas via Gcc-patches wrote: > > Hi Harald, > > > > Let's try again :-) > > > > OK for trunk? > > > > Regards > > > > Paul > > > > Fortran: Enable class expressions in structure constructors [PR49213] > > > > 2023-06-27 Paul Thomas > > > > gcc/fortran > > PR fortran/49213 > > * expr.cc (gfc_is_ptr_fcn): Remove reference to class_pointer. > > * 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 > > > > On Sat, 24 Jun 2023 at 20:50, Harald Anlauf wrote: > >> > >> 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 > > > > > > > -- "If you can't explain it simply, you don't understand it well enough" - Albert Einstein