Blame SOURCES/gcc8-fortran-equivalence.patch

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