/* Whether or not we cloned TYPE0, cache the result so that we don't do
      recompute all over next time.  */
-  TYPE_TARGET_TYPE (type0) = type;
+  type0->set_target_type (type);
 
   for (f = 0; f < nfields; f += 1)
     {
          /* Clone TYPE0 only the first time we get a new field type.  */
          if (type == type0)
            {
-             TYPE_TARGET_TYPE (type0) = type = alloc_type_copy (type0);
+             type = alloc_type_copy (type0);
+             type0->set_target_type (type);
              type->set_code (type0->code ());
              INIT_NONE_SPECIFIC (type);
              type->set_num_fields (nfields);
      the aligners.  */
   if (value_type (array)->code () == TYPE_CODE_REF
       && ada_is_aligner_type (TYPE_TARGET_TYPE (value_type (array))))
-    TYPE_TARGET_TYPE (value_type (array)) =
-      ada_aligned_type (TYPE_TARGET_TYPE (value_type (array)));
+    value_type (array)->set_target_type
+      (ada_aligned_type (TYPE_TARGET_TYPE (value_type (array))));
 
   if (ada_is_any_packed_array_type (value_type (array)))
     error (_("cannot slice a packed array"));
 
             fname == nullptr ? "noname" : fname);
     }
   rettype = fetch_tid_type (ccp, cfi.ctc_return);
-  TYPE_TARGET_TYPE (type) = rettype;
+  type->set_target_type (rettype);
   set_type_align (type, ctf_type_align (fp, tid));
 
   /* Set up function's arguments.  */
   type->set_code (TYPE_CODE_ENUM);
   TYPE_LENGTH (type) = ctf_type_size (fp, tid);
   /* Set the underlying type based on its ctf_type_size bits.  */
-  TYPE_TARGET_TYPE (type) = objfile_int_type (of, TYPE_LENGTH (type), false);
+  type->set_target_type (objfile_int_type (of, TYPE_LENGTH (type), false));
   set_type_align (type, ctf_type_align (fp, tid));
 
   return set_tid_type (of, tid, type);
 
   while (TYPE_TARGET_TYPE (inner_array)->code () == TYPE_CODE_ARRAY)
     {
-      TYPE_TARGET_TYPE (inner_array)
-       = copy_type (TYPE_TARGET_TYPE (inner_array));
+      inner_array->set_target_type (copy_type (TYPE_TARGET_TYPE (inner_array)));
       inner_array = TYPE_TARGET_TYPE (inner_array);
     }
 
   el_type = TYPE_TARGET_TYPE (inner_array);
   cnst |= TYPE_CONST (el_type);
   voltl |= TYPE_VOLATILE (el_type);
-  TYPE_TARGET_TYPE (inner_array) = make_cv_type (cnst, voltl, el_type, nullptr);
+  inner_array->set_target_type (make_cv_type (cnst, voltl, el_type, nullptr));
 
   return set_tid_type (ccp->of, tid, base_type);
 }
   set_tid_type (objfile, tid, this_type);
   target_type = fetch_tid_type (ccp, btid);
   if (target_type != this_type)
-    TYPE_TARGET_TYPE (this_type) = target_type;
+    this_type->set_target_type (target_type);
   else
-    TYPE_TARGET_TYPE (this_type) = nullptr;
+    this_type->set_target_type (nullptr);
 
   this_type->set_target_is_stub (TYPE_TARGET_TYPE (this_type) != nullptr);
 
 
   memcpy (new_fields, copy->fields (), nfields * sizeof (struct field));
   copy->set_fields (new_fields);
   if (new_target != nullptr)
-    TYPE_TARGET_TYPE (copy) = new_target;
+    copy->set_target_type (new_target);
 
   struct type *index_copy = copy_type (index_type);
   range_bounds *bounds
     {
       struct type *underlying_type = die_type (die, cu);
 
-      TYPE_TARGET_TYPE (type) = underlying_type;
+      type->set_target_type (underlying_type);
     }
 
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
 
   while (TYPE_TARGET_TYPE (inner_array)->code () == TYPE_CODE_ARRAY)
     {
-      TYPE_TARGET_TYPE (inner_array) =
-       copy_type (TYPE_TARGET_TYPE (inner_array));
+      inner_array->set_target_type (copy_type (TYPE_TARGET_TYPE (inner_array)));
       inner_array = TYPE_TARGET_TYPE (inner_array);
     }
 
   el_type = TYPE_TARGET_TYPE (inner_array);
   cnst |= TYPE_CONST (el_type);
   voltl |= TYPE_VOLATILE (el_type);
-  TYPE_TARGET_TYPE (inner_array) = make_cv_type (cnst, voltl, el_type, NULL);
+  inner_array->set_target_type (make_cv_type (cnst, voltl, el_type, NULL));
 
   return set_die_type (die, base_type, cu);
 }
   set_die_type (die, this_type, cu);
   target_type = die_type (die, cu);
   if (target_type != this_type)
-    TYPE_TARGET_TYPE (this_type) = target_type;
+    this_type->set_target_type (target_type);
   else
     {
       /* Self-referential typedefs are, it seems, not allowed by the DWARF
       complaint (_("Self-referential DW_TAG_typedef "
                   "- DIE at %s [in module %s]"),
                 sect_offset_str (die->sect_off), objfile_name (objfile));
-      TYPE_TARGET_TYPE (this_type) = NULL;
+      this_type->set_target_type (nullptr);
     }
   if (name == NULL)
     {
 
   /* __pid_t */
   pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
                        TYPE_LENGTH (int32_type) * TARGET_CHAR_BIT, "__pid_t");
-  TYPE_TARGET_TYPE (pid_type) = int32_type;
+  pid_type->set_target_type (int32_type);
   pid_type->set_target_is_stub (true);
 
   /* __uid_t */
   uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
                        TYPE_LENGTH (uint32_type) * TARGET_CHAR_BIT,
                        "__uid_t");
-  TYPE_TARGET_TYPE (uid_type) = uint32_type;
+  uid_type->set_target_type (uint32_type);
   pid_type->set_target_is_stub (true);
 
   /* _reason */
 
       TYPE_CHAIN (ntype) = chain;
     }
 
-  TYPE_TARGET_TYPE (ntype) = type;
+  ntype->set_target_type (type);
   TYPE_POINTER_TYPE (type) = ntype;
 
   /* FIXME!  Assumes the machine has only one representation for pointers!  */
       TYPE_CHAIN (ntype) = chain;
     }
 
-  TYPE_TARGET_TYPE (ntype) = type;
+  ntype->set_target_type (type);
   reftype = (refcode == TYPE_CODE_REF ? &TYPE_REFERENCE_TYPE (type)
             : &TYPE_RVALUE_REFERENCE_TYPE (type));
 
       smash_type (ntype);
     }
 
-  TYPE_TARGET_TYPE (ntype) = type;
+  ntype->set_target_type (type);
 
   TYPE_LENGTH (ntype) = 1;
   ntype->set_code (TYPE_CODE_FUNC);
   mtype->set_code (TYPE_CODE_METHOD);
   TYPE_LENGTH (mtype) = 1;
   mtype->set_is_stub (true);
-  TYPE_TARGET_TYPE (mtype) = type;
+  mtype->set_target_type (type);
   /* TYPE_SELF_TYPE (mtype) = unknown yet */
   return mtype;
 }
   if (result_type == NULL)
     result_type = alloc_type_copy (index_type);
   result_type->set_code (TYPE_CODE_RANGE);
-  TYPE_TARGET_TYPE (result_type) = index_type;
+  result_type->set_target_type (index_type);
   if (index_type->is_stub ())
     result_type->set_target_is_stub (true);
   else
     result_type = alloc_type_copy (range_type);
 
   result_type->set_code (TYPE_CODE_ARRAY);
-  TYPE_TARGET_TYPE (result_type) = element_type;
+  result_type->set_target_type (element_type);
 
   result_type->set_num_fields (1);
   result_type->set_fields
       type_instance_flags flags
        = elt_type->instance_flags () | TYPE_INSTANCE_FLAG_NOTTEXT;
       elt_type = make_qualified_type (elt_type, flags, NULL);
-      TYPE_TARGET_TYPE (inner_array) = elt_type;
+      inner_array->set_target_type (elt_type);
     }
 
   array_type->set_is_vector (true);
 {
   smash_type (type);
   type->set_code (TYPE_CODE_MEMBERPTR);
-  TYPE_TARGET_TYPE (type) = to_type;
+  type->set_target_type (to_type);
   set_type_self_type (type, self_type);
   /* Assume that a data member pointer is the same size as a normal
      pointer.  */
 {
   smash_type (type);
   type->set_code (TYPE_CODE_METHODPTR);
-  TYPE_TARGET_TYPE (type) = to_type;
+  type->set_target_type (to_type);
   set_type_self_type (type, TYPE_SELF_TYPE (to_type));
   TYPE_LENGTH (type) = cplus_method_ptr_size (to_type);
 }
 {
   smash_type (type);
   type->set_code (TYPE_CODE_METHOD);
-  TYPE_TARGET_TYPE (type) = to_type;
+  type->set_target_type (to_type);
   set_type_self_type (type, self_type);
   type->set_fields (args);
   type->set_num_fields (nargs);
          struct type *rank_type = type;
          for (int i = 1; i < rank; i++)
            {
-             TYPE_TARGET_TYPE (rank_type) = copy_type (rank_type);
+             rank_type->set_target_type (copy_type (rank_type));
              rank_type = TYPE_TARGET_TYPE (rank_type);
            }
-         TYPE_TARGET_TYPE (rank_type) = element_type;
+         rank_type->set_target_type (element_type);
        }
     }
   else
 
   /* The Ada language uses this field as a cache for static fixed types: reset
      it as RESOLVED_TYPE must have its own static fixed type.  */
-  TYPE_TARGET_TYPE (resolved_type) = NULL;
+  resolved_type->set_target_type (nullptr);
 
   return resolved_type;
 }
   if (type->code () == TYPE_CODE_TYPEDEF)
     {
       resolved_type = copy_type (type);
-      TYPE_TARGET_TYPE (resolved_type)
-       = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type), addr_stack,
-                                        top_level);
+      resolved_type->set_target_type
+       (resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type), addr_stack,
+                                       top_level));
     }
-  else 
+  else
     {
       /* Before trying to resolve TYPE, make sure it is not a stub.  */
       type = real_type;
            pinfo.next = addr_stack;
 
            resolved_type = copy_type (type);
-           TYPE_TARGET_TYPE (resolved_type)
-             = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type),
-                                              &pinfo, top_level);
+           resolved_type->set_target_type
+             (resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type),
+                                             &pinfo, top_level));
            break;
          }
 
            }
          sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0).symbol;
          if (sym)
-           TYPE_TARGET_TYPE (type) = sym->type ();
+           type->set_target_type (sym->type ());
          else                                  /* TYPE_CODE_UNDEF */
-           TYPE_TARGET_TYPE (type) = alloc_type_arch (type->arch ());
+           type->set_target_type (alloc_type_arch (type->arch ()));
        }
       type = TYPE_TARGET_TYPE (type);
 
       TYPE_LENGTH (t) = 2 * TYPE_LENGTH (target_type);
       t->set_name (name);
 
-      TYPE_TARGET_TYPE (t) = target_type;
+      t->set_target_type (target_type);
       TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type = t;
     }
 
   struct type *t;
 
   t = init_type (objfile, TYPE_CODE_PTR, bit, name);
-  TYPE_TARGET_TYPE (t) = target_type;
+  t->set_target_type (target_type);
   t->set_is_unsigned (true);
   return t;
 }
 
   /* Copy pointers to other types.  */
   if (TYPE_TARGET_TYPE (type))
-    TYPE_TARGET_TYPE (new_type) = 
-      copy_type_recursive (TYPE_TARGET_TYPE (type), copied_types);
+    new_type->set_target_type
+      (copy_type_recursive (TYPE_TARGET_TYPE (type), copied_types));
 
   /* Maybe copy the type_specific bits.
 
   struct type *t;
 
   t = arch_type (gdbarch, TYPE_CODE_PTR, bit, name);
-  TYPE_TARGET_TYPE (t) = target_type;
+  t->set_target_type (target_type);
   t->set_is_unsigned (true);
   return t;
 }
 
      the type.
      - Unused otherwise.  */
 
-  struct type *target_type;
+  struct type *m_target_type;
 
   /* * For structure and union types, a description of each field.
      For set and pascal array types, there is one "field",
     return this->field (0).type ();
   }
 
+  struct type *target_type () const
+  {
+    return this->main_type->m_target_type;
+  }
+
+  void set_target_type (struct type *target_type)
+  {
+    this->main_type->m_target_type = target_type;
+  }
+
   void set_index_type (type *index_type)
   {
     this->field (0).set_type (index_type);
    allocate_fixed_point_type_info (type))
 
 #define TYPE_MAIN_TYPE(thistype) (thistype)->main_type
-#define TYPE_TARGET_TYPE(thistype) TYPE_MAIN_TYPE(thistype)->target_type
+#define TYPE_TARGET_TYPE(thistype) ((thistype)->target_type ())
 #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
 #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
 #define TYPE_RVALUE_REFERENCE_TYPE(thistype) (thistype)->rvalue_reference_type
 
   /* __pid_t */
   pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
                        TYPE_LENGTH (int_type) * TARGET_CHAR_BIT, "__pid_t");
-  TYPE_TARGET_TYPE (pid_type) = int_type;
+  pid_type->set_target_type (int_type);
   pid_type->set_target_is_stub (true);
 
   /* __uid_t */
   uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
                        TYPE_LENGTH (uint_type) * TARGET_CHAR_BIT, "__uid_t");
-  TYPE_TARGET_TYPE (uid_type) = uint_type;
+  uid_type->set_target_type (uint_type);
   uid_type->set_target_is_stub (true);
 
   /* __clock_t */
   clock_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
                          TYPE_LENGTH (long_type) * TARGET_CHAR_BIT,
                          "__clock_t");
-  TYPE_TARGET_TYPE (clock_type) = long_type;
+  clock_type->set_target_type (long_type);
   clock_type->set_target_is_stub (true);
 
   /* _sifields */
 
   /* pid_t */
   type *pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
                              TYPE_LENGTH (int32_type) * char_bits, "pid_t");
-  TYPE_TARGET_TYPE (pid_type) = int32_type;
+  pid_type->set_target_type (int32_type);
 
   /* uid_t */
   type *uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
                              TYPE_LENGTH (uint32_type) * char_bits, "uid_t");
-  TYPE_TARGET_TYPE (uid_type) = uint32_type;
+  uid_type->set_target_type (uint32_type);
 
   /* clock_t */
   type *clock_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
                                TYPE_LENGTH (int_type) * char_bits, "clock_t");
-  TYPE_TARGET_TYPE (clock_type) = int_type;
+  clock_type->set_target_type (int_type);
 
   /* lwpid_t */
   type *lwpid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
                                TYPE_LENGTH (int32_type) * char_bits,
                                "lwpid_t");
-  TYPE_TARGET_TYPE (lwpid_type) = int32_type;
+  lwpid_type->set_target_type (int32_type);
 
   /* union sigval */
   type *sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
 
        else
          {
            type->set_target_is_stub (true);
-           TYPE_TARGET_TYPE (type) = xtype;
+           type->set_target_type (xtype);
          }
       }
       break;
 
   seh_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
                            TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
                            NULL);
-  TYPE_TARGET_TYPE (seh_ptr_type) = seh_type;
+  seh_ptr_type->set_target_type (seh_type);
 
   append_composite_type_field (seh_type, "next_seh", seh_ptr_type);
   append_composite_type_field (seh_type, "handler",
   peb_ldr_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
                                TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
                                NULL);
-  TYPE_TARGET_TYPE (peb_ldr_ptr_type) = peb_ldr_type;
+  peb_ldr_ptr_type->set_target_type (peb_ldr_type);
 
   /* struct UNICODE_STRING */
   uni_str_type = arch_composite_type (gdbarch, "unicode_string",
   peb_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
                            TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
                            NULL);
-  TYPE_TARGET_TYPE (peb_ptr_type) = peb_type;
+  peb_ptr_type->set_target_type (peb_type);
 
 
   /* struct thread information block */
   tib_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
                            TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
                            NULL);
-  TYPE_TARGET_TYPE (tib_ptr_type) = tib_type;
+  tib_ptr_type->set_target_type (tib_type);
 
   windows_gdbarch_data->tib_ptr_type = tib_ptr_type;