]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas alloc casts
authorAlan Modra <amodra@gmail.com>
Tue, 8 Jul 2025 23:32:28 +0000 (09:02 +0930)
committerAlan Modra <amodra@gmail.com>
Wed, 9 Jul 2025 00:05:07 +0000 (09:35 +0930)
All of the various memory allocation function return a "void *"
pointer, which needs no cast to assign to other pointer types.

18 files changed:
gas/cond.c
gas/config/obj-coff.c
gas/config/obj-elf.c
gas/config/tc-aarch64.c
gas/config/tc-arc.c
gas/config/tc-arm.c
gas/config/tc-bfin.c
gas/config/tc-csky.c
gas/config/tc-kvx.c
gas/config/tc-loongarch.c
gas/config/tc-mips.c
gas/config/tc-riscv.c
gas/config/tc-xtensa.c
gas/ecoff.c
gas/frags.c
gas/read.c
gas/subsegs.c
gas/write.c

index 27898df5dfa891b8af94967a692e652ea0707781..2e3b3fd6f6cddacf9b82af83dead4772f84d0ac9 100644 (file)
@@ -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 ()
index a926548af74623eb3c12e008cfe752f8447b67b2..41cc2dace445e06c3f30d9a2cc2f8f82061d95b6 100644 (file)
@@ -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);
index e2425fe357882f31834e99f7fe59a843d8842249..ff915b57cad5dd887c2b0e7328614e548ac87ac0 100644 (file)
@@ -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);
index dd66e006a7bcfe30511cf06c4f35150ad3269868..32fe7b83c067b3963439706bbfb4052c9b34c8e3 100644 (file)
@@ -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);
 
index 83f03c3f4cfd705bdb4771850bf83ed45de70056..aa3a0b2dd0b27c8f078801e670dc36cb1ec77b8c 100644 (file)
@@ -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)
     {
index f6f4eb99c93b009b3a153c909188b51d45e7556e..9a1ef1bd1c0332091b8a3e5a3a535bb0d42ac813 100644 (file)
@@ -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 =
index d4caa9e6ceed47e1c07533f042d6d17d2bb8240e..0a635f4c4dff2ef9b63cafc8c2e6c331a15d4628 100644 (file)
@@ -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;
 
index 7eaf7a90bca59c5b6e1bbcf565430aa62988cdc6..9a7749edf69258738a37bbf6ef77fba68199ee6a 100644 (file)
@@ -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)
index 558265084a69b9e8da5b7929d7fa539a32023e03..501ce1d727433d83f15cf28aefc354750c6c41c9 100644 (file)
@@ -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)
index 06fb6013cb58e369f20181d7369891ecff6a6166..a91b12eaa9cce08bf9df8eb2b127f627ba49f113 100644 (file)
@@ -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;
index 9b1ee22ee70c3308d60c059086bea74b896d0f12..84ef1842a4e4edf4d6f37a45740b25221ddc8483 100644 (file)
@@ -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
index f5740f8e81b8ec19073763d9a92887827eead04e..6b8bde94c10b026ad1288b457c40a9bcce9476bb 100644 (file)
@@ -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;
 }
 
index 040e3977a81adb38eea6ae151162da583edb1874..9afda6beba21daf9866517c4f8710f815b73862a 100644 (file)
@@ -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;
        }
index 27724bbe4744429bfd8771fd55d1cf08f5ceac93..235bb80aed64479abf5710133d1d5c4bc2964867 100644 (file)
@@ -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)
index 59699ae5943bae0d45be70d626625c0efeaf6953..0ad1240a7bdbd6fb496702facaff6eccec837867 100644 (file)
@@ -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++;
index 874802e4d67f6ed25404d32b6b808bea13b3866d..a00fa974a22502a4b996835ff5908b910b76d37e 100644 (file)
@@ -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;
     }
index bc80c850b76a4f72b461661dff5cab0841b2937e..8a5f7acfb485788f8b62a58aa824e038a9f56d28 100644 (file)
@@ -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;
index 93ec61474408ddeabb9fa03797e2444b32fba94e..353b11c47ba63292c3effce6ca3ce3cb78b79831 100644 (file)
@@ -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;