diagnostics against location *LOC, otherwise remain silent. */
bool
-riscv_process_target_attr (const char *args,
- location_t *loc,
- const struct riscv_attribute_info *attrs)
+riscv_process_target_str (string_slice args,
+ location_t *loc,
+ const struct riscv_attribute_info *attrs)
{
- size_t len = strlen (args);
+ size_t len = args.size ();
/* No need to emit warning or error on empty string here, generic code already
handle this case. */
std::unique_ptr<char[]> buf (new char[len+1]);
char *str_to_check = buf.get ();
- strcpy (str_to_check, args);
+ strncpy (str_to_check, args.begin (), args.size ());
/* Used to catch empty spaces between semi-colons i.e.
attribute ((target ("attr1;;attr2"))). */
if (num_attrs != num_semicolons + 1)
{
if (loc)
- error_at (*loc, "malformed %<target(\"%s\")%> attribute", args);
+ error_at (*loc, "malformed %<target(\"%B\")%> attribute", &args);
return false;
}
return false;
}
- return riscv_process_target_attr (TREE_STRING_POINTER (args), loc, attrs);
+ return riscv_process_target_str (TREE_STRING_POINTER (args), loc, attrs);
}
/* Implement TARGET_OPTION_VALID_ATTRIBUTE_P.
if (strcmp (str, "default") == 0)
return true;
- return riscv_process_target_attr (str, loc, riscv_target_version_attrs);
+ return riscv_process_target_str (str, loc, riscv_target_version_attrs);
}
+/* Parse the version string in STR and update the global target options space.
+ If LOC is nonnull, report diagnostics against location *LOC, otherwise
+ remain silent. */
+
+bool
+riscv_process_target_version_str (string_slice str, location_t *loc)
+{
+ return riscv_process_target_str (str, loc, riscv_target_version_attrs);
+}
/* Implement TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P. This is used to
process attribute ((target_version ("..."))). */
return default_mode_for_floating_type (ti);
}
-/* Parse the attribute arguments to target_version in DECL and modify
- the feature mask and priority required to select those targets.
+/* This parses the version string STR and modifies the feature mask and
+ priority required to select those targets.
If LOC is nonnull, report diagnostics against *LOC, otherwise
remain silent. */
static void
-parse_features_for_version (tree decl,
+parse_features_for_version (string_slice version_str,
location_t *loc,
struct riscv_feature_bits &res,
int &priority)
{
- tree version_attr = lookup_attribute ("target_version",
- DECL_ATTRIBUTES (decl));
- if (version_attr == NULL_TREE)
+ gcc_assert (version_str.is_valid ());
+ if (version_str == "default")
{
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);
cl_target_option_restore (&global_options, &global_options_set,
default_opts);
- riscv_process_target_version_attr (TREE_VALUE (version_attr), loc);
+ riscv_process_target_version_str (version_str, loc);
priority = global_options.x_riscv_fmv_priority;
const char *arch_string = global_options.x_riscv_arch_string;
struct riscv_feature_bits mask1, mask2;
int prio1, prio2;
- parse_features_for_version (decl1, nullptr, mask1, prio1);
- parse_features_for_version (decl2, nullptr, mask2, prio2);
+ string_slice v1 = get_target_version (decl1);
+ string_slice v2 = get_target_version (decl2);
+
+ if (!v1.is_valid ())
+ v1 = "default";
+ if (!v2.is_valid ())
+ v2 = "default";
+
+ parse_features_for_version (v1, nullptr, mask1, prio1);
+ parse_features_for_version (v2, nullptr, mask2, prio2);
return compare_fmv_features (mask1, mask2, prio1, prio2);
}
struct function_version_info version_info;
version_info.version_decl = version_decl;
// Get attribute string, parse it and find the right features.
- parse_features_for_version (version_decl,
+ string_slice v = get_target_version (version_decl);
+ if (!v.is_valid ())
+ v = "default";
+ parse_features_for_version (v,
&DECL_SOURCE_LOCATION (version_decl),
version_info.features,
version_info.prio);