diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index d8a2d3ee7909a24c667b661d7d35fb5b95d2c663..03eb8fef97f4c6509db5962fa1588c0ca4e86583 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 6f5f7796da8a318b24f872dfc07113bd955d39a7..3dc070cdc6b9b45b3688052ca004a9015b78af34 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 6bef88f2fc9ddb5918a2490ccccf901ad1338fa5..2f8f1a80f247183d833a996a2adbb476758c72ed 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 0000000000000000000000000000000000000000..08d6120445b87f431da29aa62e818d19b295df75
--- /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" } }