[6/7] gdb: remove make_cv_type typeptr parameter

Message ID 20251217155550.37654-7-simon.marchi@efficios.com
State New
Headers
Series gdbtypes cleanups |

Commit Message

Simon Marchi Dec. 17, 2025, 3:55 p.m. UTC
  From: Simon Marchi <simon.marchi@polymtl.ca>

It is always passed nullptr.

Change-Id: Iecc170545c0504af35d83bcb06e07d29994d18e1
---
 gdb/c-typeprint.c        |  2 +-
 gdb/ctfread.c            |  6 +++---
 gdb/dwarf2/read.c        |  8 +++----
 gdb/gdbtypes.c           | 45 ++++------------------------------------
 gdb/gdbtypes.h           |  8 ++++++-
 gdb/gnu-v3-abi.c         |  4 ++--
 gdb/guile/scm-type.c     |  6 +++---
 gdb/opencl-lang.c        |  2 +-
 gdb/python/py-type.c     | 10 ++++-----
 gdb/python/py-xmethods.c |  3 +--
 gdb/rust-lang.c          |  2 +-
 gdb/type-stack.c         |  4 ++--
 gdb/valops.c             |  4 ++--
 gdb/value.c              |  4 ++--
 14 files changed, 38 insertions(+), 70 deletions(-)
  

Patch

diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 2f921aec8fc3..c7434fa0edc8 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -543,7 +543,7 @@  c_type_print_args (struct type *type, struct ui_file *stream,
 	     And the const/volatile qualifiers are not present in the mangled
 	     names as produced by GCC.  */
 
-	  param_type = make_cv_type (0, 0, param_type, NULL);
+	  param_type = make_cv_type (0, 0, param_type);
 	}
 
       c_print_type (param_type, "", stream, -1, 0, language, flags);
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 860894bf0a02..8d0dcf09b2f1 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -717,7 +717,7 @@  add_array_cv_type (struct ctf_context *ccp,
   el_type = inner_array->target_type ();
   cnst |= TYPE_CONST (el_type);
   voltl |= TYPE_VOLATILE (el_type);
-  inner_array->set_target_type (make_cv_type (cnst, voltl, el_type, nullptr));
+  inner_array->set_target_type (make_cv_type (cnst, voltl, el_type));
 
   return set_tid_type (ccp->of, tid, base_type);
 }
@@ -783,7 +783,7 @@  read_const_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
 	  base_type = builtin_type (objfile)->builtin_error;
 	}
     }
-  cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
+  cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type);
 
   return set_tid_type (objfile, tid, cv_type);
 }
@@ -810,7 +810,7 @@  read_volatile_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
 
   if (ctf_type_kind (dict, btid) == CTF_K_ARRAY)
     return add_array_cv_type (ccp, tid, base_type, 0, 1);
-  cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
+  cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type);
 
   return set_tid_type (objfile, tid, cv_type);
 }
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 12f3e5f0e3dd..50f626c0fdbc 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -13012,7 +13012,7 @@  add_array_cv_type (struct die_info *die, struct dwarf2_cu *cu,
   el_type = inner_array->target_type ();
   cnst |= TYPE_CONST (el_type);
   voltl |= TYPE_VOLATILE (el_type);
-  inner_array->set_target_type (make_cv_type (cnst, voltl, el_type, NULL));
+  inner_array->set_target_type (make_cv_type (cnst, voltl, el_type));
 
   return set_die_type (die, base_type, cu);
 }
@@ -13034,7 +13034,7 @@  read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
   if (base_type->code () == TYPE_CODE_ARRAY)
     return add_array_cv_type (die, cu, base_type, 1, 0);
 
-  cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
+  cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type);
   return set_die_type (die, cv_type, cu);
 }
 
@@ -13056,7 +13056,7 @@  read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
   if (base_type->code () == TYPE_CODE_ARRAY)
     return add_array_cv_type (die, cu, base_type, 0, 1);
 
-  cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
+  cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type);
   return set_die_type (die, cv_type, cu);
 }
 
@@ -13380,7 +13380,7 @@  read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
 
 		  if (is_this)
 		    arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
-					     arg_type, 0);
+					     arg_type);
 		}
 
 	      ftype->field (iparams).set_type (arg_type);
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index d3e9bbbdcd52..f485dfbc8e14 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -652,25 +652,11 @@  make_type_with_address_space (struct type *type,
   return make_qualified_type (type, new_flags, NULL);
 }
 
-/* Make a "c-v" variant of a type -- a type that is identical to the
-   one supplied except that it may have const or volatile attributes
-   CNST is a flag for setting the const attribute
-   VOLTL is a flag for setting the volatile attribute
-   TYPE is the base type whose variant we are creating.
+/* See gdbtypes.h.  */
 
-   If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
-   storage to hold the new qualified type; *TYPEPTR and TYPE must be
-   in the same objfile.  Otherwise, allocate fresh memory for the new
-   type wherever TYPE lives.  If TYPEPTR is non-zero, set it to the
-   new type we construct.  */
-
-struct type *
-make_cv_type (int cnst, int voltl,
-	      struct type *type,
-	      struct type **typeptr)
+type *
+make_cv_type (int cnst, int voltl, type *type)
 {
-  struct type *ntype;	/* New type */
-
   type_instance_flags new_flags = (type->instance_flags ()
 				   & ~(TYPE_INSTANCE_FLAG_CONST
 				       | TYPE_INSTANCE_FLAG_VOLATILE));
@@ -681,30 +667,7 @@  make_cv_type (int cnst, int voltl,
   if (voltl)
     new_flags |= TYPE_INSTANCE_FLAG_VOLATILE;
 
-  if (typeptr && *typeptr != NULL)
-    {
-      /* TYPE and *TYPEPTR must be in the same objfile.  We can't have
-	 a C-V variant chain that threads across objfiles: if one
-	 objfile gets freed, then the other has a broken C-V chain.
-
-	 This code used to try to copy over the main type from TYPE to
-	 *TYPEPTR if they were in different objfiles, but that's
-	 wrong, too: TYPE may have a field list or member function
-	 lists, which refer to types of their own, etc. etc.  The
-	 whole shebang would need to be copied over recursively; you
-	 can't have inter-objfile pointers.  The only thing to do is
-	 to leave stub types as stub types, and look them up afresh by
-	 name each time you encounter them.  */
-      gdb_assert ((*typeptr)->objfile_owner () == type->objfile_owner ());
-    }
-
-  ntype = make_qualified_type (type, new_flags,
-			       typeptr ? *typeptr : NULL);
-
-  if (typeptr != NULL)
-    *typeptr = ntype;
-
-  return ntype;
+  return make_qualified_type (type, new_flags, nullptr);
 }
 
 /* Make a 'restrict'-qualified version of TYPE.  */
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 486d62244f6c..2ad8d1044336 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -2437,7 +2437,13 @@  extern struct type *lookup_rvalue_reference_type (struct type *);
 
 extern type *make_reference_type (type *type, type_code refcode);
 
-extern struct type *make_cv_type (int, int, struct type *, struct type **);
+/* Make a "c-v" variant of a type -- a type that is identical to the
+   one supplied except that it may have const or volatile attributes
+   CNST is a flag for setting the const attribute
+   VOLTL is a flag for setting the volatile attribute
+   TYPE is the base type whose variant we are creating.  */
+
+extern type *make_cv_type (int cnst, int voltl, type *type);
 
 extern struct type *make_restrict_type (struct type *);
 
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 483ae2d98909..337a85ad82d8 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -1003,7 +1003,7 @@  build_std_type_info_type (struct gdbarch *arch)
   struct type *char_type
     = builtin_type (arch)->builtin_char;
   struct type *char_ptr_type
-    = make_pointer_type (make_cv_type (1, 0, char_type, NULL));
+    = make_pointer_type (make_cv_type (1, 0, char_type));
 
   t = type_allocator (arch).new_type (TYPE_CODE_STRUCT, 0, nullptr);
 
@@ -1088,7 +1088,7 @@  gnuv3_get_typeid (struct value *value)
     type = check_typedef (type->target_type ());
 
   /* Ignore top-level cv-qualifiers.  */
-  type = make_cv_type (0, 0, type, NULL);
+  type = make_cv_type (0, 0, type);
   gdbarch = type->arch ();
 
   type_name = type_to_string (type);
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index 13676cef4f00..e5a1e646db2a 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -895,7 +895,7 @@  gdbscm_type_const (SCM self)
   gdbscm_gdb_exception exc {};
   try
     {
-      type = make_cv_type (1, 0, type, NULL);
+      type = make_cv_type (1, 0, type);
     }
   catch (const gdb_exception &except)
     {
@@ -919,7 +919,7 @@  gdbscm_type_volatile (SCM self)
   gdbscm_gdb_exception exc {};
   try
     {
-      type = make_cv_type (0, 1, type, NULL);
+      type = make_cv_type (0, 1, type);
     }
   catch (const gdb_exception &except)
     {
@@ -943,7 +943,7 @@  gdbscm_type_unqualified (SCM self)
   gdbscm_gdb_exception exc {};
   try
     {
-      type = make_cv_type (0, 0, type, NULL);
+      type = make_cv_type (0, 0, type);
     }
   catch (const gdb_exception &except)
     {
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index b3286ff4dc56..3765fc988ea6 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -292,7 +292,7 @@  create_value (struct gdbarch *gdbarch, struct value *val, enum noside noside,
       if (dst_type == NULL)
 	dst_type = init_vector_type (elm_type, n);
 
-      make_cv_type (TYPE_CONST (type), TYPE_VOLATILE (type), dst_type, NULL);
+      make_cv_type (TYPE_CONST (type), TYPE_VOLATILE (type), dst_type);
 
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
 	ret = value::allocate (dst_type);
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 5a57df41a954..fca99a0f2597 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -719,7 +719,7 @@  typy_const (PyObject *self, PyObject *args)
 
   try
     {
-      type = make_cv_type (1, TYPE_VOLATILE (type), type, NULL);
+      type = make_cv_type (1, TYPE_VOLATILE (type), type);
     }
   catch (const gdb_exception &except)
     {
@@ -737,7 +737,7 @@  typy_volatile (PyObject *self, PyObject *args)
 
   try
     {
-      type = make_cv_type (TYPE_CONST (type), 1, type, NULL);
+      type = make_cv_type (TYPE_CONST (type), 1, type);
     }
   catch (const gdb_exception &except)
     {
@@ -755,7 +755,7 @@  typy_unqualified (PyObject *self, PyObject *args)
 
   try
     {
-      type = make_cv_type (0, 0, type, NULL);
+      type = make_cv_type (0, 0, type);
     }
   catch (const gdb_exception &except)
     {
@@ -895,10 +895,10 @@  typy_lookup_type (struct demangle_component *demangled,
 	      rtype = lookup_pointer_type (type);
 	      break;
 	    case DEMANGLE_COMPONENT_CONST:
-	      rtype = make_cv_type (1, TYPE_VOLATILE (type), type, NULL);
+	      rtype = make_cv_type (1, TYPE_VOLATILE (type), type);
 	      break;
 	    case DEMANGLE_COMPONENT_VOLATILE:
-	      rtype = make_cv_type (TYPE_CONST (type), 1, type, NULL);
+	      rtype = make_cv_type (TYPE_CONST (type), 1, type);
 	      break;
 	    }
 	}
diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c
index afedd0f5008c..3ea82d56d212 100644
--- a/gdb/python/py-xmethods.c
+++ b/gdb/python/py-xmethods.c
@@ -393,8 +393,7 @@  python_xmethod_worker::do_get_arg_types (std::vector<type *> *arg_types)
      be a 'const' value.  Hence, create a 'const' variant of the 'this' pointer
      type.  */
   obj_type = type_object_to_type (m_this_type);
-  (*arg_types)[0] = make_cv_type (1, 0, lookup_pointer_type (obj_type),
-				  NULL);
+  (*arg_types)[0] = make_cv_type (1, 0, lookup_pointer_type (obj_type));
 
   return EXT_LANG_RC_OK;
 }
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 20dffbe8d206..5aae7ae63582 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1749,7 +1749,7 @@  rust_language::language_arch_info (struct gdbarch *gdbarch,
   add (init_float_type (alloc, 64, "f64", floatformats_ieee_double));
   add (init_integer_type (alloc, 0, 1, "()"));
 
-  struct type *tem = make_cv_type (1, 0, u8_type, NULL);
+  struct type *tem = make_cv_type (1, 0, u8_type);
   add (rust_slice_type ("&str", tem, usize_type));
 
   lai->set_bool_type (bool_type);
diff --git a/gdb/type-stack.c b/gdb/type-stack.c
index b9266b83f29e..2a08fc5f06dc 100644
--- a/gdb/type-stack.c
+++ b/gdb/type-stack.c
@@ -146,11 +146,11 @@  type_stack::follow_types (struct type *follow_type)
 	if (make_const)
 	  follow_type = make_cv_type (make_const,
 				      TYPE_VOLATILE (follow_type),
-				      follow_type, 0);
+				      follow_type);
 	if (make_volatile)
 	  follow_type = make_cv_type (TYPE_CONST (follow_type),
 				      make_volatile,
-				      follow_type, 0);
+				      follow_type);
 	if (make_addr_space)
 	  follow_type = make_type_with_address_space (follow_type,
 						      make_addr_space);
diff --git a/gdb/valops.c b/gdb/valops.c
index 446c14ff0350..d58ff1133253 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3879,7 +3879,7 @@  value_rtti_indirect_type (struct value *v, int *full,
       /* Copy qualifiers to the referenced object.  */
       target_type = target->type ();
       real_type = make_cv_type (TYPE_CONST (target_type),
-				TYPE_VOLATILE (target_type), real_type, NULL);
+				TYPE_VOLATILE (target_type), real_type);
       if (TYPE_IS_REFERENCE (type))
 	real_type = lookup_reference_type (real_type, type->code ());
       else if (type->code () == TYPE_CODE_PTR)
@@ -3889,7 +3889,7 @@  value_rtti_indirect_type (struct value *v, int *full,
 
       /* Copy qualifiers to the pointer/reference.  */
       real_type = make_cv_type (TYPE_CONST (type), TYPE_VOLATILE (type),
-				real_type, NULL);
+				real_type);
     }
 
   return real_type;
diff --git a/gdb/value.c b/gdb/value.c
index b7ca663d998e..93e928a7debc 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1600,8 +1600,8 @@  make_cv_value (int cnst, int voltl, struct value *v)
   struct type *m_enclosing_type = v->enclosing_type ();
   struct value *cv_val = v->copy ();
 
-  cv_val->deprecated_set_type (make_cv_type (cnst, voltl, val_type, NULL));
-  cv_val->set_enclosing_type (make_cv_type (cnst, voltl, m_enclosing_type, NULL));
+  cv_val->deprecated_set_type (make_cv_type (cnst, voltl, val_type));
+  cv_val->set_enclosing_type (make_cv_type (cnst, voltl, m_enclosing_type));
 
   return cv_val;
 }