[binutils-gdb] gas alloc casts

Alan Modra amodra@sourceware.org
Wed Jul 9 00:06:36 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=60ba816bc1dba2435f0dc03ce1ffca0fd7254719

commit 60ba816bc1dba2435f0dc03ce1ffca0fd7254719
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Jul 9 09:02:28 2025 +0930

    gas alloc casts
    
    All of the various memory allocation function return a "void *"
    pointer, which needs no cast to assign to other pointer types.

Diff:
---
 gas/cond.c                | 15 +++++----------
 gas/config/obj-coff.c     |  4 ++--
 gas/config/obj-elf.c      |  2 +-
 gas/config/tc-aarch64.c   |  2 +-
 gas/config/tc-arc.c       |  2 +-
 gas/config/tc-arm.c       |  2 +-
 gas/config/tc-bfin.c      |  8 ++++----
 gas/config/tc-csky.c      |  3 +--
 gas/config/tc-kvx.c       |  2 +-
 gas/config/tc-loongarch.c |  2 +-
 gas/config/tc-mips.c      |  2 +-
 gas/config/tc-riscv.c     | 10 ++++------
 gas/config/tc-xtensa.c    |  2 +-
 gas/ecoff.c               |  4 ++--
 gas/frags.c               |  2 +-
 gas/read.c                |  4 ++--
 gas/subsegs.c             |  2 +-
 gas/write.c               |  2 +-
 18 files changed, 31 insertions(+), 39 deletions(-)

diff --git a/gas/cond.c b/gas/cond.c
index 27898df5dfa..2e3b3fd6f6c 100644
--- a/gas/cond.c
+++ b/gas/cond.c
@@ -110,8 +110,7 @@ s_ifdef (int test_defined)
       cframe.ignoring = ! (test_defined ^ is_defined);
     }
 
-  current_cframe =
-    (struct conditional_frame *) obstack_alloc (&cond_obstack, sizeof cframe);
+  current_cframe = obstack_alloc (&cond_obstack, sizeof cframe);
   memcpy (current_cframe, &cframe, sizeof cframe);
 
   if (LISTING_SKIP_COND ()
@@ -168,8 +167,7 @@ s_if (int arg)
      using an undefined result.  No big deal.  */
   initialize_cframe (&cframe);
   cframe.ignoring = cframe.dead_tree || ! t;
-  current_cframe =
-    (struct conditional_frame *) obstack_alloc (&cond_obstack, sizeof cframe);
+  current_cframe = obstack_alloc (&cond_obstack, sizeof cframe);
   memcpy (current_cframe, & cframe, sizeof cframe);
 
   if (LISTING_SKIP_COND ()
@@ -205,8 +203,7 @@ s_ifb (int test_blank)
       cframe.ignoring = (test_blank == !is_eol);
     }
 
-  current_cframe =
-    (struct conditional_frame *) obstack_alloc (&cond_obstack, sizeof cframe);
+  current_cframe = obstack_alloc (&cond_obstack, sizeof cframe);
   memcpy (current_cframe, &cframe, sizeof cframe);
 
   if (LISTING_SKIP_COND ()
@@ -286,8 +283,7 @@ s_ifc (int arg)
 
   initialize_cframe (&cframe);
   cframe.ignoring = cframe.dead_tree || ! (res ^ arg);
-  current_cframe =
-    (struct conditional_frame *) obstack_alloc (&cond_obstack, sizeof cframe);
+  current_cframe = obstack_alloc (&cond_obstack, sizeof cframe);
   memcpy (current_cframe, &cframe, sizeof cframe);
   
  if (LISTING_SKIP_COND ()
@@ -481,8 +477,7 @@ s_ifeqs (int arg)
 
   initialize_cframe (&cframe);
   cframe.ignoring = cframe.dead_tree || ! (res ^ arg);
-  current_cframe =
-    (struct conditional_frame *) obstack_alloc (&cond_obstack, sizeof cframe);
+  current_cframe = obstack_alloc (&cond_obstack, sizeof cframe);
   memcpy (current_cframe, &cframe, sizeof cframe);
 
   if (LISTING_SKIP_COND ()
diff --git a/gas/config/obj-coff.c b/gas/config/obj-coff.c
index a926548af74..41cc2dace44 100644
--- a/gas/config/obj-coff.c
+++ b/gas/config/obj-coff.c
@@ -369,10 +369,10 @@ void
 coff_obj_symbol_new_hook (symbolS *symbolP)
 {
   size_t sz = (OBJ_COFF_MAX_AUXENTRIES + 1) * sizeof (combined_entry_type);
-  char *s  = notes_alloc (sz);
+  combined_entry_type *s  = notes_alloc (sz);
 
   memset (s, 0, sz);
-  coffsymbol (symbol_get_bfdsym (symbolP))->native = (combined_entry_type *) s;
+  coffsymbol (symbol_get_bfdsym (symbolP))->native = s;
   coffsymbol (symbol_get_bfdsym (symbolP))->native->is_sym = true;
 
   S_SET_DATA_TYPE (symbolP, T_NULL);
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index e2425fe3578..ff915b57cad 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -205,7 +205,7 @@ elf_file_symbol (const char *s)
   if (name_length > strlen (S_GET_NAME (sym)))
     {
       obstack_grow (&notes, s, name_length + 1);
-      S_SET_NAME (sym, (const char *) obstack_finish (&notes));
+      S_SET_NAME (sym, obstack_finish (&notes));
     }
   else
     strcpy ((char *) S_GET_NAME (sym), s);
diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index dd66e006a7b..32fe7b83c06 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -5632,7 +5632,7 @@ static const char *aarch64_apply_style
   gas_assert (res >= 0);
 
   /* Allocate space on the obstack and format the result.  */
-  ptr = (char *) obstack_alloc (stack, res + 1);
+  ptr = obstack_alloc (stack, res + 1);
   res = vsnprintf (ptr, (res + 1), fmt, args);
   gas_assert (res >= 0);
 
diff --git a/gas/config/tc-arc.c b/gas/config/tc-arc.c
index 83f03c3f4cf..aa3a0b2dd0b 100644
--- a/gas/config/tc-arc.c
+++ b/gas/config/tc-arc.c
@@ -4971,7 +4971,7 @@ arc_stralloc (char * s1, const char * s2)
   gas_assert (s2);
   len += strlen (s2) + 1;
 
-  p = (char *) xmalloc (len);
+  p = xmalloc (len);
 
   if (s1)
     {
diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c
index f6f4eb99c93..9a1ef1bd1c0 100644
--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -3701,7 +3701,7 @@ symbol_locate (symbolS *    symbolP,
 
   name_length = strlen (name) + 1;   /* +1 for \0.  */
   obstack_grow (&notes, name, name_length);
-  preserved_copy_of_name = (char *) obstack_finish (&notes);
+  preserved_copy_of_name = obstack_finish (&notes);
 
 #ifdef tc_canonicalize_symbol_name
   preserved_copy_of_name =
diff --git a/gas/config/tc-bfin.c b/gas/config/tc-bfin.c
index d4caa9e6cee..0a635f4c4df 100644
--- a/gas/config/tc-bfin.c
+++ b/gas/config/tc-bfin.c
@@ -937,7 +937,7 @@ Expr_Node_Create (Expr_Node_Type type,
 {
 
 
-  Expr_Node *node = (Expr_Node *) allocate (sizeof (Expr_Node));
+  Expr_Node *node = allocate (sizeof (Expr_Node));
   node->type = type;
   node->value = value;
   node->Left_Child = Left_Child;
@@ -1857,8 +1857,8 @@ bfin_gen_loop (Expr_Node *exp, REG_T reg, int rop, REG_T preg)
   symbolS *sym;
 
   loopsym = exp->value.s_value;
-  lbeginsym = (char *) xmalloc (strlen (loopsym) + strlen ("__BEGIN") + 5);
-  lendsym = (char *) xmalloc (strlen (loopsym) + strlen ("__END") + 5);
+  lbeginsym = xmalloc (strlen (loopsym) + strlen ("__BEGIN") + 5);
+  lendsym = xmalloc (strlen (loopsym) + strlen ("__END") + 5);
 
   lbeginsym[0] = 0;
   lendsym[0] = 0;
@@ -1902,7 +1902,7 @@ bfin_loop_beginend (Expr_Node *exp, int begin)
   const char *suffix = begin ? "__BEGIN" : "__END";
 
   loopsym = exp->value.s_value;
-  label_name = (char *) xmalloc (strlen (loopsym) + strlen (suffix) + 5);
+  label_name = xmalloc (strlen (loopsym) + strlen (suffix) + 5);
 
   label_name[0] = 0;
 
diff --git a/gas/config/tc-csky.c b/gas/config/tc-csky.c
index 7eaf7a90bca..9a7749edf69 100644
--- a/gas/config/tc-csky.c
+++ b/gas/config/tc-csky.c
@@ -7861,8 +7861,7 @@ static void
 csky_stack_size (int arg ATTRIBUTE_UNUSED)
 {
   expressionS exp;
-  stack_size_entry *sse
-    = (stack_size_entry *) xcalloc (1, sizeof (stack_size_entry));
+  stack_size_entry *sse = xcalloc (1, sizeof (stack_size_entry));
 
   expression (&exp);
   if (exp.X_op == O_symbol)
diff --git a/gas/config/tc-kvx.c b/gas/config/tc-kvx.c
index 558265084a6..501ce1d7274 100644
--- a/gas/config/tc-kvx.c
+++ b/gas/config/tc-kvx.c
@@ -1644,7 +1644,7 @@ md_apply_fix (fixS * fixP, valueT * valueP, segT segmentP ATTRIBUTE_UNUSED)
   valueT image;
   arelent *rel;
 
-  rel = (arelent *) xmalloc (sizeof (arelent));
+  rel = xmalloc (sizeof (arelent));
 
   rel->howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
   if (rel->howto == NULL)
diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c
index 06fb6013cb5..a91b12eaa9c 100644
--- a/gas/config/tc-loongarch.c
+++ b/gas/config/tc-loongarch.c
@@ -483,7 +483,7 @@ static symbolS *get_align_symbol (segT sec)
 							    &entry, INSERT);
   if (slot == NULL)
     return NULL;
-  *slot = (align_sec_sym *) xmalloc (sizeof (align_sec_sym));
+  *slot = xmalloc (sizeof (align_sec_sym));
   if (*slot == NULL)
     return NULL;
   **slot = entry;
diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c
index 9b1ee22ee70..84ef1842a4e 100644
--- a/gas/config/tc-mips.c
+++ b/gas/config/tc-mips.c
@@ -3384,7 +3384,7 @@ mips_parse_arguments (char *s, char float_format)
       SKIP_SPACE_TABS (s);
     }
   mips_add_token (&token, OT_END);
-  return (struct mips_operand_token *) obstack_finish (&mips_operand_tokens);
+  return obstack_finish (&mips_operand_tokens);
 }
 
 /* Return TRUE if opcode MO is valid on the currently selected ISA, ASE
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index f5740f8e81b..6b8bde94c10 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -1886,15 +1886,13 @@ riscv_record_pcrel_fixup (htab_t p, const asection *sec, bfd_vma address,
 			  symbolS *symbol, bfd_vma target)
 {
   riscv_pcrel_hi_fixup entry = {sec, address, symbol, target};
-  riscv_pcrel_hi_fixup **slot =
-	(riscv_pcrel_hi_fixup **) htab_find_slot (p, &entry, INSERT);
+  void **slot = htab_find_slot (p, &entry, INSERT);
   if (slot == NULL)
     return false;
 
-  *slot = (riscv_pcrel_hi_fixup *) xmalloc (sizeof (riscv_pcrel_hi_fixup));
-  if (*slot == NULL)
-    return false;
-  **slot = entry;
+  riscv_pcrel_hi_fixup *pent = xmalloc (sizeof (*pent));
+  *slot = pent;
+  *pent = entry;
   return true;
 }
 
diff --git a/gas/config/tc-xtensa.c b/gas/config/tc-xtensa.c
index 040e3977a81..9afda6beba2 100644
--- a/gas/config/tc-xtensa.c
+++ b/gas/config/tc-xtensa.c
@@ -2522,7 +2522,7 @@ xg_translate_idioms (char **popname, int *pnum_args, char **arg_strings)
     {
       if (*pnum_args == 0)
 	{
-	  arg_strings[0] = (char *) xmalloc (2);
+	  arg_strings[0] = xmalloc (2);
 	  strcpy (arg_strings[0], "0");
 	  *pnum_args = 1;
 	}
diff --git a/gas/ecoff.c b/gas/ecoff.c
index 27724bbe474..235bb80aed6 100644
--- a/gas/ecoff.c
+++ b/gas/ecoff.c
@@ -1524,7 +1524,7 @@ add_varray_page (varray_t *vp /* varray to add page to */)
 
 #ifdef MALLOC_CHECK
   if (vp->object_size > 1)
-    new_links->datum = (page_type *) xcalloc (1, vp->object_size);
+    new_links->datum = xcalloc (1, vp->object_size);
   else
 #endif
     new_links->datum = allocate_page ();
@@ -4715,7 +4715,7 @@ ecoff_build_debug (HDRR *hdr,
 static page_type *
 allocate_cluster (unsigned long npages)
 {
-  page_type *value = (page_type *) xmalloc (npages * PAGE_USIZE);
+  page_type *value = xmalloc (npages * PAGE_USIZE);
 
 #ifdef ECOFF_DEBUG
   if (debug > 3)
diff --git a/gas/frags.c b/gas/frags.c
index 59699ae5943..0ad1240a7bd 100644
--- a/gas/frags.c
+++ b/gas/frags.c
@@ -81,7 +81,7 @@ frag_alloc (struct obstack *ob, size_t extra)
   (void) obstack_alloc (ob, 0);
   oalign = obstack_alignment_mask (ob);
   obstack_alignment_mask (ob) = 0;
-  ptr = (fragS *) obstack_alloc (ob, extra + SIZEOF_STRUCT_FRAG);
+  ptr = obstack_alloc (ob, extra + SIZEOF_STRUCT_FRAG);
   obstack_alignment_mask (ob) = oalign;
   memset (ptr, 0, SIZEOF_STRUCT_FRAG);
   totalfrags++;
diff --git a/gas/read.c b/gas/read.c
index 874802e4d67..a00fa974a22 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -6348,7 +6348,7 @@ demand_copy_string (int *lenP)
       /* JF this next line is so demand_copy_C_string will return a
 	 null terminated string.  */
       obstack_1grow (&notes, '\0');
-      retval = (char *) obstack_finish (&notes);
+      retval = obstack_finish (&notes);
     }
   else
     {
@@ -6567,7 +6567,7 @@ s_include (int arg ATTRIBUTE_UNUSED)
 	}
 
       obstack_1grow (&notes, '\0');
-      filename = (char *) obstack_finish (&notes);
+      filename = obstack_finish (&notes);
       while (!is_end_of_stmt (*input_line_pointer))
 	++input_line_pointer;
     }
diff --git a/gas/subsegs.c b/gas/subsegs.c
index bc80c850b76..8a5f7acfb48 100644
--- a/gas/subsegs.c
+++ b/gas/subsegs.c
@@ -132,7 +132,7 @@ subseg_set_rest (segT seg, subsegT subseg)
     {
       /* This should be the only code that creates a frchainS.  */
 
-      newP = (frchainS *) obstack_alloc (&frchains, sizeof (frchainS));
+      newP = obstack_alloc (&frchains, sizeof (frchainS));
       newP->frch_subseg = subseg;
       newP->fix_root = NULL;
       newP->fix_tail = NULL;
diff --git a/gas/write.c b/gas/write.c
index 93ec6147440..353b11c47ba 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -142,7 +142,7 @@ fix_new_internal (fragS *frag,		/* Which frag?  */
 
   n_fixups++;
 
-  fixP = (fixS *) obstack_alloc (&notes, sizeof (fixS));
+  fixP = obstack_alloc (&notes, sizeof (fixS));
 
   fixP->fx_frag = frag;
   fixP->fx_where = where;


More information about the Binutils-cvs mailing list