[3/4] gdb: add type::fields / type::set_fields

Message ID 20200519184441.7838-3-simon.marchi@efficios.com
State New
Headers show
Series
  • [1/4] gdb: add type::num_fields / type::set_num_fields
Related show

Commit Message

Kevin Buettner via Gdb-patches May 19, 2020, 6:44 p.m.
Add the `fields` and `set_fields` methods on `struct type`, in order to
remove the `TYPE_FIELDS` macro.  In this patch, the `TYPE_FIELDS` macro
is changed to the `type::fields`, so all the call sites that use it to
set the fields array are changed to use `type::set_fields`.  The next
patch will remove `TYPE_FIELDS` entirely.

gdb/ChangeLog:

	* gdbtypes.h (struct type) <fields, set_fields>: New methods.
	(TYPE_FIELDS): Use type::fields.  Change all call sites that
	modify the propery to use type::set_fields instead.
---
 gdb/ada-lang.c    | 24 ++++++++++++---------
 gdb/buildsym.c    |  5 +++--
 gdb/coffread.c    | 22 +++++++++-----------
 gdb/ctfread.c     |  8 +++----
 gdb/dwarf2/read.c | 21 ++++++++++---------
 gdb/eval.c        |  4 ++--
 gdb/gdbtypes.c    | 53 +++++++++++++++++++++++++----------------------
 gdb/gdbtypes.h    | 14 ++++++++++++-
 gdb/gnu-v3-abi.c  |  4 ++--
 gdb/mdebugread.c  | 10 ++++-----
 gdb/rust-lang.c   |  4 ++--
 gdb/stabsread.c   | 21 +++++++++++--------
 12 files changed, 106 insertions(+), 84 deletions(-)

-- 
2.26.2

Comments

Tom Tromey May 22, 2020, 8:21 p.m. | #1
>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:


Simon> Add the `fields` and `set_fields` methods on `struct type`, in order to
Simon> remove the `TYPE_FIELDS` macro.  In this patch, the `TYPE_FIELDS` macro
Simon> is changed to the `type::fields`, so all the call sites that use it to
Simon> set the fields array are changed to use `type::set_fields`.  The next
Simon> patch will remove `TYPE_FIELDS` entirely.

Looks good.

Tom

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index e91ad614ce2..1e6cc5f94a1 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -8026,7 +8026,6 @@  empty_record (struct type *templ)
   struct type *type = alloc_type_copy (templ);
 
   type->set_code (TYPE_CODE_STRUCT);
-  TYPE_FIELDS (type) = NULL;
   INIT_NONE_SPECIFIC (type);
   type->set_name ("<empty>");
   TYPE_LENGTH (type) = 0;
@@ -8083,9 +8082,8 @@  ada_template_to_fixed_record_type_1 (struct type *type,
   rtype->set_code (TYPE_CODE_STRUCT);
   INIT_NONE_SPECIFIC (rtype);
   rtype->set_num_fields (nfields);
-  TYPE_FIELDS (rtype) = (struct field *)
-    TYPE_ALLOC (rtype, nfields * sizeof (struct field));
-  memset (TYPE_FIELDS (rtype), 0, sizeof (struct field) * nfields);
+  rtype->set_fields
+   ((struct field *) TYPE_ZALLOC (rtype, nfields * sizeof (struct field)));
   rtype->set_name (ada_type_name (type));
   TYPE_FIXED_INSTANCE (rtype) = 1;
 
@@ -8358,10 +8356,14 @@  template_to_static_fixed_type (struct type *type0)
 	      type->set_code (type0->code ());
 	      INIT_NONE_SPECIFIC (type);
 	      type->set_num_fields (nfields);
-	      TYPE_FIELDS (type) = (struct field *)
-		TYPE_ALLOC (type, nfields * sizeof (struct field));
-	      memcpy (TYPE_FIELDS (type), TYPE_FIELDS (type0),
+
+	      field *fields =
+		((struct field *)
+		 TYPE_ALLOC (type, nfields * sizeof (struct field)));
+	      memcpy (fields, TYPE_FIELDS (type0),
 		      sizeof (struct field) * nfields);
+	      type->set_fields (fields);
+
 	      type->set_name (ada_type_name (type0));
 	      TYPE_FIXED_INSTANCE (type) = 1;
 	      TYPE_LENGTH (type) = 0;
@@ -8407,10 +8409,12 @@  to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
   rtype->set_code (TYPE_CODE_STRUCT);
   INIT_NONE_SPECIFIC (rtype);
   rtype->set_num_fields (nfields);
-  TYPE_FIELDS (rtype) =
+
+  field *fields =
     (struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field));
-  memcpy (TYPE_FIELDS (rtype), TYPE_FIELDS (type),
-          sizeof (struct field) * nfields);
+  memcpy (fields, TYPE_FIELDS (type), sizeof (struct field) * nfields);
+  rtype->set_fields (fields);
+
   rtype->set_name (ada_type_name (type));
   TYPE_FIXED_INSTANCE (rtype) = 1;
   TYPE_LENGTH (rtype) = TYPE_LENGTH (type);
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index b25d09b5c0c..33bf6523e90 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -272,8 +272,9 @@  buildsym_compunit::finish_block_internal
 	  if (nparams > 0)
 	    {
 	      ftype->set_num_fields (nparams);
-	      TYPE_FIELDS (ftype) = (struct field *)
-		TYPE_ALLOC (ftype, nparams * sizeof (struct field));
+	      ftype->set_fields
+		((struct field *)
+		 TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
 
 	      iparams = 0;
 	      /* Here we want to directly access the dictionary, because
diff --git a/gdb/coffread.c b/gdb/coffread.c
index a2b69f44769..cd65adddef3 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -1456,12 +1456,10 @@  patch_type (struct type *type, struct type *real_type)
 
   TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
   target->set_num_fields (real_target->num_fields ());
-  TYPE_FIELDS (target) = (struct field *) TYPE_ALLOC (target,
-						      field_size);
 
-  memcpy (TYPE_FIELDS (target), 
-	  TYPE_FIELDS (real_target), 
-	  field_size);
+  field *fields = (struct field *) TYPE_ALLOC (target, field_size);
+  memcpy (fields, real_target->fields (), field_size);
+  target->set_fields (fields);
 
   if (real_target->name ())
     {
@@ -1883,7 +1881,7 @@  decode_base_type (struct coff_symbol *cs,
 	  type->set_name (NULL);
 	  INIT_CPLUS_SPECIFIC (type);
 	  TYPE_LENGTH (type) = 0;
-	  TYPE_FIELDS (type) = 0;
+	  type->set_fields (nullptr);
 	  type->set_num_fields (0);
 	}
       else
@@ -1903,7 +1901,7 @@  decode_base_type (struct coff_symbol *cs,
 	  type->set_name (NULL);
 	  INIT_CPLUS_SPECIFIC (type);
 	  TYPE_LENGTH (type) = 0;
-	  TYPE_FIELDS (type) = 0;
+	  type->set_fields (nullptr);
 	  type->set_num_fields (0);
 	}
       else
@@ -1924,7 +1922,7 @@  decode_base_type (struct coff_symbol *cs,
 	  type->set_code (TYPE_CODE_ENUM);
 	  type->set_name (NULL);
 	  TYPE_LENGTH (type) = 0;
-	  TYPE_FIELDS (type) = 0;
+	  type->set_fields (nullptr);
 	  type->set_num_fields (0);
 	}
       else
@@ -2042,8 +2040,8 @@  coff_read_struct_type (int index, int length, int lastsym,
   /* Now create the vector of fields, and record how big it is.  */
 
   type->set_num_fields (nfields);
-  TYPE_FIELDS (type) = (struct field *)
-    TYPE_ALLOC (type, sizeof (struct field) * nfields);
+  type->set_fields
+    ((struct field *) TYPE_ALLOC (type, sizeof (struct field) * nfields));
 
   /* Copy the saved-up fields into the field vector.  */
 
@@ -2122,8 +2120,8 @@  coff_read_enum_type (int index, int length, int lastsym,
     TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
   type->set_code (TYPE_CODE_ENUM);
   type->set_num_fields (nsyms);
-  TYPE_FIELDS (type) = (struct field *)
-    TYPE_ALLOC (type, sizeof (struct field) * nsyms);
+  type->set_fields
+    ((struct field *) TYPE_ALLOC (type, sizeof (struct field) * nsyms));
 
   /* Find the symbols for the values and put them into the type.
      The symbols can be found in the symlist that we put them on
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 31f927e3bc9..c0694ed312f 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -309,8 +309,8 @@  attach_fields_to_type (struct ctf_field_info *fip, struct type *type)
 
   /* Record the field count, allocate space for the array of fields.  */
   type->set_num_fields (nfields);
-  TYPE_FIELDS (type)
-    = (struct field *) TYPE_ZALLOC (type, sizeof (struct field) * nfields);
+  type->set_fields
+    ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * nfields));
 
   /* Copy the saved-up fields into the field vector.  */
   for (int i = 0; i < nfields; ++i)
@@ -1143,8 +1143,8 @@  add_stt_func (struct ctf_context *ccp, unsigned long idx)
 
   /* If argc is 0, it has a "void" type.  */
   if (argc != 0)
-    TYPE_FIELDS (ftype)
-      = (struct field *) TYPE_ZALLOC (ftype, argc * sizeof (struct field));
+    ftype->set_fields
+      ((struct field *) TYPE_ZALLOC (ftype, argc * sizeof (struct field)));
 
   /* TYPE_FIELD_TYPE must never be NULL.  Fill it with void_type, if failed
      to find the argument type.  */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index dd69d6622b2..06cf60b3b3f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9329,8 +9329,8 @@  quirk_rust_enum (struct type *type, struct objfile *objfile)
       type->set_num_fields (3);
       /* Save the field we care about.  */
       struct field saved_field = TYPE_FIELD (type, 0);
-      TYPE_FIELDS (type)
-	= (struct field *) TYPE_ZALLOC (type, 3 * sizeof (struct field));
+      type->set_fields
+	((struct field *) TYPE_ZALLOC (type, 3 * sizeof (struct field)));
 
       /* Put the discriminant at index 0.  */
       TYPE_FIELD_TYPE (type, 0) = field_type;
@@ -9424,7 +9424,7 @@  quirk_rust_enum (struct type *type, struct objfile *objfile)
 					       * sizeof (struct field)));
       memcpy (new_fields + 1, TYPE_FIELDS (type),
 	      type->num_fields () * sizeof (struct field));
-      TYPE_FIELDS (type) = new_fields;
+      type->set_fields (new_fields);
       type->set_num_fields (type->num_fields () + 1);
 
       /* Install the discriminant at index 0 in the union.  */
@@ -9474,7 +9474,7 @@  quirk_rust_enum (struct type *type, struct objfile *objfile)
 	  if (sub_type->num_fields () > 0)
 	    {
 	      sub_type->set_num_fields (sub_type->num_fields () - 1);
-	      ++TYPE_FIELDS (sub_type);
+	      sub_type->set_fields (sub_type->fields () + 1);
 	    }
 	  TYPE_FIELD_NAME (type, i) = variant_name;
 	  sub_type->set_name
@@ -14769,8 +14769,8 @@  dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
   /* Record the field count, allocate space for the array of fields,
      and create blank accessibility bitfields if necessary.  */
   type->set_num_fields (nfields);
-  TYPE_FIELDS (type) = (struct field *)
-    TYPE_ZALLOC (type, sizeof (struct field) * nfields);
+  type->set_fields
+    ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * nfields));
 
   if (fip->non_public_fields && cu->language != language_ada)
     {
@@ -15898,8 +15898,9 @@  update_enumeration_type_from_children (struct die_info *die,
   if (!fields.empty ())
     {
       type->set_num_fields (fields.size ());
-      TYPE_FIELDS (type) = (struct field *)
-	TYPE_ALLOC (type, sizeof (struct field) * fields.size ());
+      type->set_fields
+	((struct field *)
+	 TYPE_ALLOC (type, sizeof (struct field) * fields.size ()));
       memcpy (TYPE_FIELDS (type), fields.data (),
 	      sizeof (struct field) * fields.size ());
     }
@@ -17049,8 +17050,8 @@  read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
 
       /* Allocate storage for parameters and fill them in.  */
       ftype->set_num_fields (nparams);
-      TYPE_FIELDS (ftype) = (struct field *)
-	TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
+      ftype->set_fields
+	((struct field *) TYPE_ZALLOC (ftype, nparams * sizeof (struct field)));
 
       /* TYPE_FIELD_TYPE must never be NULL.  Pre-fill the array to ensure it
 	 even if we error out during the parameters reading below.  */
diff --git a/gdb/eval.c b/gdb/eval.c
index 8104c956b42..069cf5ddbc4 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -683,8 +683,8 @@  fake_method::fake_method (type_instance_flags flags,
      allocate memory for auxiliary fields, and free the memory ourselves
      when we are done with it.  */
   type->set_num_fields (num_types);
-  TYPE_FIELDS (type) = (struct field *)
-    xzalloc (sizeof (struct field) * num_types);
+  type->set_fields
+    ((struct field *) xzalloc (sizeof (struct field) * num_types));
 
   while (num_types-- > 0)
     TYPE_FIELD_TYPE (type, num_types) = param_types[num_types];
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 01d8530d0f5..d1623457a13 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -563,8 +563,8 @@  lookup_function_type_with_arguments (struct type *type,
     }
 
   fn->set_num_fields (nparams);
-  TYPE_FIELDS (fn)
-    = (struct field *) TYPE_ZALLOC (fn, nparams * sizeof (struct field));
+  fn->set_fields
+    ((struct field *) TYPE_ZALLOC (fn, nparams * sizeof (struct field)));
   for (i = 0; i < nparams; ++i)
     TYPE_FIELD_TYPE (fn, i) = param_types[i];
 
@@ -1282,8 +1282,8 @@  create_array_type_with_stride (struct type *result_type,
   TYPE_TARGET_TYPE (result_type) = element_type;
 
   result_type->set_num_fields (1);
-  TYPE_FIELDS (result_type) =
-    (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
+  result_type->set_fields
+    ((struct field *) TYPE_ZALLOC (result_type, sizeof (struct field)));
   TYPE_INDEX_TYPE (result_type) = range_type;
   if (byte_stride_prop != NULL)
     result_type->add_dyn_prop (DYN_PROP_BYTE_STRIDE, *byte_stride_prop);
@@ -1381,8 +1381,8 @@  create_set_type (struct type *result_type, struct type *domain_type)
 
   result_type->set_code (TYPE_CODE_SET);
   result_type->set_num_fields (1);
-  TYPE_FIELDS (result_type)
-    = (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
+  result_type->set_fields
+    ((struct field *) TYPE_ZALLOC (result_type, sizeof (struct field)));
 
   if (!TYPE_STUB (domain_type))
     {
@@ -1549,7 +1549,7 @@  smash_to_method_type (struct type *type, struct type *self_type,
   type->set_code (TYPE_CODE_METHOD);
   TYPE_TARGET_TYPE (type) = to_type;
   set_type_self_type (type, self_type);
-  TYPE_FIELDS (type) = args;
+  type->set_fields (args);
   type->set_num_fields (nargs);
   if (varargs)
     TYPE_VARARGS (type) = 1;
@@ -2238,10 +2238,10 @@  resolve_dynamic_union (struct type *type,
   gdb_assert (type->code () == TYPE_CODE_UNION);
 
   resolved_type = copy_type (type);
-  TYPE_FIELDS (resolved_type)
-    = (struct field *) TYPE_ALLOC (resolved_type,
-				   resolved_type->num_fields ()
-				   * sizeof (struct field));
+  resolved_type->set_fields
+    ((struct field *)
+     TYPE_ALLOC (resolved_type,
+		 resolved_type->num_fields () * sizeof (struct field)));
   memcpy (TYPE_FIELDS (resolved_type),
 	  TYPE_FIELDS (type),
 	  resolved_type->num_fields () * sizeof (struct field));
@@ -2404,10 +2404,11 @@  compute_variant_fields (struct type *type,
 
   resolved_type->set_num_fields
     (std::count (flags.begin (), flags.end (), true));
-  TYPE_FIELDS (resolved_type)
-    = (struct field *) TYPE_ALLOC (resolved_type,
-				   resolved_type->num_fields ()
-				   * sizeof (struct field));
+  resolved_type->set_fields
+    ((struct field *)
+     TYPE_ALLOC (resolved_type,
+		 resolved_type->num_fields () * sizeof (struct field)));
+
   int out = 0;
   for (int i = 0; i < type->num_fields (); ++i)
     {
@@ -2448,10 +2449,10 @@  resolve_dynamic_struct (struct type *type,
     }
   else
     {
-      TYPE_FIELDS (resolved_type)
-	= (struct field *) TYPE_ALLOC (resolved_type,
-				       resolved_type->num_fields ()
-				       * sizeof (struct field));
+      resolved_type->set_fields
+	((struct field *)
+	 TYPE_ALLOC (resolved_type,
+		     resolved_type->num_fields () * sizeof (struct field)));
       memcpy (TYPE_FIELDS (resolved_type),
 	      TYPE_FIELDS (type),
 	      resolved_type->num_fields () * sizeof (struct field));
@@ -5301,8 +5302,10 @@  copy_type_recursive (struct objfile *objfile,
       int i, nfields;
 
       nfields = type->num_fields ();
-      TYPE_FIELDS (new_type) = (struct field *)
-        TYPE_ZALLOC (new_type, nfields * sizeof (struct field));
+      new_type->set_fields
+	((struct field *)
+	 TYPE_ZALLOC (new_type, nfields * sizeof (struct field)));
+
       for (i = 0; i < nfields; i++)
 	{
 	  TYPE_FIELD_ARTIFICIAL (new_type, i) = 
@@ -5560,8 +5563,8 @@  arch_flags_type (struct gdbarch *gdbarch, const char *name, int bit)
   TYPE_UNSIGNED (type) = 1;
   type->set_num_fields (0);
   /* Pre-allocate enough space assuming every field is one bit.  */
-  TYPE_FIELDS (type)
-    = (struct field *) TYPE_ZALLOC (type, bit * sizeof (struct field));
+  type->set_fields
+    ((struct field *) TYPE_ZALLOC (type, bit * sizeof (struct field)));
 
   return type;
 }
@@ -5631,8 +5634,8 @@  append_composite_type_field_raw (struct type *t, const char *name,
   struct field *f;
 
   t->set_num_fields (t->num_fields () + 1);
-  TYPE_FIELDS (t) = XRESIZEVEC (struct field, TYPE_FIELDS (t),
-				t->num_fields ());
+  t->set_fields (XRESIZEVEC (struct field, TYPE_FIELDS (t),
+			     t->num_fields ()));
   f = &(TYPE_FIELDS (t)[t->num_fields () - 1]);
   memset (f, 0, sizeof f[0]);
   FIELD_TYPE (f[0]) = field;
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index e5f46dca0d2..3ed9f8e7fc1 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -913,6 +913,18 @@  struct type
     this->main_type->nfields = num_fields;
   }
 
+  /* Get the fields array of this type.  */
+  field *fields () const
+  {
+    return this->main_type->flds_bnds.fields;
+  }
+
+  /* Set the fields array of this type.  */
+  void set_fields (field *fields)
+  {
+    this->main_type->flds_bnds.fields = fields;
+  }
+
   /* * Return the dynamic property of the requested KIND from this type's
      list of dynamic properties.  */
   dynamic_prop *dyn_prop (dynamic_prop_node_kind kind) const;
@@ -1458,7 +1470,7 @@  extern unsigned type_align (struct type *);
    space in struct type.  */
 extern bool set_type_align (struct type *, ULONGEST);
 
-#define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields
+#define TYPE_FIELDS(thistype) (thistype)->fields ()
 
 #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
 #define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index c1967e62bb7..064f924c769 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -166,7 +166,7 @@  build_gdb_vtable_type (struct gdbarch *arch)
 
   t = arch_type (arch, TYPE_CODE_STRUCT, offset * TARGET_CHAR_BIT, NULL);
   t->set_num_fields (field - field_list);
-  TYPE_FIELDS (t) = field_list;
+  t->set_fields (field_list);
   t->set_name ("gdb_gnu_v3_abi_vtable");
   INIT_CPLUS_SPECIFIC (t);
 
@@ -1055,7 +1055,7 @@  build_std_type_info_type (struct gdbarch *arch)
 
   t = arch_type (arch, TYPE_CODE_STRUCT, offset * TARGET_CHAR_BIT, NULL);
   t->set_num_fields (field - field_list);
-  TYPE_FIELDS (t) = field_list;
+  t->set_fields (field_list);
   t->set_name ("gdb_gnu_v3_type_info");
   INIT_CPLUS_SPECIFIC (t);
 
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index f634dbb08f1..aeecb14f19e 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1018,9 +1018,8 @@  parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 	t->set_code (type_code);
 	TYPE_LENGTH (t) = sh->value;
 	t->set_num_fields (nfields);
-	TYPE_FIELDS (t) = f = ((struct field *)
-			       TYPE_ALLOC (t,
-					   nfields * sizeof (struct field)));
+	f = ((struct field *) TYPE_ALLOC (t, nfields * sizeof (struct field)));
+	t->set_fields (f);
 
 	if (type_code == TYPE_CODE_ENUM)
 	  {
@@ -1187,8 +1186,9 @@  parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 		  struct block_iterator iter;
 
 		  ftype->set_num_fields (nparams);
-		  TYPE_FIELDS (ftype) = (struct field *)
-		    TYPE_ALLOC (ftype, nparams * sizeof (struct field));
+		  ftype->set_fields
+		    ((struct field *)
+		     TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
 
 		  iparams = 0;
 		  ALL_BLOCK_SYMBOLS (cblock, iter, sym)
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index f8696628474..f7eba1d9f2f 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -985,8 +985,8 @@  rust_composite_type (struct type *original,
   result->set_name (name);
 
   result->set_num_fields (nfields);
-  TYPE_FIELDS (result)
-    = (struct field *) TYPE_ZALLOC (result, nfields * sizeof (struct field));
+  result->set_fields
+    ((struct field *) TYPE_ZALLOC (result, nfields * sizeof (struct field)));
 
   i = 0;
   bitpos = 0;
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index daf88c851c7..e710a43b7a0 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -986,8 +986,9 @@  define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
 	    }
 
 	  /* Allocate parameter information fields and fill them in.  */
-	  TYPE_FIELDS (ftype) = (struct field *)
-	    TYPE_ALLOC (ftype, nsemi * sizeof (struct field));
+	  ftype->set_fields
+	    ((struct field *)
+	     TYPE_ALLOC (ftype, nsemi * sizeof (struct field)));
 	  while (*p++ == ';')
 	    {
 	      struct type *ptype;
@@ -1836,9 +1837,9 @@  read_type (const char **pp, struct objfile *objfile)
             && arg_types->type->code () == TYPE_CODE_VOID)
           num_args = 0;
 
-        TYPE_FIELDS (func_type)
-          = (struct field *) TYPE_ALLOC (func_type,
-                                         num_args * sizeof (struct field));
+	func_type->set_fields
+	  ((struct field *) TYPE_ALLOC (func_type,
+					num_args * sizeof (struct field)));
         memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
         {
           int i;
@@ -3309,8 +3310,9 @@  attach_fields_to_type (struct stab_field_info *fip, struct type *type,
      array of fields, and create blank visibility bitfields if necessary.  */
 
   type->set_num_fields (nfields);
-  TYPE_FIELDS (type) = (struct field *)
-    TYPE_ALLOC (type, sizeof (struct field) * nfields);
+  type->set_fields
+    ((struct field *)
+     TYPE_ALLOC (type, sizeof (struct field) * nfields));
   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
 
   if (non_public_fields)
@@ -3655,8 +3657,9 @@  read_enum_type (const char **pp, struct type *type,
   if (unsigned_enum)
     TYPE_UNSIGNED (type) = 1;
   type->set_num_fields (nsyms);
-  TYPE_FIELDS (type) = (struct field *)
-    TYPE_ALLOC (type, sizeof (struct field) * nsyms);
+  type->set_fields
+    ((struct field *)
+     TYPE_ALLOC (type, sizeof (struct field) * nsyms));
   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
 
   /* Find the symbols for the values and put them into the type.