From b8849663cfee62a5458940d18bfd0511f6377dc9 Mon Sep 17 00:00:00 2001
From: Paul Thomas <pault@gcc.gnu.org>
Date: Sat, 20 Mar 2010 16:01:17 +0000
Subject: [PATCH] re PR fortran/43450 (-fwhole-file: ICE in
 gfc_create_module_variable, at fortran/trans-decl.c:3386)

2010-03-20  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/43450
	* trans-decl.c (gfc_create_module_variable): With -fwhole-file
	do not assert the context of derived types.

2010-03-20  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/43450
	* gfortran.dg/whole_file_15.f90 : New test.

From-SVN: r157595
---
 gcc/fortran/ChangeLog                       |  6 ++++
 gcc/fortran/trans-decl.c                    | 15 ++++++----
 gcc/testsuite/ChangeLog                     |  5 ++++
 gcc/testsuite/gfortran.dg/whole_file_15.f90 | 32 +++++++++++++++++++++
 4 files changed, 53 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/whole_file_15.f90

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index d8a2d3ee7909..03eb8fef97f4 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,9 @@
+2010-03-20  Paul Thomas  <pault@gcc.gnu.org>
+
+	PR fortran/43450
+	* trans-decl.c (gfc_create_module_variable): With -fwhole-file
+	do not assert the context of derived types.
+
 2010-03-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
 	PR fortran/43409
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 6f5f7796da8a..3dc070cdc6b9 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -3382,11 +3382,16 @@ gfc_create_module_variable (gfc_symbol * sym)
     {
       decl = sym->backend_decl;
       gcc_assert (sym->ns->proc_name->attr.flavor == FL_MODULE);
-      gcc_assert (TYPE_CONTEXT (decl) == NULL_TREE
-		  || TYPE_CONTEXT (decl) == sym->ns->proc_name->backend_decl);
-      gcc_assert (DECL_CONTEXT (TYPE_STUB_DECL (decl)) == NULL_TREE
-		  || DECL_CONTEXT (TYPE_STUB_DECL (decl))
-		     == sym->ns->proc_name->backend_decl);
+
+      /* -fwhole-file mixes up the contexts so these asserts are unnecessary.  */
+      if (!(gfc_option.flag_whole_file && sym->attr.use_assoc))
+	{
+	  gcc_assert (TYPE_CONTEXT (decl) == NULL_TREE
+		      || TYPE_CONTEXT (decl) == sym->ns->proc_name->backend_decl);
+	  gcc_assert (DECL_CONTEXT (TYPE_STUB_DECL (decl)) == NULL_TREE
+		      || DECL_CONTEXT (TYPE_STUB_DECL (decl))
+			   == sym->ns->proc_name->backend_decl);
+	}
       TYPE_CONTEXT (decl) = sym->ns->proc_name->backend_decl;
       DECL_CONTEXT (TYPE_STUB_DECL (decl)) = sym->ns->proc_name->backend_decl;
       gfc_module_add_decl (cur_module, TYPE_STUB_DECL (decl));
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 6bef88f2fc9d..2f8f1a80f247 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2010-03-20  Paul Thomas  <pault@gcc.gnu.org>
+
+	PR fortran/43450
+	* gfortran.dg/whole_file_15.f90 : New test.
+
 2010-03-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
 	PR fortran/43409
diff --git a/gcc/testsuite/gfortran.dg/whole_file_15.f90 b/gcc/testsuite/gfortran.dg/whole_file_15.f90
new file mode 100644
index 000000000000..08d6120445b8
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/whole_file_15.f90
@@ -0,0 +1,32 @@
+! { dg-do compile }
+! { dg-options "-fwhole-file" }
+! Test the fix for PR43450 in which the use of 'replica_env_type'
+! caused an ICE in ep_types
+!
+! Contributed by Tobias Burnus <burnus@gcc.gnu.org>
+!
+MODULE replica_types
+  TYPE replica_env_type
+  END TYPE replica_env_type
+CONTAINS
+  SUBROUTINE rep_env_create(rep_env, para_env, input, nrep, prep,&
+       sync_v,keep_wf_history,row_force)
+  END SUBROUTINE rep_env_create
+  SUBROUTINE rep_envs_add_rep_env(rep_env)
+    TYPE(replica_env_type), POINTER          :: rep_env
+  END SUBROUTINE rep_envs_add_rep_env
+END MODULE replica_types
+MODULE ep_types
+  USE replica_types
+  TYPE ep_env_type
+     TYPE(replica_env_type), POINTER :: mol_envs
+  END TYPE ep_env_type
+  TYPE ep_env_p_type
+     TYPE(ep_env_type), POINTER :: ep_env
+  END TYPE ep_env_p_type
+  TYPE(ep_env_p_type), DIMENSION(:), POINTER :: ep_envs
+CONTAINS
+  SUBROUTINE ep_force_release()
+  END SUBROUTINE ep_force_release
+END MODULE ep_types
+! { dg-final { cleanup-modules "replica_types ep_types" } }
-- 
GitLab