From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id 67D363858D35 for ; Sun, 25 Jun 2023 09:28:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 67D363858D35 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-pl1-x629.google.com with SMTP id d9443c01a7336-1b6824141b4so22107845ad.1 for ; Sun, 25 Jun 2023 02:28:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687685288; x=1690277288; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=JQKr13O/gR7kX+TGcvxNPBWo9iYiTkszv3Rcg58gpiQ=; b=Io/j8hRTvAJaQdCExpYA3nJWHWNLcMd4+fr4aJOTgJObUpYr3qn7wVcyPb3lZzRVCD LmS9nlsKGqp9nrOKC/7GGPIBr3ewEQiA7bAlg9+TLWuJU2berLK1KXEifd/yrechabJL sYhJYNO10NY8JDVWtUmLirgtHXt9kIAQS6oT4af5pNx0TL4qNAyY9agFdJnYFvL5wQ+h aB5MslPmDwgC85UlDCgnB9VacLfvJVRg9e7rbi8ydGDAGT/3ENL9M6bmlLFuSDVFyL6+ mmESe+bOYuKpFaxX5f1iqBFjFEIhh1G/2EeiuqDo5EyO6DX57Le8oMOeapLXhUq44Qot zD+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687685288; x=1690277288; 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=JQKr13O/gR7kX+TGcvxNPBWo9iYiTkszv3Rcg58gpiQ=; b=DZIebqhZC33o6CDqoxd43Geh4uUZflKd/EUhvF/bfamFHP3hJPovNZ3KR8av5IQMN3 7L0y09s6nRguv/lGQosOQLIxk868YwsMvHS7qF5+dJGwv25tOyyqVhn0TuvYfN+7O1Sa bAD6SstmmdNNFNejwvvnhwlAwgR3Byg+klvz+Xl5z0sfII2KZmYjZCweXr5zM2CrGzV3 P/NBY+0Ti6J1wbhsxIAd0+OE+oPQmILymKx+3chzTdaSUrMWBP2vairYiN22sw/dO5OZ J9NygxQmRfed63bQokKuWK1aADtY7ZgSPiZZNsCAl2HOZE5QUy1ry3WhDU+BoPPHtOSa FpSQ== X-Gm-Message-State: AC+VfDzzbZp0MVBzexzJmFIaFGksvhZQtQx3weqUOUrBBIQ93xGd0gQu yVcB2fd7/xgvGK5zhZcqI8TCN6ClCgcnFeBdvWA= X-Google-Smtp-Source: ACHHUZ7+YgaVdOovQs1Keg14d8JmAjNOnBZK2ehlyZyGo279lCiz1KOOcvsOjKFAw1dod6LIlI/nQL1EfM5WdbLS/iE= X-Received: by 2002:a17:903:41d0:b0:1b7:f64b:379b with SMTP id u16-20020a17090341d000b001b7f64b379bmr2014564ple.17.1687685288147; Sun, 25 Jun 2023 02:28:08 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Paul Richard Thomas Date: Sun, 25 Jun 2023 10:27:56 +0100 Message-ID: Subject: Re: [Patch, fortran] PR49213 - [OOP] gfortran rejects structure constructor expression To: Harald Anlauf Cc: "fortran@gcc.gnu.org" 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 feel very foolish! You are absolutely right about gfc_is_ptr_fcn (gfc_expr *e). I never checked what gfc_expr_attr did here. I have fixed character (kind=4) but have now run into trouble with expressions such as cont = tContainer(sqrt (2.0_8)). I think that simplification is being missed somewhere. I'm onto it. Paul 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