diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 32f49a7bb116cb43baf506c67e2c9180613c5bde..85d6d2addd751c3f183ee659a91611d5661377c4 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -5161,6 +5161,7 @@ layout_class_type (tree t, tree *virtuals_p)
 
       /* Record the base version of the type.  */
       CLASSTYPE_AS_BASE (t) = base_t;
+      TYPE_CONTEXT (base_t) = t;
     }
   else
     CLASSTYPE_AS_BASE (t) = t;
diff --git a/gcc/cp/dump.c b/gcc/cp/dump.c
index fa55833e2089359162ea894c76f83d07e86024fd..da207d32917f53009783a50180c14b85e5d7ffd7 100644
--- a/gcc/cp/dump.c
+++ b/gcc/cp/dump.c
@@ -265,6 +265,14 @@ cp_dump_tree (dump_info, t)
 	  return 1;
 	}
 
+      /* Is it a type used as a base? */
+      if (TYPE_CONTEXT (t) && TREE_CODE (TYPE_CONTEXT (t)) == TREE_CODE (t)
+	  && CLASSTYPE_AS_BASE (TYPE_CONTEXT (t)) == t)
+	{
+	  dump_child ("bfld", TYPE_CONTEXT (t));
+	  return 1;
+	}
+      
       dump_child ("vfld", TYPE_VFIELD (t));
       if (CLASSTYPE_TEMPLATE_SPECIALIZATION(t))
         dump_string(di, "spec");