Index: ada/gcc-interface/decl.c
===================================================================
--- ada/gcc-interface/decl.c	(revision 209359)
+++ ada/gcc-interface/decl.c	(working copy)
@@ -2671,11 +2671,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gn
 	      for (index = ndim - 1; index >= 0; index--)
 		{
 		  tree gnu_index = TYPE_INDEX_TYPE (gnu_index_types[index]);
-		  tree gnu_index_name = TYPE_NAME (gnu_index);
+		  tree gnu_index_name = TYPE_IDENTIFIER (gnu_index);
 
-		  if (TREE_CODE (gnu_index_name) == TYPE_DECL)
-		    gnu_index_name = DECL_NAME (gnu_index_name);
-
 		  /* Make sure to reference the types themselves, and not just
 		     their names, as the debugger may fall back on them.  */
 		  gnu_field = create_field_decl (gnu_index_name, gnu_index,
@@ -3652,12 +3649,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gn
 	      if (debug_info_p)
 		{
 		  tree gnu_subtype_marker = make_node (RECORD_TYPE);
-		  tree gnu_unpad_base_name = TYPE_NAME (gnu_unpad_base_type);
+		  tree gnu_unpad_base_name
+		    = TYPE_IDENTIFIER (gnu_unpad_base_type);
 		  tree gnu_size_unit = TYPE_SIZE_UNIT (gnu_type);
 
-		  if (TREE_CODE (gnu_unpad_base_name) == TYPE_DECL)
-		    gnu_unpad_base_name = DECL_NAME (gnu_unpad_base_name);
-
 		  TYPE_NAME (gnu_subtype_marker)
 		    = create_concat_name (gnat_entity, "XVS");
 		  finish_record_type (gnu_subtype_marker,
@@ -4976,11 +4971,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gn
 				   false, !gnu_decl, definition, false);
 
       if (TYPE_IS_PADDING_P (gnu_type))
-	{
-	  gnu_entity_name = TYPE_NAME (gnu_type);
-	  if (TREE_CODE (gnu_entity_name) == TYPE_DECL)
-	    gnu_entity_name = DECL_NAME (gnu_entity_name);
-	}
+	gnu_entity_name = TYPE_IDENTIFIER (gnu_type);
 
       /* Now set the RM size of the type.  We cannot do it before padding
 	 because we need to accept arbitrary RM sizes on integral types.  */
@@ -7035,7 +7026,7 @@ components_to_record (tree gnu_record_type, Node_I
     {
       Node_Id gnat_discr = Name (variant_part), variant;
       tree gnu_discr = gnat_to_gnu (gnat_discr);
-      tree gnu_name = TYPE_NAME (gnu_record_type);
+      tree gnu_name = TYPE_IDENTIFIER (gnu_record_type);
       tree gnu_var_name
 	= concat_name (get_identifier (Get_Name_String (Chars (gnat_discr))),
 		       "XVN");
@@ -7047,9 +7038,6 @@ components_to_record (tree gnu_record_type, Node_I
       unsigned int variants_align = 0;
       unsigned int i;
 
-      if (TREE_CODE (gnu_name) == TYPE_DECL)
-	gnu_name = DECL_NAME (gnu_name);
-
       gnu_union_name
 	= concat_name (gnu_name, IDENTIFIER_POINTER (gnu_var_name));
 
Index: ada/gcc-interface/utils.c
===================================================================
--- ada/gcc-interface/utils.c	(revision 209359)
+++ ada/gcc-interface/utils.c	(working copy)
@@ -706,10 +706,8 @@ make_aligning_type (tree type, unsigned int align,
   tree vblock_addr_st = size_binop (PLUS_EXPR, record_addr_st, room_st);
   tree voffset_st, pos, field;
 
-  tree name = TYPE_NAME (type);
+  tree name = TYPE_IDENTIFIER (type);
 
-  if (TREE_CODE (name) == TYPE_DECL)
-    name = DECL_NAME (name);
   name = concat_name (name, "ALIGN");
   TYPE_NAME (record_type) = name;
 
@@ -1203,15 +1201,9 @@ maybe_pad_type (tree type, tree size, unsigned int
 	   && DECL_IGNORED_P (TYPE_NAME (type))))
     {
       tree marker = make_node (RECORD_TYPE);
-      tree name = TYPE_NAME (record);
-      tree orig_name = TYPE_NAME (type);
+      tree name = TYPE_IDENTIFIER (record);
+      tree orig_name = TYPE_IDENTIFIER (type);
 
-      if (TREE_CODE (name) == TYPE_DECL)
-	name = DECL_NAME (name);
-
-      if (TREE_CODE (orig_name) == TYPE_DECL)
-	orig_name = DECL_NAME (orig_name);
-
       TYPE_NAME (marker) = concat_name (name, "XVS");
       finish_record_type (marker,
 			  create_field_decl (orig_name,
@@ -1419,7 +1411,7 @@ finish_record_type (tree record_type, tree field_l
 		    bool debug_info_p)
 {
   enum tree_code code = TREE_CODE (record_type);
-  tree name = TYPE_NAME (record_type);
+  tree name = TYPE_IDENTIFIER (record_type);
   tree ada_size = bitsize_zero_node;
   tree size = bitsize_zero_node;
   bool had_size = TYPE_SIZE (record_type) != 0;
@@ -1431,8 +1423,6 @@ finish_record_type (tree record_type, tree field_l
 
   /* Always attach the TYPE_STUB_DECL for a record type.  It is required to
      generate debug info and have a parallel type.  */
-  if (name && TREE_CODE (name) == TYPE_DECL)
-    name = DECL_NAME (name);
   TYPE_STUB_DECL (record_type) = create_type_stub_decl (name, record_type);
 
   /* Globally initialize the record first.  If this is a rep'ed record,
@@ -1692,13 +1682,10 @@ rest_of_record_type_compilation (tree record_type)
       tree new_record_type
 	= make_node (TREE_CODE (record_type) == QUAL_UNION_TYPE
 		     ? UNION_TYPE : TREE_CODE (record_type));
-      tree orig_name = TYPE_NAME (record_type), new_name;
+      tree orig_name = TYPE_IDENTIFIER (record_type), new_name;
       tree last_pos = bitsize_zero_node;
       tree old_field, prev_old_field = NULL_TREE;
 
-      if (TREE_CODE (orig_name) == TYPE_DECL)
-	orig_name = DECL_NAME (orig_name);
-
       new_name
 	= concat_name (orig_name, TREE_CODE (record_type) == QUAL_UNION_TYPE
 				  ? "XVU" : "XVE");
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h	(revision 209359)
+++ cp/cp-tree.h	(working copy)
@@ -1252,7 +1252,6 @@ extern bool statement_code_p[MAX_TREE_CODES];
 enum languages { lang_c, lang_cplusplus, lang_java };
 
 /* Macros to make error reporting functions' lives easier.  */
-#define TYPE_IDENTIFIER(NODE) (DECL_NAME (TYPE_NAME (NODE)))
 #define TYPE_LINKAGE_IDENTIFIER(NODE) \
   (TYPE_IDENTIFIER (TYPE_MAIN_VARIANT (NODE)))
 #define TYPE_NAME_STRING(NODE) (IDENTIFIER_POINTER (TYPE_IDENTIFIER (NODE)))
Index: dbxout.c
===================================================================
--- dbxout.c	(revision 209359)
+++ dbxout.c	(working copy)
@@ -2159,12 +2159,12 @@ dbxout_type (tree type, int full)
 	       another type's definition; instead, output an xref
 	       and let the definition come when the name is defined.  */
 	    stabstr_S ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
-	    if (TYPE_NAME (type) != 0
-		/* The C frontend creates for anonymous variable length
-		   records/unions TYPE_NAME with DECL_NAME NULL.  */
-		&& (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL
-		    || DECL_NAME (TYPE_NAME (type))))
-	      dbxout_type_name (type);
+	    if (TYPE_IDENTIFIER (type))
+	      {
+		/* Note that the C frontend creates for anonymous variable
+		   length records/unions TYPE_NAME with DECL_NAME NULL.  */
+		dbxout_type_name (type);
+	      }
 	    else
 	      {
 		stabstr_S ("$$");
@@ -2800,9 +2800,7 @@ dbxout_symbol (tree decl, int local ATTRIBUTE_UNUS
 		   DBX format, and it confuses some tools such as objdump.  */
 		&& tree_fits_uhwi_p (TYPE_SIZE (type)))
 	      {
-		tree name = TYPE_NAME (type);
-		if (TREE_CODE (name) == TYPE_DECL)
-		  name = DECL_NAME (name);
+		tree name = TYPE_IDENTIFIER (type);
 
 		dbxout_begin_complex_stabs ();
 		stabstr_I (name);
@@ -2859,9 +2857,7 @@ dbxout_symbol (tree decl, int local ATTRIBUTE_UNUS
 	       This is what represents `struct foo' with no typedef.  */
 	    /* In C++, the name of a type is the corresponding typedef.
 	       In C, it is an IDENTIFIER_NODE.  */
-	    tree name = TYPE_NAME (type);
-	    if (TREE_CODE (name) == TYPE_DECL)
-	      name = DECL_NAME (name);
+	    tree name = TYPE_IDENTIFIER (type);
 
 	    dbxout_begin_complex_stabs ();
 	    stabstr_I (name);
Index: dwarf2out.c
===================================================================
--- dwarf2out.c	(revision 209359)
+++ dwarf2out.c	(working copy)
@@ -10230,9 +10230,7 @@ is_cxx_auto (tree type)
 {
   if (is_cxx ())
     {
-      tree name = TYPE_NAME (type);
-      if (TREE_CODE (name) == TYPE_DECL)
-	name = DECL_NAME (name);
+      tree name = TYPE_IDENTIFIER (type);
       if (name == get_identifier ("auto")
 	  || name == get_identifier ("decltype(auto)"))
 	return true;
@@ -10509,10 +10507,7 @@ modified_type_die (tree type, int is_const_type, i
   /* This probably indicates a bug.  */
   else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
     {
-      name = TYPE_NAME (type);
-      if (name
-	  && TREE_CODE (name) == TYPE_DECL)
-	name = DECL_NAME (name);
+      name = TYPE_IDENTIFIER (type);
       add_name_attribute (mod_type_die,
 			  name ? IDENTIFIER_POINTER (name) : "__unknown__");
     }
@@ -19856,10 +19851,9 @@ gen_type_die_with_usage (tree type, dw_die_ref con
         dw_die_ref type_die = lookup_type_die (type);
         if (type_die == NULL)
           {
-	    tree name = TYPE_NAME (type);
-	    if (TREE_CODE (name) == TYPE_DECL)
-	      name = DECL_NAME (name);
-            type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
+	    tree name = TYPE_IDENTIFIER (type);
+            type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (),
+				type);
             add_name_attribute (type_die, IDENTIFIER_POINTER (name));
             equate_type_number_to_die (type, type_die);
           }
@@ -19869,9 +19863,7 @@ gen_type_die_with_usage (tree type, dw_die_ref con
     default:
       if (is_cxx_auto (type))
 	{
-	  tree name = TYPE_NAME (type);
-	  if (TREE_CODE (name) == TYPE_DECL)
-	    name = DECL_NAME (name);
+	  tree name = TYPE_IDENTIFIER (type);
 	  dw_die_ref *die = (name == get_identifier ("auto")
 			     ? &auto_die : &decltype_auto_die);
 	  if (!*die)
Index: godump.c
===================================================================
--- godump.c	(revision 209359)
+++ godump.c	(working copy)
@@ -577,9 +577,7 @@ go_format_type (struct godump_container *container
       tree name;
       void **slot;
 
-      name = TYPE_NAME (type);
-      if (TREE_CODE (name) == TYPE_DECL)
-	name = DECL_NAME (name);
+      name = TYPE_IDENTIFIER (type);
 
       slot = htab_find_slot (container->invalid_hash, IDENTIFIER_POINTER (name),
 			     NO_INSERT);
@@ -684,9 +682,7 @@ go_format_type (struct godump_container *container
 	  tree name;
 	  void **slot;
 
-	  name = TYPE_NAME (TREE_TYPE (type));
-	  if (TREE_CODE (name) == TYPE_DECL)
-	    name = DECL_NAME (name);
+	  name = TYPE_IDENTIFIER (TREE_TYPE (type));
 
 	  slot = htab_find_slot (container->invalid_hash,
 				 IDENTIFIER_POINTER (name), NO_INSERT);
@@ -805,9 +801,7 @@ go_format_type (struct godump_container *container
 		    tree name;
 		    void **slot;
 
-		    name = TYPE_NAME (TREE_TYPE (field));
-		    if (TREE_CODE (name) == TYPE_DECL)
-		      name = DECL_NAME (name);
+		    name = TYPE_IDENTIFIER (TREE_TYPE (field));
 
 		    slot = htab_find_slot (container->invalid_hash,
 					   IDENTIFIER_POINTER (name),
Index: objcp/objcp-decl.h
===================================================================
--- objcp/objcp-decl.h	(revision 209359)
+++ objcp/objcp-decl.h	(working copy)
@@ -55,16 +55,9 @@ extern tree objcp_end_compound_stmt (tree, int);
 	objcp_end_compound_stmt (stmt, flags)
 
 #undef OBJC_TYPE_NAME
-#define OBJC_TYPE_NAME(type) \
-  (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL \
-   ? DECL_NAME (TYPE_NAME (type)) \
-   : TYPE_NAME (type))
+#define OBJC_TYPE_NAME(type) (TYPE_IDENTIFIER (type))
 #undef OBJC_SET_TYPE_NAME
-#define OBJC_SET_TYPE_NAME(type, name) \
-  if(TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) \
-    DECL_NAME (TYPE_NAME (type)) = name; \
-  else \
-    TYPE_NAME (type) = name;
+#define OBJC_SET_TYPE_NAME(type, name) (TYPE_IDENTIFIER (type) = (name))
 
 #undef TYPE_OBJC_INFO
 #define TYPE_OBJC_INFO(TYPE) LANG_TYPE_CLASS_CHECK (TYPE)->objc_info
Index: tree.c
===================================================================
--- tree.c	(revision 209359)
+++ tree.c	(working copy)
@@ -7796,21 +7796,10 @@ subrange_type_for_debug_p (const_tree type, tree *
        || TREE_CODE (base_type) == BOOLEAN_TYPE)
       && int_size_in_bytes (type) == int_size_in_bytes (base_type)
       && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type))
-      && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type)))
-    {
-      tree type_name = TYPE_NAME (type);
-      tree base_type_name = TYPE_NAME (base_type);
+      && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type))
+      && TYPE_IDENTIFIER (type) == TYPE_IDENTIFIER (base_type))
+    return false;
 
-      if (type_name && TREE_CODE (type_name) == TYPE_DECL)
-	type_name = DECL_NAME (type_name);
-
-      if (base_type_name && TREE_CODE (base_type_name) == TYPE_DECL)
-	base_type_name = DECL_NAME (base_type_name);
-
-      if (type_name == base_type_name)
-	return false;
-    }
-
   if (lowval)
     *lowval = low;
   if (highval)
Index: tree.h
===================================================================
--- tree.h	(revision 209359)
+++ tree.h	(working copy)
@@ -1906,6 +1906,13 @@ extern void protected_set_expr_location (tree, loc
    It is an IDENTIFIER_NODE.  */
 #define DECL_NAME(NODE) (DECL_MINIMAL_CHECK (NODE)->decl_minimal.name)
 
+/* The IDENTIFIER_NODE associated with the TYPE_NAME field.  */
+#define TYPE_IDENTIFIER(NODE) \
+  (TYPE_NAME (NODE) \
+   && (TREE_CODE (TYPE_NAME (NODE)) == TYPE_DECL	 \
+       || TREE_CODE (TYPE_NAME (NODE)) == TEMPLATE_DECL) \
+   ? DECL_NAME (TYPE_NAME (NODE)) : TYPE_NAME (NODE))
+
 /* Every ..._DECL node gets a unique number.  */
 #define DECL_UID(NODE) (DECL_MINIMAL_CHECK (NODE)->decl_minimal.uid)
 
