re PR fortran/68154 (ICE on initializing character parameter array (explicit, implied))
authorSteven G. Kargl <kargl@gcc.gnu.org>
Fri, 30 Oct 2015 16:26:59 +0000 (16:26 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Fri, 30 Oct 2015 16:26:59 +0000 (16:26 +0000)
2015-10-30  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/68154
* decl.c (add_init_expr_to_sym): if the char length in the typespec
is NULL, check for and use a constructor.

2015-10-30  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/68154
*gfortran.dg/pr68154.f90

From-SVN: r229588

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

index 587045d..74cae2f 100644 (file)
@@ -1,4 +1,9 @@
-2015-10-29  Steven G. Kargl  <kargl@gcc.gnu.org>
+2015-10-30  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/68154
+       * decl.c (add_init_expr_to_sym): if the char length in the typespec
+       is NULL, check for and use a constructor. 
+2015-10-30  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/68054
        * decl.c (match_attr_spec): PROTECTED can only be a module.
index 6a7f386..5a95fa4 100644 (file)
@@ -1461,7 +1461,16 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus)
                    }
                  else if (init->expr_type == EXPR_ARRAY)
                    {
-                     clen = mpz_get_si (init->ts.u.cl->length->value.integer);
+                     if (init->ts.u.cl)
+                       clen = mpz_get_si (init->ts.u.cl->length->value.integer);
+                     else if (init->value.constructor)
+                       {
+                         gfc_constructor *c;
+                         c = gfc_constructor_first (init->value.constructor);   
+                         clen = c->expr->value.character.length;
+                       }
+                     else
+                         gcc_unreachable ();
                      sym->ts.u.cl->length
                                = gfc_get_int_expr (gfc_default_integer_kind,
                                                    NULL, clen);
index ffefb43..5407db7 100644 (file)
@@ -1,3 +1,8 @@
+2015-10-30  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/68154
+       *gfortran.dg/pr68154.f90
+
 2015-10-29  Nathan Sidwell  <nathan@codesourcery.com>
 
        * c-c++-common/goacc/acc_on_device-2-off.c: Delete.
diff --git a/gcc/testsuite/gfortran.dg/pr68154.f90 b/gcc/testsuite/gfortran.dg/pr68154.f90
new file mode 100644 (file)
index 0000000..6415eb0
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/68154
+! Original code contributed by Gerhard Steinmetz
+! gerhard dot steinmetz dot fortran at t-online dot de
+program p
+   character(1), parameter :: x1(2) = 'a'
+   character(*), parameter :: x2(2) = x1
+   character(*), parameter :: x3(*) = x1
+end