From patchwork Wed Feb 15 21:28:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 57741 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp427443wrn; Wed, 15 Feb 2023 13:28:51 -0800 (PST) X-Google-Smtp-Source: AK7set8YUQy3nwyvarTZncNBtpS3s4fSDhJy0l5R6IW04rkGpDIilAImbbWDBKjr3rnh+UWx8l6H X-Received: by 2002:a17:907:3f16:b0:884:c45f:1c04 with SMTP id hq22-20020a1709073f1600b00884c45f1c04mr4900977ejc.2.1676496531601; Wed, 15 Feb 2023 13:28:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676496531; cv=none; d=google.com; s=arc-20160816; b=q/jic5DNo1Hoq+2UhveOa10Y9V7wh8Q+ZqSs9bIhitTqLgNbrMsh+p0y6r//WYE4I2 EA5sTRMBEZNmeF709z3Vw38z76WpE56MzU9ziJq393N5E1ielDjF3GntCzKRWPRlMIvL dH66lIx0eEgWPGedIx5ZAc54Z4PQlYcy+vpzBFWmDQApr84scmM78CJGD+z+qlkQs0PZ PlQZ9WyU9VKkh6LOrAfk1TJxsLoOxgnlp6nVlDh1dFc9Jwf7xlR5qFsZ+Gmw8znbhGVQ mOpHyYkFKdGSrYJcsXZ2KSMqvRAWkBZ6JcP5ySSU2THXn9NFaqCq7QN2pDLpu15BnhEa cV8w== 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=hUp6Crx5A8Q2oZme6qn/e6DjOA6RCJmx+pkPLhsLnZM=; b=fL5a+J92LNW+Ya9RMFjEAb1brImiy1iyFN1eGHa1Doq748Sd5OU+Y6g+YwkZrpG3N0 lkW2+EkQMEm1qCx+AvRnLQV8pUATGdFUsKl8JN30JsEPbwUa2dJfAdO903o/KZAOoQwf KTxeZ6A6G46GaYn5muwJCZlnp/geDHgEPZkWqPH2oLcSags7s/gnCe2TzEafL0xPnowp toCg1kDYiY7c7Rsu5gODuFh0JN7KUrMQqdLRTISYrJ2SAr/2BmbX8MnBPPUsPNN9ns57 Rs3z1JKoFIzeA0afNRobiTetbSpOhBawRR0tamqAPh0yP2NhgQpHKsfT4UEaUKaXpjt/ xkNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=himMnRbp; 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 fq30-20020a1709069d9e00b0088de3d552e0si12920843ejc.859.2023.02.15.13.28.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 13:28:51 -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=himMnRbp; 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 96F19385800C for ; Wed, 15 Feb 2023 21:28:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96F19385800C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676496530; bh=hUp6Crx5A8Q2oZme6qn/e6DjOA6RCJmx+pkPLhsLnZM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=himMnRbp7NAD7G61OHhNlNF0pYaJ/IsuDp9KcRKvKVVoxgcamEYIbo6phmxaHM28g 5e88GwZgu2Gsn5QzhjWQa+lSVkQFECR0VFjS4v9VSzUYVOZvc472wb9f1y/AxW9Ejh 3DXdvRDocO9ywC8V/T9ZFgkHXbEvOxDprmfLcJjA= 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 63F403858D28; Wed, 15 Feb 2023 21:28:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 63F403858D28 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [79.251.15.143] ([79.251.15.143]) by web-mail.gmx.net (3c-app-gmx-bs56.server.lan [172.19.170.140]) (via HTTP); Wed, 15 Feb 2023 22:28:00 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH, committed] Fortran: error recovery on invalid assumed size reference [PR104554] Date: Wed, 15 Feb 2023 22:28:00 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:urenqoZmrbAPc9reec307L/dGEZWmv6hNyLG8p4wJAxN3JRbX/YxB29PCQHtIl4JFxKLy eX0PqNT4vbZ4gakGaClmjdXeSfmWZNOvGLmIMbK39HZt4zAXSxKMMQ4b5pZjgBtwCPVdOiQPWev6 2/nY3W70QvaWgFycsaJsfsLf4TJ4mKOW1uF2xPUN7NWB3vyGR6LxOMSbpZBdlwy85dn7+DkYY6Ah 0LoCtQQxVuYG9JKXFgt4g2648OFWr/iBuwPLAhmjFXuKTzJShTNkHg87Ha7C61nEUs4EXzgyCOOc 5w= UI-OutboundReport: notjunk:1;M01:P0:OaV/OFIyBcM=;9KpDaaRI37yFcAw8Ut0AaV9CndX yUkOi6b/RRDStDVTOIqv4Y+2kZbU/FEsbVbfWW9J+pAFv/Z7qQwuH+kGLTsL1q6qjrhrXZsE9 8zC7RSmSAPMOnW7AOjw8C5Zl5Cmqyo6tbWCnXje/GlNW7T5EjDTBQS0BjmrichlBdHIjBNQoj y/T3VAGml6fCohQYNPi6HdBZwXhrTjbIE9oXxognBmPK6A4/T1InjGVXWr/I5xHbxWiYL2n/f 8jjHNjZUnY6hkgAqJV3R3TvxJodTTWHzM/K0BLcoz1xDzcGTh+uZRccPPTh8ip8YpF4NhMybt V6UQVoLoDdl4PtKCWYj8D7xPg09I81VifzYLv79g64PgE/XRyoPLYNRPFrqK+gIzZDyyzUZA2 0fHhWlYRCElDTiCQJ8UNiTJhKz4YQHZ60DrAs3wjKqQCDhXukogpNuVLSBE5EHGsvfdUiEMnN 7xQyH42gIaRu+zAy4teO/4IKXeFiUfmzALSxtOqlJMks975PQD95RitVXk368mU+POUTjhJCU M9djdVvr/E/q6cj8w2q/6EB0qiFwc2hXYFFtX+xm8itdjlIMzJHiEGXu+vJ/ycYDk33v5HP42 B3XQkRHyTYNT69p778chUI377GIIdWC019zutnQec9pXANFXw+hC+FAPEyVlgpl6OPyVzllzV l8qVtf7WF8VAE1bQeVpGIflAM198IZBa7L9upZzn4UF6JIg+zaF/KsIt+jj3uTZdsVAkaFHtk PG03zMF1+ifaUczguuPOEMpsZSQWpOkZiVMaTqR0c427PoFBupe6AdaBrYvNZ9gyC7sf6bXpB 8OWwmBLWmpIETwfHdpttx7juLRAGwwSJVSNnOx9a/wQAA= X-Spam-Status: No, score=-13.0 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?1757934027358069827?= X-GMAIL-MSGID: =?utf-8?q?1757934027358069827?= Dear all, I've committed the attached obvious and trivial patch for a NULL pointer dereference on behalf of Steve and after regtesting on x86_64-pc-linux-gnu as r13-6066-ga418129273725fd02e881e6fb5e0877287a1356c Thanks, Harald From a418129273725fd02e881e6fb5e0877287a1356c Mon Sep 17 00:00:00 2001 From: Steve Kargl Date: Wed, 15 Feb 2023 22:20:22 +0100 Subject: [PATCH] Fortran: error recovery on invalid assumed size reference [PR104554] gcc/fortran/ChangeLog: PR fortran/104554 * resolve.cc (check_assumed_size_reference): Avoid NULL pointer dereference. gcc/testsuite/ChangeLog: PR fortran/104554 * gfortran.dg/pr104554.f90: New test. --- gcc/fortran/resolve.cc | 8 +++++--- gcc/testsuite/gfortran.dg/pr104554.f90 | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr104554.f90 diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 96c34065691..fb0745927ac 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -1670,9 +1670,11 @@ check_assumed_size_reference (gfc_symbol *sym, gfc_expr *e) /* FIXME: The comparison "e->ref->u.ar.type == AR_FULL" is wrong. What should it be? */ - if (e->ref && (e->ref->u.ar.end[e->ref->u.ar.as->rank - 1] == NULL) - && (e->ref->u.ar.as->type == AS_ASSUMED_SIZE) - && (e->ref->u.ar.type == AR_FULL)) + if (e->ref + && e->ref->u.ar.as + && (e->ref->u.ar.end[e->ref->u.ar.as->rank - 1] == NULL) + && (e->ref->u.ar.as->type == AS_ASSUMED_SIZE) + && (e->ref->u.ar.type == AR_FULL)) { gfc_error ("The upper bound in the last dimension must " "appear in the reference to the assumed size " diff --git a/gcc/testsuite/gfortran.dg/pr104554.f90 b/gcc/testsuite/gfortran.dg/pr104554.f90 new file mode 100644 index 00000000000..099f219c85d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr104554.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! PR fortran/104554 - ICE in check_assumed_size_reference +! Contributed by G.Steinmetz + +program p + type t + integer :: a + end type + class(t) :: x(*) ! { dg-error "Assumed size array" } + x%a = 3 +end -- 2.35.3