From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by sourceware.org (Postfix) with ESMTPS id BD3C53858280; Tue, 5 Jul 2022 20:31:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BD3C53858280 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [79.251.11.60] ([79.251.11.60]) by web-mail.gmx.net (3c-app-gmx-bs53.server.lan [172.19.170.137]) (via HTTP); Tue, 5 Jul 2022 22:31:42 +0200 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: error recovery simplifying PACK with invalid arguments [PR106049] Content-Type: multipart/mixed; boundary=sgnirk-90b32cf9-1980-463c-8067-580e21b99c84 Date: Tue, 5 Jul 2022 22:31:42 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:mEPLjEbR6I1o29kxkYUuuIC/Hl/2kvQ6JsSpg6lbvwrtmE911sYosAvth22em9Hp6+4AD LgovcPGWmVfIpIAgOnJqPWkAODnNjHg/TYQky+r79rnSI7JaqQVM6UGpT3UM7cHAHjeESHo4ytEp VNfHEaNLfOafsNXesws505zQnc2PCLakllEY6fP5jGd8zcRQ2pSiBmrhv0Y6553d6IHDNbZYV3g8 bqap7/uKWNS5a46gBUsHbp47aZJ+lY2n9E5vue6KuFgCosiuKUSQbWW7ShnykbDCWGfsTkEV2RzF pM= X-UI-Out-Filterresults: notjunk:1;V03:K0:ouDWccEQtmA=:A71xccii3sdxlTttHO/VDY 9ceN7d12oj5lfjIWFyoO2J3Q3japQRtJw5lwYZAFSD0LPBCwhIXrS0vgTRoeUmUIkXNBkZzzs MzCjJY36GpUsZH8dpzUbATCXFsvrzFpueHKwFnkaddX/RZ+RhHDqSYTj4a9Xdkj+wBhh2BERW BXuSuHwySBF2Dt36sFMCgffu4sXVOonWeeFOxLdtHaziH4gvgtQuSSoCfHngr6K0tzDwG7ptL 4R3Zg+K7ezpE21tjN7RkfQnX5FoChHzNWINn8U5Yp9WFkiWl4CBDYOEy9uvtIyB/tUXgurut8 etkeAED8NpNDs0UTRYwICDTVrgOYQ7V/6xtkT6RohyfuiRaPLHD3aqKzNCLUhyeafj+ezA+UY BRytK+qjyTPt7gWkjnAItu3yf12JZ9BR185vnwZbF/GMSLr3yBVOoGLjX1Gf8YHJHzDjyDG0e veFwjg6AzoWAnICJxp1RqUL8XwWDR1x8onpVY1bO9ofojI9tbdNvPZmSuwi4NyNGBI3V2Hdmc EBIYX+fuIAkd90fv3T07rx0ICITFgfdcCRg1vuEexWJceLTozt4LYSNplpRmsciRuZ+PY0tQH RW+ICp5PrWcKt/gaeSY+WgoVCuYx4XhoZZuwTCHB4WPZa0ZVFf8s8DZiPQMXGvsJAnS5HT2Bp GvYg2H6NOCzW10RFv/Zo5oR8d5sQe8X0vRX0P19SU0iI428hzW7BEaoB8eLI+CzSgLZklBXoW 0Hnyw8jOQ8RdcqQKDWWkusO/TxFiuulilhkWvTWqGHFuJ/e4KU3bfkKAngALhLERX6acIkyr4 7xOW3/D X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jul 2022 20:31:46 -0000 --sgnirk-90b32cf9-1980-463c-8067-580e21b99c84 Content-Type: text/plain; charset=UTF-8 Dear all, poor error recovery while trying to simplify intrinsics with given invalid arguments seems to be a recurrent theme in testcases submitted by Gerhard. In the present case, simplification of PACK() chokes on the array argument being a bad decl. The most general approach that came to my mind is to modify function is_constant_array_expr: when the declared shape of the array indicates a size greater than zero, but the constructor is missing or empty, then something bad may have happened, and the array cannot be considered constant. We thus punt on simplification of something that cannot be simplified. With some luck, this might prevent issues in similar cases elsewhere... Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald --sgnirk-90b32cf9-1980-463c-8067-580e21b99c84 Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Fortran-error-recovery-simplifying-PACK-with-invalid.patch Content-Transfer-Encoding: quoted-printable =46rom b70a225cd9ac83cd182938bb8019f9138f85b222 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Tue, 5 Jul 2022 22:20:05 +0200 Subject: [PATCH] Fortran: error recovery simplifying PACK with invalid arguments [PR106049] gcc/fortran/ChangeLog: PR fortran/106049 * simplify.cc (is_constant_array_expr): A non-zero-sized constant array shall have a non-empty constructor. When the constructor is empty or missing, treat as non-constant. gcc/testsuite/ChangeLog: PR fortran/106049 * gfortran.dg/pack_simplify_1.f90: New test. =2D-- gcc/fortran/simplify.cc | 12 ++++++++++++ gcc/testsuite/gfortran.dg/pack_simplify_1.f90 | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pack_simplify_1.f90 diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index ab59fbca622..fb725994653 100644 =2D-- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -233,6 +233,18 @@ is_constant_array_expr (gfc_expr *e) if (e->expr_type !=3D EXPR_ARRAY || !gfc_is_constant_expr (e)) return false; + /* A non-zero-sized constant array shall have a non-empty constructor. = */ + if (e->rank > 0 && e->shape !=3D NULL && e->value.constructor =3D=3D NU= LL) + { + mpz_init_set_ui (size, 1); + for (int j =3D 0; j < e->rank; j++) + mpz_mul (size, size, e->shape[j]); + bool not_size0 =3D (mpz_cmp_si (size, 0) !=3D 0); + mpz_clear (size); + if (not_size0) + return false; + } + for (c =3D gfc_constructor_first (e->value.constructor); c; c =3D gfc_constructor_next (c)) if (c->expr->expr_type !=3D EXPR_CONSTANT diff --git a/gcc/testsuite/gfortran.dg/pack_simplify_1.f90 b/gcc/testsuite= /gfortran.dg/pack_simplify_1.f90 new file mode 100644 index 00000000000..06bc55a14f3 =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/pack_simplify_1.f90 @@ -0,0 +1,15 @@ +! { dg-do compile } +! PR fortran/106049 - ICE in gfc_simplify_pack +! Contributed by G.Steinmetz + +program p + type t + end type + logical, parameter :: m(0) =3D [ logical :: ] + type(t), parameter :: a(0) =3D [ t :: ] + type(t), parameter :: b(1) =3D [ t() ] + type(t), parameter :: c(1) =3D [ t :: ] ! { dg-error "Different = shape" } + type(t), parameter :: d(0) =3D pack(a, m) + type(t), parameter :: e(1) =3D pack(b, [.true.]) + type(t), parameter :: f(1) =3D pack(c, [.true.]) +end =2D- 2.35.3 --sgnirk-90b32cf9-1980-463c-8067-580e21b99c84--