From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id C0EFC3857C68; Fri, 19 Mar 2021 08:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C0EFC3857C68 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Tobias_Burnus@mentor.com IronPort-SDR: FOQ6MP6mELppw8Fm2EhQ0dcMqo/r0ecNV5+btVirPBvWAU3DGTzcbhn5Jg3aKNY5fIbehAu4Je ww0mmQYN00KWhaNtn5VCZ6UzQHNhJoyeVRsa4NpAw9YMdfMfJeT3BBh3GtzAt1mcjGKqSBkIO7 hYDyZIbVB0XHvM+2A3aeiRFFW1Hou26Ih01nPV652xtxo0nAGAZwkugJ8Xlc7ydU5N5pz/E51f G8RuGJKfguzcTlf4r5PZBlE1i9eZWLgXGpMWfDDn8MmXBxmELrON/RGE661wFrFF8bc8h3Ab/v dGg= X-IronPort-AV: E=Sophos;i="5.81,261,1610438400"; d="diff'?scan'208";a="59285616" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2021 00:50:57 -0800 IronPort-SDR: nD97JUf7VVrRUUnMFDQSVxmt3ZeC8fLKo6Ej4rWtsFOW8O4kmSM8D5AcTjGCSJyYNdQCuEYNDL kRZl7L0X6KBzdAomEbpdSUvyyH0rYLg/Nu5m9Ih1mf/ZysDGh40+i5DExThfifcof7tOv8cwVK 3APXQfazwvs2FeknrxPuYHOrrGX1KVdJCGlSvN4iGA+ApIGHwCB+rlk+XSpfOSwvNUWbmJ1p8p ZMkCtuHzD3MFa+zZBi45ETtE7h8zYDe2S7swQwuM1HbhU0j9+jZdzqmhHY+LUChKyc5KwI5dEe 22A= To: gcc-patches , fortran From: Tobias Burnus Subject: [Patch] Fortran: Fix intrinsic null() handling [PR99651] Message-ID: <7f4a2fe7-4880-312b-4a05-9578fa431e7c@codesourcery.com> Date: Fri, 19 Mar 2021 09:50:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------79B28CD91576C5CB796131C2" Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-09.mgc.mentorg.com (139.181.222.9) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Mar 2021 08:51:00 -0000 --------------79B28CD91576C5CB796131C2 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: quoted-printable See PR for some analysis. The problem is that during gfc_intrinsic_func_interface, sym->attr.flavor =3D=3D FL_PROCEDURE, hence, attr.intrinsic is not set =E2=80=93 but later when parsing 'null()', gfortran calls: if (sym->attr.proc !=3D PROC_INTRINSIC && !(sym->attr.use_assoc && sym->attr.intrinsic) && (!gfc_add_procedure(&sym->attr, PROC_INTRINSIC, sym->name, NULL) || !gfc_add_function (&sym->attr, sym->name, NULL))) return MATCH_ERROR; The gfc_add_procedure call fails as 'sym' is use-associated and may not be modified. The obvious solution to also set attr.intrinsic for FL_PROCEDURE fails in multiple ways, e.g. for gfortran.dg/char_length_16.f90 which has: CHARACTER (LEN(ITEMVAL)) :: ITEM INTRINSIC LEN the error is that INTRINSIC has been speicified twice. It also affects the error diagnostic in for generic resolution due to (I think): if (sym->attr.intrinsic) return gfc_intrinsic_func_interface (expr, 0); For gfortran.dg/allocatable_scalar_11.f90 the specific =E2=80=98array=E2=80=99 argument of =E2=80=98allocated=E2=80=99 intrinsi= c at (1) must be a variable gets replaced by the generic Generic function 'allocated' at (1) is not consistent with a specific in= trinsic interface I have now tried it as shown. I think attr.function was not set, but am not sure. But setting it again for FL_PROCEDURE looks sensible. I am far from certain that now everything fits together, but I do hope that nothing fails which did work before ... OK for mainline? And after waiting a while for GCC 10? Tobias PS: I did see once a fail for pr93792.f90 (additional error as 't' in type(= t) is not known) =E2=80=93 but I could not reproduce it; the error is valid bu= t later runs stopped with 'cannot open module file' and did not reach that follow-up err= or. ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 M=C3=BCnchen R= egistergericht M=C3=BCnchen HRB 106955, Gesch=C3=A4ftsf=C3=BChrer: Thomas H= eurung, Frank Th=C3=BCrauf --------------79B28CD91576C5CB796131C2 Content-Type: text/x-patch; charset="UTF-8"; name="null-fix.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="null-fix.diff" Fortran: Fix intrinsic null() handling [PR99651] gcc/fortran/ChangeLog: PR fortran/99651 * intrinsic.c (gfc_intrinsic_func_interface): Set attr.proc = PROC_INTRINSIC if FL_PROCEDURE. gcc/testsuite/ChangeLog: PR fortran/99651 * gfortran.dg/null_11.f90: New test. gcc/fortran/intrinsic.c | 5 +++++ gcc/testsuite/gfortran.dg/null_11.f90 | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c index e68eff8bdbb..17fd92eb462 100644 --- a/gcc/fortran/intrinsic.c +++ b/gcc/fortran/intrinsic.c @@ -5071,6 +5071,11 @@ got_specific: sym->attr.intrinsic = 1; sym->attr.flavor = FL_PROCEDURE; } + if (sym->attr.flavor == FL_PROCEDURE) + { + sym->attr.function = 1; + sym->attr.proc = PROC_INTRINSIC; + } if (!sym->module) gfc_intrinsic_symbol (sym); diff --git a/gcc/testsuite/gfortran.dg/null_11.f90 b/gcc/testsuite/gfortran.dg/null_11.f90 new file mode 100644 index 00000000000..040cc260b5d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/null_11.f90 @@ -0,0 +1,16 @@ +! { dg-do compile } +! +! PR fortran/99651 +! +module m + type :: CHAR_STAR + character(len=1),dimension(:),pointer :: ptr + end type + type(CHAR_STAR), parameter ::CHAR_STAR_NULL = CHAR_STAR(NULL()) +end module m + +use m +type typeNode + type(typeNode), pointer :: Next => null() +end type typeNode +end --------------79B28CD91576C5CB796131C2--