diff options
author | Harald Anlauf <anlauf@gmx.de> | 2023-01-16 21:41:09 +0100 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2023-01-23 20:14:58 +0100 |
commit | e6669c0a50ed8aee9e5997d61e6271668d149218 (patch) | |
tree | 9003645d3ebca1cb341135b56b981df96cb5ff37 /gcc | |
parent | 4b125d01a5d5e601961419396332b74eea2219bb (diff) | |
download | gcc-e6669c0a50ed8aee9e5997d61e6271668d149218.zip gcc-e6669c0a50ed8aee9e5997d61e6271668d149218.tar.gz gcc-e6669c0a50ed8aee9e5997d61e6271668d149218.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/fortran/iresolve.cc | 9 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/pr108420.f90 | 10 |
2 files changed, 16 insertions, 3 deletions
diff --git a/gcc/fortran/iresolve.cc b/gcc/fortran/iresolve.cc index 711e917..33794f0 100644 --- a/gcc/fortran/iresolve.cc +++ b/gcc/fortran/iresolve.cc @@ -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"); } } diff --git a/gcc/testsuite/gfortran.dg/pr108420.f90 b/gcc/testsuite/gfortran.dg/pr108420.f90 new file mode 100644 index 0000000..985c0b3 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr108420.f90 @@ -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 |