Hi all,

the patch I proposed for this pr unfortunately did not catch all errors.
Dominique figured, that the original testcase was not resolved (thanks for
that).

This patch resolves the linker problem by putting the static token into the
parent function's decl list. Furthermore does the patch beautify the
retrieval of the symbol in gfc_get_tree_for_caf_expr () and remove the following
assert which is unnecessary then, because the symbol is either already present
or created. And gfc_get_symbol_decl () can not return NULL.

Bootstrapped and regtested ok on x86_64-linux/f25 and x86-linux/f25  for trunk.
Bootstrapped and regtested ok on x86_64-linux/f25 for gcc-6 (x86-linux has not
been tested, because the VM is not that fast).

Ok for trunk and gcc-6?

Regards,
        Andre
-- 
Andre Vehreschild * Email: vehre ad gmx dot de 
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index fffb492..51c23e8 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -971,6 +971,8 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym)
 	  DECL_CONTEXT (token) = sym->ns->proc_name->backend_decl;
 	  gfc_module_add_decl (cur_module, token);
 	}
+      else if (sym->attr.host_assoc)
+	gfc_add_decl_to_parent_function (token);
       else
 	gfc_add_decl_to_function (token);
     }
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 01b7dd2..ee8e15d 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -1839,11 +1839,10 @@ gfc_get_tree_for_caf_expr (gfc_expr *expr)
       }
 
   /* Make sure the backend_decl is present before accessing it.  */
-  if (expr->symtree->n.sym->backend_decl == NULL_TREE)
-    expr->symtree->n.sym->backend_decl
-	= gfc_get_symbol_decl (expr->symtree->n.sym);
-  caf_decl = expr->symtree->n.sym->backend_decl;
-  gcc_assert (caf_decl);
+  caf_decl = expr->symtree->n.sym->backend_decl == NULL_TREE
+      ? gfc_get_symbol_decl (expr->symtree->n.sym)
+      : expr->symtree->n.sym->backend_decl;
+
   if (expr->symtree->n.sym->ts.type == BT_CLASS)
     {
       if (expr->ref && expr->ref->type == REF_ARRAY)
diff --git a/gcc/testsuite/gfortran.dg/coarray_event_1.f08 b/gcc/testsuite/gfortran.dg/coarray_event_1.f08
new file mode 100644
index 0000000..51fc54c
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray_event_1.f08
@@ -0,0 +1,15 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=lib -lcaf_single" }
+
+! Check that pr70696 is really fixed.
+
+  use iso_fortran_env
+  type(event_type) :: x[*]
+
+  ! exchange must not be called or the link problem before the patch
+  ! does not occur.
+contains
+  subroutine exchange
+    event post (x[1])
+  end subroutine
+end 
gcc/fortran/ChangeLog:

2017-01-17  Andre Vehreschild  <ve...@gcc.gnu.org>

        PR fortran/70696
        * trans-decl.c (gfc_build_qualified_array): Add static tokens to the
        parent function's scope.
        * trans-expr.c (gfc_get_tree_for_caf_expr): Shorten code.  Remove
        unnecessary assert.

gcc/testsuite/ChangeLog:

2017-01-17  Andre Vehreschild  <ve...@gcc.gnu.org>

        PR fortran/70696
        * gfortran.dg/coarray_event_1.f08: New test.


Reply via email to