From patchwork Sun Feb 6 21:14:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1589096 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=CXVdX+iK; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JsMV56RcTz9s9c for ; Mon, 7 Feb 2022 08:14:36 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C4A453858430 for ; Sun, 6 Feb 2022 21:14:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4A453858430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1644182072; bh=aJkVsPHH/7NjzK9xQIyBEC/zGxqU8QdDZSuh9sOociQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=CXVdX+iKEQmpmpXpk2tFRv/n+AwiqZ5Z131anvB7CU7JLlDPd3tqTc/78QCt9Y0ED jmk+nADNR8dz7zOj5ZnDqqj8U06LsXyGklajJsTdwxBPTzIqCL8YSZ9RWwEK/u8Doq H4+dQL36G3sneehj87AnwksC3+Fbr0KEOjoOtS4s= 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.19]) by sourceware.org (Postfix) with ESMTPS id 398863858D3C; Sun, 6 Feb 2022 21:14:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 398863858D3C X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [79.251.6.124] ([79.251.6.124]) by web-mail.gmx.net (3c-app-gmx-bs40.server.lan [172.19.170.92]) (via HTTP); Sun, 6 Feb 2022 22:14:09 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] PR fortran/66193 - ICE for initialisation of some non-zero-sized arrays Date: Sun, 6 Feb 2022 22:14:09 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:utVVsISOxylU/ATn7Jj8jdzg2NJFU411guZMOVeSThLcw18y429kPv1wTyzGe7baOtE/n 1LMsX2kviSK2YR8oFI/l827OoI79gq4XdGuTJsesCPVvDPdprJAKij3o6yk8T246jxNR8U/guLrR X7LjHpMm+2CfPVTk+5LuEZuSgwgCiiIEuxVi+9ybEIShCFi648m1lEaWlSN7FsBS6EsneGGAbS6L Hdu/7jCavHto7ooMcZhLhHk+qKDLoU90qvb2oiaxuH7I9ja2xuoAdoMWEj/SjECYyL9mSysluxX5 go= X-UI-Out-Filterresults: notjunk:1;V03:K0:UjSUUHL8zNI=:tj/3B2ghZA02K15F/Eaof7 pKzR1b+vkasjkYdggVMQn/J5Dp4DiUGbh9DYYHB+IfR+tiUB2+A08qHFQV7wSVDmbEqwzloUT fvSXpcc/LAZJjbSmx7nqbgKp7nA+An3cF0wMTIyqb6p/1YOWvpg3p8JqtusFBeKbvm9iACyvs qSVLn3AZERiFi1koOyCJzUyg2SlSLs6VwV3nQhahpkNQ6Up4sMNBs3Tyn2zS6LYWuh0yLwwD6 t+xXXGEpDTd6nUdXEMVZt6buYZM6BPaKS7vf8qtzjSSqBaK51IMphN/7d+0wm4YYD85iy8x2e 4j6bhcBBpPrbZ8NTED1XW2n/7utEJD6vmYpVfNaP4imzDfs6XeW/PiFUae4Ux7y5YOLSm5dbk msuTJ0GwYZOBkh7MsMyEJlNi2eENXpJKErokiuc56t3eV/bRaOS2mwqKvW3DVml1LEW7PIqty mffVzEcLY7qGvn4GpxpF2aPoJMNxdvzjwU8YjGMJi4gNGJGcSdNwe51FxQeecIfu3/QSSUCxB 3+ksIobgTpFY1bH0y8GnCAR2vlbDOFGneSn45nHVVVLXReWwFB1sM3f4WoOkNNGi1FZxxbCwi 4TKITepYgbZg/ZZUDcu/GUPDNjnznCb8VormkDp+JnJsEtKLAvDh/gaUyH6CG1c2eKSATdE85 /Qs7UKvmfRx3bECWgDKZTn7VmNk4Bl2to5m50gDmqD64gGxHcIrL2H1UgnWeCiIVx9T6oh0WD SyB0StzPyO3o1CQ6wgTzCB9E/1lr6b5gJRy7Lg/+L640OCb33IDZz8+7yEU4TnEo9M2FCL9T4 jr+bi1Y X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Dear Fortranners, some instances of valid constant array constructors did lead to ICEs. It turned out that on the one hand we need to attempt simplification of elements of the constructor, especially when we encounter parenthesized expression. On the other hand the occurence of type specs and empty constructors need to be handled more gracefully. Parts of the PR have been fixed previously, so the remaining part was rather simple. The testcase is based on Gerhards latest example attached to the PR. Regtested on x86_64-pc-linux-gnu. OK for mainline? Given the simplicity of the patch and that it is an ICE on valid code, would this qualify for later application to 11-branch? Thanks, Harald From 65966b608cff757f43316e1aeed37bd07ce63fe2 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Sun, 6 Feb 2022 21:47:20 +0100 Subject: [PATCH] Fortran: try simplifications during reductions of array constructors gcc/fortran/ChangeLog: PR fortran/66193 * arith.cc (reduce_binary_ac): When reducing binary expressions, try simplification. Handle case of empty constructor. (reduce_binary_ca): Likewise. gcc/testsuite/ChangeLog: PR fortran/66193 * gfortran.dg/array_constructor_55.f90: New test. --- gcc/fortran/arith.cc | 36 ++++++++++-- .../gfortran.dg/array_constructor_55.f90 | 55 +++++++++++++++++++ 2 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/array_constructor_55.f90 diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc index b3323ecf640..06e032e22db 100644 --- a/gcc/fortran/arith.cc +++ b/gcc/fortran/arith.cc @@ -1305,6 +1305,8 @@ reduce_binary_ac (arith (*eval) (gfc_expr *, gfc_expr *, gfc_expr **), head = gfc_constructor_copy (op1->value.constructor); for (c = gfc_constructor_first (head); c; c = gfc_constructor_next (c)) { + gfc_simplify_expr (c->expr, 0); + if (c->expr->expr_type == EXPR_CONSTANT) rc = eval (c->expr, op2, &r); else @@ -1321,9 +1323,19 @@ reduce_binary_ac (arith (*eval) (gfc_expr *, gfc_expr *, gfc_expr **), else { gfc_constructor *c = gfc_constructor_first (head); - r = gfc_get_array_expr (c->expr->ts.type, c->expr->ts.kind, - &op1->where); - r->shape = gfc_copy_shape (op1->shape, op1->rank); + if (c) + { + r = gfc_get_array_expr (c->expr->ts.type, c->expr->ts.kind, + &op1->where); + r->shape = gfc_copy_shape (op1->shape, op1->rank); + } + else + { + gcc_assert (op1->ts.type != BT_UNKNOWN); + r = gfc_get_array_expr (op1->ts.type, op1->ts.kind, + &op1->where); + r->shape = gfc_get_shape (op1->rank); + } r->rank = op1->rank; r->value.constructor = head; *result = r; @@ -1345,6 +1357,8 @@ reduce_binary_ca (arith (*eval) (gfc_expr *, gfc_expr *, gfc_expr **), head = gfc_constructor_copy (op2->value.constructor); for (c = gfc_constructor_first (head); c; c = gfc_constructor_next (c)) { + gfc_simplify_expr (c->expr, 0); + if (c->expr->expr_type == EXPR_CONSTANT) rc = eval (op1, c->expr, &r); else @@ -1361,9 +1375,19 @@ reduce_binary_ca (arith (*eval) (gfc_expr *, gfc_expr *, gfc_expr **), else { gfc_constructor *c = gfc_constructor_first (head); - r = gfc_get_array_expr (c->expr->ts.type, c->expr->ts.kind, - &op2->where); - r->shape = gfc_copy_shape (op2->shape, op2->rank); + if (c) + { + r = gfc_get_array_expr (c->expr->ts.type, c->expr->ts.kind, + &op2->where); + r->shape = gfc_copy_shape (op2->shape, op2->rank); + } + else + { + gcc_assert (op2->ts.type != BT_UNKNOWN); + r = gfc_get_array_expr (op2->ts.type, op2->ts.kind, + &op2->where); + r->shape = gfc_get_shape (op2->rank); + } r->rank = op2->rank; r->value.constructor = head; *result = r; diff --git a/gcc/testsuite/gfortran.dg/array_constructor_55.f90 b/gcc/testsuite/gfortran.dg/array_constructor_55.f90 new file mode 100644 index 00000000000..52142cb10c0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/array_constructor_55.f90 @@ -0,0 +1,55 @@ +! { dg-do run } +! PR fortran/66193 - ICE for initialisation of some non-zero-sized arrays +! Testcase by G.Steinmetz + +program p + implicit none + call s1 + call s2 + call s3 + call s4 +contains + subroutine s1 + integer(8), parameter :: z1(2) = 10 + [ integer(8) :: [ integer(4) ::],1,2] + integer(8) :: z2(2) = 10 + [ integer(8) :: [ integer(4) ::],1,2] + integer(8) :: z3(2) + z3 = 10 + [ integer(8) :: [ integer(4) :: ], 1, 2 ] + if ( z1(1) /= 11 .or. z1(2) /= 12 ) stop 1 + if ( z2(1) /= 11 .or. z2(2) /= 12 ) stop 2 + if ( z3(1) /= 11 .or. z3(2) /= 12 ) stop 3 + end subroutine s1 + + subroutine s2 + logical(8), parameter :: z1(3) = .true. .or. & + [ logical(8) :: [ logical(4) :: ], .false., .false., .true. ] + logical(8) :: z2(3) = .true. .or. & + [ logical(8) :: [ logical(4) :: ], .false., .false., .true. ] + logical(8) :: z3(3) + z3 = .true. .or. & + [ logical(8) :: [ logical(4) :: ], .false., .false., .true. ] + if ( .not. all(z1) ) stop 11 + if ( .not. all(z2) ) stop 12 + if ( .not. all(z3) ) stop 13 + end subroutine s2 + + subroutine s3 + real(8), parameter :: eps = 4.0_8 * epsilon(1.0_8) + real(8), parameter :: z1(2) = 10. + [ real(8) :: [ real(4) :: ], 1., 2. ] + real(8) :: z2(2) = 10. + [ real(8) :: [ real(4) :: ], 1., 2. ] + real(8) :: z3(2) + z3 = 10.0 + [ real(8) :: [ real(4) :: ], 1.0, 2.0 ] + + if ( abs(1-z1(1)/11) > eps ) stop 21 + if ( abs(1-z1(2)/12) > eps ) stop 22 + if ( abs(1-z2(1)/11) > eps ) stop 23 + if ( abs(1-z2(2)/12) > eps ) stop 24 + if ( abs(1-z3(1)/11) > eps ) stop 25 + if ( abs(1-z3(2)/12) > eps ) stop 26 + end subroutine s3 + + subroutine s4 + real, parameter :: x(3) = 2.0 * [real :: 1, (2), 3] + real, parameter :: y(2) = [real :: 1, (2)] + 10.0 + real, parameter :: z(2) = [real ::(1),(2)] + 10.0 + end subroutine s4 +end program p -- 2.34.1