public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/40039]  New: Procedures as actual arguments: Check intent of arguments
@ 2009-05-06  8:51 janus at gcc dot gnu dot org
  2009-05-06 10:30 ` [Bug fortran/40039] " burnus at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2009-05-06  8:51 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1375 bytes --]

Consider the following module:


module m

contains

subroutine a(x,f)
  real :: x
  interface
    real function f(y)
      real,intent(in) :: y
    end function
  end interface
  print *,f(x)
end subroutine

real function func(z)
  real,intent(inout) :: z
  func = z**2
end function

subroutine caller
  call a(4.3,func)
end subroutine

end module 


ifort complains:
error #7061: The characteristics of dummy argument 1 of the associated actual
procedure differ from the characteristics of dummy argument 1 of the dummy
procedure. (12.2)   [FUNC]
  call a(4.3,func)

Although gfortran, g95 and sunf95 accept it, I think ifort is right to reject
it (but I haven't checked the standard yet). The same check should also be
applied to procedure pointer assignments.

Btw "gfortran -Wall -Wextra" produces this warning:
test.f90:5: warning: unused parameter ‘f’
This is bogus, because 'f' *is* used in the subroutine a.


-- 
           Summary: Procedures as actual arguments: Check intent of
                    arguments
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: janus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40039


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/40039] Procedures as actual arguments: Check intent of arguments
  2009-05-06  8:51 [Bug fortran/40039] New: Procedures as actual arguments: Check intent of arguments janus at gcc dot gnu dot org
@ 2009-05-06 10:30 ` burnus at gcc dot gnu dot org
  2009-05-07 21:44 ` janus at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-05-06 10:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from burnus at gcc dot gnu dot org  2009-05-06 10:29 -------
NAG f95 5.1 gives the following error:

Error: line 21: Dummy proc F arg 1 has different INTENT from actual proc FUNC
arg
Error: line 21: Incompatible procedure argument for F (no. 2) of A

After fixing this (intent INOUT -> IN), it is accepted by NAG f95. I think that
is the same as the error message of ifort.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40039


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/40039] Procedures as actual arguments: Check intent of arguments
  2009-05-06  8:51 [Bug fortran/40039] New: Procedures as actual arguments: Check intent of arguments janus at gcc dot gnu dot org
  2009-05-06 10:30 ` [Bug fortran/40039] " burnus at gcc dot gnu dot org
@ 2009-05-07 21:44 ` janus at gcc dot gnu dot org
  2009-05-13 17:16 ` janus at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2009-05-07 21:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from janus at gcc dot gnu dot org  2009-05-07 21:44 -------
Here is a preliminary patch which correctly rejects the code in comment #0:

Index: gcc/fortran/interface.c
===================================================================
--- gcc/fortran/interface.c     (revision 147246)
+++ gcc/fortran/interface.c     (working copy)
@@ -873,23 +873,29 @@
    which makes this test much easier than that for generic tests.

    This subroutine is also used when comparing a formal and actual
-   argument list when an actual parameter is a dummy procedure.  At
-   that point, two formal interfaces must be compared for equality
-   which is what happens here.  */
+   argument list when an actual parameter is a dummy procedure, and in
+   procedure pointer assignments. In these cases, two formal interfaces must
be
+   compared for equality which is what happens here.  */

 static int
 operator_correspondence (gfc_formal_arglist *f1, gfc_formal_arglist *f2)
 {
   for (;;)
     {
+      /* Check existence.  */
       if (f1 == NULL && f2 == NULL)
        break;
       if (f1 == NULL || f2 == NULL)
        return 1;

+      /* Check type and rank.  */
       if (!compare_type_rank (f1->sym, f2->sym))
        return 1;

+      /* Check intent.  */
+      if (f1->sym->attr.intent != f2->sym->attr.intent)
+       return 1;
+
       f1 = f1->next;
       f2 = f2->next;
     }

However, it produces three testsuite failures:

FAIL: gfortran.dg/defined_operators_1.f90  -O   (test for errors, line 14)
FAIL: gfortran.dg/interface_19.f90  -O0  (test for excess errors)
FAIL: gfortran.dg/proc_ptr_result_1.f90  -O0  (test for excess errors)

The last of these three test cases is probably invalid, the second failure
seems to be a problem with intrinsics, and about the first one I'm not sure.


-- 

janus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |janus at gcc dot gnu dot org
                   |dot org                     |
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-05-07 21:44:33
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40039


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/40039] Procedures as actual arguments: Check intent of arguments
  2009-05-06  8:51 [Bug fortran/40039] New: Procedures as actual arguments: Check intent of arguments janus at gcc dot gnu dot org
  2009-05-06 10:30 ` [Bug fortran/40039] " burnus at gcc dot gnu dot org
  2009-05-07 21:44 ` janus at gcc dot gnu dot org
@ 2009-05-13 17:16 ` janus at gcc dot gnu dot org
  2009-05-18  9:19 ` janus at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2009-05-13 17:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from janus at gcc dot gnu dot org  2009-05-13 17:15 -------

> FAIL: gfortran.dg/interface_19.f90  -O0  (test for excess errors)
> FAIL: gfortran.dg/proc_ptr_result_1.f90  -O0  (test for excess errors)
> 
> The last of these three test cases is probably invalid, the second failure
> seems to be a problem with intrinsics, and about the first one I'm not sure.

For intrinsics, the intent of the arguments is currently not considered at all.
We need gfc_intrinsic_arg to have an 'intent' member. The F03 standard says:   

The dummy arguments of the specific intrinsic procedures in 13.6 have
INTENT(IN). The dummy arguments of the generic intrinsic procedures in 13.7
have INTENT(IN) if the intent is not stated explicitly.

The test case proc_ptr_result_1.f90 is invalid indeed. Relevant quote from the
standard:

Section 5.1.2.7:
INTENT (INOUT) is not equivalent to omitting the INTENT attribute. The argument
corresponding to an INTENT (INOUT) dummy argument always shall be definable,
while an argument corresponding to a dummy argument without an INTENT attribute
need be definable only if the dummy argument is actually redefined.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40039


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/40039] Procedures as actual arguments: Check intent of arguments
  2009-05-06  8:51 [Bug fortran/40039] New: Procedures as actual arguments: Check intent of arguments janus at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2009-05-13 17:16 ` janus at gcc dot gnu dot org
@ 2009-05-18  9:19 ` janus at gcc dot gnu dot org
  2009-05-18  9:28 ` janus at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2009-05-18  9:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from janus at gcc dot gnu dot org  2009-05-18 09:19 -------
Subject: Bug 40039

Author: janus
Date: Mon May 18 09:19:20 2009
New Revision: 147655

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147655
Log:
2009-05-18  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/36947
        PR fortran/40039
        * expr.c (gfc_check_pointer_assign): Check intents when comparing
        interfaces.
        * gfortran.h (typedef struct gfc_intrinsic_arg): Add 'intent' member.
        (gfc_compare_interfaces): Additional argument.
        * interface.c (operator_correspondence): Add check for equality of
        intents, and new argument 'intent_check'.
        (gfc_compare_interfaces): New argument 'intent_check', which is passed
        on to operator_correspondence.
        (check_interface1): Don't check intents when comparing interfaces.
        (compare_parameter): Do check intents when comparing interfaces.
        * intrinsic.c (add_sym): Add intents for arguments of intrinsic
        procedures.
        (add_sym_1,add_sym_1s,add_sym_1m,add_sym_2,add_sym_2s,add_sym_3,
        add_sym_3ml,add_sym_3red,add_sym_3s,add_sym_4): Use INTENT_IN by
        default.
       
(add_sym_1_intent,add_sym_1s_intent,add_sym_2s_intent,add_sym_3s_intent)
        : New functions to add intrinsic symbols, specifying custom intents.
        (add_sym_4s,add_sym_5s): Add new arguments to specify intents.
        (add_functions,add_subroutines): Add intents for various intrinsics.
        * resolve.c (check_generic_tbp_ambiguity): Don't check intents when
        comparing interfaces.
        * symbol.c (gfc_copy_formal_args_intr): Copy intent.


2009-05-18  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/36947
        PR fortran/40039
        * gfortran.dg/interface_27.f90: New.
        * gfortran.dg/interface_28.f90: New.
        * gfortran.dg/proc_ptr_11.f90: Fixing invalid test case.
        * gfortran.dg/proc_ptr_result_1.f90: Ditto.


Added:
    trunk/gcc/testsuite/gfortran.dg/interface_27.f90
    trunk/gcc/testsuite/gfortran.dg/interface_28.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/intrinsic.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_11.f90
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_result_1.f90


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40039


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/40039] Procedures as actual arguments: Check intent of arguments
  2009-05-06  8:51 [Bug fortran/40039] New: Procedures as actual arguments: Check intent of arguments janus at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2009-05-18  9:19 ` janus at gcc dot gnu dot org
@ 2009-05-18  9:28 ` janus at gcc dot gnu dot org
  2009-06-16  9:06 ` janus at gcc dot gnu dot org
  2009-06-16  9:17 ` janus at gcc dot gnu dot org
  6 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2009-05-18  9:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from janus at gcc dot gnu dot org  2009-05-18 09:28 -------
The commit in comment #4 implements the basic checking of the intents.

ToDo:
 * Improve the error message, which is currently just "Type/rank mismatch in
argument ...". Should specify exactly what is not matching, and in which
argument.
 * Fix the intents of non-std intrinsics (which are currently all intent(in)).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40039


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/40039] Procedures as actual arguments: Check intent of arguments
  2009-05-06  8:51 [Bug fortran/40039] New: Procedures as actual arguments: Check intent of arguments janus at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2009-05-18  9:28 ` janus at gcc dot gnu dot org
@ 2009-06-16  9:06 ` janus at gcc dot gnu dot org
  2009-06-16  9:17 ` janus at gcc dot gnu dot org
  6 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2009-06-16  9:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from janus at gcc dot gnu dot org  2009-06-16 09:06 -------
Subject: Bug 40039

Author: janus
Date: Tue Jun 16 09:06:13 2009
New Revision: 148519

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148519
Log:
2009-06-16  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/36947
        PR fortran/40039
        * expr.c (gfc_check_pointer_assign): Call 'gfc_compare_interfaces' with
        error message.
        * gfortran.h (gfc_compare_interfaces): Additional argument.
        * interface.c (operator_correspondence): Removed.
        (gfc_compare_interfaces): Additional argument to return error message.
        Directly use the code from 'operator_correspondence' instead of calling
        the function. Check for OPTIONAL. Some rearrangements.
        (check_interface1): Call 'gfc_compare_interfaces' without error
message.
        (compare_parameter): Call 'gfc_compare_interfaces' with error message.
        * resolve.c (check_generic_tbp_ambiguity): Call
'gfc_compare_interfaces'
        without error message.


2009-06-16  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/36947
        PR fortran/40039
        * gfortran.dg/dummy_procedure_1.f90: Extended test case.
        * gfortran.dg/interface_20.f90: Modified error messages.
        * gfortran.dg/interface_21.f90: Ditto.
        * gfortran.dg/interface_26.f90: Ditto.
        * gfortran.dg/interface_27.f90: Ditto.
        * gfortran.dg/interface_28.f90: Extended test case.
        * gfortran.dg/interface_29.f90: New.
        * gfortran.dg/proc_decl_7.f90: Modified error messages.
        * gfortran.dg/proc_decl_8.f90: Ditto.
        * gfortran.dg/proc_ptr_11.f90: Ditto.
        * gfortran.dg/proc_ptr_15.f90: Ditto.


Added:
    trunk/gcc/testsuite/gfortran.dg/interface_29.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/dummy_procedure_1.f90
    trunk/gcc/testsuite/gfortran.dg/interface_20.f90
    trunk/gcc/testsuite/gfortran.dg/interface_21.f90
    trunk/gcc/testsuite/gfortran.dg/interface_26.f90
    trunk/gcc/testsuite/gfortran.dg/interface_27.f90
    trunk/gcc/testsuite/gfortran.dg/interface_28.f90
    trunk/gcc/testsuite/gfortran.dg/proc_decl_7.f90
    trunk/gcc/testsuite/gfortran.dg/proc_decl_8.f90
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_11.f90
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_15.f90


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40039


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/40039] Procedures as actual arguments: Check intent of arguments
  2009-05-06  8:51 [Bug fortran/40039] New: Procedures as actual arguments: Check intent of arguments janus at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2009-06-16  9:06 ` janus at gcc dot gnu dot org
@ 2009-06-16  9:17 ` janus at gcc dot gnu dot org
  6 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2009-06-16  9:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from janus at gcc dot gnu dot org  2009-06-16 09:17 -------
r148519 improves the error messages (besides adding a check for optional), so
the remaining ToDo item for this PR is: Fixing the intents of non-std
intrinsics (which are currently all intent(in)).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40039


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/40039] Procedures as actual arguments: Check intent of arguments
       [not found] <bug-40039-4@http.gcc.gnu.org/bugzilla/>
  2012-04-25 15:24 ` janus at gcc dot gnu.org
@ 2012-04-25 17:00 ` janus at gcc dot gnu.org
  1 sibling, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu.org @ 2012-04-25 17:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40039

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #9 from janus at gcc dot gnu.org 2012-04-25 17:00:20 UTC ---
(In reply to comment #8)
> > the remaining ToDo item for this PR is: Fixing the intents of non-std
> > intrinsics (which are currently all intent(in)).
> 
> I just went through the whole list and identified a few which apparently need
> fixing (hopefully complete):

Actually it seems that all of them were already fixed by r164052 (for PR43665).
So we can finally close this one.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/40039] Procedures as actual arguments: Check intent of arguments
       [not found] <bug-40039-4@http.gcc.gnu.org/bugzilla/>
@ 2012-04-25 15:24 ` janus at gcc dot gnu.org
  2012-04-25 17:00 ` janus at gcc dot gnu.org
  1 sibling, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu.org @ 2012-04-25 15:24 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40039

--- Comment #8 from janus at gcc dot gnu.org 2012-04-25 15:24:13 UTC ---
(In reply to comment #7)
> the remaining ToDo item for this PR is: Fixing the intents of non-std
> intrinsics (which are currently all intent(in)).

I just went through the whole list and identified a few which apparently need
fixing (hopefully complete):

 * ALARM
 * CHDIR
 * CHMOD
 * CTIME
 * DTIME
 * ETIME
 * FDATE
 * FGET
 * FGETC
 * FPUT
 * FPUTC
 * FSEEK
 * FSTAT
 * FTELL
 * GERROR
 * GETARG
 * GETCWD
 * GETENV
 * GETLOG
 * GMTIME
 * HOSTNM
 * IDATE
 * ITIME
 * KILL
 * LINK
 * LSTAT
 * LTIME
 * RENAME
 * SECOND
 * SIGNAL
 * STAT
 * SYMLINK
 * SYSTEM
 * TTYNAM
 * UMASK
 * UNLINK


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-04-25 17:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-06  8:51 [Bug fortran/40039] New: Procedures as actual arguments: Check intent of arguments janus at gcc dot gnu dot org
2009-05-06 10:30 ` [Bug fortran/40039] " burnus at gcc dot gnu dot org
2009-05-07 21:44 ` janus at gcc dot gnu dot org
2009-05-13 17:16 ` janus at gcc dot gnu dot org
2009-05-18  9:19 ` janus at gcc dot gnu dot org
2009-05-18  9:28 ` janus at gcc dot gnu dot org
2009-06-16  9:06 ` janus at gcc dot gnu dot org
2009-06-16  9:17 ` janus at gcc dot gnu dot org
     [not found] <bug-40039-4@http.gcc.gnu.org/bugzilla/>
2012-04-25 15:24 ` janus at gcc dot gnu.org
2012-04-25 17:00 ` janus at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).