Bug 34763 - bare END not allowed in an interface block in a module procedure
Summary: bare END not allowed in an interface block in a module procedure
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Tobias Burnus
URL:
Keywords: rejects-valid
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2008-01-12 21:03 UTC by Dick Hendrickson
Modified: 2008-01-13 21:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-01-12 22:35:19


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dick Hendrickson 2008-01-12 21:03:48 UTC
With gfortran 4.3.0 20080109 I get the error message

n_interface.f:7.12:

            END
           1
Error: END SUBROUTINE statement expected at (1)

with the following program
      module n
      contains
      subroutine n_interface
      INTERFACE
            SUBROUTINE NGSXDY(TLS1,TLS2)
            REAL  ::  TLS1,TLS2
            END                 
      END INTERFACE
      end
      end module

If the n_interface is an external procedure it works fine.  A bare
END statement is allowed in interface blocks.  I'd guess you
are misapplying the constraint after R1224 to things inside of
interface blocks.  But NGSXDY isn't a module subroutine.  You'll
probably need a similar fix for functions in interface blocks,
although I haven't tried that.

Dick Hendrickson
Comment 1 Tobias Burnus 2008-01-12 21:23:52 UTC
Confirm. (Though you missed "subroutine" for "end subroutine n_interface" in your example.)

The Fortran 2003 references are:
  C1243 (R1230) FUNCTION shall appear in the end-function-stmt of an internal
                or module function.
and
  C1248 (R1234) SUBROUTINE shall appear in the end-subroutine-stmt of an
                internal or module subroutine.

Seemingly, the contained_procedure() check in decl.c, called by gfc_match_end, does not work properly.

Thanks for report.
Comment 2 Tobias Burnus 2008-01-12 22:35:19 UTC
I believe the following patch is correct.

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c  (revision 131492)
+++ gcc/fortran/decl.c  (working copy)
@@ -4870,12 +4870,11 @@ gfc_match_bind_c (gfc_symbol *sym, bool
 static int
 contained_procedure (void)
 {
-  gfc_state_data *s;
+  gfc_state_data *s = gfc_state_stack;

-  for (s=gfc_state_stack; s; s=s->previous)
-    if ((s->state == COMP_SUBROUTINE || s->state == COMP_FUNCTION)
-       && s->previous != NULL && s->previous->state == COMP_CONTAINS)
-      return 1;
+  if ((s->state == COMP_SUBROUTINE || s->state == COMP_FUNCTION)
+      && s->previous != NULL && s->previous->state == COMP_CONTAINS)
+    return 1;

   return 0;
 }
Comment 3 Tobias Burnus 2008-01-13 17:41:33 UTC
Patch: http://gcc.gnu.org/ml/gcc-patches/2008-01/msg00567.html
Comment 4 Tobias Burnus 2008-01-13 21:30:33 UTC
Subject: Bug 34763

Author: burnus
Date: Sun Jan 13 21:29:49 2008
New Revision: 131512

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131512
Log:
2008-01-13  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34763
        * decl.c (contained_procedure): Only check directly preceeding
        * state.

2008-01-13  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34763
        * gfortran.dg/interface_proc_end.f90: New.


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

Comment 5 Tobias Burnus 2008-01-13 21:49:17 UTC
Fixed on the trunk (4.3.0).

Thanks for the report!