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: 48396 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp504224wrn; Wed, 25 Jan 2023 14:00:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXt19yaL5yWoJJQl5NI9jy7WGezV9ROU2lli14oSPZOa8LrF12DrCyIS6k9X8XysjvTu/YWT X-Received: by 2002:a17:907:8b0a:b0:877:5c3e:706 with SMTP id sz10-20020a1709078b0a00b008775c3e0706mr33568125ejc.73.1674684039657; Wed, 25 Jan 2023 14:00:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674684039; cv=none; d=google.com; s=arc-20160816; b=SK4DmCpJb32IbVRXLerMBwBMbEwzmrnzFPNWmoxRE9ndggXN6J8DfA2Xcq6OAmid/i ZFLiYHOrd+fkRWpJIYJKwi2ZzCe6rMsukNTJT9AVxtXpi9iFonRUvCFAtucQvijynfKb uWrEoKe4viR2MZvkUgBP8xd17bBQ0xUd2Q3CNQp0a186Ib9YaShzEemThiyDmaPGTXwE HeHHQ7m43hUVrLt8gGLta7mmcVsssJWd7eB94b5mUfW+kOA6KN9CsMyygzJZWRrJ67g1 9/iPG9Ng6TF7Thdxwg5uofEMde2Xufe1xkAcC1SaIs7MEO0vgwtKSUZ/rCGwV9qHcC/L 9Q8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:ui-outboundreport :sensitivity:importance:date:subject:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=7RZR4pRHNiYNY3pY3Wo+gVfmd7Y1+PJZFtec402Qf4g=; b=L9gNGOM1Rvweq33y0QXBFrHR2biKzt8AVLxRMPGEaQW4EwmCXid/QT+jAWwHquOIKf qcJaBMv/FyC3CQeRNKpTs5nfPfOdQWWMrqvPNxoh/pdbJjS3Ahij08FC29Wofy9a1LLT CxvpIPXRuRb5RfF5iIOgLnTmFeekhpYRfvQKat2Osz2cEP3ccxTnf87H1lbbqXQoCzhK 3xMVhsun9xEBpbTGWBJ8rDFbX745YaOymAcAgf1+5m7geoCzHnRZ7FUbXEsda1QkaHf7 DE1DUo5Y5gTUJG83Fp8zw/cV2DbEGPOCevYZMvS9SzhGfT0Qisfl81crrKO53vKwG6cm 2qag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=W3Hdfi4s; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id vs1-20020a170907138100b0078dbd939dacsi6233920ejb.545.2023.01.25.14.00.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 14:00:39 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=W3Hdfi4s; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 285903858284 for ; Wed, 25 Jan 2023 22:00:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 285903858284 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674684008; 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=W3Hdfi4sbtzJqn15WD9wmCFAAE9fAX7zViGBC6WVuNQ6q26zCGPMtJCr80FlvwUaW AVtz2TmsJyoiIeAkZJ7MWtJZGkjVWonTF9kBGb9pUua4WPi2WjoHEXvVUCwUJ2LVm0 3MX51RCXqTvhGkId3oGxUj9ESKfF2pq/UeBZ1NAY= 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: Normal X-Priority: 3 X-Provags-ID: V03:K1:e73NT6ybUuOcggc6kxzyyvOB7QuqWnbfRjG11CZr2pF5Pp4Wp0Cgr3U80m0ltpNsm8k4O ZpGOfILrDxkmH9CC46V9gOqI0DFc2x2ZMa7r0KEzFU/yd5dqxc19lfnrbDQFZWz9DPsfeBzxAEXN mbqQh+cf3yPztZU75bjZeIQD2244eWKezCWpVnb/tOcYkUXD5ussiizQY3Nuh14stLCqOu8c1wXa 3GvhjmZNxkQEkgUVBMf7dy7cjORwA0TgLR51+ofepOuXySpNNhHR6kvnYJ0+rsQ8j/PlX7Dhnz8i lA= UI-OutboundReport: notjunk:1;M01:P0:8GfyxFI53sU=;D2+caGd5TV8GGaHIoaap6ZVlIra r09aQCWEEOrZvXnGp1NP5/PFxUyXBsN4OYw99ihD9StECaeNkb6KFONgAICG3adGqc3InGHkp ENvU8RUHrajOrqFdiQup/cIoqGE4DSfOu0rKPTs4E+dQJSq9fyz0BFL/wuQP0Ky189C7NVce1 HZ6JkrLbSA7kDFjJQWUAlaMnBXDDl1qvTONy9N/iPxbH9EH1982fSa7IeC6WIKQAZ+swk2YD+ TDjMJoXpv3ej19amVjiYC87e2MUm0E1UneHzutFo3QRILNc1BvVYRfg/5hkTKv7y0STDJrlEp 3CIrW5owJncemonhW7L7ujOM6uU5zuxWq1shsMJ6DRDDd9y+lRB28INsPo3ammyB1B24kQLrc kFu/w1JKeYOC+7Zkthg78cNyFWWrkPxBXzk7UzMoN0APE8TS4ui+xrH5dWUbI4+BJcTjfeH4o kCyAZDxxx6i/HKH5vft/hLm0okN+kscnjJ24WSQQ0xQajvjFlwHZeob1OhiTktRMt4WjAxeOc HlM/gCadz9/AMGGdSuGUY0U8yFjo8KvmpDrQwPLMvxA+P5sydDTGfDpcSDdfmtPZexG4PK/Pf AcPJs0Hyk8nux3XQq1dAWV4dznPVKMOoGm5sXrTxygbyhtorJXGxSEeKP+JOpJU9cqhISu0aw ukFqiscPNwFnB9nWhSR7dyecNaoDeIj5MaGLupRd6115bSQSU9vhl+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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756033491244203196?= X-GMAIL-MSGID: =?utf-8?q?1756033491244203196?= 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