Bug 91390 - treatment of extra parameter in a subroutine call
Summary: treatment of extra parameter in a subroutine call
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 5.4.0
: P3 enhancement
Target Milestone: ---
Assignee: Thomas Koenig
URL:
Keywords:
Depends on: 91443
Blocks: 40976
  Show dependency treegraph
 
Reported: 2019-08-07 14:08 UTC by valera.veryazov
Modified: 2019-08-26 20:07 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-08-07 00:00:00


Attachments
Something that sort of works... (12.99 KB, patch)
2019-08-18 12:03 UTC, Thomas Koenig
Details | Diff
Much better patch (6.73 KB, patch)
2019-08-18 22:22 UTC, Thomas Koenig
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description valera.veryazov 2019-08-07 14:08:15 UTC
==== file1.f =====
        program test
            n=10
c   correct call
           call s('hej')
c   one extra parameter
           call s('hej',n)
           end
==== file2.f =====
       subroutine s(a)
       character a*(*)
       print *, len(a)
       end

First call is correct, the second call prints garbage. 
(of course, it is not a bug, but a feature of handling 
strings as a parameter).
Comment 1 Thomas Koenig 2019-08-07 19:14:46 UTC
The first one, with the two different calls, should be flagged.  It does
not do so even with trunk.

Confirmed as an enhancement.

Of course, using modules would catch this.
Comment 2 Thomas Koenig 2019-08-14 10:15:33 UTC
Any solution for 40976 will also fix this one.

*** This bug has been marked as a duplicate of bug 40976 ***
Comment 3 Thomas Koenig 2019-08-15 11:52:51 UTC
Changed my mind :-)

It's the next logical step after the fix for 91443 goes in.
Comment 4 Thomas Koenig 2019-08-18 09:46:56 UTC
I'm currently working on this... finding a lot of interesting
cases in the test suite, in particular one where I am not sure
what to do.

The test case is gfortran.dg/goacc/acc_on_device-1.f95 , and the code is

! Have to enable optimizations, as otherwise builtins won't be expanded.
! { dg-additional-options "-O -fdump-rtl-expand" }

logical function f ()
  implicit none

  external acc_on_device
  logical (4) acc_on_device

  f = .false.
  f = f .or. acc_on_device ()
  f = f .or. acc_on_device (1, 2)
  f = f .or. acc_on_device (3.14)
  f = f .or. acc_on_device ("hello")

  return
end function f

! Unsuitable to be handled as a builtin, so we're expecting four calls.
! { dg-final { scan-rtl-dump-times "\\\(call \[^\\n\]* acc_on_device" 4 "expand" } }

With my current patch, this would result in

/home/ig25/Gcc/trunk/gcc/testsuite/gfortran.dg/goacc/acc_on_device-1.f95:12:12:

   11 |   f = f .or. acc_on_device ()
      |            2
   12 |   f = f .or. acc_on_device (1, 2)
      |            1
Error: More actual than formal arguments in procedure call at (1) for procedure defined at (2)
/home/ig25/Gcc/trunk/gcc/testsuite/gfortran.dg/goacc/acc_on_device-1.f95:13:12:

   11 |   f = f .or. acc_on_device ()
      |            2
   12 |   f = f .or. acc_on_device (1, 2)
   13 |   f = f .or. acc_on_device (3.14)
      |            1
Error: More actual than formal arguments in procedure call at (1) for procedure defined at (2)
/home/ig25/Gcc/trunk/gcc/testsuite/gfortran.dg/goacc/acc_on_device-1.f95:14:12:

   11 |   f = f .or. acc_on_device ()
      |            2
......
   14 |   f = f .or. acc_on_device ("hello")
      |            1
Error: More actual than formal arguments in procedure call at (1) for procedure defined at (2)

where the warnings could be mitigated to a warning using -std=legacy.

Now, needless to say, this is illegal Fortran. Is the test case actually
a valid use case?  Wouldn't it be better to make this into an intrinsic
with -fopenacc? Would it be acceptable to have to set -std=legacy on that
particular use case?
Comment 5 Thomas Koenig 2019-08-18 12:03:11 UTC
Created attachment 46724 [details]
Something that sort of works...

and also extends the error message with a reference to where the
mismatching procedure is defined.
Comment 6 Thomas Koenig 2019-08-18 22:22:43 UTC
Created attachment 46726 [details]
Much better patch

It a) does not try to do two things at once, and b) has passed
regression-testing at least once.
Comment 7 Thomas Koenig 2019-08-24 21:13:17 UTC
Author: tkoenig
Date: Sat Aug 24 21:12:45 2019
New Revision: 274902

URL: https://gcc.gnu.org/viewcvs?rev=274902&root=gcc&view=rev
Log:
2019-08-24  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/91390
	PR fortran/91519
	* frontend-passes.c (check_externals_procedure): New
	function. If a procedure is not in the translation unit, create
	an "interface" for it, including its formal arguments.
	(check_externals_code): Use check_externals_procedure for common
	code with check_externals_expr.
	(check_externals_expr): Vice versa.
	* gfortran.h (gfc_get_formal_from_actual-arglist): New prototype.
	(gfc_compare_actual_formal): New prototype.
	* interface.c (compare_actual_formal): Rename to
	(gfc_compare_actual_formal): New function, make global.
	(gfc_get_formal_from_actual_arglist): Make global, and move here from
	* trans-types.c (get_formal_from_actual_arglist): Remove here.
	(gfc_get_function_type): Use gfc_get_formal_from_actual_arglist.

2019-08-24  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/91390
	PR fortran/91519
	* gfortran.dg/bessel_3.f90: Add type mismatch errors.
	* gfortran.dg/coarray_7.f90: Rename subroutines to avoid
	additional errors.
	* gfortran.dg/g77/20010519-1.f: Add -std=legacy. Remove
	warnings for ASSIGN. Add warnings for type mismatch.
	* gfortran.dg/goacc/acc_on_device-1.f95: Add -std=legacy.
	Add catch-all warning.
	* gfortran.dg/internal_pack_9.f90: Rename subroutine to
	avoid type error.
	* gfortran.dg/internal_pack_9.f90: Add -std=legacy. Add
	warnings for type mismatch.
	* gfortran.dg/pr39937.f: Add -std=legacy and type warnings. Move
	here from
	* gfortran.fortran-torture/compile/pr39937.f: Move to
	gfortran.dg.


Added:
    trunk/gcc/testsuite/gfortran.dg/pr39937.f
Removed:
    trunk/gcc/testsuite/gfortran.fortran-torture/compile/pr39937.f
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/frontend-passes.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/bessel_3.f90
    trunk/gcc/testsuite/gfortran.dg/coarray_7.f90
    trunk/gcc/testsuite/gfortran.dg/g77/20010519-1.f
    trunk/gcc/testsuite/gfortran.dg/goacc/acc_on_device-1.f95
    trunk/gcc/testsuite/gfortran.dg/internal_pack_9.f90
    trunk/gcc/testsuite/gfortran.dg/pr24823.f
Comment 8 Thomas Koenig 2019-08-26 20:06:03 UTC
Author: tkoenig
Date: Mon Aug 26 20:05:32 2019
New Revision: 274937

URL: https://gcc.gnu.org/viewcvs?rev=274937&root=gcc&view=rev
Log:
2019-08-26  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/91390
	PR fortran/91473
	* frontend-passes.c (gfc_check_externals): Make
	gfc_errors_to_warnings conditional on -fallow-argument-mismatch.
	* invoke.texi: Document -fallow-argument-mismatch.
	* lang.opt: Add -fallow-argument-mismatch.

2019-08-26  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/91390
	PR fortran/91473
	* gfortran.dg/used_before_typed_4.f90: Change warning to error.
	* gfortran.dg/argument_checking_20.f90: New test.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/frontend-passes.c
    trunk/gcc/fortran/invoke.texi
    trunk/gcc/fortran/lang.opt
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/used_before_typed_4.f90
Comment 9 Thomas Koenig 2019-08-26 20:07:37 UTC
OK, I think we can mark this as fixed.

Thanks for the report!  I wasn't aware that this would open such
a can of worms...