From patchwork Tue Sep 20 20:35:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1325 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp1633414wrt; Tue, 20 Sep 2022 13:35:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5lwTRnEiyBvKS1idXgdi2OLHbKZPKhPO0KhHbX8slUUKQfu/u2pVvKKBQjOYK5EzL04Yj2 X-Received: by 2002:a17:906:db0d:b0:77b:a7cd:8396 with SMTP id xj13-20020a170906db0d00b0077ba7cd8396mr19316867ejb.264.1663706155746; Tue, 20 Sep 2022 13:35:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663706155; cv=none; d=google.com; s=arc-20160816; b=wqjZIDrgtACtEC4VZgQ2EO3SYSu70wHBkCUIOHAtnvi4dP+/KnYVZpCu7PWop5gAQl oddWvLPQyslp8WDvpM2//oaUC/f8EU4sJyI/PxNDK6tdQQrl6RL3tJFz/33R5iyNk0+F d/TO6mvVguPFgvudUhoiqahQdaB3JzsbrnDnCUv7lMaxXCDNFkBLYeN2kLhmCC7krYuk +eXXxDDVGyym5eTJasGb7DPw/9J+JECKDLEbtILEsd8VpRF6IvSXFOG/CgWkFGUdf1Zr UWrRaB4tlF7hEN4scmTm+6NN3GJ2gNERuGzg1Faij0/xavIWUAJzuthYjAZYM7dBAL15 07Ow== 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:sensitivity :importance:date:subject:to:message-id:mime-version:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=e4nhbHQyiQrZqlM9sIADa5XEA7qFV6bpGu3uKncaHBw=; b=V0VJVn4Q9tgT2g7qAc0Q7lhYfXGce1t9o+38YjOE9+PZWRWTYRam17lXpA7W3RAKJE n12n9yssnV6sQ5+dRGcyQYFuZ0YHUmVk/5lNaxiAFWNKLmGIT17f7DmnmRMdHJjvsiJL C+D0IMX3Xwjau5jpLm/EZVgPvfCKAB34aMIpv2VD+UN1eeDSTlXZjd6xdv5OLNp15rhC 1S10Fu9jMMr+bDvg1lOHNCTpDVgKO0H6iEiNEJb4TBivM/ARRVRs8W+BzYukyrtzXynO 5Zl3k3pIcP8CHcgAKDUC2jAY01xBPCJosDheE5kuP3DfBN4hVHUX1lzaDBDMuSkau6uK 0pHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DUEzzaKx; 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 w5-20020a50d785000000b00453eecfd69dsi633914edi.431.2022.09.20.13.35.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 13:35:55 -0700 (PDT) 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=DUEzzaKx; 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 67236385841F for ; Tue, 20 Sep 2022 20:35:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 67236385841F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663706154; bh=e4nhbHQyiQrZqlM9sIADa5XEA7qFV6bpGu3uKncaHBw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DUEzzaKxT42KYkE/P5cH4mjnh2mmJkhdy2pWXRMPYxWkODZyYCjtgCh3UfN79bd0g wLS0YNjt3C8sksqZZEbtdAy5q4dIp0TYj2dpOVweph4nnWbAh04OPQBYcZR4RkWYsy qluvYFCIulmUHNzBnRvONmp6PMyjEoPDmFXrDsDE= 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.17.20]) by sourceware.org (Postfix) with ESMTPS id 6F5123858C55; Tue, 20 Sep 2022 20:35:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6F5123858C55 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [93.207.88.67] ([93.207.88.67]) by web-mail.gmx.net (3c-app-gmx-bap12.server.lan [172.19.172.82]) (via HTTP); Tue, 20 Sep 2022 22:35:04 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH, committed] Fortran: NULL pointer dereference in invalid simplification [PR106985] Date: Tue, 20 Sep 2022 22:35:04 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:CoQVhcd9GX+TOvtyriGFW224ZhSnEjCXwFfXu3ZPGsug9hk0kP+JIdCYxxzWy3kjhjEO+ hSOARi5/wxbxMJ54lfb3sDzX6B4OMoGy0pzKkycp8RzLwdhYTV9Dwqh4SCip1gfurBlfBwe3whJ6 QFeNHgvoR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VALID, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, 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?1744522346202491758?= X-GMAIL-MSGID: =?utf-8?q?1744522346202491758?= Dear all, Gerhard found a NULL pointer dereference in a PARAMETER declaration that referenced the same declared parameter. Simple & obvious enough, see attached patch. Regtested on x86_64-pc-linux-gnu, and pushed to mainline: https://gcc.gnu.org/g:8dbb15bc2d019488240c1e69d93121b0347ac092 Thanks, Harald From 8dbb15bc2d019488240c1e69d93121b0347ac092 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Tue, 20 Sep 2022 22:23:43 +0200 Subject: [PATCH] Fortran: NULL pointer dereference in invalid simplification [PR106985] gcc/fortran/ChangeLog: PR fortran/106985 * expr.cc (gfc_simplify_expr): Avoid NULL pointer dereference. gcc/testsuite/ChangeLog: PR fortran/106985 * gfortran.dg/pr106985.f90: New test. --- gcc/fortran/expr.cc | 3 ++- gcc/testsuite/gfortran.dg/pr106985.f90 | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pr106985.f90 diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc index be94c18c836..290ddf360c8 100644 --- a/gcc/fortran/expr.cc +++ b/gcc/fortran/expr.cc @@ -2287,7 +2287,8 @@ gfc_simplify_expr (gfc_expr *p, int type) initialization expression, or we want a subsection. */ if (p->symtree->n.sym->attr.flavor == FL_PARAMETER && (gfc_init_expr_flag || p->ref - || p->symtree->n.sym->value->expr_type != EXPR_ARRAY)) + || (p->symtree->n.sym->value + && p->symtree->n.sym->value->expr_type != EXPR_ARRAY))) { if (!simplify_parameter_variable (p, type)) return false; diff --git a/gcc/testsuite/gfortran.dg/pr106985.f90 b/gcc/testsuite/gfortran.dg/pr106985.f90 new file mode 100644 index 00000000000..f4ed92577a3 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr106985.f90 @@ -0,0 +1,8 @@ +! { dg-do compile } +! PR fortran/106985 - ICE in gfc_simplify_expr +! Contributed by G.Steinmetz + +program p + integer, parameter :: a(2) = 1 + integer, parameter :: b = a(2) + b ! { dg-error "before its definition is complete" } +end -- 2.35.3