re PR fortran/80945 (Invalid code with allocatable character array in READ/WRITE...
authorPaul Thomas <pault@gcc.gnu.org>
Sun, 18 Feb 2018 08:59:06 +0000 (08:59 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sun, 18 Feb 2018 08:59:06 +0000 (08:59 +0000)
2018-02-18  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/80945
* trans-array.c (gfc_conv_expr_descriptor): Set parmtype from
the typenode in the case of deferred length characters.

2018-02-18  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/80945
* gfortran.dg/associate_35.f90: Remove error, add stop n's and
change to run.

From-SVN: r257788

gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/deferred_character_19.f90 [new file with mode: 0644]

index ce98b760ec8457d1a08599789b8a79674f524e8e..8ecc90af879225b224f2a32833754ad10cb2ff2c 100644 (file)
@@ -1,3 +1,9 @@
+2018-02-18  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/80945
+       * trans-array.c (gfc_conv_expr_descriptor): Set parmtype from
+       the typenode in the case of deferred length characters.
+
 2018-02-17  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/84270
index 79d4d171bddb3552195fb9fbbef3e2806a867e8d..e321db35ac206d17d79420379424bba874fd3e1b 100644 (file)
@@ -7341,7 +7341,11 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
       else
        {
          /* Otherwise make a new one.  */
-         parmtype = gfc_get_element_type (TREE_TYPE (desc));
+         if (expr->ts.type == BT_CHARACTER && expr->ts.deferred)
+           parmtype = gfc_typenode_for_spec (&expr->ts);
+         else
+           parmtype = gfc_get_element_type (TREE_TYPE (desc));
+
          parmtype = gfc_get_array_type_bounds (parmtype, loop.dimen, codim,
                                                loop.from, loop.to, 0,
                                                GFC_ARRAY_UNKNOWN, false);
index 76d8f4982957285e1eaaf20e89ca651483634c70..207a3bad7629be088fbb06694723104d167c53fa 100644 (file)
@@ -1,3 +1,9 @@
+2018-02-18  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/80945
+       * gfortran.dg/associate_35.f90: Remove error, add stop n's and
+       change to run.
+
 2018-02-17  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/84270
diff --git a/gcc/testsuite/gfortran.dg/deferred_character_19.f90 b/gcc/testsuite/gfortran.dg/deferred_character_19.f90
new file mode 100644 (file)
index 0000000..96722a1
--- /dev/null
@@ -0,0 +1,20 @@
+! { dg-do run }
+!
+! Test fix for PR80945, in which the character length was fixed at zero.
+!
+! Contributed by Nicolas Koenig  <koenigni@gcc.gnu.org>
+!
+program main
+    implicit none
+    integer:: i
+    integer, parameter:: N = 10
+    character(20) :: buffer
+    character(len=:), dimension(:),allocatable:: ca
+    character(len=:), dimension(:,:),allocatable:: cb
+    allocate(character(len=N) :: ca(3))
+    ca(1) = "foo"
+    ca(2) = "bar"
+    ca(3) = "xyzzy"
+    write (buffer, '(3A5)') ca(1:3)
+    if (trim (buffer) .ne. "foo  bar  xyzzy") stop 1
+end program