Bug 34231 - Scalar actual not distinguished from assumed size formal argument
Scalar actual not distinguished from assumed size formal argument
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.3.0
: P3 normal
: ---
Assigned To: Paul Thomas
:
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2007-11-25 22:53 UTC by francois.jacq
Modified: 2007-11-27 20:51 UTC (History)
2 users (show)

See Also:
Host: GNU Fortran (GCC) 4.3.0
Target: 20071123 (experimental)
Build: [trunk revision 130366]
Known to work:
Known to fail:
Last reconfirmed: 2007-11-26 09:47:12


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description francois.jacq 2007-11-25 22:53:38 UTC
The following test program calls the wrong routine :

[lcoul@b04p0004 test]$ gfortran test3.f90
[lcoul@b04p0004 test]$ a.out
 odfamilycnames

With ifort (or g95, lf95, SUN f90) the result is :

[lcoul@b04p0004 test]$ ifort test3.f90
[lcoul@b04p0004 test]$ a.out
 odfamilycname

File test3.f90 :

MODULE test

   TYPE odbase ; INTEGER :: value ; END TYPE

   INTERFACE odfname
      MODULE PROCEDURE odfamilycname,odfamilycnames
   END INTERFACE

   CONTAINS
   
   SUBROUTINE odfamilycnames(base,nfam,cnames)
      TYPE(odbase),INTENT(in)  :: base
      INTEGER     ,INTENT(out) :: nfam
      CHARACTER(*),INTENT(out) :: cnames(*)
      nfam=0
      cnames(1:nfam)=' '
      write(*,*) 'odfamilycnames'
   END SUBROUTINE
   
   SUBROUTINE odfamilycname(base,pos,cname)
      TYPE(odbase),INTENT(in)  :: base
      INTEGER     ,INTENT(in)  :: pos
      CHARACTER(*),INTENT(out) :: cname
      cname=' '
      write(*,*) 'odfamilycname'
   END SUBROUTINE
   
END MODULE

PROGRAM main
  USE test
  TYPE(odbase) :: base
  INTEGER :: i=1
  CHARACTER(8) :: cname
  CALL odfname(base,i,cname)
END PROGRAM
Comment 1 Paul Thomas 2007-11-26 09:03:54 UTC
Francois,

Many thanks for the report.

gfortran works correctly if you change cnames to assumed shape:

   SUBROUTINE odfamilycnames(base,nfam,cnames)
      TYPE(odbase),INTENT(in)  :: base
      INTEGER     ,INTENT(out) :: nfam
      CHARACTER(*),INTENT(out) :: cnames(:) <= Assumed size not working here
      nfam=0
      cnames(1:nfam)=' '
      write(*,*) 'odfamilycnames'
   END SUBROUTINE

This is a double bug because gfortran is failing to recognise the error in the call:

  CALL odfamilycnames(base,i,cname)

Paul
Comment 2 Paul Thomas 2007-11-26 09:47:12 UTC
The patch below does the job but has yet to be regtested. I think that the required F2003 survives correctly but I am having difficulty to find in the ChangeLog where this was added. Tobias, what do you think? 

Index: gcc/fortran/interface.c
===================================================================
*** gcc/fortran/interface.c     (révision 130286)
--- gcc/fortran/interface.c     (copie de travail)
*************** compare_actual_formal (gfc_actual_arglis
*** 1782,1788 ****
                       || f->sym->as->type == AS_DEFERRED);

        if (f->sym->ts.type == BT_CHARACTER && a->expr->ts.type == BT_CHARACTER
!         && a->expr->rank == 0
          && f->sym->as && f->sym->as->type != AS_ASSUMED_SHAPE)
        {
          if (where && (gfc_option.allow_std & GFC_STD_F2003) == 0)
--- 1782,1788 ----
                       || f->sym->as->type == AS_DEFERRED);

        if (f->sym->ts.type == BT_CHARACTER && a->expr->ts.type == BT_CHARACTER
!         && a->expr->rank == 0 && !ranks_must_agree
          && f->sym->as && f->sym->as->type != AS_ASSUMED_SHAPE)
        {
          if (where && (gfc_option.allow_std & GFC_STD_F2003) == 0)

Paul
Comment 3 Tobias Burnus 2007-11-26 13:58:02 UTC
> I think that the required F2003 survives correctly but
> I am having difficulty to find in the ChangeLog where this was added.

It was added for PR 30940.

> Tobias, what do you think?

Looks OK. At least the following works as expected and prints:
 two: character(*) scalar        ! finds right generic interface
 one: character(*), dimension(*) ! F2003 storage equivalence: ok for specific
                                 ! function.
 two: character(*) scalar        ! obviously ok.

And if one comments out "two" in "interface gen", one gets the expected compile-time error.

MODULE test
  implicit none
   INTERFACE gen
      MODULE PROCEDURE one,two
   END INTERFACE
CONTAINS
   SUBROUTINE one(cnames)
      CHARACTER(*) :: cnames(*)
      write(*,*) 'one: character(*), dimension(*)'
   END SUBROUTINE one
   SUBROUTINE two(cname)
      CHARACTER(*) :: cname
      write(*,*) 'two: character(*) scalar'
   END SUBROUTINE two
END MODULE

PROGRAM main
  USE test
  CHARACTER(11) :: cname = 'Hello World'
  CALL gen(cname)
  CALL one(cname)
  CALL two(cname)
END PROGRAM
Comment 4 Paul Thomas 2007-11-27 19:22:10 UTC
Subject: Bug 34231

Author: pault
Date: Tue Nov 27 19:21:52 2007
New Revision: 130471

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

	PR fortran/33541
	*interface.c (compare_actual_formal): Exclude assumed size
	arrays from the possibility of scalar to array mapping.
	* decl.c (get_proc_name): Fix whitespace problem.

	PR fortran/34231
	* gfortran.h : Add 'use_rename' bit to symbol_attribute.
	* module.c : Add 'renamed' field to pointer_info.u.rsym.
	(load_generic_interfaces): Add 'renamed' that is set after the
	number_use_names is called.  This is used to set the attribute
	use_rename, which, in its turn identifies those symbols that
	have not been renamed.
	(load_needed): If pointer_info.u.rsym->renamed is set, then
	set the use_rename attribute of the symbol.
	(read_module): Correct an erroneous use of use_flag. Use the
	renamed flag and the use_rename attribute to determine which
	symbols are not renamed.

2007-11-27  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/33541
	* gfortran.dg/use_11.f90: New test.

	PR fortran/34231
	* gfortran.dg/generic_15.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/generic_15.f90
    trunk/gcc/testsuite/gfortran.dg/use_11.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/module.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Paul Thomas 2007-11-27 20:51:23 UTC
Fixed on trunk

Paul