From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 678553857811; Wed, 19 Jan 2022 20:43:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 678553857811 From: "anlauf at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/104127] [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244 Date: Wed, 19 Jan 2022 20:43:51 +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: 12.0 X-Bugzilla-Keywords: ice-on-valid-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: Wed, 19 Jan 2022 20:43:51 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104127 --- Comment #3 from anlauf at gcc dot gnu.org --- Tentative patch: diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index 3881370d947..366b00c28dd 100644 --- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -8162,7 +8162,15 @@ gfc_simplify_transfer (gfc_expr *source, gfc_expr *m= old, gfc_expr *size) set even for array expressions, in order to pass this information into gfc_target_interpret_expr. */ if (result->ts.type =3D=3D BT_CHARACTER && gfc_is_constant_expr (mold_el= ement)) - result->value.character.length =3D mold_element->value.character.lengt= h; + { + result->value.character.length =3D mold_element->value.character.len= gth; + + /* A zero-sized result array needs to inherit the string length. */ + if (result_length =3D=3D 0) + result->ts.u.cl->length =3D + gfc_get_int_expr (gfc_charlen_int_kind, NULL, + mold_element->value.character.length); + } /* Set the number of elements in the result, and determine its size. */ This fixes the ICE as well as now produces a correct result e.g. for print *, len (transfer('ab', 'xyz', size=3D0)) However, looking at the tree dump of comment#0 I see very similar multiple temporaries being generated as for other empty array constructors being pas= sed to procedures (pr86277).=