]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Use char* for deferred length character arrays [PR82904]
authorAndre Vehreschild <vehre@gcc.gnu.org>
Wed, 10 Jul 2024 12:37:37 +0000 (14:37 +0200)
committerAndre Vehreschild <vehre@gcc.gnu.org>
Thu, 18 Jul 2024 07:27:46 +0000 (09:27 +0200)
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.

PR fortran/82904

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
gcc/fortran/trans.cc
gcc/testsuite/gfortran.dg/deferred_character_38.f90 [new file with mode: 0644]

index f7b80a9761c4abe87e3327c837db2765c8701528..01ce54f0ac0ad7ef1d7ea7756fc0eea0fbf40e7f 100644 (file)
@@ -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))))
index 1067e032621becba7e95959603ca26d1f4cc5c4c..d4c54093cbc3fb674e7ca57bc8a0028254b80a05 100644 (file)
@@ -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 (file)
index 0000000..d5a6c0e
--- /dev/null
@@ -0,0 +1,20 @@
+! { dg-do run }
+
+! Check for PR fortran/82904
+! Contributed by G.Steinmetz  <gscfq@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
+