Bug 33233 - Parent and contained procedure: Wrongly treated as generic procedures
Summary: Parent and contained procedure: Wrongly treated as generic procedures
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Paul Thomas
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2007-08-29 16:02 UTC by Tobias Burnus
Modified: 2007-10-18 13:54 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-10-03 04:13:42


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-08-29 16:02:32 UTC
This is a follow up to PR30746.

While I believe the test case in PR30746 is correct, I think the gfortran.dg/host_assoc_function_1.f90 test case is wrong.

(Simplified, see testsuite for the full file)

MODULE m
  REAL :: x(3) = (/ 1.5, 2.5, 3.5 /)
CONTAINS
  SUBROUTINE s
    if (x(2) .ne. 2.5) call abort ()
  CONTAINS
    FUNCTION x(n, m)
      x = REAL(n)**m
    END FUNCTION
  END SUBROUTINE s
END MODULE m

I am very much in favour of the other compilers which think the "x" in "s" refers to only the contained function "x" and not to the variable. gfortran somehow seems to treat the symbol "x" as generic symbol which means with one argument the variable and with two the function.
I would argue that the function name makes the variable inaccessible.

Using NAG's f95:
Error: host_assoc_function_1.f90, line 22: Too few arguments in reference to X
Error: host_assoc_function_1.f90, line 23: Too few arguments in reference to Z

ifort:
fortcom: Error: host_assoc_function_1.f90, line 22: A non-optional actual argument must be present when invoking a procedure with an explicit interface.   [M] [...]
Comment 1 Paul Thomas 2007-10-03 04:13:42 UTC
Tobias,

I am not sure how this got so screwed up.  As you say, the Cohen testcase is correct and I must, surely(?), have been checking that.... *sigh*

Confirmed

Paul
Comment 2 Paul Thomas 2007-10-11 14:55:37 UTC
(In reply to comment #1)
Ah.... this bug was present before my patch for PR30746.  I can see from my notes that I was fixated on PR30746, whilst not altering the behaviour of gfortran in any other way....., whether right or wrong.  Bah!

With the patch below, we get the correct behaviour for 

MODULE m
  REAL :: x(3) = (/ 1.5, 2.5, 3.5 /)
CONTAINS
  SUBROUTINE s
    if (x(2) .eq. 2.5) call abort ()
  CONTAINS
    FUNCTION x(n, m)
      integer, optional :: m
      if (present(m)) then
        x = REAL(n)**m
      else
	x = 0.0
      end if
    END FUNCTION
  END SUBROUTINE s
END MODULE m
  use m
  call s
end

Paul

Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c       (révision 129121)
--- gcc/fortran/resolve.c       (copie de travail)
*************** check_host_association (gfc_expr *e)
*** 3989,3999 ****
      return retval;

    if (gfc_current_ns->parent
-       && gfc_current_ns->parent->parent
        && old_sym->ns != gfc_current_ns)
      {
!       gfc_find_symbol (old_sym->name, gfc_current_ns->parent, 1, &sym);
!       if (sym && old_sym != sym && sym->attr.flavor == FL_PROCEDURE)
        {
          temp_locus = gfc_current_locus;
          gfc_current_locus = e->where;
--- 3989,4000 ----
      return retval;

    if (gfc_current_ns->parent
        && old_sym->ns != gfc_current_ns)
      {
!       gfc_find_symbol (old_sym->name, gfc_current_ns, 1, &sym);
!       if (sym && old_sym != sym
!             && sym->attr.flavor == FL_PROCEDURE
!             && sym->attr.contained)
        {
          temp_locus = gfc_current_locus;
          gfc_current_locus = e->where;

Index: D:/svn/trunk/gcc/testsuite/gfortran.dg/host_assoc_function_1.f90
===================================================================
*** D:/svn/trunk/gcc/testsuite/gfortran.dg/host_assoc_function_1.f90    (révisio
n 129121)
--- D:/svn/trunk/gcc/testsuite/gfortran.dg/host_assoc_function_1.f90    (copie d
e travail)
*************** MODULE m
*** 19,26 ****
    end interface
  CONTAINS
    SUBROUTINE s
!     if (x(2) .ne. 2.5) call abort ()
!     if (z(3) .ne. real (3)**3) call abort ()
      CALL inner
    CONTAINS
      SUBROUTINE inner
--- 19,26 ----
    end interface
  CONTAINS
    SUBROUTINE s
!     if (x(2, 3) .ne. real (2)**3) call abort ()
!     if (z(3, 3) .ne. real (3)**3) call abort ()
      CALL inner
    CONTAINS
      SUBROUTINE inner
Comment 3 Dominique d'Humieres 2007-10-11 17:30:51 UTC
Works as expected: now gfortran agrees with xlf. Regtest almost finished in 32 bit mode.
Comment 4 patchapp@dberlin.org 2007-10-15 01:06:42 UTC
Subject: Bug number PR33233

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-10/msg00745.html
Comment 5 Paul Thomas 2007-10-18 12:48:49 UTC
Subject: Bug 33233

Author: pault
Date: Thu Oct 18 12:48:37 2007
New Revision: 129437

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129437
Log:
2007-10-18  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/33233
	* resolve.c (check_host_association): Check singly contained
	namespaces and start search for symbol in current namespace.

2007-10-18  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/33233
	* gfortran.dg/host_assoc_function_1.f90: Correct references.
	* gfortran.dg/host_assoc_function_3.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/host_assoc_function_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/host_assoc_function_1.f90

Comment 6 Paul Thomas 2007-10-18 13:54:24 UTC
Fixed on trunk.

Paul