https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89462

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW
           Assignee|jakub at gcc dot gnu.org           |unassigned at gcc dot 
gnu.org

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
--- gcc/fortran/trans-decl.c.jj 2019-03-13 09:23:46.689383077 +0100
+++ gcc/fortran/trans-decl.c    2019-03-14 20:59:59.395041828 +0100
@@ -236,7 +236,7 @@ tree gfor_fndecl_random_init;
 static void
 gfc_add_decl_to_parent_function (tree decl)
 {
-  gcc_assert (decl);
+  gcc_assert (decl && DECL_CONTEXT (decl) == NULL_TREE);
   DECL_CONTEXT (decl) = DECL_CONTEXT (current_function_decl);
   DECL_NONLOCAL (decl) = 1;
   DECL_CHAIN (decl) = saved_parent_function_decls;
@@ -246,7 +246,7 @@ gfc_add_decl_to_parent_function (tree de
 void
 gfc_add_decl_to_function (tree decl)
 {
-  gcc_assert (decl);
+  gcc_assert (decl && DECL_CONTEXT (decl) == NULL_TREE);
   TREE_USED (decl) = 1;
   DECL_CONTEXT (decl) = current_function_decl;
   DECL_CHAIN (decl) = saved_function_decls;
@@ -256,7 +256,7 @@ gfc_add_decl_to_function (tree decl)
 static void
 add_decl_as_local (tree decl)
 {
-  gcc_assert (decl);
+  gcc_assert (decl && DECL_CONTEXT (decl) == NULL_TREE);
   TREE_USED (decl) = 1;
   DECL_CONTEXT (decl) = current_function_decl;
   DECL_CHAIN (decl) = saved_local_decls;
@@ -612,7 +612,7 @@ gfc_finish_var_decl (tree decl, gfc_symb
   /* Chain this decl to the pending declarations.  Don't do pushdecl()
      because this would add them to the current scope rather than the
      function scope.  */
-  if (current_function_decl != NULL_TREE)
+  if (current_function_decl != NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE)
     {
       if (sym->ns->proc_name
          && (sym->ns->proc_name->backend_decl == current_function_decl
@@ -640,8 +640,8 @@ gfc_finish_var_decl (tree decl, gfc_symb
         variables that it interoperates with and the draft says that
         either Fortran or C should be able to initialize it (but not
         both, of course.) (J3/04-007, section 15.3).  */
-      TREE_PUBLIC(decl) = 1;
-      DECL_COMMON(decl) = 1;
+      TREE_PUBLIC (decl) = 1;
+      DECL_COMMON (decl) = 1;
       if (sym->attr.access == ACCESS_PRIVATE && !sym->attr.public_used)
        {
          DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;

avoids the ICE.  But that is not a full fix, I think the problem is sharing the
same ts between all the character variables (or at least trying to share it
between the function or entry symbols and other variables (perhaps also dummy
variables).
Don't know what exactly the Fortran standard wants here though, so not working
on this anymore.

Reply via email to