From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by sourceware.org (Postfix) with ESMTPS id C96F33858D1E; Tue, 11 Jul 2023 20:24:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C96F33858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1689107079; x=1689711879; i=anlauf@gmx.de; bh=3IRG4uVHdg5JyMrcCVPVcdtS+y1B6SXVI11MaCYv594=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=aInuczT2MhqlcV/8nqksNkjZ4EDQIWYsq8vV+heN4b18TZssM8qxgmxeuLkLQfbJOvGOboj cPT6fOWYoF8NLZfQui3LeWgbiajXcYj9dyEmuTDPffALejYAdD59yfYvw80FEy0wbzoa3vcVO kcAMVNCPVleActNeQlPWx5oKej6exfZcNedNiw6laOQN4yHe93aWSoc25AWwcdU3Mcn9fMKby qW1wKEgqlav4BaVHOJwiRm/q1mNvQhXRGXsbhrGLxAFHlWb040Dc+A84qU0msnIL09j8vKJM/ 9GY6N5+dNiGKIiHdC1LKbTzaE8VENbeVge4BihVTnvS0wcHy5AuA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.178.29] ([79.232.149.3]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MNswE-1qdA7T0zMG-00ODIt; Tue, 11 Jul 2023 22:24:39 +0200 Message-ID: Date: Tue, 11 Jul 2023 22:24:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [Patch, Fortran] Allow ref'ing PDT's len() in parameter-initializer [PR102003] To: Andre Vehreschild Cc: GCC-Patches-ML , GCC-Fortran-ML , Paul Richard Thomas Newsgroups: gmane.comp.gcc.patches,gmane.comp.gcc.fortran References: <20230710174826.48f9230c@vepi2> <3114593a-0197-62cd-41e9-59f2a8ae9f29@gmx.de> <20230711182352.0e59f735@vepi2> Content-Language: en-US From: Harald Anlauf In-Reply-To: <20230711182352.0e59f735@vepi2> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:FpnjE6Bbj1Q0H4Saka0SVhZTquDJlxmU262/rr6jL8SkJouczUC BKq3k3449ZTGt3MT56PsxW+lObceIdpWklNM8//Y8vDhy2olqVfUhtB474eOLyinLSQXqOJ nMNksDIQph1gOY0E64+mRAA71e5ZYJXSMFYwNDNCx/sIpl5qmDZ+j6yxDP+khiMjyf7ebBG VABQe0PZuqr5sxjpo/9DQ== UI-OutboundReport: notjunk:1;M01:P0:EWaE2iqJ1Cw=;jhIjKqIR9MrxiZxGSl4AjKrHTDP SKuH7q+0QA7BAgiFAj4vixB4v6pJLZpzN8lml+fHqF+bRObu2k8YaRy6wpfDtFL3xInGJa/9N ZaT+C68c/hjDgXArLtKo8Sv1/eKK6rEe95eCAXP1N+R2900uDube53ikxui4gX7UWyG5Uzsju RiY7+gBZZn6KORwwSO6KPdzadZiFcZyLXeDtZnt1FwAVYJAkQmG7U9LPPWgx0VZ12cY04OV0+ 4ww2XbUoC6zN7j3OfzsZzZ9Vz4ikJFfVJa2tMb0CGEbhdrr8kWRmBCa7clfNjvNSi9KJkpyzF LBopEPytcMkaIjnVxQUPcItq70O7tM7h1OVR9uXpHPh9rLSURZoE4DvvIqPyZwJZ+sDWDTqv9 ZGo2YyoUIhcBLIfekuzclcAMQMPIsw8VD6Oqac8GFQyatnaqhLGQbLZug6gwQhLmMARAPASC0 qarEvRydU9btCKxRwhm5Lv2wTFU7XAaoYZPcv69HJ45GTpSiHmjCKiuKG+qqNF0vhT9Sl8o5N gZkw3alJsRmC9zb0eBY6uPbhhqSqrc6Ok3z35MR84zyYtaKtnUqRYPYPOmYp5LjsQL2rxdt66 s/YB04LyqmvGuMea2v5R4fdVT1zGQFhmzAVacd2iiutRHv/ZT+cVncOq4AzzTHJaUw6pyh5H3 OfCPgJG79AILTa/t/fXWKUIbdoQLBZiw50QLbe1n/6DJg3euHCbTeIy7QjtqaeTYG7vVLvN0d PQLumcXOUXM53ISRZCOFcXAb46b72u/8BGvHJwZyQSDHERPdYNO6+FUR7hB4HPzYW+U+tCRhL hKGMOSueSj4/uRiRIlzRBysP0v79Mw9UgY6BSoB9NACaAgRmg3eD55TeMcorkfGJJ8UG3ZMbj zEkpGanAmzGnd/MQdNuswF5LvGXU1YeFmpGrceXynqDz/m2VXzrrKoZmFwmWdCqXZ8u/sSls4 ERZ2TQ== X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,WEIRD_PORT 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: Hi Andre, this looks much better now! This looks mostly good to me, except for a typo in the testcase: + if (p% ci% len /=3D 42) stop 4 There is no component "ci", only "c". The testsuite would fail. Regarding the memleak: replacing // TODO: Fix leaking expr tmp, when simplify is done twice. tmp =3D gfc_copy_expr (*newp); by if (inquiry->next) { gfc_free_expr (tmp); tmp =3D gfc_copy_expr (*newp); } or rather if (inquiry->next) gfc_replace_expr (tmp, *newp); at least shrinks the leak a bit. (Untested otherwise). OK with one of the above changes (provided it survives regtesting). Thanks for the patch! Harald Am 11.07.23 um 18:23 schrieb Andre Vehreschild via Gcc-patches: > Hi Harald, > > attached is a new version of the patch. This now also respects inquiry-L= EN. > Btw, there is a potential memory leak in the simplify for inquiry functi= ons. I > have added a note into the code. > > I tried to use a pdt within a derived type as a component. Is that not a= llowed > by the standard? I know, I could hunt in the standard for it, but when s= omeone > knows out of his head, he could greatly help me out. > > Regtests ok on x86_64-linux-gnu/F37. > > Regards, > Andre > > On Mon, 10 Jul 2023 20:55:29 +0200 > Harald Anlauf wrote: > >> Hi Andre, >> >> thanks for looking into this! >> >> While it fixes the original PR, here is a minor extension of the >> testcase that ICEs here with your patch: >> >> program pr102003 >> type pdt(n) >> integer, len :: n =3D 8 >> character(len=3Dn) :: c >> end type pdt >> type(pdt(42)) :: p >> integer, parameter :: m =3D len (p% c) >> integer, parameter :: n =3D p% c% len >> >> if (m /=3D 42) stop 1 >> if (len (p% c) /=3D 42) stop 2 >> print *, p% c% len ! OK >> if (p% c% len /=3D 42) stop 3 ! OK >> print *, n ! ICE >> end >> >> I get: >> >> pdt_33.f03:14:27: >> >> 14 | integer, parameter :: n =3D p% c% len >> | 1 >> Error: non-constant initialization expression at (1) >> pdt_33.f03:20:31: >> >> 20 | print *, n ! ICE >> | 1 >> internal compiler error: tree check: expected record_type or union_type >> or qual_union_type, have integer_type in gfc_conv_component_ref, at >> fortran/trans-expr.cc:2757 >> 0x84286c tree_check_failed(tree_node const*, char const*, int, char >> const*, ...) >> ../../gcc-trunk/gcc/tree.cc:8899 >> 0xa6d6fb tree_check3(tree_node*, char const*, int, char const*, >> tree_code, tree_code, tree_code) >> ../../gcc-trunk/gcc/tree.h:3617 >> 0xa90847 gfc_conv_component_ref(gfc_se*, gfc_ref*) >> ../../gcc-trunk/gcc/fortran/trans-expr.cc:2757 >> 0xa91bbc gfc_conv_variable >> ../../gcc-trunk/gcc/fortran/trans-expr.cc:3137 >> 0xaa8e9c gfc_conv_expr(gfc_se*, gfc_expr*) >> ../../gcc-trunk/gcc/fortran/trans-expr.cc:9594 >> 0xaa92ae gfc_conv_expr_reference(gfc_se*, gfc_expr*) >> ../../gcc-trunk/gcc/fortran/trans-expr.cc:9713 >> 0xad67f6 gfc_trans_transfer(gfc_code*) >> ../../gcc-trunk/gcc/fortran/trans-io.cc:2607 >> 0xa43cb7 trans_code >> ../../gcc-trunk/gcc/fortran/trans.cc:2449 >> 0xad37c6 build_dt >> ../../gcc-trunk/gcc/fortran/trans-io.cc:2051 >> 0xa43cd7 trans_code >> ../../gcc-trunk/gcc/fortran/trans.cc:2421 >> 0xa84711 gfc_generate_function_code(gfc_namespace*) >> ../../gcc-trunk/gcc/fortran/trans-decl.cc:7762 >> 0x9d9ca7 translate_all_program_units >> ../../gcc-trunk/gcc/fortran/parse.cc:6929 >> 0x9d9ca7 gfc_parse_file() >> ../../gcc-trunk/gcc/fortran/parse.cc:7235 >> 0xa40a1f gfc_be_parse_file >> ../../gcc-trunk/gcc/fortran/f95-lang.cc:229 >> >> The fortran-dump confirms that n is not simplified to a constant. >> So while you're at it, do you also see a solution to this variant? >> >> Harald >> >> >> Am 10.07.23 um 17:48 schrieb Andre Vehreschild via Gcc-patches: >>> Hi all, >>> >>> while browsing the pdt meta-bug I came across 102003 and thought to my= self: >>> Well, that one is easy. How foolish of me... >>> >>> Anyway, the solution attached prevents a pdt_len (or pdt_kind) express= ion >>> in a function call (e.g. len() or kind()) to mark the whole expression= as a >>> pdt one. The second part of the patch in simplify.cc then takes care o= f >>> either generating the correct component ref or when a constant express= ion >>> (i.e. gfc_init_expr_flag is set) is required to look this up from the >>> actual symbol (not from the type, because there the default value is >>> stored). >>> >>> Regtested ok on x86_64-linux-gnu/Fedora 37. >>> >>> Regards, >>> Andre >>> -- >>> Andre Vehreschild * Email: vehre ad gmx dot de >> > > > -- > Andre Vehreschild * Email: vehre ad gmx dot de