From patchwork Mon Feb 24 12:24:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mark Eggleston X-Patchwork-Id: 1243031 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519977-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=codethink.co.uk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=kWutb/SI; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48R1Vd21gRz9sPk for ; Mon, 24 Feb 2020 23:25:27 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:message-id:date:mime-version:content-type; q=dns; s= default; b=nf3KNkGoRtmR2jo6mBbq2pLREQyd70kwysz8v2ppwGeS2Q6vw0cVT a9Wv0iUJuVlGpLsDjh93ZMFIK+MWJehLhUk2yaJyHigMMK6u1mmaTXe8WLxzucG7 0hKbQsTWbMnpobt7UxpGd8bs73X3zhxt65QZHNQVReejtRif/NHmns= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:message-id:date:mime-version:content-type; s= default; bh=ByqKvm5SoG8Mwnl+VskT2fuepgw=; b=kWutb/SIGpstd1xdTohS 3ZAQ+yVMa1tpSWE3bQSi22t+of7Q0JpXNqu3grAyCRS1vWMsJAsZEHWuK1/Kp59o hg/PFgQm4MaZRtjQJ++PedsTpXadtb5ReZKx41WGEVUkpdz979HSbY6FgrhTAsqp xzeYqNCU5mnK1obKy6AsrBA= Received: (qmail 62593 invoked by alias); 24 Feb 2020 12:24:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 62480 invoked by uid 89); 24 Feb 2020 12:24:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_COUK, KAM_NUMSUBJECT, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: imap3.hz.codethink.co.uk Received: from imap3.hz.codethink.co.uk (HELO imap3.hz.codethink.co.uk) (176.9.8.87) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Feb 2020 12:24:30 +0000 Received: from [167.98.27.226] (helo=[10.35.4.152]) by imap3.hz.codethink.co.uk with esmtpsa (Exim 4.92 #3 (Debian)) id 1j6Cmh-0008Ru-H8; Mon, 24 Feb 2020 12:24:27 +0000 From: Mark Eggleston To: gcc-patches , fortran Subject: [9/10 Regression, fortran, patch] ICE in simplify_findloc_nodim, at fortran/simplify.c:5513 Message-ID: <28ac0912-40d0-69e7-6529-902d286dcbc9@codethink.co.uk> Date: Mon, 24 Feb 2020 12:24:27 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Please find attached a patch to fix PR93835. This patch ensures that the array returned by SHAPE has its shape defined, the original patch from Steve Kargl handled the lack of shape for the returned array. The bonus white space issues fixed in the original patch have been retained. A side affect of the patch is a change in the errors expected by the test case pr77351.f90. Instead of "Error: Different shape for elemental binary operation at (1) on dimension 1 (1 and 2)" and "Error: Array operands are incommensurate at (1)" there is only "Error: Shapes for operands at (1) and (2) are not conformable" which is effectively the same. gcc/fortran/ChangeLog     Mark Eggleston     Steven G. Kargl     PR fortran/93835     * decl.c (gfc_match_data) : Check whether the data expression     is a derived type and is a constructor. If a BOZ constant     is encountered in the constructor output an error and return     MATCH_ERROR. gcc/testsuite/ChangeLog     Mark Eggleston     PR fortran/93835     * gfortran.dg/pr77351.f90 : Check for one error instead of two.     * gfortran.dg/pr93835.f08 : New test. From b4a3defca6a9a7fa0c8b407a4d2f906dc074079d Mon Sep 17 00:00:00 2001 From: Mark Eggleston Date: Thu, 20 Feb 2020 13:25:39 +0000 Subject: [PATCH] fortran: ICE using SHAPE with FINDLOC PR93835 The expression reprenting the array returned by SHAPE does not have its shape defined. An ICE occurs when FINDLOC attempts to use the shape of the array. Whitespace issues identified by Steven G. Kargl have also been fixed. gcc/fortran/ChangeLog PR fortran/93835 * simplify.c (simplify_findloc_nodim) : Fix whitespace issues. (gfc_simplify_shape) : Create and initialise one shape value for the result expression. Set shape value with the rank of the source array. gcc/testsuite/ChangeLog PR fortran/93835 * gfortran.dg/pr77351.f90 : Check for one error instead of two. * gfortran.dg/pr93835.f08 : New test. --- gcc/fortran/simplify.c | 12 ++++++++---- gcc/testsuite/gfortran.dg/pr77351.f90 | 6 ++++-- gcc/testsuite/gfortran.dg/pr93835.f08 | 8 ++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr93835.f08 diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 613fdafd1a6..eb9d2f2c759 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -5497,7 +5497,7 @@ simplify_findloc_nodim (gfc_expr *result, gfc_expr *value, gfc_expr *array, bool continue_loop; bool ma; - for (i = 0; irank; i++) + for (i = 0; i < array->rank; i++) res[i] = -1; /* Shortcut for constant .FALSE. MASK. */ @@ -5540,7 +5540,7 @@ simplify_findloc_nodim (gfc_expr *result, gfc_expr *value, gfc_expr *array, if (ma && gfc_compare_expr (a, value, INTRINSIC_EQ) == 0) { - for (i = 0; irank; i++) + for (i = 0; i < array->rank; i++) res[i] = count[i]; if (!back_val) goto finish; @@ -5565,9 +5565,9 @@ simplify_findloc_nodim (gfc_expr *result, gfc_expr *value, gfc_expr *array, } while (count[n] == extent[n]); } - finish: +finish: result_ctor = gfc_constructor_first (result->value.constructor); - for (i = 0; irank; i++) + for (i = 0; i < array->rank; i++) { gfc_expr *r_expr; r_expr = result_ctor->expr; @@ -7228,6 +7228,8 @@ gfc_simplify_shape (gfc_expr *source, gfc_expr *kind) return NULL; result = gfc_get_array_expr (BT_INTEGER, k, &source->where); + result->shape = gfc_get_shape (1); + mpz_init (result->shape[0]); if (source->rank == 0) return result; @@ -7284,6 +7286,8 @@ gfc_simplify_shape (gfc_expr *source, gfc_expr *kind) if (t) gfc_clear_shape (shape, source->rank); + mpz_set_si (result->shape[0], source->rank); + return result; } diff --git a/gcc/testsuite/gfortran.dg/pr77351.f90 b/gcc/testsuite/gfortran.dg/pr77351.f90 index 76ce5c528b2..e3e8bc4f64b 100644 --- a/gcc/testsuite/gfortran.dg/pr77351.f90 +++ b/gcc/testsuite/gfortran.dg/pr77351.f90 @@ -1,6 +1,8 @@ ! { dg-do compile } +! +! PR93835 resulted in different but valid error message program p integer :: z(4) = [1, 2, 3, 4] - print *, any(shape(z) /= [4,1]) ! { dg-error "shape for elemental binary" } + print *, any(shape(z) /= [4,1]) ! { dg-error "Shapes for operands at .1. and .2. are not conformable" } end -! { dg-excess-errors "operands are incommensurate" } + diff --git a/gcc/testsuite/gfortran.dg/pr93835.f08 b/gcc/testsuite/gfortran.dg/pr93835.f08 new file mode 100644 index 00000000000..933e249e632 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr93835.f08 @@ -0,0 +1,8 @@ +! {dg-do run } +! +! PR fortran/93835 - the following code resulted in an ICE +! +program p + if (any(findloc(shape(1), 1) .ne. 0)) stop 1 +end + -- 2.11.0