From patchwork Thu Jul 14 20:34:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 7 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a98:d5ce:0:b0:178:cc93:bf7d with SMTP id g14csp527980eik; Thu, 14 Jul 2022 13:35:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ucAViimN3m4RxeLUUGCSfTreBlh2ER2tyl6O7F7wXYEdJ6njQOfcpetu2Qs/25cjW4bqOC X-Received: by 2002:a17:906:b01a:b0:718:cc50:4c6 with SMTP id v26-20020a170906b01a00b00718cc5004c6mr10252784ejy.630.1657830951861; Thu, 14 Jul 2022 13:35:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657830951; cv=none; d=google.com; s=arc-20160816; b=rtLQgYmVZgXfj8QmqhfffCnwFY/VDxjpzbk2eMddgrlKYhdr5p2qdTn/wQDc/37k12 m6wKDTT1il7zrZ1cd0kwcQssKGA5av5u1GJ0jHMGX8qRmTffP1570DL1at8jGoDJ7SVe ZXJmgH//av4/cFCnmUKSv5J/Qr7icoLY2+yGSZIvsZ7zYuOXbEgBD8Um43Xf7Hxzn1Gb QYlpkwVHD7fG5HUlVhyiYDX25iGWBx4WG8wqCmFbuSpK1volI8sCail2uBzF4UI4yauO hIc0Z8DTVq1UB29Xvrx761qwts1OJTXSIahEBUwieT1b8FJrcuoKpM6hbkFidl1kDk9A yd6w== 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=lhO9AVLpPQkEoNKmdBqKohtkrj/Gdt/i9oyypV+LT4o=; b=VnqSYMrjmqPmYHxgLIpuHMeka9yMqXAUhqD8LyW01Vr8XVX1FUU/NKPV5k+XPdwIDf 49IpADXDl/OsjgCiq86fX9IU0r4PZvIZiYNBy3lSfqnbSInn1T3Mh0hUwZJq6L09P6E5 YJ+fFCfudZUK6lBg4t0U6b79qvky12B8sri0BckMDEdE5dNmAVwV/cJcSuzlTZpbXzmV gc+1NBYw7wRgUXPE2Z+o8vIlR0sfxPjqHESKHpliSklGCY1GLoHdEey/VPtyxJkiNwLh 8X6sGxdBPNfABruCQ3MJWxxER63YRVthooy1NLQyuo/c2AgYtCT5+HS4LvBo73MjKHru ez3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DrE9f68F; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w12-20020a05640234cc00b0043a72fe76e5si3859475edc.366.2022.07.14.13.35.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 13:35:51 -0700 (PDT) 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=DrE9f68F; 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 E04C73857407 for ; Thu, 14 Jul 2022 20:35:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E04C73857407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1657830950; bh=lhO9AVLpPQkEoNKmdBqKohtkrj/Gdt/i9oyypV+LT4o=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DrE9f68FLz2VaEwWd1f0f3VJoeSA0Y7M07rQtrOk8DmvSa+131ZVv/LdD2T6soajh NyQ0FjU/mhOs8VHluc0wNX7Il/vHwlovO+UseStNsGrv6+e1iZUN1nZP1d3/uYw8W/ LD7x4CZTAVHGeskiAb/fopmTpK02fYpyqYInvWXY= 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 835673858D37; Thu, 14 Jul 2022 20:34:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 835673858D37 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [79.251.15.109] ([79.251.15.109]) by web-mail.gmx.net (3c-app-gmx-bap08.server.lan [172.19.172.78]) (via HTTP); Thu, 14 Jul 2022 22:34:46 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH, committed] Fortran: error recovery for bad initializers of implied-shape arrays [PR106209] Date: Thu, 14 Jul 2022 22:34:46 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:pTBgMJX937F1jtp+IphXecda9i3FL4f5CZ+gkFkGL/pY9TIosD/Pxy8y30FQqiLOypjCA 9k9UXxpke8+jzv5IikzpdLHwGLPo6zpYhU04keiRe1Eaq9WPl02TrgVWJVcft8EvRdWojDVHGYqw RuCD9ED/SdUgquw9KrBagLQbuSvz8LWjcJG+40mn3529KxtepfuqTX6O8LV+GZw2d23NBTX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ORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: "Li, Pan2 via Gcc-patches" 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?1738361748153547968?= X-GMAIL-MSGID: =?utf-8?q?1738361748153547968?= Dear all, the attached patch introduces error recovery for two cases of using an invalid array in a declaration of an implied-shape array instead of hitting internal errors. Initial patch by Steve. The final version was approved in the PR by Steve. Committed as: https://gcc.gnu.org/g:748f8a8b145dde59c7b63aa68b5a59515b7efc49 Thanks, Harald From 748f8a8b145dde59c7b63aa68b5a59515b7efc49 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Thu, 14 Jul 2022 22:24:55 +0200 Subject: [PATCH] Fortran: error recovery for bad initializers of implied-shape arrays [PR106209] gcc/fortran/ChangeLog: PR fortran/106209 * decl.cc (add_init_expr_to_sym): Handle bad initializers for implied-shape arrays. gcc/testsuite/ChangeLog: PR fortran/106209 * gfortran.dg/pr106209.f90: New test. Co-authored-by: Steven G. Kargl --- gcc/fortran/decl.cc | 15 +++++++++++++-- gcc/testsuite/gfortran.dg/pr106209.f90 | 9 +++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr106209.f90 diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index 339f8b15035..b6400514731 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -2129,10 +2129,21 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus) /* The shape may be NULL for EXPR_ARRAY, set it. */ if (init->shape == NULL) { - gcc_assert (init->expr_type == EXPR_ARRAY); + if (init->expr_type != EXPR_ARRAY) + { + gfc_error ("Bad shape of initializer at %L", &init->where); + return false; + } + init->shape = gfc_get_shape (1); if (!gfc_array_size (init, &init->shape[0])) - gfc_internal_error ("gfc_array_size failed"); + { + gfc_error ("Cannot determine shape of initializer at %L", + &init->where); + free (init->shape); + init->shape = NULL; + return false; + } } for (dim = 0; dim < sym->as->rank; ++dim) diff --git a/gcc/testsuite/gfortran.dg/pr106209.f90 b/gcc/testsuite/gfortran.dg/pr106209.f90 new file mode 100644 index 00000000000..44f9233ec2f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr106209.f90 @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR fortran/106209 - ICE in add_init_expr_to_sym +! Contributed by G.Steinmetz + +program p + integer, parameter :: a(:) = 0 ! { dg-error "of deferred shape" } + integer, parameter :: b(*) = a ! { dg-error "Bad shape of initializer" } + integer, parameter :: c(*) = [a] ! { dg-error "Cannot determine shape" } +end -- 2.35.3