diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index bb615906ea527507f87bffe500f1b528f3aca9f9..ef3b9c40455d76cac3df848a4ac8dbcf26733e70 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2012-07-04  Richard Guenther  <rguenther@suse.de>
+
+	* tree.c (find_decls_types_r): Handle TYPE_CONTEXT the same
+	as in free_lang_data_in_type.
+
 2012-07-04  Tobias Grosser <tobias@grosser.es>
 	Michael Matz  <matz@suse.de>
 
diff --git a/gcc/tree.c b/gcc/tree.c
index f9942fb04874ac670027b087e38f10227f99de38..9be0c9a7e31522809ce578f360ca2652071f5ccd 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -4910,7 +4910,15 @@ find_decls_types_r (tree *tp, int *ws, void *data)
       fld_worklist_push (TYPE_MAIN_VARIANT (t), fld);
       /* Do not walk TYPE_NEXT_VARIANT.  We do not stream it and thus
          do not and want not to reach unused variants this way.  */
-      fld_worklist_push (TYPE_CONTEXT (t), fld);
+      if (TYPE_CONTEXT (t))
+	{
+	  tree ctx = TYPE_CONTEXT (t);
+	  /* We adjust BLOCK TYPE_CONTEXTs to the innermost non-BLOCK one.
+	     So push that instead.  */
+	  while (ctx && TREE_CODE (ctx) == BLOCK)
+	    ctx = BLOCK_SUPERCONTEXT (ctx);
+	  fld_worklist_push (ctx, fld);
+	}
       /* Do not walk TYPE_CANONICAL.  We do not stream it and thus do not
 	 and want not to reach unused types this way.  */