From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 98BA33858280; Tue, 5 Jul 2022 20:09:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 98BA33858280 From: "anlauf at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/106049] ICE in gfc_simplify_pack, at fortran/simplify.cc:6481 Date: Tue, 05 Jul 2022 20:09:54 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: ice-on-invalid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: anlauf at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jul 2022 20:09:54 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106049 --- Comment #2 from anlauf at gcc dot gnu.org --- (In reply to anlauf from comment #1) > Maybe there is a better solution. Here's an alternative, probably more general approach that modifies is_constant_array_expr: when the array size - as implied by the shape - is larger than zero, but the constructor is empty, then something went wrong, and we return false: diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index ab59fbca622..fb725994653 100644 --- 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 NUL= L) + { + 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 This seems to regtest OK.=