public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/46952] New: Spurious "recursive call" error with type bound procedure
@ 2010-12-15  2:46 ian_harvey at bigpond dot com
  2010-12-15  8:25 ` [Bug fortran/46952] [OOP] " burnus at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: ian_harvey at bigpond dot com @ 2010-12-15  2:46 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Spurious "recursive call" error with type bound
                    procedure
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ian_harvey@bigpond.com


Created attachment 22759
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22759
Example that generate the error

The attached, using a gfortran 4.6 from November 3 on i686-pc-mingw32,
generates the error "SUBROUTINE 'relay_proc' ... cannot be called recursively".
 But I don't think the call is recursive - relay_proc is just the interface for
what gets called, not the actual procedure.

But Intel Fortran 12.0.1.127 also complains, so maybe I'm wrong.


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

* [Bug fortran/46952] [OOP] Spurious "recursive call" error with type bound procedure
  2010-12-15  2:46 [Bug fortran/46952] New: Spurious "recursive call" error with type bound procedure ian_harvey at bigpond dot com
@ 2010-12-15  8:25 ` burnus at gcc dot gnu.org
  2010-12-15  8:38 ` burnus at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2010-12-15  8:25 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |ice-on-invalid-code,
                   |                            |rejects-valid
   Last reconfirmed|                            |2010.12.15 08:25:18
                 CC|                            |burnus at gcc dot gnu.org,
                   |                            |janus at gcc dot gnu.org
     Ever Confirmed|0                           |1
            Summary|Spurious "recursive call"   |[OOP] Spurious "recursive
                   |error with type bound       |call" error with type bound
                   |procedure                   |procedure

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2010-12-15 08:25:18 UTC ---
At a glance it looks valid to me. The crucial part seems to be:

  PROCEDURE(relay_proc), DEFERRED :: TwoProc
...
  SUBROUTINE relay_proc(obj)
    CALL obj%TwoProc
                    1
Error: SUBROUTINE 'relay_proc' at (1) cannot be called recursively, as it is
not RECURSIVE

  *  *  *

I managed to create an ICE-on-invalid-code: The following program segfaults w/o
printing any error/warning message at

==31463== Invalid read of size 1
==31463==    at 0x50871E: gfc_match_varspec (primary.c:1771)
==31463==    by 0x4F06A3: gfc_match_call (match.c:3442)
==31463==    by 0x501622: match_word (parse.c:65)


The following program is invalid for several reasons: the ICE seems to be due
to "bar" having no dummy argument. If one adds one, one gets the bogus
"recursive" error; fixing that one gets the correct error that the argument
must be of type CLASS(t2) and not of CLASS(t).

module m
  type, abstract :: t
  contains
    procedure(bar), pass, deferred :: foo
    procedure(bar), pass, deferred :: bar
  end type
  type,extends(t) :: t2
  contains
    procedure, pass :: bar => bar
    procedure, pass :: foo => foo
  end type t2
contains
  subroutine foo(this)
    class(t) :: this
  end subroutine foo
  subroutine bar()   ! pass but "this" argument is missing; no error only ICE
    class(t) :: this
    call this%foo()
  end subroutine
end module m


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

* [Bug fortran/46952] [OOP] Spurious "recursive call" error with type bound procedure
  2010-12-15  2:46 [Bug fortran/46952] New: Spurious "recursive call" error with type bound procedure ian_harvey at bigpond dot com
  2010-12-15  8:25 ` [Bug fortran/46952] [OOP] " burnus at gcc dot gnu.org
@ 2010-12-15  8:38 ` burnus at gcc dot gnu.org
  2013-01-10  8:51 ` janus at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2010-12-15  8:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2010-12-15 08:37:42 UTC ---
Reduced test case. Crucial seems to be that "inter" and "bar" call "foo" and
that foo and bar are defined via the interface "inter".

Similarly to gfortran and ifort also Crayftn rejects the following program.
However, I do no see any possibility how one could create a recursive call.
Thus, I do not see the need for a RECURSIVE attribute ("The RECURSIVE
prefix-spec shall appear if any procedure defined by the subprogram directly or
indirectly invokes itself or any other procedure defined by the subprogram.")

module m
  type, abstract :: t
  contains
    procedure(inter), pass, deferred :: foo
    procedure(inter), pass, deferred :: bar
  end type
  type,extends(t) :: t2
  contains
    procedure, pass :: bar => bar
    procedure, pass :: foo => foo
  end type t2
contains
  subroutine inter(this)
    class(t) :: this
    call this%foo()
  end subroutine inter
  subroutine foo(this)
    class(t2) :: this
  end subroutine foo
  subroutine bar(this)
    class(t2) :: this
    call this%foo()
  end subroutine
end module m


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

* [Bug fortran/46952] [OOP] Spurious "recursive call" error with type bound procedure
  2010-12-15  2:46 [Bug fortran/46952] New: Spurious "recursive call" error with type bound procedure ian_harvey at bigpond dot com
  2010-12-15  8:25 ` [Bug fortran/46952] [OOP] " burnus at gcc dot gnu.org
  2010-12-15  8:38 ` burnus at gcc dot gnu.org
@ 2013-01-10  8:51 ` janus at gcc dot gnu.org
  2013-01-10 11:49 ` janus at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu.org @ 2013-01-10  8:51 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from janus at gcc dot gnu.org 2013-01-10 08:50:51 UTC ---
Further reducing the test case:


module m

  type, abstract :: t
  contains
    procedure(inter), pass, deferred :: foo
  end type

contains

  subroutine inter(this)
    class(t) :: this
    call this%foo()
  end subroutine inter

end module m


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

* [Bug fortran/46952] [OOP] Spurious "recursive call" error with type bound procedure
  2010-12-15  2:46 [Bug fortran/46952] New: Spurious "recursive call" error with type bound procedure ian_harvey at bigpond dot com
                   ` (2 preceding siblings ...)
  2013-01-10  8:51 ` janus at gcc dot gnu.org
@ 2013-01-10 11:49 ` janus at gcc dot gnu.org
  2013-01-10 14:10 ` janus at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu.org @ 2013-01-10 11:49 UTC (permalink / raw)
  To: gcc-bugs


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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |janus at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #4 from janus at gcc dot gnu.org 2013-01-10 11:48:54 UTC ---
I think the following patch makes sense:

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c    (revision 194927)
+++ gcc/fortran/resolve.c    (working copy)
@@ -3803,7 +3803,7 @@ resolve_call (gfc_code *c)

   /* Subroutines without the RECURSIVE attribution are not allowed to
    * call themselves.  */
-  if (csym && is_illegal_recursion (csym, gfc_current_ns))
+  if (!c->expr1 && csym && is_illegal_recursion (csym, gfc_current_ns))
     {
       if (csym->attr.entry && csym->ns->entries)
     gfc_error ("ENTRY '%s' at %L cannot be called recursively, as"


This is the same workaround that we use in resolve_call for deferred TBPs with
abstract interfaces.


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

* [Bug fortran/46952] [OOP] Spurious "recursive call" error with type bound procedure
  2010-12-15  2:46 [Bug fortran/46952] New: Spurious "recursive call" error with type bound procedure ian_harvey at bigpond dot com
                   ` (3 preceding siblings ...)
  2013-01-10 11:49 ` janus at gcc dot gnu.org
@ 2013-01-10 14:10 ` janus at gcc dot gnu.org
  2013-01-18 21:30 ` janus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu.org @ 2013-01-10 14:10 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #5 from janus at gcc dot gnu.org 2013-01-10 14:09:54 UTC ---
The following patch is equivalent in functionality to the one in comment 4, but
includes some minor cleanup (and regtests cleanly):


Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c    (revision 194927)
+++ gcc/fortran/resolve.c    (working copy)
@@ -3792,28 +3792,30 @@ resolve_call (gfc_code *c)
     }
     }

-  /* If this ia a deferred TBP with an abstract interface
-     (which may of course be referenced), c->expr1 will be set.  */
-  if (csym && csym->attr.abstract && !c->expr1)
+  /* If this ia a deferred TBP, c->expr1 will be set.  */
+  if (!c->expr1 && csym)
     {
-      gfc_error ("ABSTRACT INTERFACE '%s' must not be referenced at %L",
-         csym->name, &c->loc);
-      return FAILURE;
-    }
+      if (csym->attr.abstract)
+    {
+      gfc_error ("ABSTRACT INTERFACE '%s' must not be referenced at %L",
+            csym->name, &c->loc);
+      return FAILURE;
+    }

-  /* Subroutines without the RECURSIVE attribution are not allowed to
-   * call themselves.  */
-  if (csym && is_illegal_recursion (csym, gfc_current_ns))
-    {
-      if (csym->attr.entry && csym->ns->entries)
-    gfc_error ("ENTRY '%s' at %L cannot be called recursively, as"
-           " subroutine '%s' is not RECURSIVE",
-           csym->name, &c->loc, csym->ns->entries->sym->name);
-      else
-    gfc_error ("SUBROUTINE '%s' at %L cannot be called recursively, as it"
-           " is not RECURSIVE", csym->name, &c->loc);
+      /* Subroutines without the RECURSIVE attribution are not allowed to
+     call themselves.  */
+      if (is_illegal_recursion (csym, gfc_current_ns))
+    {
+      if (csym->attr.entry && csym->ns->entries)
+        gfc_error ("ENTRY '%s' at %L cannot be called recursively, "
+               "as subroutine '%s' is not RECURSIVE",
+               csym->name, &c->loc, csym->ns->entries->sym->name);
+      else
+        gfc_error ("SUBROUTINE '%s' at %L cannot be called recursively, "
+               "as it is not RECURSIVE", csym->name, &c->loc);

-      t = FAILURE;
+      t = FAILURE;
+    }
     }

   /* Switch off assumed size checking and do this again for certain kinds


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

* [Bug fortran/46952] [OOP] Spurious "recursive call" error with type bound procedure
  2010-12-15  2:46 [Bug fortran/46952] New: Spurious "recursive call" error with type bound procedure ian_harvey at bigpond dot com
                   ` (4 preceding siblings ...)
  2013-01-10 14:10 ` janus at gcc dot gnu.org
@ 2013-01-18 21:30 ` janus at gcc dot gnu.org
  2013-02-12 12:16 ` janus at gcc dot gnu.org
  2013-02-12 12:21 ` janus at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu.org @ 2013-01-18 21:30 UTC (permalink / raw)
  To: gcc-bugs


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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|ice-on-invalid-code         |

--- Comment #6 from janus at gcc dot gnu.org 2013-01-18 21:29:42 UTC ---
(In reply to comment #1) 
> I managed to create an ICE-on-invalid-code: The following program segfaults w/o
> printing any error/warning message at

I don't see the ICE with any of 4.6, 4.7 and trunk.


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

* [Bug fortran/46952] [OOP] Spurious "recursive call" error with type bound procedure
  2010-12-15  2:46 [Bug fortran/46952] New: Spurious "recursive call" error with type bound procedure ian_harvey at bigpond dot com
                   ` (5 preceding siblings ...)
  2013-01-18 21:30 ` janus at gcc dot gnu.org
@ 2013-02-12 12:16 ` janus at gcc dot gnu.org
  2013-02-12 12:21 ` janus at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu.org @ 2013-02-12 12:16 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #7 from janus at gcc dot gnu.org 2013-02-12 12:15:40 UTC ---
Author: janus
Date: Tue Feb 12 12:15:26 2013
New Revision: 195975

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195975
Log:
2013-02-12  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/46952
    * resolve.c (resolve_call): Do not check deferred procedures for
    recursiveness.


2013-02-12  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/46952
    * gfortran.dg/typebound_deferred_1.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/typebound_deferred_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug fortran/46952] [OOP] Spurious "recursive call" error with type bound procedure
  2010-12-15  2:46 [Bug fortran/46952] New: Spurious "recursive call" error with type bound procedure ian_harvey at bigpond dot com
                   ` (6 preceding siblings ...)
  2013-02-12 12:16 ` janus at gcc dot gnu.org
@ 2013-02-12 12:21 ` janus at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu.org @ 2013-02-12 12:21 UTC (permalink / raw)
  To: gcc-bugs


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

janus at gcc dot gnu.org changed:

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

--- Comment #8 from janus at gcc dot gnu.org 2013-02-12 12:21:01 UTC ---
Fixed with r195975. Closing.


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

end of thread, other threads:[~2013-02-12 12:21 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-15  2:46 [Bug fortran/46952] New: Spurious "recursive call" error with type bound procedure ian_harvey at bigpond dot com
2010-12-15  8:25 ` [Bug fortran/46952] [OOP] " burnus at gcc dot gnu.org
2010-12-15  8:38 ` burnus at gcc dot gnu.org
2013-01-10  8:51 ` janus at gcc dot gnu.org
2013-01-10 11:49 ` janus at gcc dot gnu.org
2013-01-10 14:10 ` janus at gcc dot gnu.org
2013-01-18 21:30 ` janus at gcc dot gnu.org
2013-02-12 12:16 ` janus at gcc dot gnu.org
2013-02-12 12:21 ` 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).