Hi all, pinging for attached patch rebased on master and my patch for 78466.
Anyone in for a review? Regtests ok on x86_64-pc-linux-gnu / Fedora 39. Ok for mainline? Regards, Andre On Wed, 10 Jul 2024 14:51:53 +0200 Andre Vehreschild <ve...@gmx.de> wrote: > Hi all, > > the patch attached fixes the use of an uninitialized variable for the string > length in the declaration of the char[1:_len] type (the _len!). The type for > save'd deferred length char arrays is now char*, so that there is no need for > the length in the type declaration anymore. The length is of course still > provided and needed later on. > > I hope this fixes the ICE in the IPA: inline phase, because I never saw it. Is > that what you had in mind @Richard? > > Regtests ok on x86_64-pc-linux-gnu/Fedora 39. Ok for mainline? > > Regards, > Andre > -- > Andre Vehreschild * Email: vehre ad gmx dot de -- Andre Vehreschild * Email: vehre ad gmx dot de
From e66e66ed6ac191763b430789f804fabafd9dfc4c Mon Sep 17 00:00:00 2001 From: Andre Vehreschild <ve...@gcc.gnu.org> Date: Wed, 10 Jul 2024 14:37:37 +0200 Subject: [PATCH] Fortran: Use char* for deferred length character arrays [PR82904] Randomly during compiling the pass IPA: inline would ICE. This was caused by a saved deferred length string. The length variable was not set, but the variable was used in the array's declaration. Now using a character pointer to prevent this. gcc/fortran/ChangeLog: * trans-types.cc (gfc_sym_type): Use type `char*` for saved deferred length char arrays. * trans.cc (get_array_span): Get `.span` also for `char*` typed arrays, i.e. for those that have INTEGER_TYPE instead of ARRAY_TYPE. gcc/testsuite/ChangeLog: * gfortran.dg/deferred_character_38.f90: New test. --- gcc/fortran/trans-types.cc | 6 ++++-- gcc/fortran/trans.cc | 4 +++- .../gfortran.dg/deferred_character_38.f90 | 20 +++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/deferred_character_38.f90 diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc index 6743adfc9bab..59d72136a0de 100644 --- a/gcc/fortran/trans-types.cc +++ b/gcc/fortran/trans-types.cc @@ -2334,8 +2334,10 @@ gfc_sym_type (gfc_symbol * sym, bool is_bind_c) || ((sym->attr.result || sym->attr.value) && sym->ns->proc_name && sym->ns->proc_name->attr.is_bind_c) - || (sym->ts.deferred && (!sym->ts.u.cl - || !sym->ts.u.cl->backend_decl)) + || (sym->ts.deferred + && (!sym->ts.u.cl + || !sym->ts.u.cl->backend_decl + || sym->attr.save)) || (sym->attr.dummy && sym->attr.value && gfc_length_one_character_type_p (&sym->ts)))) diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc index 1067e032621b..d4c54093cbc3 100644 --- a/gcc/fortran/trans.cc +++ b/gcc/fortran/trans.cc @@ -398,7 +398,9 @@ get_array_span (tree type, tree decl) return gfc_conv_descriptor_span_get (decl); /* Return the span for deferred character length array references. */ - if (type && TREE_CODE (type) == ARRAY_TYPE && TYPE_STRING_FLAG (type)) + if (type + && (TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == INTEGER_TYPE) + && TYPE_STRING_FLAG (type)) { if (TREE_CODE (decl) == PARM_DECL) decl = build_fold_indirect_ref_loc (input_location, decl); diff --git a/gcc/testsuite/gfortran.dg/deferred_character_38.f90 b/gcc/testsuite/gfortran.dg/deferred_character_38.f90 new file mode 100644 index 000000000000..d5a6c0e50136 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/deferred_character_38.f90 @@ -0,0 +1,20 @@ +! { dg-do run } + +! Check for PR fortran/82904 +! Contributed by G.Steinmetz <gs...@t-online.de> + +! This test checks that 'IPA pass: inline' passes. +! The initial version of the testcase contained coarrays, which does not work +! yet. + +program p + save + character(:), allocatable :: x + character(:), allocatable :: y + allocate (character(3) :: y) + allocate (x, source='abc') + y = x + + if (y /= 'abc') stop 1 +end + -- 2.45.2