http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51809

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-01-16 
12:54:31 UTC ---
I have not quite found why it works in one order and not the other. There is
some reading/fixup oddness. In particular, when reading in 'bar', in
module_read's fixup setup, one already has a symtree for __vtab_foo_Foo_t
available - which in principle is needed for _extension.

In any case, what we do for __vtab (as PARAMETER) is not possible in Fortran
itself. Namely, having a PARAMETER with a (non-NULL) pointer. In Fortran, it's
not allowed as one could use the parameter's pointer target in a TRANSFER.
Thus, one had to know the address at compile time. However, the address is only
known at link time. See PR 51266 and related PR 45290 and PR 51076.

While accessing __vtab_...%_extension is not possible within Fortran, the
module reading does not seem to be prepared for it.

A simple revert of comment 1 is not possible as one runs into similar problems
for __def_init - causing an ICE. Ditto for a simple revert of only class.c.

 * * *

In any case, I planing to submit the following (regtested) patch, which is a
revert of comment 1 plus FL_PARAMETER->FL_VARIABLE for __def_init plus a patch
to trans-decl.c.

--- a/gcc/fortran/class.c
+++ b/gcc/fortran/class.c
@@ -590,3 +590,3 @@ gfc_find_derived_vtab (gfc_symbol *derived)
          vtab->ts.type = BT_DERIVED;
-         if (gfc_add_flavor (&vtab->attr, FL_PARAMETER, NULL,
+         if (gfc_add_flavor (&vtab->attr, FL_VARIABLE, NULL,
                              &gfc_current_locus) == FAILURE)
@@ -684,3 +684,3 @@ gfc_find_derived_vtab (gfc_symbol *derived)
                  def_init->attr.access = ACCESS_PUBLIC;
-                 def_init->attr.flavor = FL_PARAMETER;
+                 def_init->attr.flavor = FL_VARIABLE;
                  gfc_set_sym_referenced (def_init);
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -1885,4 +1885,3 @@ gfc_simplify_expr (gfc_expr *p, int type)
          && (gfc_init_expr_flag || p->ref
-             || p->symtree->n.sym->value->expr_type != EXPR_ARRAY)
-         && !p->symtree->n.sym->attr.vtab)
+             || p->symtree->n.sym->value->expr_type != EXPR_ARRAY))
        {
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -9639,3 +9639,3 @@ resolve_values (gfc_symbol *sym)

-  if (sym->value == NULL || sym->attr.use_assoc)
+  if (sym->value == NULL)
     return;
@@ -12197,3 +12197,3 @@ resolve_fl_parameter (gfc_symbol *sym)
      refer to a derived type from the host.  */
-  if (sym->ts.type == BT_DERIVED && sym->value
+  if (sym->ts.type == BT_DERIVED
       && !gfc_compare_types (&sym->ts, &sym->value->ts))
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -1487,3 +1487,6 @@ gfc_get_symbol_decl (gfc_symbol * sym)
       || (sym->name[0] == '_' && strncmp ("__def_init", sym->name, 10) == 0))
-    GFC_DECL_PUSH_TOPLEVEL (decl) = 1;
+    {
+      TREE_READONLY (decl) = 1;
+      GFC_DECL_PUSH_TOPLEVEL (decl) = 1;
+    }

Reply via email to