re PR fortran/66107 (ICE on missing parameter value for initialisation (segfault))
authorLouis Krupp <louis.krupp@zoho.com>
Thu, 22 Sep 2016 07:07:53 +0000 (07:07 +0000)
committerLouis Krupp <lkrupp@gcc.gnu.org>
Thu, 22 Sep 2016 07:07:53 +0000 (07:07 +0000)
2016-09-21  Louis Krupp  <louis.krupp@zoho.com>

PR fortran/66107
* gfortran.dg/pr66107.f90: New test.

2016-09-21  Louis Krupp  <louis.krupp@zoho.com>

PR fortran/66107
* decl.c (add_init_expr_to_sym): Catch variable character length
in parameter array.

From-SVN: r240341

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

index 5d9a10df6b27173e26c60ab6a832e62005cc7138..971c34838148342c8b75f742324827929ed0222a 100644 (file)
@@ -1,3 +1,9 @@
+2016-09-21  Louis Krupp  <louis.krupp@zoho.com>
+
+       PR fortran/66107
+       * decl.c (add_init_expr_to_sym): Catch variable character length
+       in parameter array.
+
 2016-09-21  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/77657
index d9fae5753d07b66052dda56f432267d48283d512..2982e86bac043c5402369708397b7e710e401a69 100644 (file)
@@ -1672,7 +1672,18 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus)
                  else if (init->expr_type == EXPR_ARRAY)
                    {
                      if (init->ts.u.cl)
-                       clen = mpz_get_si (init->ts.u.cl->length->value.integer);
+                       {
+                         const gfc_expr *length = init->ts.u.cl->length;
+                         if (length->expr_type != EXPR_CONSTANT)
+                           {
+                             gfc_error ("Cannot initialize parameter array "
+                                        "at %L "
+                                        "with variable length elements",
+                                        &sym->declared_at);
+                             return false;
+                           }
+                         clen = mpz_get_si (length->value.integer);
+                       }
                      else if (init->value.constructor)
                        {
                          gfc_constructor *c;
index 6a1dae9cf3cf4ae5ad2530edd12e86f918867b8a..e6480d85374b3f086cc5b3dc262075c6c5e85602 100644 (file)
@@ -1,3 +1,8 @@
+2016-09-21  Louis Krupp  <louis.krupp@zoho.com>
+
+       PR fortran/66107
+       * gfortran.dg/pr66107.f90: New test.
+
 2016-09-21  Ian Lance Taylor  <iant@golang.org>
 
        * go.go-torture/execute/map-1.go: Replace old map deletion syntax
diff --git a/gcc/testsuite/gfortran.dg/pr66107.f90 b/gcc/testsuite/gfortran.dg/pr66107.f90
new file mode 100644 (file)
index 0000000..5127efa
--- /dev/null
@@ -0,0 +1,6 @@
+! { dg-do compile }
+! PR fortran/66107
+subroutine p
+ integer n
+ character(*), parameter :: z(1) = [character(len=n) :: 'x'] ! { dg-error "Cannot initialize parameter array at .1. with variable length elements" }
+end subroutine