Bug 36459 - Wrong interface use for PROCEDURE
Summary: Wrong interface use for PROCEDURE
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2008-06-07 18:24 UTC by Tobias Burnus
Modified: 2008-06-08 12:16 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-06-07 21:01:38


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2008-06-07 18:24:21 UTC
The following valid program is rejected. The problem is that gfortran assigns the interface of the INTRINSIC function "cos" to "f" and not the one of the abstract interface. If one uses "interface" instead of "abstract interface" it works.

abstract interface
  function dim()
    integer :: dim
  end function dim
end interface
procedure(dim) :: f
print *, f()
end
Comment 1 janus 2008-06-07 20:15:13 UTC
> The problem is that gfortran assigns the interface
> of the INTRINSIC function "cos" to "f"

You surely mean the intrinsic function DIM ;)


> If one uses "interface" instead of "abstract interface" it works.

No, for me it actually doesn't make a difference.
In particular the following is also rejected:

interface
  integer function dim()
  end function
end interface
procedure(dim) :: f
print *, dim()
end

Without the PROCEDURE line it works fine.

Comment 2 janus 2008-06-07 21:01:38 UTC
This patch fixes both of the test cases in comment #0 and comment#1:

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c  (revision 136533)
+++ gcc/fortran/decl.c  (working copy)
@@ -4085,8 +4085,10 @@ match_procedure_decl (void)
          return MATCH_ERROR;
        }
       /* Handle intrinsic procedures.  */
-      if (gfc_intrinsic_name (proc_if->name, 0)
-         || gfc_intrinsic_name (proc_if->name, 1))
+      if (!(proc_if->attr.external || proc_if->attr.use_assoc
+           || proc_if->attr.if_source == IFSRC_IFBODY)
+         && (gfc_intrinsic_name (proc_if->name, 0)
+             || gfc_intrinsic_name (proc_if->name, 1)))
        proc_if->attr.intrinsic = 1;
       if (proc_if->attr.intrinsic
          && !gfc_intrinsic_actual_ok (proc_if->name, 0))

This is the same check that's done in resolve.c (resolve_actual_arglist) for dummy procedures.
Comment 3 Tobias Burnus 2008-06-07 21:15:50 UTC
> This is the same check that's done in resolve.c (resolve_actual_arglist) for
> dummy procedures.

Thanks for the quick patch.
(Do you think my patch for PR35830 is OK? Off topic: I'd really like to see proc pointers being checked in; one can still work afterwards on related PRs such as PR36322 or loosely related PRs PR35831 and PR36426.)
Comment 4 janus 2008-06-08 11:56:27 UTC
Subject: Bug 36459

Author: janus
Date: Sun Jun  8 11:55:41 2008
New Revision: 136555

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

	PR fortran/36459
	* decl.c (match_procedure_decl): Correctly recognize if the interface
	is an intrinsic procedure.


2008-06-08  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/36459
	* gfortran.dg/proc_decl_16.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/proc_decl_16.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 janus 2008-06-08 12:16:18 UTC
Fixed in rev 136555. Closing.