Blame SOURCES/gcc7-fortran-equivalence.patch

870cb9
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
870cb9
index c373419..880630a 100644
870cb9
--- a/gcc/fortran/gfortran.h
870cb9
+++ b/gcc/fortran/gfortran.h
870cb9
@@ -2867,6 +2867,7 @@ bool gfc_merge_new_implicit (gfc_typespec *);
870cb9
 void gfc_set_implicit_none (bool, bool, locus *);
870cb9
 void gfc_check_function_type (gfc_namespace *);
870cb9
 bool gfc_is_intrinsic_typename (const char *);
870cb9
+bool check_conflict (symbol_attribute *, const char *, locus *);
870cb9
 
870cb9
 gfc_typespec *gfc_get_default_type (const char *, gfc_namespace *);
870cb9
 bool gfc_set_default_type (gfc_symbol *, int, gfc_namespace *);
870cb9
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
870cb9
index 67ad504..29b40fd 100644
870cb9
--- a/gcc/fortran/symbol.c
870cb9
+++ b/gcc/fortran/symbol.c
870cb9
@@ -363,7 +363,7 @@ gfc_check_function_type (gfc_namespace *ns)
870cb9
                                 goto conflict_std;\
870cb9
                               }
870cb9
 
870cb9
-static bool
870cb9
+bool
870cb9
 check_conflict (symbol_attribute *attr, const char *name, locus *where)
870cb9
 {
870cb9
   static const char *dummy = "DUMMY", *save = "SAVE", *pointer = "POINTER",
870cb9
@@ -496,7 +496,9 @@ check_conflict (symbol_attribute *attr, const char *name, locus *where)
870cb9
   conf (allocatable, elemental);
870cb9
 
870cb9
   conf (in_common, automatic);
870cb9
+#if 0
870cb9
   conf (in_equivalence, automatic);
870cb9
+#endif
870cb9
   conf (result, automatic);
870cb9
   conf (use_assoc, automatic);
870cb9
   conf (dummy, automatic);
870cb9
diff --git a/gcc/fortran/trans-common.c b/gcc/fortran/trans-common.c
870cb9
index 36370eb..4cfaf61 100644
870cb9
--- a/gcc/fortran/trans-common.c
870cb9
+++ b/gcc/fortran/trans-common.c
870cb9
@@ -948,6 +948,61 @@ add_condition (segment_info *f, gfc_equiv *eq1, gfc_equiv *eq2)
870cb9
     confirm_condition (f, eq1, n, eq2);
870cb9
 }
870cb9
 
870cb9
+static void
870cb9
+accumulate_equivalence_attributes (symbol_attribute *dummy_symbol, gfc_equiv *e)
870cb9
+{
870cb9
+  symbol_attribute attr = e->expr->symtree->n.sym->attr;
870cb9
+
870cb9
+  dummy_symbol->dummy |= attr.dummy;
870cb9
+  dummy_symbol->pointer |= attr.pointer;
870cb9
+  dummy_symbol->target |= attr.target;
870cb9
+  dummy_symbol->external |= attr.external;
870cb9
+  dummy_symbol->intrinsic |= attr.intrinsic;
870cb9
+  dummy_symbol->allocatable |= attr.allocatable;
870cb9
+  dummy_symbol->elemental |= attr.elemental;
870cb9
+  dummy_symbol->recursive |= attr.recursive;
870cb9
+  dummy_symbol->in_common |= attr.in_common;
870cb9
+  dummy_symbol->result |= attr.result;
870cb9
+  dummy_symbol->in_namelist |= attr.in_namelist;
870cb9
+  dummy_symbol->optional |= attr.optional;
870cb9
+  dummy_symbol->entry |= attr.entry;
870cb9
+  dummy_symbol->function |= attr.function;
870cb9
+  dummy_symbol->subroutine |= attr.subroutine;
870cb9
+  dummy_symbol->dimension |= attr.dimension;
870cb9
+  dummy_symbol->in_equivalence |= attr.in_equivalence;
870cb9
+  dummy_symbol->use_assoc |= attr.use_assoc;
870cb9
+  dummy_symbol->cray_pointer |= attr.cray_pointer;
870cb9
+  dummy_symbol->cray_pointee |= attr.cray_pointee;
870cb9
+  dummy_symbol->data |= attr.data;
870cb9
+  dummy_symbol->value |= attr.value;
870cb9
+  dummy_symbol->volatile_ |= attr.volatile_;
870cb9
+  dummy_symbol->is_protected |= attr.is_protected;
870cb9
+  dummy_symbol->is_bind_c |= attr.is_bind_c;
870cb9
+  dummy_symbol->procedure |= attr.procedure;
870cb9
+  dummy_symbol->proc_pointer |= attr.proc_pointer;
870cb9
+  dummy_symbol->abstract |= attr.abstract;
870cb9
+  dummy_symbol->asynchronous |= attr.asynchronous;
870cb9
+  dummy_symbol->codimension |= attr.codimension;
870cb9
+  dummy_symbol->contiguous |= attr.contiguous;
870cb9
+  dummy_symbol->generic |= attr.generic;
870cb9
+  dummy_symbol->automatic |= attr.automatic;
870cb9
+  dummy_symbol->threadprivate |= attr.threadprivate;
870cb9
+  dummy_symbol->omp_declare_target |= attr.omp_declare_target;
870cb9
+  dummy_symbol->omp_declare_target_link |= attr.omp_declare_target_link;
870cb9
+  dummy_symbol->oacc_declare_copyin |= attr.oacc_declare_copyin;
870cb9
+  dummy_symbol->oacc_declare_create |= attr.oacc_declare_create;
870cb9
+  dummy_symbol->oacc_declare_deviceptr |= attr.oacc_declare_deviceptr;
870cb9
+  dummy_symbol->oacc_declare_device_resident
870cb9
+    |= attr.oacc_declare_device_resident;
870cb9
+
870cb9
+  /* Not strictly correct, but probably close enough.  */
870cb9
+  if (attr.save > dummy_symbol->save)
870cb9
+    dummy_symbol->save = attr.save;
870cb9
+  if (attr.intent > dummy_symbol->intent)
870cb9
+    dummy_symbol->intent = attr.intent;
870cb9
+  if (attr.access > dummy_symbol->access)
870cb9
+    dummy_symbol->access = attr.access;
870cb9
+}
870cb9
 
870cb9
 /* Given a segment element, search through the equivalence lists for unused
870cb9
    conditions that involve the symbol.  Add these rules to the segment.  */
870cb9
@@ -966,8 +1021,11 @@ find_equivalence (segment_info *n)
870cb9
 
870cb9
       /* Search the equivalence list, including the root (first) element
870cb9
          for the symbol that owns the segment.  */
870cb9
+      symbol_attribute dummy_symbol;
870cb9
+      memset (&dummy_symbol, 0, sizeof (dummy_symbol));
870cb9
       for (e2 = e1; e2; e2 = e2->eq)
870cb9
 	{
870cb9
+	  accumulate_equivalence_attributes (&dummy_symbol, e2);
870cb9
 	  if (!e2->used && e2->expr->symtree->n.sym == n->sym)
870cb9
 	    {
870cb9
 	      eq = e2;
870cb9
@@ -975,6 +1033,8 @@ find_equivalence (segment_info *n)
870cb9
 	    }
870cb9
 	}
870cb9
 
870cb9
+      check_conflict (&dummy_symbol, e1->expr->symtree->name, &e1->expr->where);
870cb9
+
870cb9
       /* Go to the next root element.  */
870cb9
       if (eq == NULL)
870cb9
 	continue;
870cb9
diff -Nrcp gcc-8.2.1-20180801/gcc/fortran/trans-common.c save/gcc/fortran/trans-common.c
870cb9
*** a/gcc/fortran/trans-common.c	2018-08-14 18:17:28.000000000 -0400
870cb9
--- b/gcc/fortran/trans-common.c	2018-08-14 17:57:51.000000000 -0400
870cb9
*************** build_field (segment_info *h, tree union
870cb9
*** 339,345 ****
870cb9
  /* Get storage for local equivalence.  */
870cb9
  
870cb9
  static tree
870cb9
! build_equiv_decl (tree union_type, bool is_init, bool is_saved)
870cb9
  {
870cb9
    tree decl;
870cb9
    char name[18];
870cb9
--- 339,345 ----
870cb9
  /* Get storage for local equivalence.  */
870cb9
  
870cb9
  static tree
870cb9
! build_equiv_decl (tree union_type, bool is_init, bool is_saved, bool is_auto)
870cb9
  {
870cb9
    tree decl;
870cb9
    char name[18];
870cb9
*************** build_equiv_decl (tree union_type, bool
870cb9
*** 359,366 ****
870cb9
    DECL_ARTIFICIAL (decl) = 1;
870cb9
    DECL_IGNORED_P (decl) = 1;
870cb9
  
870cb9
!   if (!gfc_can_put_var_on_stack (DECL_SIZE_UNIT (decl))
870cb9
!       || is_saved)
870cb9
      TREE_STATIC (decl) = 1;
870cb9
  
870cb9
    TREE_ADDRESSABLE (decl) = 1;
870cb9
--- 359,367 ----
870cb9
    DECL_ARTIFICIAL (decl) = 1;
870cb9
    DECL_IGNORED_P (decl) = 1;
870cb9
  
870cb9
!   if (!is_auto
870cb9
!       && (!gfc_can_put_var_on_stack (DECL_SIZE_UNIT (decl))
870cb9
! 	  || is_saved))
870cb9
      TREE_STATIC (decl) = 1;
870cb9
  
870cb9
    TREE_ADDRESSABLE (decl) = 1;
870cb9
*************** create_common (gfc_common_head *com, seg
870cb9
*** 611,616 ****
870cb9
--- 612,618 ----
870cb9
    tree decl;
870cb9
    bool is_init = false;
870cb9
    bool is_saved = false;
870cb9
+   bool is_automatic = false;
870cb9
  
870cb9
    /* Declare the variables inside the common block.
870cb9
       If the current common block contains any equivalence object, then
870cb9
*************** create_common (gfc_common_head *com, seg
870cb9
*** 654,659 ****
870cb9
--- 656,665 ----
870cb9
        /* Has SAVE attribute.  */
870cb9
        if (s->sym->attr.save)
870cb9
          is_saved = true;
870cb9
+ 
870cb9
+       /* Has AUTOMATIC attribute.  */
870cb9
+       if (s->sym->attr.automatic)
870cb9
+ 	is_automatic = true;
870cb9
      }
870cb9
  
870cb9
    finish_record_layout (rli, true);
870cb9
*************** create_common (gfc_common_head *com, seg
870cb9
*** 661,667 ****
870cb9
    if (com)
870cb9
      decl = build_common_decl (com, union_type, is_init);
870cb9
    else
870cb9
!     decl = build_equiv_decl (union_type, is_init, is_saved);
870cb9
  
870cb9
    if (is_init)
870cb9
      {
870cb9
--- 667,673 ----
870cb9
    if (com)
870cb9
      decl = build_common_decl (com, union_type, is_init);
870cb9
    else
870cb9
!     decl = build_equiv_decl (union_type, is_init, is_saved, is_automatic);
870cb9
  
870cb9
    if (is_init)
870cb9
      {