> diff --git a/gcc/config/riscv/riscv-target-attr.cc > b/gcc/config/riscv/riscv-target-attr.cc > index 087fbae77b0..4c85ad60b72 100644 > --- a/gcc/config/riscv/riscv-target-attr.cc > +++ b/gcc/config/riscv/riscv-target-attr.cc > @@ -239,10 +239,6 @@ riscv_target_attr_parser::update_settings (struct > gcc_options *opts) const > { > std::string local_arch = m_subset_list->to_string (true); > const char* local_arch_str = local_arch.c_str (); > - struct cl_target_option *default_opts > - = TREE_TARGET_OPTION (target_option_default_node); > - if (opts->x_riscv_arch_string != default_opts->x_riscv_arch_string) > - free (CONST_CAST (void *, (const void *) opts->x_riscv_arch_string));
Could you give a little more context why you decide to remove those logics? > opts->x_riscv_arch_string = xstrdup (local_arch_str); > > riscv_set_arch_by_subset_list (m_subset_list, opts); > diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc > index 3ac40234345..947864fc3a6 100644 > --- a/gcc/config/riscv/riscv.cc > +++ b/gcc/config/riscv/riscv.cc > @@ -12574,6 +12574,127 @@ riscv_c_mode_for_floating_type (enum tree_index ti) > return default_mode_for_floating_type (ti); > } > > +/* This parses the attribute arguments to target_version in DECL and modifies > + the feature mask and priority required to select those targets. */ > +static void > +parse_features_for_version (tree decl, > + struct riscv_feature_bits &res, > + int &priority) > +{ > + tree version_attr = lookup_attribute ("target_version", > + DECL_ATTRIBUTES (decl)); > + if (version_attr == NULL_TREE) > + { > + res.length = 0; > + priority = 0; > + return; > + } > + > + const char *version_string = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE > + (version_attr))); > + gcc_assert (version_string != NULL); > + if (strcmp (version_string, "default") == 0) > + { > + res.length = 0; > + priority = 0; > + return; > + } > + struct cl_target_option cur_target; > + cl_target_option_save (&cur_target, &global_options, > + &global_options_set); > + /* Always set to default option before parsing "arch=+..." */ > + struct cl_target_option *default_opts > + = TREE_TARGET_OPTION (target_option_default_node); > + cl_target_option_restore (&global_options, &global_options_set, > + default_opts); > + > + riscv_process_target_attr (version_string, > + DECL_SOURCE_LOCATION (decl)); Is it possible to just use DECL_FUNCTION_SPECIFIC_TARGET (decl) here rather than parse and apply that globally?