I've committed the following patch, which avoids a NULL
pointer dereference.

2016-11-23  Steven G. Kargl  <ka...@gcc.gnu.org>

        PR fortran/78297
        * trans-common.c (finish_equivalences): Do not dereference a NULL 
pointer.

2016-11-23  Steven G. Kargl  <ka...@gcc.gnu.org>

        PR fortran/78297
        * gfortran.dg/pr78297.f90: New test.

Index: gcc/fortran/trans-common.c
===================================================================
--- gcc/fortran/trans-common.c  (revision 242638)
+++ gcc/fortran/trans-common.c  (working copy)
@@ -1246,8 +1246,12 @@ finish_equivalences (gfc_namespace *ns)
          {
            c = gfc_get_common_head ();
            /* We've lost the real location, so use the location of the
-              enclosing procedure.  */
-           c->where = ns->proc_name->declared_at;
+              enclosing procedure.  If we're in a BLOCK DATA block, then
+              use the location in the sym_root.  */
+           if (ns->proc_name)
+             c->where = ns->proc_name->declared_at;
+           else if (ns->is_block_data)
+             c->where = ns->sym_root->n.sym->declared_at;
            strcpy (c->name, z->module);
          }
        else

Index: gcc/testsuite/gfortran.dg/pr78297.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr78297.f90       (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr78297.f90       (working copy)
@@ -0,0 +1,11 @@
+! { dg-do compile }
+module m
+   real :: a(2), b(2)
+   real :: c(2), d(2)
+   equivalence (a, b)
+   equivalence (c, d)
+   common /xcom/ a
+end
+block data
+   use m
+end block data
-- 
Steve

Reply via email to