re PR fortran/70149 ([F08] Character pointer initialization causes ICE)
authorPaul Thomas <pault@gcc.gnu.org>
Sun, 30 Sep 2018 07:02:49 +0000 (07:02 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sun, 30 Sep 2018 07:02:49 +0000 (07:02 +0000)
2018-09-30  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/70149
* trans-decl.c (gfc_get_symbol_decl): A deferred character
length pointer that is initialized needs the string length to
be initialized as well.

2018-09-30  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/70149
* gfortran.dg/deferred_character_24.f90 : New test.

From-SVN: r264721

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

index ffada92df3149171981e93a5d21e660aefe8fc14..db17d97fe83566b80e03ce8ef8a2f938d3547d1f 100644 (file)
@@ -1,3 +1,10 @@
+2018-09-30  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/70149
+       * trans-decl.c (gfc_get_symbol_decl): A deferred character
+       length pointer that is initialized needs the string length to
+       be initialized as well.
+
 2018-09-29  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/65667
index 159c3dbbc6b45634a9f1fa1138e4abd8862424b3..f7568d5a6c42dec031c6bf2da51f335720c32e76 100644 (file)
@@ -1759,7 +1759,17 @@ gfc_get_symbol_decl (gfc_symbol * sym)
       && TREE_CODE (sym->ts.u.cl->backend_decl) != INDIRECT_REF)
     {
       gfc_finish_var_decl (length, sym);
-      gcc_assert (!sym->value);
+      if (!sym->attr.associate_var
+         && TREE_CODE (length) == VAR_DECL
+         && sym->value && sym->value->ts.u.cl->length)
+       {
+         gfc_expr *len = sym->value->ts.u.cl->length;
+         DECL_INITIAL (length) = gfc_conv_initializer (len, &len->ts,
+                                                       TREE_TYPE (length),
+                                                       false, false, false);
+       }
+      else
+       gcc_assert (!sym->value);
     }
 
   gfc_finish_var_decl (decl, sym);
index 2f021f78aac1ce1cada2cc2ee9ee44e8dfa3de46..2257b179c779288d09dd53665813c20fef4d2b81 100644 (file)
@@ -1,3 +1,8 @@
+2018-09-30  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/70149
+       * gfortran.dg/deferred_character_24.f90 : New test.
+
 2018-09-29  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR target/87370
diff --git a/gcc/testsuite/gfortran.dg/deferred_character_24.f90 b/gcc/testsuite/gfortran.dg/deferred_character_24.f90
new file mode 100644 (file)
index 0000000..9f5f7bc
--- /dev/null
@@ -0,0 +1,23 @@
+! { dg-do run }
+!
+! Test the fix for PR70149 in which the string length for
+! 'number_string' was not initialized.
+!
+! Contributed by Walter Spector  <w6ws@earthlink.net>
+!
+module myptr_mod
+  implicit none
+
+  integer, target, save :: int_data = 42
+  character(16), target, save :: char_data = 'forty two'
+
+  integer, pointer :: number => int_data
+  character(:), pointer :: number_string => char_data
+
+end module
+
+  use myptr_mod
+  if (LEN (number_string) .ne. 16) stop 1
+  if (trim (number_string) .ne. 'forty two') stop 2
+end
+