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 9B9B33858412; Wed, 25 Jan 2023 21:59:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B9B33858412 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=1674683962; bh=qrgXGIQn+Wc6uHFEvatUdDCIsOM1kk7tLzUs0FUxWnE=; h=X-UI-Sender-Class:From:To:Subject:Date; b=HkaBvwQMMuFk5Zo/Uy2AD8GFmNSvqKRe9OdmXRw/Rb6idJsbwOZbY4Q8pznugRD9O VRDijI2BVDwZTAGvEmVXmNTSeZ2iYiPu+KpP1yIA3mSt3UDadIFuENVJ7sIGcOO5Ll 9bdQYlNBPcrzns2UU5IuoeVU5n2ojr62bW66M4L9bPOSoaGGc+XQyCq8L6qk0JfDgn SI72AkmhRfl9qZS1La8cd/FrUDjFV8WZ8X7XEtcZUmu+nQdOru7JgyxUG9v9U9mPb8 Bvdn5ypYNJ+0Bl16vt0OwvVaI2lCJVP/X7hGDP3jid1NEstUnyizU/aSrpAsp91eNz ascfDCD+50rPg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.89.26] ([93.207.89.26]) by web-mail.gmx.net (3c-app-gmx-bs46.server.lan [172.19.170.98]) (via HTTP); Wed, 25 Jan 2023 22:59:22 +0100 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: fix ICE in check_host_association [PR108544] Content-Type: multipart/mixed; boundary=abmob-366c3da7-dc28-4c13-9af3-cadf773a5791 Date: Wed, 25 Jan 2023 22:59:22 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K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BVM0RNpqrK+Byk xo9otygQ3F4ZUU1IIcwWrUstTW/9MQiXbGoM87GqwzZd5SnEbjwDzKcOpfQL2wWTiOCIkofax AYgNGrAOLMf8KQ0QnVetPaAA== X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP 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: --abmob-366c3da7-dc28-4c13-9af3-cadf773a5791 Content-Type: text/plain; charset=UTF-8 Dear all, the attached patch fixes two issues: first it addresses a NULL pointer dereference on invalid input, triggered by the provided testcase. Second, while analyzing the context of the affected code, I looked into the testcase for PR96102, and by varying it slightly, i.e. replacing functions by subroutines I found that we accept invalid code that is rejected by several other brands tested. To fix this, I removed one line of a condition that did not seem to make sense to me. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald --abmob-366c3da7-dc28-4c13-9af3-cadf773a5791 Content-Type: text/x-patch Content-Disposition: attachment; filename=pr108544.diff Content-Transfer-Encoding: quoted-printable =46rom 59034b3b938a2f5e3391208fca56fcf54d5b6d18 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Wed, 25 Jan 2023 22:47:26 +0100 Subject: [PATCH] Fortran: fix ICE in check_host_association [PR108544] gcc/fortran/ChangeLog: PR fortran/108544 * resolve.cc (check_host_association): Extend host association check so that it is not restricted to functions. Also prevent NULL pointer dereference. gcc/testsuite/ChangeLog: PR fortran/108544 * gfortran.dg/pr108544.f90: New test. * gfortran.dg/pr96102b.f90: New test. =2D-- gcc/fortran/resolve.cc | 4 +++- gcc/testsuite/gfortran.dg/pr108544.f90 | 11 +++++++++++ gcc/testsuite/gfortran.dg/pr96102b.f90 | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pr108544.f90 create mode 100644 gcc/testsuite/gfortran.dg/pr96102b.f90 diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 94213cd3cd4..9e2edf7be71 100644 =2D-- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -6087,7 +6087,6 @@ check_host_association (gfc_expr *e) gfc_find_symbol (e->symtree->name, gfc_current_ns, 1, &sym); if (sym && old_sym !=3D sym - && sym->ts.type =3D=3D old_sym->ts.type && sym->attr.flavor =3D=3D FL_PROCEDURE && sym->attr.contained) { @@ -6132,6 +6131,9 @@ check_host_association (gfc_expr *e) return false; } + if (ref =3D=3D NULL) + return false; + gcc_assert (ref->type =3D=3D REF_ARRAY); /* Grab the start expressions from the array ref and diff --git a/gcc/testsuite/gfortran.dg/pr108544.f90 b/gcc/testsuite/gfortr= an.dg/pr108544.f90 new file mode 100644 index 00000000000..783cb7aaf7b =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr108544.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! PR fortran/108544 - ICE in check_host_association +! Contributed by G.Steinmetz + +module m +contains + subroutine s + select type (s =3D> 1) ! { dg-error "Selector shall be polymorphic" } + end select + end +end diff --git a/gcc/testsuite/gfortran.dg/pr96102b.f90 b/gcc/testsuite/gfortr= an.dg/pr96102b.f90 new file mode 100644 index 00000000000..82147da3893 =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr96102b.f90 @@ -0,0 +1,24 @@ +! { dg-do compile } +! +! PR fortran/108544 - host association +! Variation of testcase pr96102.f90 using subroutines instead of function= s + +module m + type mytype + integer :: i + end type + type(mytype) :: d =3D mytype (42) ! { dg-error "is host associated" } + integer :: n =3D 2 ! { dg-error "is host associated" } +contains + subroutine s + if ( n /=3D 0 ) stop 1 ! { dg-error "internal procedure of the sam= e name" } + if ( d%i /=3D 0 ) stop 2 ! { dg-error "internal procedure of the sam= e name" } + contains + subroutine n() + end + subroutine d() + end + end +end + +! { dg-prune-output "Operands of comparison operator" } =2D- 2.35.3 --abmob-366c3da7-dc28-4c13-9af3-cadf773a5791--