]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/79402 (ICE with submodules: module procedure interface defined in paren...
authorPaul Thomas <pault@gcc.gnu.org>
Thu, 19 Oct 2017 17:54:58 +0000 (17:54 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Thu, 19 Oct 2017 17:54:58 +0000 (17:54 +0000)
2017-10-19  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/79402
* resolve.c (fixup_unique_dummy): New function.
(gfc_resolve_expr): Call it for dummy variables with a unique
symtree name.

2017-10-19  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/79402
* gfortran.dg/submodule_23.f90: New test.

From-SVN: r253908

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/submodule_23.f90 [new file with mode: 0644]

index 49177ba05ed2651d9f08a4d15f43392df660b255..47cf5fb1f08cbb9aafae1873709748ca88a0ebd5 100644 (file)
@@ -1,3 +1,11 @@
+2017-10-19  Paul Thomas  <pault@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/79402
+       * resolve.c (fixup_unique_dummy): New function.
+       (gfc_resolve_expr): Call it for dummy variables with a unique
+       symtree name.
+
 2017-10-19  Paul Thomas  <pault@gcc.gnu.org>
 
        Backport from trunk
index e068f78268a15e9f1c9fc37b3045f53014ad3ec1..4fc8653ac3606335b97746c666d3434d5cb0d777 100644 (file)
@@ -6313,6 +6313,31 @@ gfc_is_expandable_expr (gfc_expr *e)
   return false;
 }
 
+
+/* Sometimes variables in specification expressions of the result
+   of module procedures in submodules wind up not being the 'real'
+   dummy.  Find this, if possible, in the namespace of the first
+   formal argument.  */
+
+static void
+fixup_unique_dummy (gfc_expr *e)
+{
+  gfc_symtree *st = NULL;
+  gfc_symbol *s = NULL;
+
+  if (e->symtree->n.sym->ns->proc_name
+      && e->symtree->n.sym->ns->proc_name->formal)
+    s = e->symtree->n.sym->ns->proc_name->formal->sym;
+
+  if (s != NULL)
+    st = gfc_find_symtree (s->ns->sym_root, e->symtree->n.sym->name);
+
+  if (st != NULL
+      && st->n.sym != NULL
+      && st->n.sym->attr.dummy)
+    e->symtree = st;
+}
+
 /* Resolve an expression.  That is, make sure that types of operands agree
    with their operators, intrinsic operators are converted to function calls
    for overloaded types and unresolved function references are resolved.  */
@@ -6337,6 +6362,14 @@ gfc_resolve_expr (gfc_expr *e)
       actual_arg = false;
       first_actual_arg = false;
     }
+  else if (e->symtree != NULL
+          && *e->symtree->name == '@'
+          && e->symtree->n.sym->attr.dummy)
+    {
+      /* Deal with submodule specification expressions that are not
+        found to be referenced in module.c(read_cleanup).  */
+      fixup_unique_dummy (e);
+    }
 
   switch (e->expr_type)
     {
index 80e766f514f28e02287abc72e4f35ad4185e480c..0044c7d8760ad7b0c893b3088826426684186484 100644 (file)
@@ -1,3 +1,9 @@
+2017-10-19  Paul Thomas  <pault@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/79402
+       * gfortran.dg/submodule_23.f90: New test.
+
 2017-10-19  Richard Earnshaw  <rearnsha@arm.com>
 
        PR target/82445
diff --git a/gcc/testsuite/gfortran.dg/submodule_23.f90 b/gcc/testsuite/gfortran.dg/submodule_23.f90
new file mode 100644 (file)
index 0000000..63674fb
--- /dev/null
@@ -0,0 +1,29 @@
+! { dg-do compile }
+!
+! Test the fix for PR79402, in which the module procedure 'fun1' picked
+! up a spurious symbol for the dummy 'n' in the specification expression
+! for the result 'y'.
+!
+! Contributed by Chris Coutinho  <chrisbcoutinho@gmail.com>
+!
+module mod
+  interface myfun
+    module function fun1(n) result(y)
+      integer,  intent(in)    :: n
+      real, dimension(n)  :: y
+    end function fun1
+  end interface myfun
+
+end module mod
+
+submodule (mod) submod
+contains
+  module procedure fun1
+    integer :: i
+    y = [(float (i), i = 1, n)]
+  end procedure fun1
+end submodule
+
+  use mod
+  print *, fun1(10)
+end