re PR fortran/40629 (Host association problem)
authorPaul Thomas <pault@gcc.gnu.org>
Thu, 9 Jul 2009 16:48:50 +0000 (16:48 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Thu, 9 Jul 2009 16:48:50 +0000 (16:48 +0000)
2008-07-09  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/40629
* resolve.c (check_host_association):  Use the existing
accessible symtree and treat function expressions with
symbols that have procedure flavor.

2008-07-09  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/40629
* gfortran.dg/host_assoc_function_9.f90: New test.

From-SVN: r149422

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

index ceabd6053ba98184021d8f5cccf60e7ba933838b..5b1ed7728295da3e0ccbd8dee6e1907bb9a22c0d 100644 (file)
@@ -1,3 +1,10 @@
+2008-07-09  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/40629
+       * resolve.c (check_host_association):  Use the existing
+       accessible symtree and treat function expressions with
+       symbols that have procedure flavor.
+
 2009-07-09  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/40646
index e3aba1a1af2278325f82e0e40670f63283a3fc91..9b091ad01625195d1d3d1fbb38a5739d7f650434 100644 (file)
@@ -4402,12 +4402,13 @@ check_host_association (gfc_expr *e)
              gfc_free (e->shape);
            }
 
-         /* Give the symbol a symtree in the right place!  */
-         gfc_get_sym_tree (sym->name, gfc_current_ns, &st, false);
-         st->n.sym = sym;
+         /* Give the expression the right symtree!  */
+         gfc_find_sym_tree (e->symtree->name, NULL, 1, &st);
+         gcc_assert (st != NULL);
 
-         if (old_sym->attr.flavor == FL_PROCEDURE)
-           {
+         if (old_sym->attr.flavor == FL_PROCEDURE
+               || e->expr_type == EXPR_FUNCTION)
+           {
              /* Original was function so point to the new symbol, since
                 the actual argument list is already attached to the
                 expression. */
index 6dc3393175446f87e61e057e39698872830a0dce..e04e25e87536e05798c36bafa6d0130040c4906e 100644 (file)
@@ -1,3 +1,8 @@
+2008-07-09  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/40629
+       * gfortran.dg/host_assoc_function_9.f90: New test.
+
 2009-07-09  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/40646
diff --git a/gcc/testsuite/gfortran.dg/host_assoc_function_9.f90 b/gcc/testsuite/gfortran.dg/host_assoc_function_9.f90
new file mode 100644 (file)
index 0000000..58cae43
--- /dev/null
@@ -0,0 +1,33 @@
+! { dg-do run }
+! Tests the fix for the bug PR40629, in which the reference to 'x'
+! in 'upper' wrongly host-associated with the symbol 'x' at module
+! leve rather than the function.
+!
+! Contributed by Philippe Marguinaud  <philippe.marguinaud@meteo.fr>
+!
+MODULE m
+  REAL :: x = 0
+CONTAINS
+  subroutine s
+    call upper
+    call lower
+  CONTAINS
+    SUBROUTINE upper
+     y = x(3,1)
+     if (int(y) .ne. 3) call abort
+    END SUBROUTINE
+    FUNCTION x(n, m)
+       x = m*n
+    END FUNCTION
+    SUBROUTINE lower
+     y = x(2,1)
+     if (int(y) .ne. 2) call abort
+    END SUBROUTINE
+  END SUBROUTINE
+END MODULE
+
+  use m
+  call s
+end
+! { dg-final { cleanup-modules "m" } }
+