re PR fortran/83224 (creating character array from elements shorter than declared...
authorThomas Koenig <tkoenig@gcc.gnu.org>
Fri, 1 Dec 2017 18:06:31 +0000 (18:06 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Fri, 1 Dec 2017 18:06:31 +0000 (18:06 +0000)
2017-12-01  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/83224
* frontend-passes.c (create_var): Also handle
character arrays, handling deferred lenghts.

2017-12-01  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/83224
* gfortran.dg/dependency_51.f90: New test.

From-SVN: r255331

gcc/fortran/ChangeLog
gcc/fortran/frontend-passes.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/dependency_51.f90 [new file with mode: 0644]

index 75a2b7a4108de80c16130758af18e98949294e2c..b7f8a5856e421d99cdd70e3697b26d28586ce451 100644 (file)
@@ -1,3 +1,9 @@
+2017-12-01  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/83224
+       * frontend-passes.c (create_var): Also handle
+       character arrays, handling deferred lenghts.
+
 2017-12-01  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/82605
index 80d8767fc03ed06cc28b58a9d64e11b06ff7b746..33820585c868f56d2ecb3b0186ba40d2df9ba3b3 100644 (file)
@@ -767,7 +767,7 @@ create_var (gfc_expr * e, const char *vname)
     }
 
   deferred = 0;
-  if (e->ts.type == BT_CHARACTER && e->rank == 0)
+  if (e->ts.type == BT_CHARACTER)
     {
       gfc_expr *length;
 
@@ -778,6 +778,8 @@ create_var (gfc_expr * e, const char *vname)
       else
        {
          symbol->attr.allocatable = 1;
+         symbol->ts.u.cl->length = NULL;
+         symbol->ts.deferred = 1;
          deferred = 1;
        }
     }
@@ -790,7 +792,7 @@ create_var (gfc_expr * e, const char *vname)
 
   result = gfc_get_expr ();
   result->expr_type = EXPR_VARIABLE;
-  result->ts = e->ts;
+  result->ts = symbol->ts;
   result->ts.deferred = deferred;
   result->rank = e->rank;
   result->shape = gfc_copy_shape (e->shape, e->rank);
index cd00f52b5745caba4d7a76e2c4d4a83f716a4a99..41092f02c70e3f94ec1b2ba81fcf5fc14784b12b 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-01  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/83224
+       * gfortran.dg/dependency_51.f90: New test.
+
 2017-12-01  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/82605
diff --git a/gcc/testsuite/gfortran.dg/dependency_51.f90 b/gcc/testsuite/gfortran.dg/dependency_51.f90
new file mode 100644 (file)
index 0000000..62b76e1
--- /dev/null
@@ -0,0 +1,14 @@
+! { dg-do  run }
+! PR 83224 - dependency mishandling with an array constructor
+! Original test case by Urban Jost
+program dusty_corner
+  implicit none
+  character(len=:),allocatable :: words(:)
+  integer :: n
+
+  words=[character(len=3) :: 'one', 'two']
+  n = 5
+  words=[character(len=n) :: words, 'three']
+  if (any(words /= [ "one  ", "two  ", "three"])) call abort
+
+end program dusty_corner