From patchwork Thu Dec 1 20:25:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 28547 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp470372wrr; Thu, 1 Dec 2022 12:26:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf6CgB+HzJ85aqB3bv13UAn9ni1h0g2oRMHlzl0B/MkcvBXTgnloR3w9EIbmdeB7z1n+yeSc X-Received: by 2002:a17:906:6d8e:b0:7ad:a2e9:a48c with SMTP id h14-20020a1709066d8e00b007ada2e9a48cmr46030709ejt.77.1669926406682; Thu, 01 Dec 2022 12:26:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669926406; cv=none; d=google.com; s=arc-20160816; b=eVRtnlkLWZgjZvOa813ariaL+O+7F3p3LyqB+uhTvqeMne4oL7Jtbk8Z3VZTNg9nTJ UqOxzmQDMQG5KknU1DaUd561d4Uz1wngw9127ic5DIvqFqi+MSfXd1xtXLrL3UdJ9ROs 9IbtivdX2TxX6I3bxpHrbs1oX2mdxEWYbMgYaWRjCiUxx04IPk8wV5hfWGnd+3oyerJc wQSdQcgz+hzs+4OhOCoMcYenKzo53Q+fxktDqvCwjc8+WEaz2Ry8foUIpU4rg/QUaXHy ck7eMM09uv2JhE6d4IKXr06fyD+vpuVUO1bFIFHaOqEFoTT9PwBeYxCjSKaJj1dCbNUa Q7aA== 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=x0yqEKinNp1Dnf9zVyJuzEO9pVACaMyGPpT9pg14+UE=; b=o/Z3616yr4PURLh5boLFPeJe7bGIPQfMQVDnCHJL2aTHAL2L6bPiPBCUQ6b1riFaIr Dxhujn8altKnFUcdJ4IeOeCl1Hin2WoDwsbswTljD53uZ3KmwPBLVV+L301bPHNtxCsR +nxDmI7puHisMZZnkonIUuQqnH4lAuJPL25EhLf5psmJE94Uxizo3AXQXoqX9m8RnWWL RI14CgmuqlZ7w+ig/fv376tf73ndqN6E1jZYlBwPzipwiEGZy2DYIzl9kPnapncoOOjk IFEqEAt7Pt60YCXHB0Xdmb+P0KiFRQdb96jw5XqkUs2T4ExSPuuvcmCCS/GJbvjwkXZx fZrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uP5asXM5; 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 qa31-20020a170907869f00b0077d854aa10dsi5571831ejc.57.2022.12.01.12.26.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 12:26:46 -0800 (PST) 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=uP5asXM5; 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 43FEE385800C for ; Thu, 1 Dec 2022 20:26:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 43FEE385800C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669926400; bh=x0yqEKinNp1Dnf9zVyJuzEO9pVACaMyGPpT9pg14+UE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=uP5asXM5+eop0uhsZ3YaFAmecIDH31cZj/JmpQt1t7vH8vop4FxqgZNCCe6gsGl6e y8/jWiR6yvUDvhRU0hCTNgF80v5nFcuqH05Iw41PhMiMwE92lBRTIQScx7AM9rUhWD 53gdaL91AIfD/AXsAuuCw+RybuFpLJheIU8vZEXg= 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.18]) by sourceware.org (Postfix) with ESMTPS id 715AC3858D32; Thu, 1 Dec 2022 20:25:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 715AC3858D32 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.88.222] ([93.207.88.222]) by web-mail.gmx.net (3c-app-gmx-bs60.server.lan [172.19.170.144]) (via HTTP); Thu, 1 Dec 2022 21:25:30 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: error recovery simplifying UNPACK for insufficient FIELD [PR107922] Date: Thu, 1 Dec 2022 21:25:30 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:8rVrdIMU+85OfBHHeA/xyL8Q6B5XzgCcPJNkIHVbc3PvHHfD3vG5ekKFFlBwStXkeIGfo dJxdyIr+Qb6zxrPbi7XWJKjnkglWooxW3WFDR+im0OZrooiMBC24myNU9VFWNFKYNWrYxm00XAQR 7h8MlR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AYES_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?1751044751986861127?= X-GMAIL-MSGID: =?utf-8?q?1751044751986861127?= Dear all, we did not properly handle the case of insufficient array-valued FIELD when trying to simplify UNPACK and could run into a NULL pointer dereference. The fix is obvious. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From 0ff50e73c6fce52263b9530daffe6743c1fc9b2c Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Thu, 1 Dec 2022 21:16:46 +0100 Subject: [PATCH] Fortran: error recovery simplifying UNPACK for insufficient FIELD [PR107922] gcc/fortran/ChangeLog: PR fortran/107922 * simplify.cc (gfc_simplify_unpack): Terminate simplification when array-valued argument FIELD does not provide enough elements. gcc/testsuite/ChangeLog: PR fortran/107922 * gfortran.dg/unpack_field_1.f90: New test. --- gcc/fortran/simplify.cc | 9 ++++++++- gcc/testsuite/gfortran.dg/unpack_field_1.f90 | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/unpack_field_1.f90 diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index b6184181f26..0a0a7755f4c 100644 --- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -8485,7 +8485,14 @@ gfc_simplify_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field) } } else if (field->expr_type == EXPR_ARRAY) - e = gfc_copy_expr (field_ctor->expr); + if (field_ctor) + e = gfc_copy_expr (field_ctor->expr); + else + { + /* Not enough elements in array FIELD. */ + gfc_free_expr (result); + return &gfc_bad_expr; + } else e = gfc_copy_expr (field); diff --git a/gcc/testsuite/gfortran.dg/unpack_field_1.f90 b/gcc/testsuite/gfortran.dg/unpack_field_1.f90 new file mode 100644 index 00000000000..ca3cfbd2bd4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/unpack_field_1.f90 @@ -0,0 +1,15 @@ +! { dg-do compile } +! PR fortran/107922 - ICE in gfc_simplify_unpack +! Test error recovery when shapes of FIELD and MASK do not match +! Contributed by G.Steinmetz + +program p + integer, parameter :: a(2) = 1 + integer, parameter :: d(3) = 1 + logical, parameter :: mask(3) = [.false.,.true.,.false.] + integer, parameter :: b(2) = unpack(a,mask,a) ! { dg-error "must have identical shape" } + integer :: c(3) = unpack(a,[.false.,.true.,.false.],a) ! { dg-error "must have identical shape" } + print *, unpack(a,mask,a) ! { dg-error "must have identical shape" } + print *, unpack(a,mask,d) ! OK + print *, unpack(a,mask,3) ! OK +end -- 2.35.3