From: Alan Modra Date: Mon, 9 Jun 2025 02:36:00 +0000 (+0930) Subject: str_hash_find_int X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b387c0127ea720f2a5d08d8bb7446a15772bc5f5;p=thirdparty%2Fbinutils-gdb.git str_hash_find_int This changes the internal representation of string_tuple.value from a void* to an intptr_t, removing any concerns that code wanting to store an integer value will use values that are trap encodings or suchlike for a pointer. The ISO C standard says any void* can be converted to intptr_t and back again and will compare equal to the original pointer. It does *not* say any intptr_t can be converted to void* and back again to get the original integer.. Two new functions, str_hash_find_int and str_hash_insert_int are provided for handling integer values. str_hash_find_int returns (intptr_t) -1 on failing to find the key string. Most target code need minimal changes to use the new interface, but some simplification is possible since now a zero can be stored and differentiated from the NULL "can't find" return. (Yes, that means (intptr_t) -1 can't be stored.) I've changed the avr_no_sreg_hash dummy value to zero, and the loongarch register numbers don't need to be incremented. loongarch also doesn't need to store an empty key string (if it ever did). --- diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c index 8de146586df..368594d3a04 100644 --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -492,13 +492,6 @@ get_section_by_match (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *inf) && match_section (sec, match)); } -static void -free_section_idx (void *ent) -{ - string_tuple_t *tuple = ent; - free ((char *) tuple->value); -} - /* Go look in section lists kept per group for SEC_NAME with properties given by MATCH. If info for the group named by MATCH->GROUP_NAME has been initialised, set GROUP_IDX. */ @@ -506,24 +499,24 @@ free_section_idx (void *ent) static asection * group_section_find (const struct elf_section_match *match, const char *sec_name, - unsigned int **group_idx) + unsigned int *group_idx) { if (!groups.indexes) { groups.num_group = 0; groups.head = NULL; groups.indexes = htab_create_alloc (16, hash_string_tuple, eq_string_tuple, - free_section_idx, notes_calloc, NULL); - *group_idx = NULL; + NULL, notes_calloc, NULL); + *group_idx = ~0u; return NULL; } - *group_idx = str_hash_find (groups.indexes, match->group_name); - if (*group_idx == NULL) + *group_idx = str_hash_find_int (groups.indexes, match->group_name); + if (*group_idx == ~0u) return NULL; asection *s; - for (s = groups.head[**group_idx]; s != NULL; s = elf_next_in_group (s)) + for (s = groups.head[*group_idx]; s != NULL; s = elf_next_in_group (s)) if ((s->name == sec_name || strcmp (s->name, sec_name) == 0) && match_section (s, match)) @@ -537,12 +530,12 @@ group_section_find (const struct elf_section_match *match, static void group_section_insert (const struct elf_section_match *match, asection *sec, - unsigned int **group_idx) + unsigned int *group_idx) { - if (*group_idx != NULL) + if (*group_idx != ~0u) { - elf_next_in_group (sec) = groups.head[**group_idx]; - groups.head[**group_idx] = sec; + elf_next_in_group (sec) = groups.head[*group_idx]; + groups.head[*group_idx] = sec; return; } @@ -553,14 +546,8 @@ group_section_insert (const struct elf_section_match *match, groups.num_group += 1; /* We keep the index into groups.head rather than the entry address - because groups.head may be realloc'd, and because str_hash values - are a void* we make a copy of the index. Strictly speaking there - is no guarantee that void* can represent any int value, so doing - without the indirection by casting an int or even uintptr_t may - for example lose lsbs of the value. */ - unsigned int *idx_ptr = XNEW (unsigned int); - *idx_ptr = i; - str_hash_insert (groups.indexes, match->group_name, idx_ptr, 0); + because groups.head may be realloc'd. */ + str_hash_insert_int (groups.indexes, match->group_name, i, 0); } /* Handle the .section pseudo-op. This code supports two different @@ -622,7 +609,7 @@ change_section (const char *name, obj_elf_section_change_hook (); - unsigned int *group_idx = NULL; + unsigned int group_idx = ~0u; if (match_p->group_name) old_sec = group_section_find (match_p, name, &group_idx); else @@ -1151,7 +1138,7 @@ elf_set_group_name (asection *sec, const char *gname) & SEC_ASSEMBLER_SHF_MASK); match.flags = bfd_section_flags (sec) & SEC_ASSEMBLER_SECTION_ID; - unsigned int *group_idx; + unsigned int group_idx; if (!group_section_find (&match, sec->name, &group_idx)) group_section_insert (&match, sec, &group_idx); } diff --git a/gas/config/tc-avr.c b/gas/config/tc-avr.c index a7678e24ccc..9d53e715c19 100644 --- a/gas/config/tc-avr.c +++ b/gas/config/tc-avr.c @@ -841,8 +841,7 @@ md_begin (void) for (i = 0; i < ARRAY_SIZE (avr_no_sreg); ++i) { gas_assert (str_hash_find (avr_hash, avr_no_sreg[i])); - str_hash_insert (avr_no_sreg_hash, avr_no_sreg[i], - (void *) 4 /* dummy */, 0); + str_hash_insert_int (avr_no_sreg_hash, avr_no_sreg[i], 0 /* dummy */, 0); } avr_gccisr_opcode = (struct avr_opcodes_s*) str_hash_find (avr_hash, @@ -2464,7 +2463,7 @@ avr_update_gccisr (struct avr_opcodes_s *opcode, int reg1, int reg2) /* SREG: Look up instructions that don't clobber SREG. */ if (!avr_isr.need_sreg - && !str_hash_find (avr_no_sreg_hash, opcode->name)) + && str_hash_find_int (avr_no_sreg_hash, opcode->name) < 0) { avr_isr.need_sreg = 1; } diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index 78411441634..acf446c3077 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -320,115 +320,98 @@ loongarch_after_parse_args () /* Init ilp32/lp64 registers names. */ if (!r_htab) - r_htab = str_htab_create (), str_hash_insert (r_htab, "", 0, 0); + r_htab = str_htab_create (); if (!r_deprecated_htab) - r_deprecated_htab = str_htab_create (), - str_hash_insert (r_deprecated_htab, "", 0, 0); + r_deprecated_htab = str_htab_create (); /* Init cfi registers alias. */ if (!cfi_r_htab) - cfi_r_htab = str_htab_create (), str_hash_insert (cfi_r_htab, "", 0, 0); + cfi_r_htab = str_htab_create (); r_abi_names = loongarch_r_normal_name; for (i = 0; i < ARRAY_SIZE (loongarch_r_normal_name); i++) { - str_hash_insert (r_htab, loongarch_r_normal_name[i], - (void *) (i + 1), 0); - str_hash_insert (cfi_r_htab, loongarch_r_normal_name[i], - (void *) (i + 1), 0); + str_hash_insert_int (r_htab, loongarch_r_normal_name[i], i, 0); + str_hash_insert_int (cfi_r_htab, loongarch_r_normal_name[i], i, 0); } /* Init ilp32/lp64 registers alias. */ r_abi_names = loongarch_r_alias; for (i = 0; i < ARRAY_SIZE (loongarch_r_alias); i++) { - str_hash_insert (r_htab, loongarch_r_alias[i], - (void *) (i + 1), 0); - str_hash_insert (cfi_r_htab, loongarch_r_alias[i], - (void *) (i + 1), 0); + str_hash_insert_int (r_htab, loongarch_r_alias[i], i, 0); + str_hash_insert_int (cfi_r_htab, loongarch_r_alias[i], i, 0); } for (i = 0; i < ARRAY_SIZE (loongarch_r_alias_1); i++) - str_hash_insert (r_htab, loongarch_r_alias_1[i], (void *) (i + 1), 0); + str_hash_insert_int (r_htab, loongarch_r_alias_1[i], i, 0); for (i = 0; i < ARRAY_SIZE (loongarch_r_alias_deprecated); i++) - str_hash_insert (r_deprecated_htab, loongarch_r_alias_deprecated[i], - (void *) (i + 1), 0); + str_hash_insert_int (r_deprecated_htab, loongarch_r_alias_deprecated[i], + i, 0); /* The .cfi directive supports register aliases without the "$" prefix. */ for (i = 0; i < ARRAY_SIZE (loongarch_r_cfi_name); i++) { - str_hash_insert (cfi_r_htab, loongarch_r_cfi_name[i], - (void *)(i + 1), 0); - str_hash_insert (cfi_r_htab, loongarch_r_cfi_name_alias[i], - (void *)(i + 1), 0); + str_hash_insert_int (cfi_r_htab, loongarch_r_cfi_name[i], i, 0); + str_hash_insert_int (cfi_r_htab, loongarch_r_cfi_name_alias[i], i, 0); } if (!cr_htab) - cr_htab = str_htab_create (), str_hash_insert (cr_htab, "", 0, 0); + cr_htab = str_htab_create (); for (i = 0; i < ARRAY_SIZE (loongarch_cr_normal_name); i++) - str_hash_insert (cr_htab, loongarch_cr_normal_name[i], (void *) (i + 1), 0); + str_hash_insert_int (cr_htab, loongarch_cr_normal_name[i], i, 0); /* Init single/double float registers names. */ if (LARCH_opts.ase_sf || LARCH_opts.ase_df) { if (!f_htab) - f_htab = str_htab_create (), str_hash_insert (f_htab, "", 0, 0); + f_htab = str_htab_create (); if (!f_deprecated_htab) - f_deprecated_htab = str_htab_create (), - str_hash_insert (f_deprecated_htab, "", 0, 0); + f_deprecated_htab = str_htab_create (); if (!cfi_f_htab) - cfi_f_htab = str_htab_create (), str_hash_insert (cfi_f_htab, "", 0, 0); + cfi_f_htab = str_htab_create (); f_abi_names = loongarch_f_normal_name; for (i = 0; i < ARRAY_SIZE (loongarch_f_normal_name); i++) { - str_hash_insert (f_htab, loongarch_f_normal_name[i], - (void *) (i + 1), 0); - str_hash_insert (cfi_f_htab, loongarch_f_normal_name[i], - (void *) (i + 1), 0); + str_hash_insert_int (f_htab, loongarch_f_normal_name[i], i, 0); + str_hash_insert_int (cfi_f_htab, loongarch_f_normal_name[i], i, 0); } /* Init float-ilp32/lp64 registers alias. */ f_abi_names = loongarch_f_alias; for (i = 0; i < ARRAY_SIZE (loongarch_f_alias); i++) { - str_hash_insert (f_htab, loongarch_f_alias[i], - (void *) (i + 1), 0); - str_hash_insert (cfi_f_htab, loongarch_f_alias[i], - (void *) (i + 1), 0); + str_hash_insert_int (f_htab, loongarch_f_alias[i], i, 0); + str_hash_insert_int (cfi_f_htab, loongarch_f_alias[i], i, 0); } for (i = 0; i < ARRAY_SIZE (loongarch_f_alias_deprecated); i++) - str_hash_insert (f_deprecated_htab, loongarch_f_alias_deprecated[i], - (void *) (i + 1), 0); + str_hash_insert_int (f_deprecated_htab, loongarch_f_alias_deprecated[i], + i, 0); /* The .cfi directive supports register aliases without the "$" prefix. */ for (i = 0; i < ARRAY_SIZE (loongarch_f_cfi_name); i++) { - str_hash_insert (cfi_f_htab, loongarch_f_cfi_name[i], - (void *)(i + 1), 0); - str_hash_insert (cfi_f_htab, loongarch_f_cfi_name_alias[i], - (void *)(i + 1), 0); + str_hash_insert_int (cfi_f_htab, loongarch_f_cfi_name[i], i, 0); + str_hash_insert_int (cfi_f_htab, loongarch_f_cfi_name_alias[i], i, 0); } if (!fc_htab) - fc_htab = str_htab_create (), str_hash_insert (fc_htab, "", 0, 0); + fc_htab = str_htab_create (); for (i = 0; i < ARRAY_SIZE (loongarch_fc_normal_name); i++) - str_hash_insert (fc_htab, loongarch_fc_normal_name[i], (void *) (i + 1), - 0); + str_hash_insert_int (fc_htab, loongarch_fc_normal_name[i], i, 0); if (!fcn_htab) - fcn_htab = str_htab_create (), str_hash_insert (fcn_htab, "", 0, 0); + fcn_htab = str_htab_create (); for (i = 0; i < ARRAY_SIZE (loongarch_fc_numeric_name); i++) - str_hash_insert (fcn_htab, loongarch_fc_numeric_name[i], (void *) (i + 1), - 0); + str_hash_insert_int (fcn_htab, loongarch_fc_numeric_name[i], i, 0); if (!c_htab) - c_htab = str_htab_create (), str_hash_insert (c_htab, "", 0, 0); + c_htab = str_htab_create (); for (i = 0; i < ARRAY_SIZE (loongarch_c_normal_name); i++) - str_hash_insert (c_htab, loongarch_c_normal_name[i], (void *) (i + 1), - 0); + str_hash_insert_int (c_htab, loongarch_c_normal_name[i], i, 0); } @@ -436,20 +419,18 @@ loongarch_after_parse_args () if (LARCH_opts.ase_lsx) { if (!v_htab) - v_htab = str_htab_create (), str_hash_insert (v_htab, "", 0, 0); + v_htab = str_htab_create (); for (i = 0; i < ARRAY_SIZE (loongarch_v_normal_name); i++) - str_hash_insert (v_htab, loongarch_v_normal_name[i], (void *) (i + 1), - 0); + str_hash_insert_int (v_htab, loongarch_v_normal_name[i], i, 0); } /* Init lasx registers names. */ if (LARCH_opts.ase_lasx) { if (!x_htab) - x_htab = str_htab_create (), str_hash_insert (x_htab, "", 0, 0); + x_htab = str_htab_create (); for (i = 0; i < ARRAY_SIZE (loongarch_x_normal_name); i++) - str_hash_insert (x_htab, loongarch_x_normal_name[i], (void *) (i + 1), - 0); + str_hash_insert_int (x_htab, loongarch_x_normal_name[i], i, 0); } } @@ -934,15 +915,15 @@ loongarch_args_parser_can_match_arg_helper (char esc_ch1, char esc_ch2, } break; case 'r': - imm = (intptr_t) str_hash_find (r_htab, arg); - ip->match_now = 0 < imm; - ret = imm - 1; + imm = str_hash_find_int (r_htab, arg); + ip->match_now = 0 <= imm; + ret = imm; if (ip->match_now) break; /* Handle potential usage of deprecated register aliases. */ - imm = (intptr_t) str_hash_find (r_deprecated_htab, arg); - ip->match_now = 0 < imm; - ret = imm - 1; + imm = str_hash_find_int (r_deprecated_htab, arg); + ip->match_now = 0 <= imm; + ret = imm; /* !ip->expand_from_macro: avoiding duplicate output warnings, only the first macro output warning. */ if (ip->match_now && !ip->expand_from_macro) @@ -953,23 +934,21 @@ loongarch_args_parser_can_match_arg_helper (char esc_ch1, char esc_ch2, switch (esc_ch2) { case 'c': - imm = (intptr_t) str_hash_find (fc_htab, arg); - if (0 >= imm) - { - imm = (intptr_t) str_hash_find (fcn_htab, arg); - } + imm = str_hash_find_int (fc_htab, arg); + if (0 > imm) + imm = str_hash_find_int (fcn_htab, arg); break; default: - imm = (intptr_t) str_hash_find (f_htab, arg); + imm = str_hash_find_int (f_htab, arg); } - ip->match_now = 0 < imm; - ret = imm - 1; + ip->match_now = 0 <= imm; + ret = imm; if (ip->match_now && !ip->expand_from_macro) break; /* Handle potential usage of deprecated register aliases. */ - imm = (intptr_t) str_hash_find (f_deprecated_htab, arg); - ip->match_now = 0 < imm; - ret = imm - 1; + imm = str_hash_find_int (f_deprecated_htab, arg); + ip->match_now = 0 <= imm; + ret = imm; if (ip->match_now) as_warn (_("register alias %s is deprecated, use %s instead"), arg, f_abi_names[ret]); @@ -978,23 +957,23 @@ loongarch_args_parser_can_match_arg_helper (char esc_ch1, char esc_ch2, switch (esc_ch2) { case 'r': - imm = (intptr_t) str_hash_find (cr_htab, arg); + imm = str_hash_find_int (cr_htab, arg); break; default: - imm = (intptr_t) str_hash_find (c_htab, arg); + imm = str_hash_find_int (c_htab, arg); } - ip->match_now = 0 < imm; - ret = imm - 1; + ip->match_now = 0 <= imm; + ret = imm; break; case 'v': - imm = (intptr_t) str_hash_find (v_htab, arg); - ip->match_now = 0 < imm; - ret = imm - 1; + imm = str_hash_find_int (v_htab, arg); + ip->match_now = 0 <= imm; + ret = imm; break; case 'x': - imm = (intptr_t) str_hash_find (x_htab, arg); - ip->match_now = 0 < imm; - ret = imm - 1; + imm = str_hash_find_int (x_htab, arg); + ip->match_now = 0 <= imm; + ret = imm; break; case '\0': ip->all_match = ip->match_now; @@ -1913,12 +1892,12 @@ tc_loongarch_regname_to_dw2regnum (char *regname) int reg; /* Look up in the general purpose register table. */ - if ((reg = (intptr_t) str_hash_find (cfi_r_htab, regname)) > 0) - return reg - 1; + if ((reg = str_hash_find_int (cfi_r_htab, regname)) >= 0) + return reg; /* Look up in the floating point register table. */ - if ((reg = (intptr_t) str_hash_find (cfi_f_htab, regname)) > 0) - return reg + 31; + if ((reg = str_hash_find_int (cfi_f_htab, regname)) >= 0) + return reg + 32; as_bad (_("unknown register `%s`"), regname); return -1; diff --git a/gas/config/tc-nds32.c b/gas/config/tc-nds32.c index 3c16216f531..a159ddb2c54 100644 --- a/gas/config/tc-nds32.c +++ b/gas/config/tc-nds32.c @@ -6265,7 +6265,7 @@ static int nds32_elf_append_relax_relocs_traverse (void **slot, void *arg ATTRIBUTE_UNUSED) { string_tuple_t *tuple = *((string_tuple_t **) slot); - nds32_elf_append_relax_relocs (tuple->key, tuple->value); + nds32_elf_append_relax_relocs (tuple->key, (void *) tuple->value); return 1; } diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index bcffc7f8858..c06a2d17a43 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -961,15 +961,15 @@ static htab_t reg_names_hash = NULL; static htab_t csr_extra_hash = NULL; #define ENCODE_REG_HASH(cls, n) \ - ((void *)(uintptr_t)((n) * RCLASS_MAX + (cls) + 1)) -#define DECODE_REG_CLASS(hash) (((uintptr_t)(hash) - 1) % RCLASS_MAX) -#define DECODE_REG_NUM(hash) (((uintptr_t)(hash) - 1) / RCLASS_MAX) + ((n) * RCLASS_MAX + (cls) + 1) +#define DECODE_REG_CLASS(hash) (((hash) - 1) % RCLASS_MAX) +#define DECODE_REG_NUM(hash) (((hash) - 1) / RCLASS_MAX) static void hash_reg_name (enum reg_class class, const char *name, unsigned n) { - void *hash = ENCODE_REG_HASH (class, n); - if (str_hash_insert (reg_names_hash, name, hash, 0) != NULL) + uintptr_t hash = ENCODE_REG_HASH (class, n); + if (str_hash_insert_int (reg_names_hash, name, hash, 0) != NULL) as_fatal (_("internal: duplicate %s"), name); } @@ -1222,13 +1222,13 @@ reg_csr_lookup_internal (const char *s) static unsigned int reg_lookup_internal (const char *s, enum reg_class class) { - void *r; + uintptr_t r; if (class == RCLASS_CSR) return reg_csr_lookup_internal (s); - r = str_hash_find (reg_names_hash, s); - if (r == NULL || DECODE_REG_CLASS (r) != class) + r = str_hash_find_int (reg_names_hash, s); + if (r == (uintptr_t) -1 || DECODE_REG_CLASS (r) != class) return -1; if (riscv_subset_supports (&riscv_rps_as, "e") diff --git a/gas/config/tc-tilegx.c b/gas/config/tc-tilegx.c index 26612acfd15..f70388ca854 100644 --- a/gas/config/tc-tilegx.c +++ b/gas/config/tc-tilegx.c @@ -275,7 +275,7 @@ md_begin (void) /* Initialize special operator hash table. */ special_operator_hash = str_htab_create (); #define INSERT_SPECIAL_OP(name) \ - str_hash_insert (special_operator_hash, #name, (void *) O_##name, 0) + str_hash_insert_int (special_operator_hash, #name, O_##name, 0) INSERT_SPECIAL_OP (hw0); INSERT_SPECIAL_OP (hw1); @@ -285,7 +285,7 @@ md_begin (void) INSERT_SPECIAL_OP (hw1_last); INSERT_SPECIAL_OP (hw2_last); /* hw3_last is a convenience alias for the equivalent hw3. */ - str_hash_insert (special_operator_hash, "hw3_last", (void *) O_hw3, 0); + str_hash_insert_int (special_operator_hash, "hw3_last", O_hw3, 0); INSERT_SPECIAL_OP (hw0_got); INSERT_SPECIAL_OP (hw0_last_got); INSERT_SPECIAL_OP (hw1_last_got); @@ -329,14 +329,14 @@ md_begin (void) { char buf[64]; - str_hash_insert (main_reg_hash, tilegx_register_names[i], - (void *) (long) (i | CANONICAL_REG_NAME_FLAG), 0); + str_hash_insert_int (main_reg_hash, tilegx_register_names[i], + i | CANONICAL_REG_NAME_FLAG, 0); /* See if we should insert a noncanonical alias, like r63. */ sprintf (buf, "r%d", i); if (strcmp (buf, tilegx_register_names[i]) != 0) - str_hash_insert (main_reg_hash, xstrdup (buf), - (void *) (long) (i | NONCANONICAL_REG_NAME_FLAG), 0); + str_hash_insert_int (main_reg_hash, xstrdup (buf), + i | NONCANONICAL_REG_NAME_FLAG, 0); } } @@ -1027,10 +1027,10 @@ tilegx_parse_name (char *name, expressionS *e, char *nextcharP) else { /* Look up the operator in our table. */ - void* val = str_hash_find (special_operator_hash, name); - if (val == 0) + int opint = str_hash_find_int (special_operator_hash, name); + if (opint < 0) return 0; - op = (operatorT)(long)val; + op = opint; } /* Restore old '(' and skip it. */ @@ -1083,23 +1083,17 @@ tilegx_parse_name (char *name, expressionS *e, char *nextcharP) static void parse_reg_expression (expressionS* expression) { - char *regname; - char terminating_char; - void *pval; - int regno_and_flags; - int regno; - /* Zero everything to make sure we don't miss any flags. */ memset (expression, 0, sizeof *expression); - terminating_char = get_symbol_name (®name); + char *regname; + char terminating_char = get_symbol_name (®name); - pval = str_hash_find (main_reg_hash, regname); - if (pval == NULL) + int regno_and_flags = str_hash_find_int (main_reg_hash, regname); + if (regno_and_flags < 0) as_bad (_("Expected register, got '%s'."), regname); - regno_and_flags = (int)(size_t)pval; - regno = EXTRACT_REGNO(regno_and_flags); + int regno = EXTRACT_REGNO(regno_and_flags); if ((regno_and_flags & NONCANONICAL_REG_NAME_FLAG) && require_canonical_reg_names) diff --git a/gas/config/tc-tilepro.c b/gas/config/tc-tilepro.c index a7c599d15bb..738b24a1b92 100644 --- a/gas/config/tc-tilepro.c +++ b/gas/config/tc-tilepro.c @@ -218,7 +218,7 @@ md_begin (void) /* Initialize special operator hash table. */ special_operator_hash = str_htab_create (); #define INSERT_SPECIAL_OP(name) \ - str_hash_insert (special_operator_hash, #name, (void *) O_##name, 0) + str_hash_insert_int (special_operator_hash, #name, O_##name, 0) INSERT_SPECIAL_OP(lo16); INSERT_SPECIAL_OP(hi16); @@ -265,29 +265,29 @@ md_begin (void) { char buf[64]; - str_hash_insert (main_reg_hash, tilepro_register_names[i], - (void *) (long) (i | CANONICAL_REG_NAME_FLAG), 0); + str_hash_insert_int (main_reg_hash, tilepro_register_names[i], + i | CANONICAL_REG_NAME_FLAG, 0); /* See if we should insert a noncanonical alias, like r63. */ sprintf (buf, "r%d", i); if (strcmp (buf, tilepro_register_names[i]) != 0) - str_hash_insert (main_reg_hash, xstrdup (buf), - (void *) (long) (i | NONCANONICAL_REG_NAME_FLAG), 0); + str_hash_insert_int (main_reg_hash, xstrdup (buf), + i | NONCANONICAL_REG_NAME_FLAG, 0); } /* Insert obsolete backwards-compatibility register names. */ - str_hash_insert (main_reg_hash, "io0", - (void *) (long) (TREG_IDN0 | CANONICAL_REG_NAME_FLAG), 0); - str_hash_insert (main_reg_hash, "io1", - (void *) (long) (TREG_IDN1 | CANONICAL_REG_NAME_FLAG), 0); - str_hash_insert (main_reg_hash, "us0", - (void *) (long) (TREG_UDN0 | CANONICAL_REG_NAME_FLAG), 0); - str_hash_insert (main_reg_hash, "us1", - (void *) (long) (TREG_UDN1 | CANONICAL_REG_NAME_FLAG), 0); - str_hash_insert (main_reg_hash, "us2", - (void *) (long) (TREG_UDN2 | CANONICAL_REG_NAME_FLAG), 0); - str_hash_insert (main_reg_hash, "us3", - (void *) (long) (TREG_UDN3 | CANONICAL_REG_NAME_FLAG), 0); + str_hash_insert_int (main_reg_hash, "io0", + TREG_IDN0 | CANONICAL_REG_NAME_FLAG, 0); + str_hash_insert_int (main_reg_hash, "io1", + TREG_IDN1 | CANONICAL_REG_NAME_FLAG, 0); + str_hash_insert_int (main_reg_hash, "us0", + TREG_UDN0 | CANONICAL_REG_NAME_FLAG, 0); + str_hash_insert_int (main_reg_hash, "us1", + TREG_UDN1 | CANONICAL_REG_NAME_FLAG, 0); + str_hash_insert_int (main_reg_hash, "us2", + TREG_UDN2 | CANONICAL_REG_NAME_FLAG, 0); + str_hash_insert_int (main_reg_hash, "us3", + TREG_UDN3 | CANONICAL_REG_NAME_FLAG, 0); } @@ -915,10 +915,10 @@ tilepro_parse_name (char *name, expressionS *e, char *nextcharP) else { /* Look up the operator in our table. */ - void *val = str_hash_find (special_operator_hash, name); - if (val == 0) + int opint = str_hash_find_int (special_operator_hash, name); + if (opint < 0) return 0; - op = (operatorT)(long)val; + op = opint; } /* Restore old '(' and skip it. */ @@ -977,12 +977,10 @@ parse_reg_expression (expressionS* expression) char *regname; char terminating_char = get_symbol_name (®name); - void* pval = str_hash_find (main_reg_hash, regname); - - if (pval == NULL) + int regno_and_flags = str_hash_find_int (main_reg_hash, regname); + if (regno_and_flags < 0) as_bad (_("Expected register, got '%s'."), regname); - int regno_and_flags = (int)(size_t)pval; int regno = EXTRACT_REGNO(regno_and_flags); if ((regno_and_flags & NONCANONICAL_REG_NAME_FLAG) diff --git a/gas/hash.h b/gas/hash.h index 6f6c1d431e4..97e23a9325f 100644 --- a/gas/hash.h +++ b/gas/hash.h @@ -24,7 +24,7 @@ struct string_tuple { const char *key; - const void *value; + intptr_t value; }; typedef struct string_tuple string_tuple_t; @@ -50,7 +50,7 @@ extern void htab_print_statistics (FILE *f, const char *name, htab_t table); /* Inline string hash table functions. */ static inline string_tuple_t * -string_tuple_alloc (htab_t table, const char *key, const void *value) +string_tuple_alloc (htab_t table, const char *key, intptr_t value) { string_tuple_t *tuple = table->alloc_f (1, sizeof (*tuple)); tuple->key = key; @@ -61,18 +61,26 @@ string_tuple_alloc (htab_t table, const char *key, const void *value) static inline void * str_hash_find (htab_t table, const char *key) { - string_tuple_t needle = { key, NULL }; + string_tuple_t needle = { key, 0 }; string_tuple_t *tuple = htab_find (table, &needle); return tuple != NULL ? (void *) tuple->value : NULL; } +static inline intptr_t +str_hash_find_int (htab_t table, const char *key) +{ + string_tuple_t needle = { key, 0 }; + string_tuple_t *tuple = htab_find (table, &needle); + return tuple != NULL ? tuple->value : -1; +} + static inline void * str_hash_find_n (htab_t table, const char *key, size_t n) { char *tmp = XNEWVEC (char, n + 1); memcpy (tmp, key, n); tmp[n] = '\0'; - string_tuple_t needle = { tmp, NULL }; + string_tuple_t needle = { tmp, 0 }; string_tuple_t *tuple = htab_find (table, &needle); free (tmp); return tuple != NULL ? (void *) tuple->value : NULL; @@ -81,12 +89,12 @@ str_hash_find_n (htab_t table, const char *key, size_t n) static inline void str_hash_delete (htab_t table, const char *key) { - string_tuple_t needle = { key, NULL }; + string_tuple_t needle = { key, 0 }; htab_remove_elt (table, &needle); } static inline void ** -str_hash_insert (htab_t table, const char *key, const void *value, int replace) +str_hash_insert_int (htab_t table, const char *key, intptr_t value, int replace) { string_tuple_t *elt = string_tuple_alloc (table, key, value); void **slot = htab_insert (table, elt, replace); @@ -95,6 +103,12 @@ str_hash_insert (htab_t table, const char *key, const void *value, int replace) return slot; } +static inline void ** +str_hash_insert (htab_t table, const char *key, const void *value, int replace) +{ + return str_hash_insert_int (table, key, (intptr_t) value, replace); +} + static inline htab_t str_htab_create (void) {