Bug 30668 - -fwhole-file should catch function of wrong type
Summary: -fwhole-file should catch function of wrong type
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 minor
Target Milestone: 4.5.1
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 39700 (view as bug list)
Depends on:
Blocks: 40011
  Show dependency treegraph
 
Reported: 2007-02-01 14:54 UTC by Vivek Rao
Modified: 2010-07-18 21:12 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-05-03 13:53:02


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vivek Rao 2007-02-01 14:54:24 UTC
In the following program it would be nice if gfortran reported that two() has type REAL in the main program because of implicit typing but actually has type DOUBLE PRECISION. Below is what gfortran says and then what g95 says for comparison.

U:\vrao\fortran>type bug_print.f90 
double precision function two()
two = 2.0d0
end function two

program xx
print*,two(),kind(two())
end program xx

U:\vrao\fortran>gfortran -v 
Using built-in specs.
Target: i386-pc-mingw32
Configured with: ../trunk/configure --prefix=/mingw --enable-languages=c,fortran --with-gmp=/home/coudert/local --disable-nls --with-ld=/mingw/bin/ld --with-as=/mingw/bin/as --disable-werror --enable-bootstrap --enable-threads --host=i386-pc-mingw32 --disable-shared --enable-libgomp
Thread model: win32
gcc version 4.3.0 20061021 (experimental)

U:\vrao\fortran>gfortran -W -Wall -pedantic-errors -std=f2003 -fbounds-check -Werror bug_print.f90 

U:\vrao\fortran>a.exe
   2.000000               4

U:\vrao\fortran>g95 -v 
Using built-in specs.
Target: 
Configured with: /src/G95/gcc-4.0-20060302/configure --with-gcc --with-gnu-ld --with-ld=/mingw/bin/ld --with-gnu-as --with-as=/mingw/bin/as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c --disable-win32-registry --disable-shared --without-x --disable-libmudflap --disable-libssp
Thread model: win32
gcc version 4.0.3 (g95 0.91!) Jan 23 2007

U:\vrao\fortran>g95 -Wall -pedantic -fbounds-check -ftrace=full bug_print.f90 
In file bug_print.f90:1

double precision function two()
                          1
In file bug_print.f90:6

print*,two(),kind(two())
       2
Error: FUNCTION 'two' is of type REAL(8) at (1) and type REAL(4) at (2)

This program was discussed in the gg95 newsgroup in a thread "bug with double precision function" at http://groups.google.com/group/gg95/browse_frm/thread/73ea96b2925195f0?hl=en
Comment 1 Tobias Burnus 2007-02-02 07:50:59 UTC
This actually planed to do, cf.
http://gcc.gnu.org/wiki/GFortran43

"Projects for inclusion into gfortran-4.3"

"Formal/actual argument checking for same file procedures

There are a large number of PRs associated with this. [...] The main wrinkle is to deal with actual arguments for references to procedures that have not yet been seen. [...] PR26227 (refers to PRs28809, 28443, 27587, 27586 and 27594), PR27318 and PR24878"
Comment 2 Andrew Pinski 2009-04-09 17:15:24 UTC
*** Bug 39700 has been marked as a duplicate of this bug. ***
Comment 3 Francois-Xavier Coudert 2009-05-03 13:53:02 UTC
I guess -fwhole-file should catch this one, but it does not. The testcase I used is:

integer function two()
  two = 2
end function two

program xx
  ! real, external :: two
  print *, two(), kind(two())
end program xx


You can comment or uncomment the line with "external", both versions should be caught.
Comment 4 Tobias Burnus 2009-12-15 08:44:05 UTC
It also should check (kind/length) type-parameters, cf. http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/d710371aed91e75f
This is kind of a follow up to PR 41235; cf. also PR 41603.
Comment 5 Daniel Franke 2010-05-25 18:10:19 UTC
Subject: Bug 30668

Author: dfranke
Date: Tue May 25 18:10:01 2010
New Revision: 159838

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159838
Log:
gcc/fortran/:
2010-05-25  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/30668
	PR fortran/31346
	PR fortran/34260
	* resolve.c (resolve_global_procedure): Add check for global
	procedures with implicit interfaces and assumed-shape or optional
	dummy arguments. Verify that function return type, kind and string
	lengths match.

gcc/testsuite/:
2010-05-25  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/30668
	PR fortran/31346
	PR fortran/34260
	* gfortran.dg/pr40999.f: Fix function type.
	* gfortran.dg/whole_file_5.f90: Likewise.
	* gfortran.dg/whole_file_6.f90: Likewise.
	* gfortran.dg/whole_file_16.f90: New.
	* gfortran.dg/whole_file_17.f90: New.
	* gfortran.dg/whole_file_18.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/whole_file_16.f90
    trunk/gcc/testsuite/gfortran.dg/whole_file_17.f90
    trunk/gcc/testsuite/gfortran.dg/whole_file_18.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/pr40999.f
    trunk/gcc/testsuite/gfortran.dg/whole_file_5.f90
    trunk/gcc/testsuite/gfortran.dg/whole_file_6.f90

Comment 6 Daniel Franke 2010-07-18 20:49:52 UTC
Subject: Bug 30668

Author: dfranke
Date: Sun Jul 18 20:49:30 2010
New Revision: 162287

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162287
Log:
gcc/fortran/:
2010-07-18  Daniel Franke  <franke.daniel@gmail.com>
	    Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/30668
	PR fortran/31346
	PR fortran/34260
        * resolve.c (resolve_global_procedure): Improved checking if an
        explicit interface is required.

	PR fortran/40011
	* resolve.c (resolve_global_procedure): Resolve the gsymbol's
	namespace before trying to reorder the gsymbols.

gcc/testsuite/:
2010-07-18  Daniel Franke  <franke.daniel@gmail.com>
	    Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/30668
	PR fortran/31346
	PR fortran/34260
	PR fortran/40011
	* gfortran.dg/pr40999.f: Fix function type.
	* gfortran.dg/whole_file_5.f90: Likewise.
	* gfortran.dg/whole_file_6.f90: Likewise.
	* gfortran.dg/whole_file_16.f90: New.
	* gfortran.dg/whole_file_17.f90: New.
	* gfortran.dg/whole_file_18.f90: New.
	* gfortran.dg/whole_file_19.f90: New.


Added:
    branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/whole_file_16.f90
    branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/whole_file_17.f90
    branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/whole_file_18.f90
    branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/whole_file_19.f90
Modified:
    branches/gcc-4_5-branch/gcc/fortran/ChangeLog
    branches/gcc-4_5-branch/gcc/fortran/resolve.c
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/pr40999.f
    branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/whole_file_5.f90
    branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/whole_file_6.f90

Comment 7 Daniel Franke 2010-07-18 21:12:51 UTC
Fixed in trunk and 4.5. Closing.