From a5b6fadf8854c72f7fd5a03b4fd332ead30c5117 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 9 Jul 2025 09:03:45 +0930 Subject: [PATCH] gas various other void* casts This removes assorted unneeded casts of void* pointers, and casts when passing args to void* parameters or storing to void* pointers. The patch also changes obj-coff.c stack_push to take a void* parameter, and replaces an odd memcpy in tc-metag.c find_insn_templates with a simple assignment. --- gas/config/obj-coff.c | 4 ++-- gas/config/obj-elf.c | 4 ++-- gas/config/obj-evax.c | 3 +-- gas/config/obj-macho.c | 11 +++++------ gas/config/tc-aarch64.c | 4 ++-- gas/config/tc-arc.c | 2 +- gas/config/tc-hppa.c | 14 +++++++------- gas/config/tc-m32r.c | 2 +- gas/config/tc-metag.c | 13 ++++++------- gas/config/tc-mmix.c | 6 ++---- gas/config/tc-riscv.c | 4 ++-- gas/config/tc-score.c | 2 +- gas/config/tc-sh.c | 2 +- gas/config/tc-sparc.c | 8 ++++---- gas/config/tc-tic54x.c | 6 +++--- gas/config/tc-v850.c | 2 +- gas/config/tc-vax.c | 8 +++----- gas/flonum-copy.c | 11 +++++------ gas/symbols.c | 8 ++++---- gas/write.c | 4 ++-- 20 files changed, 55 insertions(+), 63 deletions(-) diff --git a/gas/config/obj-coff.c b/gas/config/obj-coff.c index 41cc2dace44..3467d646428 100644 --- a/gas/config/obj-coff.c +++ b/gas/config/obj-coff.c @@ -90,7 +90,7 @@ stack_init (unsigned long chunk_size, } static char * -stack_push (stack *st, char *element) +stack_push (stack *st, void *element) { if (st->pointer + st->element_size >= st->size) { @@ -1325,7 +1325,7 @@ coff_frob_symbol (symbolS *symp, int *punt) if (S_GET_STORAGE_CLASS (symp) == C_BLOCK) { if (streq (S_GET_NAME (symp), ".bb")) - stack_push (block_stack, (char *) &symp); + stack_push (block_stack, &symp); else { symbolS *begin; diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c index 9342d11eb11..8eb267d7782 100644 --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -481,7 +481,7 @@ match_section (const asection *sec, const struct elf_section_match *match) static bool get_section_by_match (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *inf) { - struct elf_section_match *match = (struct elf_section_match *) inf; + struct elf_section_match *match = inf; const char *gname = match->group_name; const char *group_name = elf_group_name (sec); @@ -614,7 +614,7 @@ change_section (const char *name, old_sec = group_section_find (match_p, name, &group_idx); else old_sec = bfd_get_section_by_name_if (stdoutput, name, get_section_by_match, - (void *) match_p); + match_p); if (old_sec) { sec = old_sec; diff --git a/gas/config/obj-evax.c b/gas/config/obj-evax.c index c5317e8b434..9fbde27baff 100644 --- a/gas/config/obj-evax.c +++ b/gas/config/obj-evax.c @@ -107,8 +107,7 @@ evax_frob_symbol (symbolS *sym, int *punt) else if ((symbol->flags & BSF_GLOBAL) && (symbol->flags & BSF_FUNCTION)) { - struct evax_private_udata_struct *udata - = (struct evax_private_udata_struct *)symbol->udata.p; + struct evax_private_udata_struct *udata = symbol->udata.p; /* Fix up equates of function definitions. */ while (udata->enbsym == NULL) diff --git a/gas/config/obj-macho.c b/gas/config/obj-macho.c index adcdb99c740..c7171244acf 100644 --- a/gas/config/obj-macho.c +++ b/gas/config/obj-macho.c @@ -1698,7 +1698,7 @@ obj_mach_o_set_section_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *v_p { bfd_mach_o_section *ms = bfd_mach_o_get_mach_o_section (sec); unsigned bfd_align = bfd_section_alignment (sec); - obj_mach_o_set_vma_data *p = (struct obj_mach_o_set_vma_data *)v_p; + obj_mach_o_set_vma_data *p = v_p; unsigned sectype = (ms->flags & BFD_MACH_O_SECTION_TYPE_MASK); unsigned zf; @@ -1741,11 +1741,11 @@ void obj_mach_o_post_relax_hook (void) memset (&d, 0, sizeof (d)); - bfd_map_over_sections (stdoutput, obj_mach_o_set_section_vma, (char *) &d); + bfd_map_over_sections (stdoutput, obj_mach_o_set_section_vma, &d); if ((d.vma_pass = d.zerofill_seen) != 0) - bfd_map_over_sections (stdoutput, obj_mach_o_set_section_vma, (char *) &d); + bfd_map_over_sections (stdoutput, obj_mach_o_set_section_vma, &d); if ((d.vma_pass = d.gb_zerofill_seen) != 0) - bfd_map_over_sections (stdoutput, obj_mach_o_set_section_vma, (char *) &d); + bfd_map_over_sections (stdoutput, obj_mach_o_set_section_vma, &d); } static void @@ -1777,8 +1777,7 @@ obj_mach_o_set_indirect_symbols (bfd *abfd, asection *sec, obj_mach_o_indirect_sym *isym; obj_mach_o_indirect_sym *list = NULL; obj_mach_o_indirect_sym *list_tail = NULL; - unsigned long eltsiz = - bfd_mach_o_section_get_entry_size (abfd, ms); + unsigned long eltsiz = bfd_mach_o_section_get_entry_size (abfd, ms); for (isym = indirect_syms; isym != NULL; isym = isym->next) { diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c index 32fe7b83c06..b52d4b705de 100644 --- a/gas/config/tc-aarch64.c +++ b/gas/config/tc-aarch64.c @@ -5622,7 +5622,7 @@ static const char *aarch64_apply_style { int res; char *ptr; - struct obstack *stack = (struct obstack *) styler->state; + struct obstack *stack = styler->state; va_list ap; /* Calculate the required space. */ @@ -5651,7 +5651,7 @@ print_operands (char *buf, const aarch64_opcode *opcode, obstack_init (&content); styler.apply_style = aarch64_apply_style; - styler.state = (void *) &content; + styler.state = &content; for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i) { diff --git a/gas/config/tc-arc.c b/gas/config/tc-arc.c index cd1ef338379..4c27c60c0e3 100644 --- a/gas/config/tc-arc.c +++ b/gas/config/tc-arc.c @@ -778,7 +778,7 @@ arc_insert_opcode (const struct arc_opcode *opcode) static void arc_opcode_free (void *elt) { - string_tuple_t *tuple = (string_tuple_t *) elt; + string_tuple_t *tuple = elt; struct arc_opcode_hash_entry *entry = (void *) tuple->value; free (entry->opcode); free (entry); diff --git a/gas/config/tc-hppa.c b/gas/config/tc-hppa.c index 3240e8d1a7a..b147bdc1713 100644 --- a/gas/config/tc-hppa.c +++ b/gas/config/tc-hppa.c @@ -1200,7 +1200,7 @@ fix_new_hppa (fragS *frag, new_fix = fix_new_exp (frag, where, size, exp, pcrel, r_type); else new_fix = fix_new (frag, where, size, add_symbol, offset, pcrel, r_type); - new_fix->tc_fix_data = (void *) hppa_fix; + new_fix->tc_fix_data = hppa_fix; hppa_fix->fx_r_type = r_type; hppa_fix->fx_r_field = r_field; hppa_fix->fx_r_format = r_format; @@ -1351,7 +1351,7 @@ tc_gen_reloc (asection *section, fixS *fixp) if (fixp->fx_addsy == 0) return &no_relocs; - hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data; + hppa_fixp = fixp->tc_fix_data; gas_assert (hppa_fixp != 0); gas_assert (section != 0); @@ -1726,7 +1726,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) fixP->fx_done = 1; /* There should be a HPPA specific fixup associated with the GAS fixup. */ - hppa_fixP = (struct hppa_fix_struct *) fixP->tc_fix_data; + hppa_fixP = fixP->tc_fix_data; if (hppa_fixP == NULL) { as_bad_where (fixP->fx_file, fixP->fx_line, @@ -8317,7 +8317,7 @@ hppa_fix_adjustable (fixS *fixp) #endif struct hppa_fix_struct *hppa_fix; - hppa_fix = (struct hppa_fix_struct *) fixp->tc_fix_data; + hppa_fix = fixp->tc_fix_data; #ifdef OBJ_ELF /* LR/RR selectors are implicitly used for a number of different relocation @@ -8436,7 +8436,7 @@ hppa_force_relocation (struct fix *fixp) { struct hppa_fix_struct *hppa_fixp; - hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data; + hppa_fixp = fixp->tc_fix_data; #ifdef OBJ_SOM if (fixp->fx_r_type == (int) R_HPPA_ENTRY || fixp->fx_r_type == (int) R_HPPA_EXIT @@ -8545,7 +8545,7 @@ pa_vtable_entry (int ignore ATTRIBUTE_UNUSED) hppa_fix->fx_r_format = 32; hppa_fix->fx_arg_reloc = 0; hppa_fix->segment = now_seg; - new_fix->tc_fix_data = (void *) hppa_fix; + new_fix->tc_fix_data = hppa_fix; new_fix->fx_r_type = (int) R_PARISC_GNU_VTENTRY; } } @@ -8566,7 +8566,7 @@ pa_vtable_inherit (int ignore ATTRIBUTE_UNUSED) hppa_fix->fx_r_format = 32; hppa_fix->fx_arg_reloc = 0; hppa_fix->segment = now_seg; - new_fix->tc_fix_data = (void *) hppa_fix; + new_fix->tc_fix_data = hppa_fix; new_fix->fx_r_type = (int) R_PARISC_GNU_VTINHERIT; } } diff --git a/gas/config/tc-m32r.c b/gas/config/tc-m32r.c index 2bd32afab1d..de51726d2b7 100644 --- a/gas/config/tc-m32r.c +++ b/gas/config/tc-m32r.c @@ -615,7 +615,7 @@ expand_debug_syms (sym_linkS *syms, int align) next_syms = syms->next; input_line_pointer = (char *) ".\n"; pseudo_set (symbolP); - free ((char *) syms); + free (syms); } input_line_pointer = save_input_line; diff --git a/gas/config/tc-metag.c b/gas/config/tc-metag.c index e6ba16ce188..c367a8fca9c 100644 --- a/gas/config/tc-metag.c +++ b/gas/config/tc-metag.c @@ -6263,10 +6263,9 @@ find_insn_templates (const char *mnemonic) insn_templates *slot; entry.template = &template; + template.name = mnemonic; - memcpy ((void *)&entry.template->name, &mnemonic, sizeof (char *)); - - slot = (insn_templates *) htab_find (mnemonic_htab, &entry); + slot = htab_find (mnemonic_htab, &entry); if (slot) return slot; @@ -6307,8 +6306,8 @@ hash_templates (const void *p) static int eq_templates (const void *a, const void *b) { - insn_templates *ta = (insn_templates *)a; - insn_templates *tb = (insn_templates *)b; + const insn_templates *ta = a; + const insn_templates *tb = b; return strcasecmp (ta->template->name, tb->template->name) == 0; } @@ -6456,8 +6455,8 @@ hash_scond (const void *p) static int eq_scond (const void *a, const void *b) { - split_condition *ra = (split_condition *)a; - split_condition *rb = (split_condition *)b; + const split_condition *ra = a; + const split_condition *rb = b; return strcasecmp (ra->name, rb->name) == 0; } diff --git a/gas/config/tc-mmix.c b/gas/config/tc-mmix.c index 631dcc924e6..d86ae7a25de 100644 --- a/gas/config/tc-mmix.c +++ b/gas/config/tc-mmix.c @@ -3686,10 +3686,8 @@ mmix_md_finish (void) static int cmp_greg_symbol_fixes (const void *parg, const void *qarg) { - const struct mmix_symbol_greg_fixes *p - = (const struct mmix_symbol_greg_fixes *) parg; - const struct mmix_symbol_greg_fixes *q - = (const struct mmix_symbol_greg_fixes *) qarg; + const struct mmix_symbol_greg_fixes *p = parg; + const struct mmix_symbol_greg_fixes *q = qarg; return p->offs > q->offs ? 1 : p->offs < q->offs ? -1 : 0; } diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index 6db93fd10bd..0492311b40a 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -538,7 +538,7 @@ make_mapping_symbol (enum riscv_seg_mstate state, { /* Store current $x+arch into tc_segment_info. */ seg_info (now_seg)->tc_segment_info_data.arch_map_symbol = symbol; - xfree ((void *) buff); + xfree (buff); } /* If .fill or other data filling directive generates zero sized data, @@ -5753,7 +5753,7 @@ riscv_insert_uleb128_fixes (bfd *abfd ATTRIBUTE_UNUSED, exp_dup->X_add_number = 0; /* Set addend of SUB_ULEB128 to zero. */ fix_new_exp (fragP, fragP->fr_fix, 0, exp_dup, 0, BFD_RELOC_RISCV_SUB_ULEB128); - free ((void *) exp_dup); + free (exp_dup); } } diff --git a/gas/config/tc-score.c b/gas/config/tc-score.c index 47f30501756..10795a7de53 100644 --- a/gas/config/tc-score.c +++ b/gas/config/tc-score.c @@ -6504,7 +6504,7 @@ s3_normal_chars_to_number (const char *buf, int n) static void s3_number_to_chars_littleendian (void *p, valueT data, int n) { - char *buf = (char *) p; + char *buf = p; switch (n) { diff --git a/gas/config/tc-sh.c b/gas/config/tc-sh.c index d49abc25501..6d077b27a74 100644 --- a/gas/config/tc-sh.c +++ b/gas/config/tc-sh.c @@ -2871,7 +2871,7 @@ struct sh_count_relocs static void sh_count_relocs (bfd *abfd ATTRIBUTE_UNUSED, segT sec, void *data) { - struct sh_count_relocs *info = (struct sh_count_relocs *) data; + struct sh_count_relocs *info = data; segment_info_type *seginfo; symbolS *sym; fixS *fix; diff --git a/gas/config/tc-sparc.c b/gas/config/tc-sparc.c index f71b743c64e..321a21299e9 100644 --- a/gas/config/tc-sparc.c +++ b/gas/config/tc-sparc.c @@ -805,8 +805,8 @@ struct priv_reg_entry v9a_asr_table[] = static int cmp_reg_entry (const void *parg, const void *qarg) { - const struct priv_reg_entry *p = (const struct priv_reg_entry *) parg; - const struct priv_reg_entry *q = (const struct priv_reg_entry *) qarg; + const struct priv_reg_entry *p = parg; + const struct priv_reg_entry *q = qarg; if (p->name == q->name) return 0; @@ -921,8 +921,8 @@ struct perc_entry perc_table[NUM_PERC_ENTRIES]; static int cmp_perc_entry (const void *parg, const void *qarg) { - const struct perc_entry *p = (const struct perc_entry *) parg; - const struct perc_entry *q = (const struct perc_entry *) qarg; + const struct perc_entry *p = parg; + const struct perc_entry *q = qarg; if (p->name == q->name) return 0; diff --git a/gas/config/tc-tic54x.c b/gas/config/tc-tic54x.c index 0add19b23ea..b1d5bc1ed43 100644 --- a/gas/config/tc-tic54x.c +++ b/gas/config/tc-tic54x.c @@ -1149,7 +1149,7 @@ tic54x_global (int type) static void free_subsym_ent (void *ent) { - string_tuple_t *tuple = (string_tuple_t *) ent; + string_tuple_t *tuple = ent; subsym_ent_t *val = (void *) tuple->value; if (val->freekey) free ((void *) tuple->key); @@ -1169,7 +1169,7 @@ subsym_htab_create (void) static void free_local_label_ent (void *ent) { - string_tuple_t *tuple = (string_tuple_t *) ent; + string_tuple_t *tuple = ent; free ((void *) tuple->key); free ((void *) tuple->value); free (ent); @@ -2371,7 +2371,7 @@ tic54x_mlib (int ignore ATTRIBUTE_UNUSED) /* Write to a temporary file, then use s_include to include it a bit of a hack. */ ftmp = fopen (fname, "w+b"); - fwrite ((void *) buf, size, 1, ftmp); + fwrite (buf, size, 1, ftmp); if (size == 0 || buf[size - 1] != '\n') fwrite ("\n", 1, 1, ftmp); fclose (ftmp); diff --git a/gas/config/tc-v850.c b/gas/config/tc-v850.c index 7aa946175dc..f160ec283c2 100644 --- a/gas/config/tc-v850.c +++ b/gas/config/tc-v850.c @@ -3509,7 +3509,7 @@ md_apply_fix (fixS *fixP, valueT *valueP, segT seg ATTRIBUTE_UNUSED) && ((struct v850_operand *) fixP->tc_fix_data)->insert != NULL) { const char * message = NULL; - struct v850_operand * operand = (struct v850_operand *) fixP->tc_fix_data; + struct v850_operand * operand = fixP->tc_fix_data; unsigned long insn; /* The variable "where" currently points at the exact point inside diff --git a/gas/config/tc-vax.c b/gas/config/tc-vax.c index dca86dac195..9670b1aae32 100644 --- a/gas/config/tc-vax.c +++ b/gas/config/tc-vax.c @@ -332,8 +332,7 @@ bignum_copy (LITTLENUM_TYPE *in, LITTLENUM_TYPE *p; /* -> most significant (non-zero) input littlenum. */ - memcpy ((void *) out, (void *) in, - (unsigned int) out_length << LITTLENUM_SHIFT); + memcpy (out, in, (unsigned int) out_length << LITTLENUM_SHIFT); for (p = in + in_length - 1; p >= in; --p) { if (*p) @@ -346,11 +345,10 @@ bignum_copy (LITTLENUM_TYPE *in, } else { - memcpy ((char *) out, (char *) in, - (unsigned int) in_length << LITTLENUM_SHIFT); + memcpy (out, in, (unsigned int) in_length << LITTLENUM_SHIFT); if (out_length > in_length) - memset ((char *) (out + in_length), '\0', + memset (out + in_length, 0, (unsigned int) (out_length - in_length) << LITTLENUM_SHIFT); significant_littlenums_dropped = 0; diff --git a/gas/flonum-copy.c b/gas/flonum-copy.c index b7554952e2f..5c37ad31b04 100644 --- a/gas/flonum-copy.c +++ b/gas/flonum-copy.c @@ -46,12 +46,11 @@ flonum_copy (FLONUM_TYPE *in, FLONUM_TYPE *out) and wasting time, so why bother??? */ if (in_length < out_length) { - memset ((char *) (out->low + in_length + 1), '\0', - out_length - in_length); + memset (out->low + in_length + 1, 0, out_length - in_length); } } - memcpy ((void *) (out->low), (void *) (in->low), - ((in_length + 1) * sizeof (LITTLENUM_TYPE))); + memcpy (out->low, in->low, + (in_length + 1) * sizeof (LITTLENUM_TYPE)); out->exponent = in->exponent; out->leader = in->leader - in->low + out->low; } @@ -61,8 +60,8 @@ flonum_copy (FLONUM_TYPE *in, FLONUM_TYPE *out) shorten = in_length - out_length; /* Assume out_length >= 0 ! */ - memcpy ((void *) (out->low), (void *) (in->low + shorten), - ((out_length + 1) * sizeof (LITTLENUM_TYPE))); + memcpy (out->low, in->low + shorten, + (out_length + 1) * sizeof (LITTLENUM_TYPE)); out->leader = out->high; out->exponent = in->exponent + shorten; } diff --git a/gas/symbols.c b/gas/symbols.c index 94d0f4d2acf..775736f5a53 100644 --- a/gas/symbols.c +++ b/gas/symbols.c @@ -194,8 +194,8 @@ hash_symbol_entry (const void *e) static int eq_symbol_entry (const void *a, const void *b) { - const symbol_entry_t *ea = (const symbol_entry_t *) a; - const symbol_entry_t *eb = (const symbol_entry_t *) b; + const symbol_entry_t *ea = a; + const symbol_entry_t *eb = b; return (ea->sy.hash == eb->sy.hash && strcmp (ea->sy.name, eb->sy.name) == 0); @@ -464,7 +464,7 @@ local_symbol_make (const char *name, segT section, fragS *frag, valueT val) static symbolS * local_symbol_convert (void *sym) { - symbol_entry_t *ent = (symbol_entry_t *) sym; + symbol_entry_t *ent = sym; struct xsymbol *xtra; valueT val; @@ -2059,7 +2059,7 @@ static size_t fb_label_max; static void fb_label_init (void) { - memset ((void *) fb_low_counter, '\0', sizeof (fb_low_counter)); + memset (fb_low_counter, 0, sizeof (fb_low_counter)); } /* Add one to the instance number of this fb label. */ diff --git a/gas/write.c b/gas/write.c index fcacf202e91..02dfcc70017 100644 --- a/gas/write.c +++ b/gas/write.c @@ -352,7 +352,7 @@ get_recorded_alignment (segT seg) static void renumber_sections (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *countparg) { - int *countp = (int *) countparg; + int *countp = countparg; sec->index = *countp; ++*countp; @@ -553,7 +553,7 @@ static void relax_seg (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *xxx) { segment_info_type *seginfo = seg_info (sec); - struct relax_seg_info *info = (struct relax_seg_info *) xxx; + struct relax_seg_info *info = xxx; if (seginfo && seginfo->frchainP && relax_segment (seginfo->frchainP->frch_root, sec, info->pass)) -- 2.47.2