From f2f8171fb15c0cdbefdead5387d5d253c4008ff2 Mon Sep 17 00:00:00 2001
From: Janus Weil <janus@gcc.gnu.org>
Date: Fri, 12 Oct 2012 10:16:17 +0200
Subject: [PATCH] re PR fortran/40453 ([F95] Enhanced (recursive) argument
 checking)

2012-10-12  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/40453
	* interface.c (check_dummy_characteristics): Recursively check dummy
	procedures.

2012-10-12  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/40453
	* gfortran.dg/dummy_procedure_9.f90: New.

From-SVN: r192391
---
 gcc/fortran/ChangeLog                         |  6 +++
 gcc/fortran/interface.c                       | 13 +++++++
 gcc/testsuite/ChangeLog                       |  5 +++
 .../gfortran.dg/dummy_procedure_9.f90         | 37 +++++++++++++++++++
 4 files changed, 61 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/dummy_procedure_9.f90

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index a3d282b15a88..ad701865927d 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,9 @@
+2012-10-12  Janus Weil  <janus@gcc.gnu.org>
+
+	PR fortran/40453
+	* interface.c (check_dummy_characteristics): Recursively check dummy
+	procedures.
+
 2012-10-11  Janus Weil  <janus@gcc.gnu.org>
 
 	PR fortran/54784
diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index 4822149cc0bd..2bdabfe806cd 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -1063,6 +1063,19 @@ check_dummy_characteristics (gfc_symbol *s1, gfc_symbol *s2,
   /* FIXME: Do more comprehensive testing of attributes, like e.g.
 	    ASYNCHRONOUS, CONTIGUOUS, VALUE, VOLATILE, etc.  */
 
+  /* Check interface of dummy procedures.  */
+  if (s1->attr.flavor == FL_PROCEDURE)
+    {
+      char err[200];
+      if (!gfc_compare_interfaces (s1, s2, s2->name, 0, 1, err, sizeof(err),
+				   NULL, NULL))
+	{
+	  snprintf (errmsg, err_len, "Interface mismatch in dummy procedure "
+		    "'%s': %s", s1->name, err);
+	  return FAILURE;
+	}
+    }
+
   /* Check string length.  */
   if (s1->ts.type == BT_CHARACTER
       && s1->ts.u.cl && s1->ts.u.cl->length
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 776727c88afb..0612d04351fa 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2012-10-12  Janus Weil  <janus@gcc.gnu.org>
+
+	PR fortran/40453
+	* gfortran.dg/dummy_procedure_9.f90: New.
+
 2012-10-12  Richard Biener  <rguenther@suse.de>
 
 	PR tree-optimization/54894
diff --git a/gcc/testsuite/gfortran.dg/dummy_procedure_9.f90 b/gcc/testsuite/gfortran.dg/dummy_procedure_9.f90
new file mode 100644
index 000000000000..16da37f18931
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dummy_procedure_9.f90
@@ -0,0 +1,37 @@
+! { dg-do compile }
+!
+! PR 40453: [F95] Enhanced (recursive) argument checking
+!
+! Contributed by Tobias Burnus <burnus@gcc.gnu.org>
+
+program RecursiveInterface
+  
+  call c(b2)  ! { dg-error "Interface mismatch in dummy procedure" }
+
+ contains
+
+    subroutine a1(x)
+      real :: x
+    end subroutine
+
+    subroutine a2(i)
+      integer :: i
+    end subroutine
+
+    !!!!!!!!!!!!!!!
+
+    subroutine b1 (f1)
+      procedure(a1) :: f1
+    end subroutine
+
+    subroutine b2 (f2)
+      procedure(a2) :: f2
+    end subroutine
+
+    !!!!!!!!!!!!!!!
+
+    subroutine c(g)
+     procedure(b1) :: g
+    end subroutine
+  
+end
-- 
GitLab