From 083de129c8dd26ae3dcd5f24c77a3f424763e69f Mon Sep 17 00:00:00 2001
From: Tobias Burnus <burnus@net-b.de>
Date: Sun, 13 Jan 2008 22:29:49 +0100
Subject: [PATCH] re PR fortran/34763 (bare END not allowed in an interface
 block in a module procedure)

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.

From-SVN: r131512
---
 gcc/fortran/ChangeLog                         |  5 +++++
 gcc/fortran/decl.c                            |  9 ++++-----
 gcc/testsuite/ChangeLog                       |  5 +++++
 .../gfortran.dg/interface_proc_end.f90        | 19 +++++++++++++++++++
 4 files changed, 33 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/interface_proc_end.f90

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 5f94e76b0462..683d66bbf913 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,8 @@
+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/34759
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index dd8eb35ae6b5..74d096267bc1 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -4870,12 +4870,11 @@ gfc_match_bind_c (gfc_symbol *sym, bool allow_binding_name)
 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;
 }
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 98557e6043f0..09b233e06440 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2008-01-13  Tobias Burnus  <burnus@net-b.de>
+
+	PR fortran/34763
+	* gfortran.dg/interface_proc_end.f90: New.
+
 2008-01-13  Tobias Burnus  <burnus@net-b.de>
 
 	PR fortran/34759
diff --git a/gcc/testsuite/gfortran.dg/interface_proc_end.f90 b/gcc/testsuite/gfortran.dg/interface_proc_end.f90
new file mode 100644
index 000000000000..d037de694a52
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/interface_proc_end.f90
@@ -0,0 +1,19 @@
+! { dg-do compile}
+!
+! PR fortran/34763
+! Before, gfortran did not allow for the "END" in
+! the interface, which is no module procedure.
+!
+! Test case contributed by Dick Hendrickson
+!
+      module n
+      contains
+      subroutine n_interface
+      INTERFACE
+            SUBROUTINE NGSXDY(TLS1,TLS2)
+            REAL  ::  TLS1,TLS2
+            END ! OK
+      END INTERFACE
+      end ! { dg-error "END SUBROUTINE statement" }
+      end module ! { dg-error "END SUBROUTINE statement" }
+! { dg-excess-errors "Unexpected end of file" }
-- 
GitLab