[PATCH 13/19] RISC-V: riscv_parse_subset_t's isa_spec is only parser, input
Jiawei
jiawei@iscas.ac.cn
Wed Apr 29 12:17:17 GMT 2026
> Make the field pointer-to-const and drop indirection from
> riscv_get_default_ext_version(). This way it's more clear that parsing
> won't alter the field.
>
> --- a/bfd/elfxx-riscv.c
> +++ b/bfd/elfxx-riscv.c
> @@ -1892,14 +1892,13 @@ riscv_add_subset (riscv_subset_list_t *s
> /* Get the default versions from the riscv_supported_*ext tables. */
>
> static void
> -riscv_get_default_ext_version (enum riscv_spec_class *default_isa_spec,
> +riscv_get_default_ext_version (enum riscv_spec_class default_isa_spec,
> const char *name,
> int *major_version,
> int *minor_version)
> {
> if (name == NULL
> - || default_isa_spec == NULL
> - || *default_isa_spec == ISA_SPEC_CLASS_NONE)
> + || default_isa_spec == ISA_SPEC_CLASS_NONE)
> return;
>
> const struct riscv_supported_ext *table = NULL;
> @@ -1919,7 +1918,7 @@ riscv_get_default_ext_version (enum risc
> {
> if (strcmp (table[i].name, name) == 0
> && (table[i].isa_spec_class == ISA_SPEC_CLASS_DRAFT
> - || table[i].isa_spec_class == *default_isa_spec))
> + || table[i].isa_spec_class == default_isa_spec))
> {
> *major_version = table[i].major_version;
> *minor_version = table[i].minor_version;
> @@ -1945,7 +1944,7 @@ riscv_parse_add_subset (riscv_parse_subs
>
> if (major_version == RISCV_UNKNOWN_VERSION
> || minor_version == RISCV_UNKNOWN_VERSION)
> - riscv_get_default_ext_version (rps->isa_spec, subset,
> + riscv_get_default_ext_version (*rps->isa_spec, subset,
> &major_version, &minor_version);
>
> /* We don't care the versions of the implicit extensions. */
> --- a/bfd/elfxx-riscv.h
> +++ b/bfd/elfxx-riscv.h
> @@ -92,7 +92,7 @@ typedef struct
> void (*error_handler) (const char *,
> ...) ATTRIBUTE_PRINTF_1;
> unsigned *xlen;
> - enum riscv_spec_class *isa_spec;
> + const enum riscv_spec_class *isa_spec;
> bool check_unknown_prefixed_ext;
> } riscv_parse_subset_t;
>
This const-correctness cleanup looks good to me. isa_spec is parser input,
and passing the default spec class by value makes
riscv_get_default_ext_version() much clearer.
Reviewed-by: Jiawei <jiawei@iscas.ac.cn>
More information about the Binutils
mailing list