From patchwork Tue Sep 27 19:05:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1496 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp486769wrt; Tue, 27 Sep 2022 12:06:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5e3WV7M+0tpNX5w2IGxKqMnzPc5wFbBglV87YnXJB/LTIKi3Y9yo82P+5FbGkHgOoQFyRe X-Received: by 2002:a17:906:730b:b0:782:2eaf:a4ad with SMTP id di11-20020a170906730b00b007822eafa4admr25361036ejc.27.1664305582386; Tue, 27 Sep 2022 12:06:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664305582; cv=none; d=google.com; s=arc-20160816; b=0fIGnssTGLA+U6qAvK2nFp0rpPET6+MdwsyIdkSwQn6yowmAKut56pp12ZaqsD60N9 XSloXqm0hk6AFTk+6fFU3QzDSzOLDF7kh/5O3I6gWCnBXkf6FJDCkJUZBj2B4vNWVkFA 5dXVzguXAWyiV2s5usDcXAKarrc9TL/nulLwGgYrql5fltQ+lEplrB7O9cgP3bHxMTaJ 95RYj7ZaGtYCOB5ZbcbNAmCl/L83loQ7eaQL9OK6g+7G1Wd1lRkM2lNi8r9AN40hLCVX fNgGmG50Wk+AoI1S/0UJPHmUFdI1Cm/JgylLmky391zuyc1xKDRlVZN2y4ferelon8MM uPBw== 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=EI5dJ34M/UJxFLNVFWhCG91LbDqHos0lRLqI5JgrCkA=; b=lsXbxfhF/GR0/HnhpFw/gPIkBCc8/YIG7j1T3J50NNKiF6f4kw1BYZdHB0JEEAgv0P mQT+Ygm/LQxoIjREe9k6qHGvZmDyi9WktLXgzW5uwKbSA+j6nIIsZFOY35z+T6n/I9kI qYPusfh5rzIz4+CFYXtZFPOq9eS3rgPjyjsjHVbihCsriwyN7a6blFHQP8jXJEGnYK7/ DY/Rz9J18pV0T9U7fa8abosJr6jUpPEXH2OLSWxT3jFRC5vcK8AhEQ1LByn9wMMC2QCf pAJ1iyb+sSiConiM03j8XjG/L6Wm4VlL6G4nS/SugUw4WsmBy7HwteTXMuDCl7Uu2U08 UnJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Q6Ijh999; 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 dz11-20020a0564021d4b00b0045440929f87si2816620edb.86.2022.09.27.12.06.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 12:06:22 -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=Q6Ijh999; 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 39FE63858404 for ; Tue, 27 Sep 2022 19:06:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39FE63858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664305581; bh=EI5dJ34M/UJxFLNVFWhCG91LbDqHos0lRLqI5JgrCkA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Q6Ijh999RDZLrv+WKJddh9kNiEntVaXIQ6mYexvxyx/ipKD73NL5XUq5AiBrGNmKY 7jYCGctA6AFTUfTBy5WB04H85FOYigzdpVsfyvIZAg6iW/0pF1G3iyeN5WOb/k8JeA UKDGAc6YUjYa+RVlp9KMBgXJTDM5VR+ngWGTANkU= 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.21]) by sourceware.org (Postfix) with ESMTPS id 10F823858C52; Tue, 27 Sep 2022 19:05:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 10F823858C52 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [93.207.82.123] ([93.207.82.123]) by web-mail.gmx.net (3c-app-gmx-bap61.server.lan [172.19.172.131]) (via HTTP); Tue, 27 Sep 2022 21:05:29 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: error recovery while simplifying intrinsic UNPACK [PR107054] Date: Tue, 27 Sep 2022 21:05:29 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:yhoz9UBoQjzxNbzH16PkkF70RTD5gHJh6wrAEGpBF7VfF7dj3Ldtnb5kfs/l0aekMM29m WZh8lChHejyioc5ErIZvdSlri1iZUDmalwSV5I6GuyRZ6WBYNoflTB3mL9HG7ZcQVvuoJqOW7jpj 9scPrzfSWyTI4jWdaCnFLc8iqI7/1qS+vAA8F9rSLGQ9xmnOrfJGUeLs20TpZAlf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LOW, RCVD_IN_MSPIKE_BL, RCVD_IN_MSPIKE_H2, RCVD_IN_MSPIKE_ZBI, 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?1745150890081716316?= X-GMAIL-MSGID: =?utf-8?q?1745150890081716316?= Dear all, invalid input may trigger an assert while trying to simplify an expression involving the intrinsic UNPACK and when the constructor is lacking sufficient valid elements. The obvious solution is to replace the assert by a condition that terminates simplification in that case. Report and testcase by Gerhard. Regtested on x86_64-pc-linux-gnu. OK for mainline? This is a 10/11/12/13 regression and shall be backported. Thanks, Harald From 80285cdad1fe98c52ebf38f9f66070b2a50191c6 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Tue, 27 Sep 2022 20:54:28 +0200 Subject: [PATCH] Fortran: error recovery while simplifying intrinsic UNPACK [PR107054] gcc/fortran/ChangeLog: PR fortran/107054 * simplify.cc (gfc_simplify_unpack): Replace assert by condition that terminates simplification when there are not enough elements in the constructor of argument VECTOR. gcc/testsuite/ChangeLog: PR fortran/107054 * gfortran.dg/pr107054.f90: New test. --- gcc/fortran/simplify.cc | 13 ++++++++++--- gcc/testsuite/gfortran.dg/pr107054.f90 | 13 +++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr107054.f90 diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index c0fbd0ed7c2..6ac92cf9db8 100644 --- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -8458,9 +8458,16 @@ gfc_simplify_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field) { if (mask_ctor->expr->value.logical) { - gcc_assert (vector_ctor); - e = gfc_copy_expr (vector_ctor->expr); - vector_ctor = gfc_constructor_next (vector_ctor); + if (vector_ctor) + { + e = gfc_copy_expr (vector_ctor->expr); + vector_ctor = gfc_constructor_next (vector_ctor); + } + else + { + gfc_free_expr (result); + return NULL; + } } else if (field->expr_type == EXPR_ARRAY) e = gfc_copy_expr (field_ctor->expr); diff --git a/gcc/testsuite/gfortran.dg/pr107054.f90 b/gcc/testsuite/gfortran.dg/pr107054.f90 new file mode 100644 index 00000000000..bbfe646beba --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr107054.f90 @@ -0,0 +1,13 @@ +! { dg-do compile } +! PR fortran/107054 - ICE in gfc_simplify_unpack +! Contributed by G.Steinmetz + +program p + type t + integer :: n = 0 + end type + type(t), parameter :: a(4) = t(2) + type(t), parameter :: b(4) = reshape(a,[2]) ! { dg-error "Different shape" } + type(t), parameter :: c(2) = pack(b,[.false.,.true.,.false.,.true.]) ! { dg-error "Different shape" } + type(t), parameter :: d(4) = unpack(c,[.false.,.true.,.false.,.true.],a) +end -- 2.35.3