From patchwork Mon Dec 12 20:22:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 32526 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2447953wrr; Mon, 12 Dec 2022 12:22:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf6ZyGeH/Fhi8WDRyxv6tP/6Ar88sxH2MwzRtUlGMXDB/92eDBuOjoc5CgokNK71678e/nrv X-Received: by 2002:a05:6402:1f08:b0:462:330a:ce35 with SMTP id b8-20020a0564021f0800b00462330ace35mr19398427edb.11.1670876577827; Mon, 12 Dec 2022 12:22:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670876577; cv=none; d=google.com; s=arc-20160816; b=MGSYly9FrAa0X/6uVshrRqttGcfbjZHun9aDGO5wpMxJt6WlOUgPUYw9+ROUUwLaIh SgJHw2Ods3ow2mBuFbQJ0JpLh3Cbz5o3HmjngVHWPImnEmYQvGmKYtjhOICQlc35HjlX jyUGKXwpMtj5ajWQdo//cUjbjxkth9tuxgLSpyOCGkguwyP0IuUyVrjUwFaQ8XEZ7Uk0 /sMUhzno+5qGyYhdBwurTttjF7RUZxqi1iexwpHeDUHOYtHwZ848NuHZM9myZ/mU92p9 u1Jmr3FKilYM3Vn7tFFeM5obHeE+Tezy4ZUf0huQm4w7Pq3t+4T7uYYR6S7/ye2tr+qr 8WNQ== 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=Xtt+KJx0RLM0tK1TYNkXKdYZWLwhk5rEbRgOeJlyIGU=; b=hg6i+Ri7QyUcnFF0r2HVvxUiLwk3rbT3EpI2kknzoFihDDROTCWdaZ13faDwiSOcg8 I1EfmQ5gf54C71mUoCe5dASsRuWl2Bkv6R2xo35JdJ4IIBG9ZTrtc9a5mWr2Wpof536Q sZ1SBsxkkdLmRhY0YJn4qWk+PO4F+nFhpm+w+QU5gqa9/wQSlHrZBnHJXxkC1NQK13yN JqLbT/V91g7N41PFbGqm33CKvdgIGSkbwh0V0T89Pdbnpwpsjx7psr4dEJcQWsc/VUyK RuvXVMikD2GnvG6XX5tqumbrzKjY6D/S9rZFRcQE5knLYdVHSeb4QXTkn8byjebid12v yFng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="Es/Zr4hL"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id s20-20020a50ab14000000b0046a09ce4d1csi6906164edc.349.2022.12.12.12.22.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 12:22:57 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="Es/Zr4hL"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 74FDF384E7B0 for ; Mon, 12 Dec 2022 20:22:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74FDF384E7B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670876576; bh=Xtt+KJx0RLM0tK1TYNkXKdYZWLwhk5rEbRgOeJlyIGU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Es/Zr4hLd+/3mPk7e+9hdxohwJ1wQm1SwNCfS47k5nlH+muH46P6BvgAs4MZ4Eu80 ASZVB1llaVktjh3A9lEf+7Kuz6HXstTNNSxhU2VJZpILpCgZyFLTQUhggSBgorrifE mDVYSIobNaVZudlFzVYSdcpTC5f9mMLv/w67KijM= 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.19]) by sourceware.org (Postfix) with ESMTPS id 0EF83384E7A1; Mon, 12 Dec 2022 20:22:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0EF83384E7A1 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.85.103] ([93.207.85.103]) by web-mail.gmx.net (3c-app-gmx-bs69.server.lan [172.19.170.214]) (via HTTP); Mon, 12 Dec 2022 21:22:12 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: NULL pointer dereference while parsing a function [PR107423] Date: Mon, 12 Dec 2022 21:22:12 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:niCoHPHDIgoyxV3gWcoB4gmrttC5Y3q3BHDj2AwBqcCpITjW+9Apyq/TJGRGjCUFMT+BW 3EfGkTOnNeTieHlKbSKT/8xN8jFvcTPtEnN9LAm/8L9hStv7wuqTdzUnz9UdTcFeLytLmVbVA5n3 eSWwenVJJ3pPJpmiZA7mDcnuzgV2T+2MCcxdNJxENq5jr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KIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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?1752041078463830494?= X-GMAIL-MSGID: =?utf-8?q?1752041078463830494?= Dear all, here's another obvious patch by Steve which prevents a NULL pointer dereference during parsing. Regtested on x86_64-pc-linux-gnu. Will commit to mainline within 24h unless there are comments. Thanks, Harald From f23a5252ee086f9b78c44150d409e40a445c6928 Mon Sep 17 00:00:00 2001 From: Steve Kargl Date: Mon, 12 Dec 2022 21:11:07 +0100 Subject: [PATCH] Fortran: NULL pointer dereference while parsing a function [PR107423] gcc/fortran/ChangeLog: PR fortran/107423 * parse.cc (parse_spec): Avoid NULL pointer dereference when parsing a function and an error occured. gcc/testsuite/ChangeLog: PR fortran/107423 * gfortran.dg/pr107423.f90: New test. --- gcc/fortran/parse.cc | 2 +- gcc/testsuite/gfortran.dg/pr107423.f90 | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pr107423.f90 diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc index cdae43fa1fd..bc2b2188eea 100644 --- a/gcc/fortran/parse.cc +++ b/gcc/fortran/parse.cc @@ -4015,7 +4015,7 @@ parse_spec (gfc_statement st) gfc_symbol* proc = gfc_current_ns->proc_name; gcc_assert (proc); - if (proc->result->ts.type == BT_UNKNOWN) + if (proc->result && proc->result->ts.type == BT_UNKNOWN) function_result_typed = true; } diff --git a/gcc/testsuite/gfortran.dg/pr107423.f90 b/gcc/testsuite/gfortran.dg/pr107423.f90 new file mode 100644 index 00000000000..9ae64c94ae0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr107423.f90 @@ -0,0 +1,18 @@ +! { dg-do compile } +! { dg-options "-std=f95" } +! PR fortran/107423 - ICE in parse_spec +! Contributed by G.Steinmetz + +program p + type t(k) + integer, kind :: k ! { dg-error "Fortran 2003" } + integer :: a + end type +contains + function f() + type(t(4)), allocatable :: x ! { dg-error "Invalid character" } + allocate (t(4) :: x) ! { dg-error "cannot be used" } + end ! { dg-error "END" } +end ! { dg-error "END" } + +! { dg-prune-output "Unexpected end of file" } -- 2.35.3