From patchwork Wed Oct 19 20:49:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 5839 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp528408wrs; Wed, 19 Oct 2022 13:50:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4T4fwoLOg6JUyyNnKB2NV+gFkIfTs/fQUuEIyD3xnRA0xk+tH1U6K1+Aa1ymw4wEfP0HRP X-Received: by 2002:a05:6402:26cf:b0:45d:48d7:928e with SMTP id x15-20020a05640226cf00b0045d48d7928emr8900646edd.275.1666212647466; Wed, 19 Oct 2022 13:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666212647; cv=none; d=google.com; s=arc-20160816; b=LMHtnEsghYL9/n96ZLWRm9pdL+rIkIOKavUwKxQiCBgVaOO+oEz23eMUroR2OJLvc/ SDjHVbsaH9CgYBGixGAb03a00AdoJ7LTmE7e8sH4nZiT3g4gLK6vdOb3vblgUvvYsGTz TncJovutkF9QUigqM6ISeNv5uoLZ1xfVk4R7TUR5sVFQt5T6uSYfYd3mnsDDvNnJ+StR dazjXQerir0pRwnw45txfARf3byl6Tbxe3xOLLDJlED+XPzCOGJHB2KXBohpFJNFxNSg LsyETLugkClcHD2DCNPprdAKyqRwDo/tezBZdnfH0YxlL6OYxumYEloPl79TRUqvirq/ ZdJQ== 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=eQgytPFyloZ8yElqwic/UT0MZJ3ngHE2EdM+TK/iq7g=; b=XM+ji0cmBaaPV9VMHP48+eWjTHfplP+bybzWhTDFzjikkIA3Lwnd5TQspjHHsMuB6S 94klAWt2mPzF0DyKN6HYV+3Oxsg8hseQ6WM4YtiyJ6fY/zq3mY/ygMDnUoOa0m50V33s 9yFB32quRFJCV6QXU2Q49zIzItah3tcR9V8dRmML+wcqenKEDflbBUkrALffygQpLOMy aRSB78GCux9wP9RMnfTkldh0cSi5GwtB/BgpOZ8dLUll03qYRUaIXNz+GVTRdquilkuO puM3Gg94LXqOngZNa6FqlEJkgCwq1N6BiskTLrWSRVhHGobOZK4TWFtRLmQ8TtPAi2YL V91Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="jqCA/1iY"; 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 u29-20020a50d51d000000b00459141c6f75si15210471edi.100.2022.10.19.13.50.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 13:50:47 -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="jqCA/1iY"; 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 1725A3857B87 for ; Wed, 19 Oct 2022 20:50:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1725A3857B87 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666212633; bh=eQgytPFyloZ8yElqwic/UT0MZJ3ngHE2EdM+TK/iq7g=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jqCA/1iYJ17+/b8ert02QeWgCcOpo3y5ikjjk62c2DijRJgJu80iMWchy6JbZRjOO mmxFcT7TFkH8G1vPmTwdeCdzUPqvVGzAYVfxMh2Mm5qBuvE9L4mb2Nf+VV3ZgZ20ud hl5deLbA3ojONYZ5rOvMKoOOswmhwTfEInDmgsz0= 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.22]) by sourceware.org (Postfix) with ESMTPS id 74E353858D3C; Wed, 19 Oct 2022 20:49:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 74E353858D3C X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [93.207.84.161] ([93.207.84.161]) by web-mail.gmx.net (3c-app-gmx-bap39.server.lan [172.19.172.109]) (via HTTP); Wed, 19 Oct 2022 22:49:44 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: error recovery with references of bad array constructors [PR105633] Date: Wed, 19 Oct 2022 22:49:44 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:bMchlx/tLvHjXze8NfCBb1kBSyNNpQn8sUXkl1F5w8ALVr1HElSrwAZQyKJCP3j15jRIM Ei98wI4ThhMEQyCBOCxfUHCRj1j9glQ+aUGQUJAzXpg0ms8UvjS6R7w8Me/x9OLIPVxKxyzFeUnW 5HSKxKp/RYJ8InTOqflEbSdSS2KF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x sALl7YhKjR3srKQHZlIqJPC5jf913JjMjaX6IVZL87Ytsdf9KUjOuHsfhhTTbC/y59T4nKnB8 ytNB1vj8r6MDgDwMAZ77xjW+QIcGZ+o23Ls3tloMjWbAHSTSiqL2rlJWyFRf1NfljufOE0jVn tN9uXaRTgKkS/Yvs8Bav/D0MlSF1e9nNnYiIueQSQDVC32xNFZ4BXTiqs8I5rRrfXZpdWIPXr gQUJM/meuinSdAe+TrmYKmqlrDSJy50Z+hP2bBU4c5u75Gumc44LBpSLeNrrSCqtMCYoAYa7e C/jN4Usv4WvKMqtKAv5teWJAxkRoCMIW0G7C/RNKaMH/nagGKOcSsLz12xBFc4zJERM9Erj6K ZzVIbQsUWqQHfnfAiLJv88ywiF5YtOvv6rj+BPG5R/XC9nt1DEZ36nwZxlh9etxA5t2we7oZ2 ATkX2hCO X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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?1747150593367859267?= X-GMAIL-MSGID: =?utf-8?q?1747150593367859267?= Dear Fortranners, here's another patch that improves error receovery with references of bad array constructors leading to an ICE after a NULL pointer dereference. Original patch by Steve, which I amended with a logic cleanup. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From 0da12c71a6ccbefa1456be5759974a4b450c78e6 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Wed, 19 Oct 2022 22:37:56 +0200 Subject: [PATCH] Fortran: error recovery with references of bad array constructors [PR105633] gcc/fortran/ChangeLog: PR fortran/105633 * expr.cc (find_array_section): Move check for NULL pointers so that both subscript triplets and vector subscripts are covered. gcc/testsuite/ChangeLog: PR fortran/105633 * gfortran.dg/pr105633.f90: New test. Co-authored-by: Steven G. Kargl --- gcc/fortran/expr.cc | 10 +++++++--- gcc/testsuite/gfortran.dg/pr105633.f90 | 8 ++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr105633.f90 diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc index 290ddf360c8..69d0b57c688 100644 --- a/gcc/fortran/expr.cc +++ b/gcc/fortran/expr.cc @@ -1552,6 +1552,12 @@ find_array_section (gfc_expr *expr, gfc_ref *ref) lower = ref->u.ar.as->lower[d]; upper = ref->u.ar.as->upper[d]; + if (!lower || !upper) + { + t = false; + goto cleanup; + } + if (ref->u.ar.dimen_type[d] == DIMEN_VECTOR) /* Vector subscript. */ { gfc_constructor *ci; @@ -1594,9 +1600,7 @@ find_array_section (gfc_expr *expr, gfc_ref *ref) { if ((begin && begin->expr_type != EXPR_CONSTANT) || (finish && finish->expr_type != EXPR_CONSTANT) - || (step && step->expr_type != EXPR_CONSTANT) - || !lower - || !upper) + || (step && step->expr_type != EXPR_CONSTANT)) { t = false; goto cleanup; diff --git a/gcc/testsuite/gfortran.dg/pr105633.f90 b/gcc/testsuite/gfortran.dg/pr105633.f90 new file mode 100644 index 00000000000..f2dbc5e742a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr105633.f90 @@ -0,0 +1,8 @@ +! { dg-do compile } +! PR fortran/105633 - ICE in find_array_section +! Contributed by G.Steinmetz + +program p + integer, parameter :: a(:) = [1,2] ! { dg-error "deferred shape" } + print *, [a([1,2])] +end -- 2.35.3