OSDN Git Service

2013-01-07 Steven G. Kargl <kargl@gcc.gnu.org>
authormikael <mikael@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 7 Jan 2013 17:56:53 +0000 (17:56 +0000)
committermikael <mikael@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 7 Jan 2013 17:56:53 +0000 (17:56 +0000)
    Mikael Morin  <mikael@gcc.gnu.org>

PR fortran/55827
* class.c (gfc_fix_class_refs): Adapt ts initialization for the case
e->symtree == NULL.
* trans-expr.c (gfc_conv_function_expr): Init sym earlier. Use it.

2013-01-07  Steven G. Kargl  <kargl@gcc.gnu.org>
    Mikael Morin  <mikael@gcc.gnu.org>

PR fortran/55827
* gfortran.dg/use_22.f90: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@194985 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/class.c
gcc/fortran/trans-expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/use_22.f90 [new file with mode: 0644]

index 72a6659..b9a649e 100644 (file)
@@ -1,3 +1,11 @@
+2013-01-07  Steven G. Kargl  <kargl@gcc.gnu.org>
+           Mikael Morin  <mikael@gcc.gnu.org>
+
+       PR fortran/55827
+       * class.c (gfc_fix_class_refs): Adapt ts initialization for the case
+       e->symtree == NULL.
+       * trans-expr.c (gfc_conv_function_expr): Init sym earlier. Use it.
+
 2012-12-20  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/54818
index bfa8740..7257e83 100644 (file)
@@ -162,7 +162,23 @@ gfc_fix_class_refs (gfc_expr *e)
          && e->value.function.isym != NULL))
     return;
 
-  ts = &e->symtree->n.sym->ts;
+  if (e->expr_type == EXPR_VARIABLE)
+    ts = &e->symtree->n.sym->ts;
+  else
+    {
+      gfc_symbol *func;
+
+      gcc_assert (e->expr_type == EXPR_FUNCTION);
+      if (e->value.function.esym != NULL)
+       func = e->value.function.esym;
+      else
+       func = e->symtree->n.sym;
+
+      if (func->result != NULL)
+       ts = &func->result->ts;
+      else
+       ts = &func->ts;
+    }
 
   for (ref = &e->ref; *ref != NULL; ref = &(*ref)->next)
     {
index 3552da3..94bd041 100644 (file)
@@ -4799,20 +4799,20 @@ gfc_conv_function_expr (gfc_se * se, gfc_expr * expr)
       return;
     }
 
+  /* expr.value.function.esym is the resolved (specific) function symbol for
+     most functions.  However this isn't set for dummy procedures.  */
+  sym = expr->value.function.esym;
+  if (!sym)
+    sym = expr->symtree->n.sym;
+
   /* We distinguish statement functions from general functions to improve
      runtime performance.  */
-  if (expr->symtree->n.sym->attr.proc == PROC_ST_FUNCTION)
+  if (sym->attr.proc == PROC_ST_FUNCTION)
     {
       gfc_conv_statement_function (se, expr);
       return;
     }
 
-  /* expr.value.function.esym is the resolved (specific) function symbol for
-     most functions.  However this isn't set for dummy procedures.  */
-  sym = expr->value.function.esym;
-  if (!sym)
-    sym = expr->symtree->n.sym;
-
   gfc_conv_procedure_call (se, sym, expr->value.function.actual, expr, NULL);
 }
 
index dd49bc4..3b8ac3f 100644 (file)
@@ -1,3 +1,9 @@
+2013-01-07  Steven G. Kargl  <kargl@gcc.gnu.org>
+           Mikael Morin  <mikael@gcc.gnu.org>
+
+       PR fortran/55827
+       * gfortran.dg/use_22.f90: New test.
+
 2013-01-07  Terry Guo  <terry.guo@arm.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/gfortran.dg/use_22.f90 b/gcc/testsuite/gfortran.dg/use_22.f90
new file mode 100644 (file)
index 0000000..d61df67
--- /dev/null
@@ -0,0 +1,35 @@
+! { dg-do compile }
+!
+! PR fortran/55827
+! gfortran used to ICE with the call to `tostring' depending on how the
+! `tostring' symbol was USE-associated.
+!
+! Contributed by Lorenz Hüdepohl <bugs@stellardeath.org>
+
+module stringutils
+  interface
+    pure function strlen(handle) result(len)
+      integer, intent(in) :: handle
+      integer :: len
+    end function
+  end interface
+end module
+module intermediate ! does not die if this module is merged with stringutils
+  contains
+  function tostring(handle) result(string)
+    use stringutils
+    integer, intent(in) :: handle
+    character(len=strlen(handle)) :: string
+  end function
+end module
+module usage
+  contains
+  subroutine dies_here(handle)
+    use stringutils ! does not die if this unnecessary line is omitted or placed after "use intermediate"
+    use intermediate
+    integer :: handle
+    write(*,*) tostring(handle) ! ICE
+  end subroutine
+end module
+
+