diff mbox series

[fortran] PR70149 - [F08] Character pointer initialization causes ICE

Message ID CAGkQGiJ8w-bm6TEP47bwf=H2z63joXtQCxnP6UGtqVZQSXMDYA@mail.gmail.com
State New
Headers show
Series [fortran] PR70149 - [F08] Character pointer initialization causes ICE | expand

Commit Message

Paul Richard Thomas Sept. 25, 2018, 4:43 p.m. UTC
This is yet another deferred length character bug. The fix speaks for
itself. I'll dream up a more suitable name for the testcase before
committing.

Bootstraps and regtests on FC21/x86_64 - OK for trunk and 8-branch?

Paul

2018-09-25  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-25  Paul Thomas  <pault@gcc.gnu.org>

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

Comments

Janne Blomqvist Sept. 25, 2018, 6:36 p.m. UTC | #1
On Tue, Sep 25, 2018 at 7:43 PM Paul Richard Thomas <
paul.richard.thomas@gmail.com> wrote:

> This is yet another deferred length character bug. The fix speaks for
> itself. I'll dream up a more suitable name for the testcase before
> committing.
>
> Bootstraps and regtests on FC21/x86_64 - OK for trunk and 8-branch?
>

Ok, looks good.
diff mbox series

Patch

diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 159c3dbb..f7568d5 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -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);