Fortran: fix ICE in check_charlen_present [PR108420]
Checks
Commit Message
Dear all,
it appears that the fix for pr107874 uncovered a latent bug
for the case of arrays of type character and size zero when
passed to the intrinsics MERGE and SPREAD as SOURCE. In that
case, there is no constructor from which we could obtain
another character length. A reasonable solution seems to
retain the array's character length.
Since I could not find a simple case where this fails, I've
added an assertion that we actually have a meaningful length.
Regtested on x86_64-pc-linux-gnu. OK for mainline?
Thanks,
Harald
Comments
Ping!
Am 16.01.23 um 22:11 schrieb Harald Anlauf via Gcc-patches:
> Dear all,
>
> it appears that the fix for pr107874 uncovered a latent bug
> for the case of arrays of type character and size zero when
> passed to the intrinsics MERGE and SPREAD as SOURCE. In that
> case, there is no constructor from which we could obtain
> another character length. A reasonable solution seems to
> retain the array's character length.
>
> Since I could not find a simple case where this fails, I've
> added an assertion that we actually have a meaningful length.
>
> Regtested on x86_64-pc-linux-gnu. OK for mainline?
>
> Thanks,
> Harald
>
Hi Harald,
This is fine for mainline and for backporting if you feel so inclined.
Thanks for the patch.
Paul
On Mon, 16 Jan 2023 at 21:12, Harald Anlauf via Fortran <fortran@gcc.gnu.org>
wrote:
> Dear all,
>
> it appears that the fix for pr107874 uncovered a latent bug
> for the case of arrays of type character and size zero when
> passed to the intrinsics MERGE and SPREAD as SOURCE. In that
> case, there is no constructor from which we could obtain
> another character length. A reasonable solution seems to
> retain the array's character length.
>
> Since I could not find a simple case where this fails, I've
> added an assertion that we actually have a meaningful length.
>
> Regtested on x86_64-pc-linux-gnu. OK for mainline?
>
> Thanks,
> Harald
>
>
From a4fbab560a202f4541f8f9a872774b2cbf72b4b0 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Mon, 16 Jan 2023 21:41:09 +0100
Subject: [PATCH] Fortran: fix ICE in check_charlen_present [PR108420]
gcc/fortran/ChangeLog:
PR fortran/108420
* iresolve.cc (check_charlen_present): Preserve character length if
there is no array constructor.
gcc/testsuite/ChangeLog:
PR fortran/108420
* gfortran.dg/pr108420.f90: New test.
---
gcc/fortran/iresolve.cc | 9 ++++++---
gcc/testsuite/gfortran.dg/pr108420.f90 | 10 ++++++++++
2 files changed, 16 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gfortran.dg/pr108420.f90
@@ -94,9 +94,12 @@ check_charlen_present (gfc_expr *source)
else if (source->expr_type == EXPR_ARRAY)
{
gfc_constructor *c = gfc_constructor_first (source->value.constructor);
- source->ts.u.cl->length
- = gfc_get_int_expr (gfc_charlen_int_kind, NULL,
- c->expr->value.character.length);
+ if (c)
+ source->ts.u.cl->length
+ = gfc_get_int_expr (gfc_charlen_int_kind, NULL,
+ c->expr->value.character.length);
+ if (source->ts.u.cl->length == NULL)
+ gfc_internal_error ("check_charlen_present(): length not set");
}
}
new file mode 100644
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! PR fortran/108420
+! Contributed by G.Steinmetz
+
+program p
+ character :: c = 'c'
+ logical :: m = .true.
+ print *, merge(transfer('a', 'b', 0), c, .true.)
+ print *, merge(transfer('a', 'b', 0), c, m)
+end
--
2.35.3