From patchwork Thu Sep 15 20:51:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1243 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp452800wrt; Thu, 15 Sep 2022 13:52:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4JWl6CQx+9QFb+FE2CQTh9PVXW3JseCqLhptd242UGP8RQ6qhO2NMQySYZmYM9lat/rQnH X-Received: by 2002:a05:6402:4310:b0:451:3b07:9114 with SMTP id m16-20020a056402431000b004513b079114mr1374867edc.153.1663275154315; Thu, 15 Sep 2022 13:52:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663275154; cv=none; d=google.com; s=arc-20160816; b=X80e/mhD0Gho0pVcAkpZX9nBRIN9Bd71cjwJdZegpGcqq6rBLQRy021orHhm7vg12t uSK1F8HREakBnbfk211uPNYCQgmIkB+15XGRBnauRG2dJ/CG09v/fCCK1l1/i6me94Uy HDA3a0EBS/3LkC/HFIiluGdf6kGBcGZr7sYgdTKD8I2J+CUytTfMDI1NoAK/5CdiEoTG r+YnxMe9xj4ReUKsjEcGNYwWycO9BjdK1bNcbJI2qOHfbXOL/EghiQJXdvhqz1gVDoK8 wTI/E7Op5FZzXYmSEZUV/9o+Zj2cQjYJAPyUDjI7867UdoEDOZAEqvAOLEx+FGoa8oW1 gkvA== 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=I1dOkrlkZxWE+vuhQXTMLD1x/MMtuYhd4IVc3CMfchk=; b=q2Ag+Njrniey4MskNmwRCtJ4Sz7Zh/Xxb2cescoeG4T79JpfwbBEdIy8nfm+E7EpAy wfV5K6i+8pKkpckW+Wq2bVbnH+KXfQrvl2JYd81On7mnYasnuAhWBLcUABVEwkxhs0nT SvJ/BgRlRsg0cCKvarHrstgXO/7bIfaSH/Ovw4Hq7gmOuCnLIrkAPOU92kw7aYU9mhI4 50k1GjlD9y/ygPEozgPsn6OD7PNb97r9uYiglTv9wSd0Oec5FkOYqXYc7UxEO5rfu2bX vzYDIO/gQeyifP7w87WYCywyYVMNjys98iQOy9MF4ASHAyw1rGmcvMV1r9ax4TnsvYpP VQvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UXoAz+Vh; 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 w2-20020a05640234c200b0044efdf9db9fsi426374edc.68.2022.09.15.13.52.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 13:52:34 -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=UXoAz+Vh; 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 438E5381FE6E for ; Thu, 15 Sep 2022 20:52:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 438E5381FE6E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663275153; bh=I1dOkrlkZxWE+vuhQXTMLD1x/MMtuYhd4IVc3CMfchk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=UXoAz+VhL+u64B7ssBaYheUnrTA6vEZioloo5euRt9q/rTKm8gJh0hjTzzvO2EnpJ DbJ0soG5VMzW6L/XDp8arFtUaFH+WyKhKhcMCV0TLjkVaUgZ8me5BpoWTTER2v3Cjq MmIHZ8SvTt0Yxz/DMnTEyyG+c0Vs/LjPL83ymhhU= 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 B3F3F381FE4A; Thu, 15 Sep 2022 20:51:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B3F3F381FE4A X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [93.207.80.54] ([93.207.80.54]) by web-mail.gmx.net (3c-app-gmx-bs27.server.lan [172.19.170.79]) (via HTTP); Thu, 15 Sep 2022 22:51:32 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH, committed] Fortran: catch NULL pointer dereferences while simplifying PACK [PR106857] Date: Thu, 15 Sep 2022 22:51:32 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:5nNn1G6XD4EvKr9DLN9nHAM35Wl2/XIMqAXP1gNa2RKZykn53DQ3HlFysFvce8t1LB85J AOnaVAN1sGN4JZ3eZjRpV/F3/8WrMszC0RBr3YTH6vGr0HfynIx7QaAvfvSQxYdvhXH1pAe2w5N3 Q+0qe4swIwxRpVu03UgTUBOx5NP2/F+mAno4JskWiuFXCWAFM7SlapD1ou9f2AcV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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?1744070408036969980?= X-GMAIL-MSGID: =?utf-8?q?1744070408036969980?= Dear all, we hit a NULL pointer dereference when trying to simplify PACK when the MASK argument was present. The obvious and trivial solution is to check for NULL pointer dereferences why looking at the constructor for the ARRAY argument, which we already do in the case the MASK is not present. Committed to mainline after regtesting on x86_64-pc-linux-gnu as commit r13-2691-g2b75d5f533b9d6b39f4055949aff64ed0d22dd24 This is a 10/11/12/13 regression, so I will check if it can be backported. Thanks, Harald From 2b75d5f533b9d6b39f4055949aff64ed0d22dd24 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Thu, 15 Sep 2022 22:39:24 +0200 Subject: [PATCH] Fortran: catch NULL pointer dereferences while simplifying PACK [PR106857] gcc/fortran/ChangeLog: PR fortran/106857 * simplify.cc (gfc_simplify_pack): Check for NULL pointer dereferences while walking through constructors (error recovery). gcc/testsuite/ChangeLog: PR fortran/106857 * gfortran.dg/pr106857.f90: New test. --- gcc/fortran/simplify.cc | 2 +- gcc/testsuite/gfortran.dg/pr106857.f90 | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pr106857.f90 diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index bc178d54891..140c17721a7 100644 --- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -6431,7 +6431,7 @@ gfc_simplify_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector) /* Copy only those elements of ARRAY to RESULT whose MASK equals .TRUE.. */ mask_ctor = gfc_constructor_first (mask->value.constructor); - while (mask_ctor) + while (mask_ctor && array_ctor) { if (mask_ctor->expr->value.logical) { diff --git a/gcc/testsuite/gfortran.dg/pr106857.f90 b/gcc/testsuite/gfortran.dg/pr106857.f90 new file mode 100644 index 00000000000..4b0f86a75a6 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr106857.f90 @@ -0,0 +1,12 @@ +! { dg-do compile } +! PR fortran/106857 - ICE in gfc_simplify_pack +! Contributed by G.Steinmetz + +program p + type t + integer :: n + end type + type(t), parameter :: a(2,2) = t(1) + 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" } +end -- 2.35.3