re PR fortran/58618 (Wrong code with character substring and ASSOCIATE)
authorPaul Thomas <pault@gcc.gnu.org>
Thu, 18 Oct 2018 10:33:25 +0000 (10:33 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Thu, 18 Oct 2018 10:33:25 +0000 (10:33 +0000)
2018-10-18  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/58618
* trans-decl.c (gfc_get_symbol_decl): Deal correctly with the
initialization with NULL() of a deferred length pointer.

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

PR fortran/58618
* gfortran.dg/deferred_character_30.f90 : New test.

From-SVN: r265263

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

index 4f216d94cae4c65c2630897e4c6c29ea968c81a8..5ca39af187a9dc25dd3d930e59664bb694e032ff 100644 (file)
@@ -1,3 +1,9 @@
+2018-10-18  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/58618
+       * trans-decl.c (gfc_get_symbol_decl): Deal correctly with the
+       initialization with NULL() of a deferred length pointer.
+
 2018-10-17  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/87632
index b0c12e5fc38107559a734d1dc87fd675a2466630..88f9f5707255ceccc7e58efc1abf5dd09ec0e703 100644 (file)
@@ -1762,7 +1762,8 @@ gfc_get_symbol_decl (gfc_symbol * sym)
       gfc_finish_var_decl (length, sym);
       if (!sym->attr.associate_var
          && TREE_CODE (length) == VAR_DECL
-         && sym->value && sym->value->ts.u.cl->length)
+         && sym->value && sym->value->expr_type != EXPR_NULL
+         && sym->value->ts.u.cl->length)
        {
          gfc_expr *len = sym->value->ts.u.cl->length;
          DECL_INITIAL (length) = gfc_conv_initializer (len, &len->ts,
@@ -1772,7 +1773,7 @@ gfc_get_symbol_decl (gfc_symbol * sym)
                                                DECL_INITIAL (length));
        }
       else
-       gcc_assert (!sym->value);
+       gcc_assert (!sym->value || sym->value->expr_type == EXPR_NULL);
     }
 
   gfc_finish_var_decl (decl, sym);
index 9cf4cbc40195ef2fa9bd24ffd2f6fb2dbbd84e77..57cbb79bba25e48268bc358f45d8d140c78f997c 100644 (file)
@@ -1,3 +1,8 @@
+2018-10-18  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/58618
+       * gfortran.dg/deferred_character_30.f90 : New test.
+
 2018-10-18  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/87087
diff --git a/gcc/testsuite/gfortran.dg/deferred_character_30.f90 b/gcc/testsuite/gfortran.dg/deferred_character_30.f90
new file mode 100644 (file)
index 0000000..6d9bd5a
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+!
+! Fix a regression introduced by the patch for PR70149.
+!
+    character (:), pointer :: ptr => NULL() ! The NULL () caused an ICE.
+    character (6), target :: tgt = 'lmnopq'
+    ptr => tgt
+    print *, len (ptr), ptr
+end