From patchwork Wed Jan 25 21:59:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 63697 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D8A51385B501 for ; Wed, 25 Jan 2023 21:59:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D8A51385B501 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674683992; bh=7RZR4pRHNiYNY3pY3Wo+gVfmd7Y1+PJZFtec402Qf4g=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=n3tXq/X0kdeyb6wCrbPl3Kd3TGdSbcbVsqWIOlq7t42c2C9csNKnmTjy2WPwoNl0X Tq/jGA6mdRHMrjWJncTo5lq/QHngE9LP5Juw8oejexX86qP6G8wurq1HpYRy6iBWcI U1l0hqF/zV1WR0TNBiWAokBQsJuD0Tb2nPHHdm2M= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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: To: fortran , gcc-patches Subject: [PATCH] Fortran: fix ICE in check_host_association [PR108544] Date: Wed, 25 Jan 2023 22:59:22 +0100 Importance: normal Sensitivity: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MaGLupRd6115bSQSU9vhl+BBqVSBVM0RNpqrK+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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 From 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. --- 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 --- 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 != sym - && sym->ts.type == old_sym->ts.type && sym->attr.flavor == FL_PROCEDURE && sym->attr.contained) { @@ -6132,6 +6131,9 @@ check_host_association (gfc_expr *e) return false; } + if (ref == NULL) + return false; + gcc_assert (ref->type == REF_ARRAY); /* Grab the start expressions from the array ref and diff --git a/gcc/testsuite/gfortran.dg/pr108544.f90 b/gcc/testsuite/gfortran.dg/pr108544.f90 new file mode 100644 index 00000000000..783cb7aaf7b --- /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 => 1) ! { dg-error "Selector shall be polymorphic" } + end select + end +end diff --git a/gcc/testsuite/gfortran.dg/pr96102b.f90 b/gcc/testsuite/gfortran.dg/pr96102b.f90 new file mode 100644 index 00000000000..82147da3893 --- /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 functions + +module m + type mytype + integer :: i + end type + type(mytype) :: d = mytype (42) ! { dg-error "is host associated" } + integer :: n = 2 ! { dg-error "is host associated" } +contains + subroutine s + if ( n /= 0 ) stop 1 ! { dg-error "internal procedure of the same name" } + if ( d%i /= 0 ) stop 2 ! { dg-error "internal procedure of the same name" } + contains + subroutine n() + end + subroutine d() + end + end +end + +! { dg-prune-output "Operands of comparison operator" } -- 2.35.3