else
len = strlen (str);
- if (len >= 2 && strncmp (str, "no", 2) == 0)
+ if (len >= 2 && startswith (str, "no"))
{
adding_ext = 0;
len -= 2;
i = 0;
while ((p = bfin_cpus[i].name) != NULL)
{
- if (strncmp (arg, p, strlen (p)) == 0)
+ if (startswith (arg, p))
break;
i++;
}
riscv_subset_list *subset_list = new riscv_subset_list (arch, loc);
riscv_subset_t *itr;
const char *p = arch;
- if (strncmp (p, "rv32", 4) == 0)
+ if (startswith (p, "rv32"))
{
subset_list->m_xlen = 32;
p += 4;
}
- else if (strncmp (p, "rv64", 4) == 0)
+ else if (startswith (p, "rv64"))
{
subset_list->m_xlen = 64;
p += 4;
if (ch == 'e')
{
- if (strncmp (format, "pattern", 7) == 0)
+ if (startswith (format, "pattern"))
{
format += 7;
return acle_svpattern;
}
- if (strncmp (format, "prfop", 5) == 0)
+ if (startswith (format, "prfop"))
{
format += 5;
return acle_svprfop;
if (*str_to_check == '+')
return aarch64_handle_attr_isa_flags (str_to_check);
- if (len > 3 && strncmp (str_to_check, "no-", 3) == 0)
+ if (len > 3 && startswith (str_to_check, "no-"))
{
invert = true;
str_to_check += 3;
unsigned int flags = 0;
if (strcmp (name, ".sdata") == 0
- || strncmp (name, ".sdata.", 7) == 0
- || strncmp (name, ".gnu.linkonce.s.", 16) == 0
+ || startswith (name, ".sdata.")
+ || startswith (name, ".gnu.linkonce.s.")
|| strcmp (name, ".sbss") == 0
- || strncmp (name, ".sbss.", 6) == 0
- || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
+ || startswith (name, ".sbss.")
+ || startswith (name, ".gnu.linkonce.sb."))
flags = SECTION_SMALL;
flags |= default_section_type_flags (decl, name, reloc);
for (unsigned i = 0, n = outputs.length (); i < n; ++i)
{
const char *con = constraints[i];
- if (strncmp (con, "=@cc", 4) != 0)
+ if (!startswith (con, "=@cc"))
continue;
con += 4;
if (strchr (con, ',') != NULL)
else
arm_print_asm_arch_directives ();
}
- else if (strncmp (arm_active_target.core_name, "generic", 7) == 0)
+ else if (startswith (arm_active_target.core_name, "generic"))
{
asm_fprintf (asm_out_file, "\t.arch %s\n",
arm_active_target.core_name + 8);
else if (!strcmp (q, "general-regs-only"))
opts->x_target_flags |= MASK_GENERAL_REGS_ONLY;
- else if (!strncmp (q, "fpu=", 4))
+ else if (startswith (q, "fpu="))
{
int fpu_index;
if (! opt_enum_arg_to_value (OPT_mfpu_, q + 4,
}
opts->x_arm_fpu_index = (enum fpu_type) fpu_index;
}
- else if (!strncmp (q, "arch=", 5))
+ else if (startswith (q, "arch="))
{
char *arch = q + 5;
const arch_option *arm_selected_arch
HARD_REG_SET & /*clobbered_regs*/)
{
for (unsigned i = 0, n = outputs.length (); i < n; ++i)
- if (strncmp (constraints[i], "=@cc", 4) == 0)
+ if (startswith (constraints[i], "=@cc"))
{
sorry ("asm flags not supported in thumb1 mode");
break;
while (fgets (buf, sizeof (buf), f) != NULL)
{
/* Find the vendor table associated with this implementer. */
- if (strncmp (buf, "CPU implementer", sizeof ("CPU implementer") - 1) == 0)
+ if (startswith (buf, "CPU implementer"))
{
int i;
for (i = 0; vendors_table[i].vendor_no != NULL; i++)
}
/* Detect arch/cpu. */
- if (strncmp (buf, "CPU part", sizeof ("CPU part") - 1) == 0)
+ if (startswith (buf, "CPU part"))
{
int i;
/* Maximal allowed offset for an address in the LD command */
#define MAX_LD_OFFSET(MODE) (64 - (signed)GET_MODE_SIZE (MODE))
-/* Return true if STR starts with PREFIX and false, otherwise. */
-#define STR_PREFIX_P(STR,PREFIX) (strncmp (STR, PREFIX, strlen (PREFIX)) == 0)
-
/* The 4 bits starting at SECTION_MACH_DEP are reserved to store the
address space where data is to be located.
As the only non-generic address spaces are all located in flash,
that the name of the function is "__vector_NN" so as to catch
when the user misspells the vector name. */
- if (!STR_PREFIX_P (name, "__vector"))
+ if (!startswith (name, "__vector"))
warning_at (loc, OPT_Wmisspelled_isr, "%qs appears to be a misspelled "
"%qs handler, missing %<__vector%> prefix", name, isr);
#endif // AVR-LibC naming conventions
avr_handle_addr_attribute (tree *node, tree name, tree args,
int flags ATTRIBUTE_UNUSED, bool *no_add)
{
- bool io_p = (strncmp (IDENTIFIER_POINTER (name), "io", 2) == 0);
+ bool io_p = startswith (IDENTIFIER_POINTER (name), "io");
location_t loc = DECL_SOURCE_LOCATION (*node);
if (!VAR_P (*node))
/* __gnu_lto_slim is just a marker for the linker injected by toplev.c.
There is no need to trigger __do_clear_bss code for them. */
- if (!STR_PREFIX_P (name, "__gnu_lto"))
+ if (!startswith (name, "__gnu_lto"))
avr_need_clear_bss_p = true;
if (local_p)
const char *old_prefix = ".rodata";
const char *new_prefix = avr_addrspace[as].section_name;
- if (STR_PREFIX_P (name, old_prefix))
+ if (startswith (name, old_prefix))
{
const char *sname = ACONCAT ((new_prefix,
name + strlen (old_prefix), NULL));
}
if (!avr_need_copy_data_p)
- avr_need_copy_data_p = (STR_PREFIX_P (name, ".data")
- || STR_PREFIX_P (name, ".gnu.linkonce.d"));
+ avr_need_copy_data_p = (startswith (name, ".data")
+ || startswith (name, ".gnu.linkonce.d"));
if (!avr_need_copy_data_p
#if defined HAVE_LD_AVR_AVRXMEGA3_RODATA_IN_FLASH
&& avr_arch->flash_pm_offset == 0
#endif
)
- avr_need_copy_data_p = (STR_PREFIX_P (name, ".rodata")
- || STR_PREFIX_P (name, ".gnu.linkonce.r"));
+ avr_need_copy_data_p = (startswith (name, ".rodata")
+ || startswith (name, ".gnu.linkonce.r"));
if (!avr_need_clear_bss_p)
- avr_need_clear_bss_p = STR_PREFIX_P (name, ".bss");
+ avr_need_clear_bss_p = startswith (name, ".bss");
default_elf_asm_named_section (name, flags, decl);
}
{
unsigned int flags = default_section_type_flags (decl, name, reloc);
- if (STR_PREFIX_P (name, ".noinit"))
+ if (startswith (name, ".noinit"))
{
if (decl && TREE_CODE (decl) == VAR_DECL
&& DECL_INITIAL (decl) == NULL_TREE)
const char * old_prefix = ".rodata";
const char * new_prefix = avr_addrspace[as].section_name;
- if (STR_PREFIX_P (name, old_prefix))
+ if (startswith (name, old_prefix))
{
const char *sname = ACONCAT ((new_prefix,
name + strlen (old_prefix), NULL));
const char *section = DECL_SECTION_NAME (exp);
if (strcmp (section, ".neardata") == 0
- || strncmp (section, ".neardata.", 10) == 0
- || strncmp (section, ".gnu.linkonce.s.", 16) == 0
+ || startswith (section, ".neardata.")
+ || startswith (section, ".gnu.linkonce.s.")
|| strcmp (section, ".bss") == 0
- || strncmp (section, ".bss.", 5) == 0
- || strncmp (section, ".gnu.linkonce.sb.", 17) == 0
+ || startswith (section, ".bss.")
+ || startswith (section, ".gnu.linkonce.sb.")
|| strcmp (section, ".rodata") == 0
- || strncmp (section, ".rodata.", 8) == 0
- || strncmp (section, ".gnu.linkonce.s2.", 17) == 0)
+ || startswith (section, ".rodata.")
+ || startswith (section, ".gnu.linkonce.s2."))
return true;
}
else
unsigned int flags = 0;
if (strcmp (name, ".far") == 0
- || strncmp (name, ".far.", 5) == 0)
+ || startswith (name, ".far."))
flags |= SECTION_BSS;
flags |= default_section_type_flags (decl, name, reloc);
tn = DECL_NAME (tn);
return (tn
&& IDENTIFIER_POINTER (tn)
- && !strncmp (IDENTIFIER_POINTER (tn), "CFStringRef",
- strlen ("CFStringRef")));
+ && startswith (IDENTIFIER_POINTER (tn), "CFStringRef"));
}
/* At present the behavior of this is undefined and it does nothing. */
size_t len = strlen (reference) + strlen(name) + 2;
char *buf = (char *) alloca (len);
- gcc_checking_assert (!strncmp (name, ".objc_class_name_", 17));
+ gcc_checking_assert (startswith (name, ".objc_class_name_"));
snprintf (buf, len, "%s%s", reference, name);
symtab->finalize_toplevel_asm (build_string (strlen (buf), buf));
size_t len = strlen (xname) + 7 + 5;
char *buf = (char *) alloca (len);
- gcc_checking_assert (!strncmp (name, ".objc_class_name_", 17)
- || !strncmp (name, "*.objc_category_name_", 21));
+ gcc_checking_assert (startswith (name, ".objc_class_name_")
+ || startswith (name, "*.objc_category_name_"));
/* Mimic default_globalize_label. */
snprintf (buf, len, ".globl\t%s", xname);
lprefix = (((name[0] == '*' || name[0] == '&')
&& (name[1] == 'L' || (name[1] == '"' && name[2] == 'L')))
- || (strncmp (name, "_OBJC_", 6) == 0));
+ || (startswith (name, "_OBJC_")));
return ! lprefix;
}
tree o2meta = lookup_attribute ("OBJC2META", DECL_ATTRIBUTES (decl));
o2meta = o2meta ? TREE_VALUE (o2meta) : NULL_TREE;
- if (o2meta && strncmp (IDENTIFIER_POINTER (o2meta), "V2_IVRF",7) == 0)
+ if (o2meta && startswith (IDENTIFIER_POINTER (o2meta), "V2_IVRF"))
SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_MUST_INDIRECT;
#endif
}
/* Most of the OBJC2 META-data end up in the base section, so check it
first. */
- if (!strncmp (p, "V2_BASE", 7))
+ if (startswith (p, "V2_BASE"))
return base;
- else if (!strncmp (p, "V2_CNAM", 7))
+ else if (startswith (p, "V2_CNAM"))
return darwin_sections[objc2_class_names_section];
- else if (!strncmp (p, "V2_MNAM", 7))
+ else if (startswith (p, "V2_MNAM"))
return darwin_sections[objc2_method_names_section];
- else if (!strncmp (p, "V2_MTYP", 7))
+ else if (startswith (p, "V2_MTYP"))
return darwin_sections[objc2_method_types_section];
- else if (!strncmp (p, "V2_STRG", 7))
+ else if (startswith (p, "V2_STRG"))
return darwin_sections[cstring_section];
- else if (!strncmp (p, "G2_META", 7) || !strncmp (p, "G2_CLAS", 7))
+ else if (startswith (p, "G2_META") || startswith (p, "G2_CLAS"))
return darwin_sections[objc2_classdefs_section];
- else if (!strncmp (p, "V2_PCOL", 7))
+ else if (startswith (p, "V2_PCOL"))
return ld_uses_coal_sects ? darwin_sections[data_coal_section]
: darwin_sections[objc2_data_section];
- else if (!strncmp (p, "V2_MREF", 7))
+ else if (startswith (p, "V2_MREF"))
return darwin_sections[objc2_message_refs_section];
- else if (!strncmp (p, "V2_CLRF", 7))
+ else if (startswith (p, "V2_CLRF"))
return darwin_sections[objc2_classrefs_section];
- else if (!strncmp (p, "V2_SURF", 7))
+ else if (startswith (p, "V2_SURF"))
return darwin_sections[objc2_super_classrefs_section];
- else if (!strncmp (p, "V2_NLCL", 7))
+ else if (startswith (p, "V2_NLCL"))
return darwin_sections[objc2_nonlazy_class_section];
- else if (!strncmp (p, "V2_CLAB", 7))
+ else if (startswith (p, "V2_CLAB"))
{
classes_seen = 1;
return darwin_sections[objc2_classlist_section];
}
- else if (!strncmp (p, "V2_SRFS", 7))
+ else if (startswith (p, "V2_SRFS"))
return darwin_sections[objc2_selector_refs_section];
- else if (!strncmp (p, "V2_NLCA", 7))
+ else if (startswith (p, "V2_NLCA"))
return darwin_sections[objc2_nonlazy_category_section];
- else if (!strncmp (p, "V2_CALA", 7))
+ else if (startswith (p, "V2_CALA"))
return darwin_sections[objc2_categorylist_section];
- else if (!strncmp (p, "V2_PLST", 7))
+ else if (startswith (p, "V2_PLST"))
return darwin_sections[objc2_protocollist_section];
- else if (!strncmp (p, "V2_PRFS", 7))
+ else if (startswith (p, "V2_PRFS"))
return darwin_sections[objc2_protocolrefs_section];
- else if (!strncmp (p, "V2_INFO", 7))
+ else if (startswith (p, "V2_INFO"))
return darwin_sections[objc2_image_info_section];
- else if (!strncmp (p, "V2_EHTY", 7))
+ else if (startswith (p, "V2_EHTY"))
return ld_uses_coal_sects ? darwin_sections[data_coal_section]
: data_section;
- else if (!strncmp (p, "V2_CSTR", 7))
+ else if (startswith (p, "V2_CSTR"))
return darwin_sections[objc2_constant_string_object_section];
- else if (!strncmp (p, "V2_IVRF", 7))
+ else if (startswith (p, "V2_IVRF"))
return darwin_sections[objc2_ivar_section];
/* Not recognized, default. */
objc_metadata_seen = 1;
/* String sections first, cos there are lots of strings. */
- if (!strncmp (p, "V1_STRG", 7))
+ if (startswith (p, "V1_STRG"))
return darwin_sections[cstring_section];
- else if (!strncmp (p, "V1_CLSN", 7))
+ else if (startswith (p, "V1_CLSN"))
return darwin_sections[objc_class_names_section];
- else if (!strncmp (p, "V1_METN", 7))
+ else if (startswith (p, "V1_METN"))
return darwin_sections[objc_meth_var_names_section];
- else if (!strncmp (p, "V1_METT", 7))
+ else if (startswith (p, "V1_METT"))
return darwin_sections[objc_meth_var_types_section];
- else if (!strncmp (p, "V1_CLAS", 7))
+ else if (startswith (p, "V1_CLAS"))
{
classes_seen = 1;
return darwin_sections[objc_class_section];
}
- else if (!strncmp (p, "V1_META", 7))
+ else if (startswith (p, "V1_META"))
return darwin_sections[objc_meta_class_section];
- else if (!strncmp (p, "V1_CATG", 7))
+ else if (startswith (p, "V1_CATG"))
return darwin_sections[objc_category_section];
- else if (!strncmp (p, "V1_PROT", 7))
+ else if (startswith (p, "V1_PROT"))
return darwin_sections[objc_protocol_section];
- else if (!strncmp (p, "V1_CLCV", 7))
+ else if (startswith (p, "V1_CLCV"))
return darwin_sections[objc_class_vars_section];
- else if (!strncmp (p, "V1_CLIV", 7))
+ else if (startswith (p, "V1_CLIV"))
return darwin_sections[objc_instance_vars_section];
- else if (!strncmp (p, "V1_CLCM", 7))
+ else if (startswith (p, "V1_CLCM"))
return darwin_sections[objc_cls_meth_section];
- else if (!strncmp (p, "V1_CLIM", 7))
+ else if (startswith (p, "V1_CLIM"))
return darwin_sections[objc_inst_meth_section];
- else if (!strncmp (p, "V1_CACM", 7))
+ else if (startswith (p, "V1_CACM"))
return darwin_sections[objc_cat_cls_meth_section];
- else if (!strncmp (p, "V1_CAIM", 7))
+ else if (startswith (p, "V1_CAIM"))
return darwin_sections[objc_cat_inst_meth_section];
- else if (!strncmp (p, "V1_PNSM", 7))
+ else if (startswith (p, "V1_PNSM"))
return darwin_sections[objc_cat_inst_meth_section];
- else if (!strncmp (p, "V1_PCLM", 7))
+ else if (startswith (p, "V1_PCLM"))
return darwin_sections[objc_cat_cls_meth_section];
- else if (!strncmp (p, "V1_CLPR", 7))
+ else if (startswith (p, "V1_CLPR"))
return darwin_sections[objc_cat_cls_meth_section];
- else if (!strncmp (p, "V1_CAPR", 7))
+ else if (startswith (p, "V1_CAPR"))
return darwin_sections[objc_category_section]; /* ??? CHECK me. */
- else if (!strncmp (p, "V1_PRFS", 7))
+ else if (startswith (p, "V1_PRFS"))
return darwin_sections[objc_cat_cls_meth_section];
- else if (!strncmp (p, "V1_CLRF", 7))
+ else if (startswith (p, "V1_CLRF"))
return darwin_sections[objc_cls_refs_section];
- else if (!strncmp (p, "V1_SRFS", 7))
+ else if (startswith (p, "V1_SRFS"))
return darwin_sections[objc_selector_refs_section];
- else if (!strncmp (p, "V1_MODU", 7))
+ else if (startswith (p, "V1_MODU"))
return darwin_sections[objc_module_info_section];
- else if (!strncmp (p, "V1_SYMT", 7))
+ else if (startswith (p, "V1_SYMT"))
return darwin_sections[objc_symbols_section];
- else if (!strncmp (p, "V1_INFO", 7))
+ else if (startswith (p, "V1_INFO"))
return darwin_sections[objc_image_info_section];
- else if (!strncmp (p, "V1_PLST", 7))
+ else if (startswith (p, "V1_PLST"))
return darwin_sections[objc1_prop_list_section];
- else if (!strncmp (p, "V1_PEXT", 7))
+ else if (startswith (p, "V1_PEXT"))
return darwin_sections[objc1_protocol_ext_section];
- else if (!strncmp (p, "V1_CEXT", 7))
+ else if (startswith (p, "V1_CEXT"))
return darwin_sections[objc1_class_ext_section];
- else if (!strncmp (p, "V2_CSTR", 7))
+ else if (startswith (p, "V2_CSTR"))
return darwin_sections[objc_constant_string_object_section];
return base;
&& DECL_NAME (decl)
&& TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE
&& IDENTIFIER_POINTER (DECL_NAME (decl))
- && !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "_OBJC_", 6))
+ && startswith (IDENTIFIER_POINTER (DECL_NAME (decl)), "_OBJC_"))
/* c) legacy meta-data selection was deprecated at 4.6, removed now. */
gcc_unreachable ();
void
darwin_globalize_label (FILE *stream, const char *name)
{
- if (!!strncmp (name, "_OBJC_", 6))
+ if (!startswith (name, "_OBJC_"))
default_globalize_label (stream, name);
/* We have some Objective C cases that need to be global, but only on newer
OS versions. */
if (flag_objc_abi < 2 || flag_next_runtime < 100700)
return;
- if (!strncmp (name+6, "LabelPro", 8))
+ if (startswith (name+6, "LabelPro"))
default_globalize_label (stream, name);
- if (!strncmp (name+6, "Protocol_", 9))
+ if (startswith (name+6, "Protocol_"))
default_globalize_label (stream, name);
}
while (*p >= '0' && *p <= '9')
p++;
}
- if (strncmp ((const char *)p, "_OBJC_", 6) != 0)
+ if (!startswith ((const char *)p, "_OBJC_"))
return false;
/* We need some of the objective c meta-data symbols to be visible to the
return true;
p += 6;
- if (!strncmp ((const char *)p, "ClassRef", 8))
+ if (startswith ((const char *)p, "ClassRef"))
return false;
- else if (!strncmp ((const char *)p, "SelRef", 6))
+ else if (startswith ((const char *)p, "SelRef"))
return false;
- else if (!strncmp ((const char *)p, "Category", 8))
+ else if (startswith ((const char *)p, "Category"))
{
if (p[8] == '_' || p[8] == 'I' || p[8] == 'P' || p[8] == 'C' )
return false;
return true;
}
- else if (!strncmp ((const char *)p, "ClassMethods", 12))
+ else if (startswith ((const char *)p, "ClassMethods"))
return false;
- else if (!strncmp ((const char *)p, "Instance", 8))
+ else if (startswith ((const char *)p, "Instance"))
{
if (p[8] == 'I' || p[8] == 'M')
return false;
return true;
}
- else if (!strncmp ((const char *)p, "CLASS_RO", 8))
+ else if (startswith ((const char *)p, "CLASS_RO"))
return false;
- else if (!strncmp ((const char *)p, "METACLASS_RO", 12))
+ else if (startswith ((const char *)p, "METACLASS_RO"))
return false;
- else if (!strncmp ((const char *)p, "Protocol", 8))
+ else if (startswith ((const char *)p, "Protocol"))
{
if (p[8] == '_' || p[8] == 'I' || p[8] == 'P'
|| p[8] == 'M' || p[8] == 'C' || p[8] == 'O')
return false;
return true;
}
- else if (!strncmp ((const char *)p, "LabelPro", 8))
+ else if (startswith ((const char *)p, "LabelPro"))
return false;
return true;
}
{
/* LTO sections go in a special section that encapsulates the (unlimited)
number of GNU LTO sections within a single mach-o one. */
- if (strncmp (name, LTO_SECTION_NAME_PREFIX,
- strlen (LTO_SECTION_NAME_PREFIX)) == 0)
+ if (startswith (name, LTO_SECTION_NAME_PREFIX))
{
darwin_lto_section_e e;
/* We expect certain flags to be set... */
vec_alloc (lto_section_names, 16);
vec_safe_push (lto_section_names, e);
}
- else if (strncmp (name, "__DWARF,", 8) == 0)
+ else if (startswith (name, "__DWARF,"))
darwin_asm_dwarf_section (name, flags, decl, false);
- else if (strncmp (name, "__GNU_DWARF_LTO,", 16) == 0)
+ else if (startswith (name, "__GNU_DWARF_LTO,"))
darwin_asm_dwarf_section (name, flags, decl, true);
else
fprintf (asm_out_file, "\t.section %s\n", name);
const char *lto_add = "";
gcc_checking_assert (base->common.flags & SECTION_NAMED);
- is_for_lto = strncmp (base->named.name, "__GNU_DWARF_LTO,", 16) == 0;
+ is_for_lto = startswith (base->named.name, "__GNU_DWARF_LTO,");
gcc_checking_assert (is_for_lto
- || strncmp (base->named.name, "__DWARF,", 8) == 0);
+ || startswith (base->named.name, "__DWARF,"));
const char *name = strchr (base->named.name, ',') + 1;
gcc_checking_assert (name);
static void frv_option_override (void);
static bool frv_legitimate_address_p (machine_mode, rtx, bool);
static int frv_default_flags_for_cpu (void);
-static int frv_string_begins_with (const char *, const char *);
static FRV_INLINE bool frv_small_data_reloc_p (rtx, int);
static void frv_print_operand (FILE *, rtx, int);
static void frv_print_operand_address (FILE *, machine_mode, rtx);
}
\f
-/* Return true if NAME (a STRING_CST node) begins with PREFIX. */
-
-static int
-frv_string_begins_with (const char *name, const char *prefix)
-{
- const int prefix_len = strlen (prefix);
-
- /* Remember: NAME's length includes the null terminator. */
- return (strncmp (name, prefix, prefix_len) == 0);
-}
-\f
/* Implement TARGET_CONDITIONAL_REGISTER_USAGE. */
static void
section_name = DECL_SECTION_NAME (decl);
if (section_name)
{
- if (frv_string_begins_with (section_name, ".sdata"))
+ if (startswith (section_name, ".sdata"))
return true;
- if (frv_string_begins_with (section_name, ".sbss"))
+ if (startswith (section_name, ".sbss"))
return true;
return false;
}
bool fpic = false;
for (int i = 1; i < argc; i++)
{
-#define STR "-foffload-abi="
- if (strncmp (argv[i], STR, strlen (STR)) == 0)
+ if (startswith (argv[i], "-foffload-abi="))
{
if (strcmp (argv[i] + strlen (STR), "lp64") == 0)
offload_abi = OFFLOAD_ABI_LP64;
fatal_error (input_location,
"unrecognizable argument of option " STR);
}
-#undef STR
else if (strcmp (argv[i], "-fopenmp") == 0)
fopenmp = true;
else if (strcmp (argv[i], "-fopenacc") == 0)
obstack_ptr_grow (&ld_argv_obstack, "-lgomp");
for (int i = 1; i < argc; i++)
- if (strncmp (argv[i], "-l", 2) == 0
- || strncmp (argv[i], "-Wl", 3) == 0
- || strncmp (argv[i], "-march", 6) == 0)
+ if (startswith (argv[i], "-l")
+ || startswith (argv[i], "-Wl")
+ || startswith (argv[i], "-march"))
obstack_ptr_grow (&ld_argv_obstack, argv[i]);
obstack_ptr_grow (&cc_argv_obstack, "-dumpdir");
while (token != NULL)
{
/* Do not process "arch=" */
- if (strncmp (token, "arch=", 5) == 0)
+ if (startswith (token, "arch="))
{
token = strtok (NULL, ",");
continue;
/* opts->x_ix86_tune_string is set to opts->x_ix86_arch_string
or defaulted. We need to use a sensible tune option. */
- if (!strncmp (opts->x_ix86_tune_string, "x86-64", 6)
+ if (startswith (opts->x_ix86_tune_string, "x86-64")
&& (opts->x_ix86_tune_string[6] == '\0'
|| (!strcmp (opts->x_ix86_tune_string + 6, "-v2")
|| !strcmp (opts->x_ix86_tune_string + 6, "-v3")
flags |= SECTION_RELRO;
if (strcmp (name, ".lbss") == 0
- || strncmp (name, ".lbss.", sizeof (".lbss.") - 1) == 0
- || strncmp (name, ".gnu.linkonce.lb.",
- sizeof (".gnu.linkonce.lb.") - 1) == 0)
+ || startswith (name, ".lbss.")
+ || startswith (name, ".gnu.linkonce.lb."))
flags |= SECTION_BSS;
return flags;
for (unsigned i = 0, n = outputs.length (); i < n; ++i)
{
const char *con = constraints[i];
- if (strncmp (con, "=@cc", 4) != 0)
+ if (!startswith (con, "=@cc"))
continue;
con += 4;
if (strchr (con, ',') != NULL)
/* Scan the argument vector. */
for (int i = 1; i < argc; i++)
{
-#define STR "-foffload-abi="
- if (strncmp (argv[i], STR, strlen (STR)) == 0)
+ if (startswith (argv[i], "-foffload-abi="))
{
if (strcmp (argv[i] + strlen (STR), "lp64") == 0)
offload_abi = OFFLOAD_ABI_LP64;
fatal_error (input_location,
"unrecognizable argument of option " STR);
}
-#undef STR
else if (strcmp (argv[i], "-save-temps") == 0)
save_temps = true;
else if (strcmp (argv[i], "-v") == 0)
/* LTO sections need 1-byte alignment to avoid confusing the
zlib decompression algorithm with trailing zero pad bytes. */
- if (strncmp (name, LTO_SECTION_NAME_PREFIX,
- strlen (LTO_SECTION_NAME_PREFIX)) == 0)
+ if (startswith (name, LTO_SECTION_NAME_PREFIX))
*f++ = '0';
*f = '\0';
oname = name;
if (name[0] == '.')
++name;
- if (strncmp (name, "refptr.", 7) != 0)
+ if (!startswith (name, "refptr."))
continue;
name += 7;
fprintf (asm_out_file, "\t.section\t.rdata$%s, \"dr\"\n"
const char *section = DECL_SECTION_NAME (exp);
if (strcmp (section, ".sdata") == 0
- || strncmp (section, ".sdata.", 7) == 0
- || strncmp (section, ".gnu.linkonce.s.", 16) == 0
+ || startswith (section, ".sdata.")
+ || startswith (section, ".gnu.linkonce.s.")
|| strcmp (section, ".sbss") == 0
- || strncmp (section, ".sbss.", 6) == 0
- || strncmp (section, ".gnu.linkonce.sb.", 17) == 0)
+ || startswith (section, ".sbss.")
+ || startswith (section, ".gnu.linkonce.sb."))
return true;
}
else
unsigned int flags = 0;
if (strcmp (name, ".sdata") == 0
- || strncmp (name, ".sdata.", 7) == 0
- || strncmp (name, ".gnu.linkonce.s.", 16) == 0
- || strncmp (name, ".sdata2.", 8) == 0
- || strncmp (name, ".gnu.linkonce.s2.", 17) == 0
+ || startswith (name, ".sdata.")
+ || startswith (name, ".gnu.linkonce.s.")
+ || startswith (name, ".sdata2.")
+ || startswith (name, ".gnu.linkonce.s2.")
|| strcmp (name, ".sbss") == 0
- || strncmp (name, ".sbss.", 6) == 0
- || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
+ || startswith (name, ".sbss.")
+ || startswith (name, ".gnu.linkonce.sb."))
flags = SECTION_SMALL;
flags |= default_section_type_flags (decl, name, reloc);
return NULL;
while (fgets (buf, sizeof (buf), f) != NULL)
- if (strncmp (buf, "cpu model", sizeof ("cpu model") - 1) == 0)
+ if (startswith (buf, "cpu model"))
{
if (strstr (buf, "Godson2 V0.2") != NULL
|| strstr (buf, "Loongson-2 V0.2") != NULL
*no_add_attrs = true;
}
else if (strcmp (TREE_STRING_POINTER (cst), "eic") != 0
- && strncmp (TREE_STRING_POINTER (cst), "vector=", 7) != 0)
+ && !startswith (TREE_STRING_POINTER (cst), "vector="))
{
warning (OPT_Wattributes,
"argument to %qE attribute is neither eic, nor "
"vector=<line>", name);
*no_add_attrs = true;
}
- else if (strncmp (TREE_STRING_POINTER (cst), "vector=", 7) == 0)
+ else if (startswith (TREE_STRING_POINTER (cst), "vector="))
{
const char *arg = TREE_STRING_POINTER (cst) + 7;
mips16_stub_function_p (const_rtx x)
{
return (GET_CODE (x) == SYMBOL_REF
- && strncmp (XSTR (x, 0), "__mips16_", 9) == 0);
+ && startswith (XSTR (x, 0), "__mips16_"));
}
/* Return true if function X is a locally-defined and locally-binding
if (decl && DECL_SECTION_NAME (decl))
{
const char *name = DECL_SECTION_NAME (decl);
- if (DECL_COMDAT_GROUP (decl) && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
+ if (DECL_COMDAT_GROUP (decl) && startswith (name, ".gnu.linkonce.t."))
{
char *rname = ASTRDUP (name);
rname[14] = 'd';
}
else if (flag_function_sections
&& flag_data_sections
- && strncmp (name, ".text.", 6) == 0)
+ && startswith (name, ".text."))
{
char *rname = ASTRDUP (name);
memcpy (rname + 1, "data", 4);
/* The 'i' in the device name symbol for msp430i* devices must be lower
case, to match the expected symbol in msp430.h. */
- if (strncmp (target_mcu, "msp430i", 7) == 0)
+ if (startswith (target_mcu, "msp430i"))
{
snprintf (mcu_name, sizeof (mcu_name) - 1, "__MSP430i%s__",
target_mcu + 7);
const char * prefix = gen_prefix (decl);
if (prefix == NULL
- || strncmp (name, prefix, strlen (prefix)) == 0)
+ || startswith (name, prefix))
return default_function_section (decl, freq, startup, exit);
name = ACONCAT ((prefix, name, NULL));
unsigned int
msp430_section_type_flags (tree decl, const char * name, int reloc)
{
- if (strncmp (name, lower_prefix, strlen (lower_prefix)) == 0)
+ if (startswith (name, lower_prefix))
name += strlen (lower_prefix);
- else if (strncmp (name, upper_prefix, strlen (upper_prefix)) == 0)
+ else if (startswith (name, upper_prefix))
name += strlen (upper_prefix);
- else if (strncmp (name, either_prefix, strlen (either_prefix)) == 0)
+ else if (startswith (name, either_prefix))
name += strlen (either_prefix);
return default_section_type_flags (decl, name, reloc);
machine_mode arg0mode = GET_MODE (operands[0]);
machine_mode arg1mode = GET_MODE (operands[1]);
machine_mode arg2mode = GET_MODE (operands[2]);
- int expand_mpy = strncmp (helper_name, "__mspabi_mpy",
- sizeof ("__mspabi_mpy") - 1) == 0;
+ int expand_mpy = startswith (helper_name, "__mspabi_mpy");
/* This function has been used incorrectly if CONST_VARIANTS is TRUE for a
hwmpy function. */
gcc_assert (!(expand_mpy && const_variants));
nios2_small_section_name_p (const char *section)
{
return (strcmp (section, ".sbss") == 0
- || strncmp (section, ".sbss.", 6) == 0
+ || startswith (section, ".sbss.")
|| strcmp (section, ".sdata") == 0
- || strncmp (section, ".sdata.", 7) == 0
+ || startswith (section, ".sdata.")
|| (nios2_gprel_sec
&& regexec (&nios2_gprel_sec_regex, section, 0, NULL, 0) == 0));
}
*p = '\0';
if (eq) *eq = '\0';
- if (!strncmp (argstr, "no-", 3))
+ if (startswith (argstr, "no-"))
{
no_opt = true;
argstr += 3;
}
- if (!strncmp (argstr, "custom-fpu-cfg", 14))
+ if (startswith (argstr, "custom-fpu-cfg"))
{
char *end_eq = p;
if (no_opt)
nios2_handle_custom_fpu_cfg (eq, end_eq + 1, true);
}
- else if (!strncmp (argstr, "custom-", 7))
+ else if (startswith (argstr, "custom-"))
{
int code = -1;
unsigned int i;
for (i = 0; i < ARRAY_SIZE (nios2_fpu_insn); i++)
- if (!strncmp (argstr + 7, N2FPU_NAME (i),
- strlen (N2FPU_NAME (i))))
+ if (startswith (argstr + 7, N2FPU_NAME (i)))
{
/* Found insn. */
code = i;
case '\n':
fprintf (out, "\\n\"\n\t\"");
/* Look for mappings on subsequent lines. */
- while (strncmp (input + i, "//:", 3) == 0)
+ while (startswith (input + i, "//:"))
{
i += 3;
- if (strncmp (input + i, "VAR_MAP ", 8) == 0)
+ if (startswith (input + i, "VAR_MAP "))
record_id (input + i + 8, &vars_tail);
- else if (strncmp (input + i, "FUNC_MAP ", 9) == 0)
+ else if (startswith (input + i, "FUNC_MAP "))
record_id (input + i + 9, &funcs_tail);
else
abort ();
bool fpic = false;
for (int i = 1; i < argc; i++)
{
-#define STR "-foffload-abi="
- if (strncmp (argv[i], STR, strlen (STR)) == 0)
+ if (startswith (argv[i], "-foffload-abi="))
{
if (strcmp (argv[i] + strlen (STR), "lp64") == 0)
offload_abi = OFFLOAD_ABI_LP64;
fatal_error (input_location,
"unrecognizable argument of option " STR);
}
-#undef STR
else if (strcmp (argv[i], "-fopenmp") == 0)
fopenmp = true;
else if (strcmp (argv[i], "-fopenacc") == 0)
do { \
static int in_shlib_list = 0; \
while (*PTR == ' ') PTR++; \
- if (strncmp (PTR, "shared library list:", \
- sizeof ("shared library list:") - 1) == 0) \
+ if (startswith (PTR, "shared library list:")) \
{ \
PTR = 0; \
in_shlib_list = 1; \
} \
- else if (strncmp (PTR, "shared library binding:", \
- sizeof ("shared library binding:") - 1) == 0)\
+ else if (startswith (PTR, "shared library binding:")) \
{ \
PTR = 0; \
in_shlib_list = 0; \
} \
- else if (strncmp (PTR, "static branch prediction disabled", \
- sizeof ("static branch prediction disabled") - 1) == 0)\
+ else if (startswith (PTR, "static branch prediction disabled")) \
{ \
PTR = 0; \
in_shlib_list = 0; \
} \
else if (in_shlib_list \
- && strncmp (PTR, "dynamic", sizeof ("dynamic") - 1) == 0) \
+ && startswith (PTR, "dynamic")) \
{ \
PTR += sizeof ("dynamic") - 1; \
while (*p == ' ') PTR++; \
} \
else if (in_shlib_list \
- && strncmp (PTR, "static", sizeof ("static") - 1) == 0) \
+ && startswith (PTR, "static")) \
{ \
PTR += sizeof ("static") - 1; \
while (*p == ' ') PTR++; \
{
if (TARGET_DEC_ASM)
{
- if (strncmp (ident, "GCC:", 4) != 0)
+ if (!startswith (ident, "GCC:"))
fprintf (asm_out_file, "\t.ident\t\"%s\"\n", ident);
}
if (riscv_size_ok_for_small_data_p (GET_MODE_SIZE (mode)))
{
- if (strncmp (s->named.name, ".rodata.cst", strlen (".rodata.cst")) == 0)
+ if (startswith (s->named.name, ".rodata.cst"))
{
/* Rename .rodata.cst* to .srodata.cst*. */
char *name = (char *) alloca (strlen (s->named.name) + 2);
instead, there should be some programmatic way of inquiring as
to whether or not an object is a vtable. */
-#define VTABLE_NAME_P(NAME) \
- (strncmp ("_vt.", name, strlen ("_vt.")) == 0 \
- || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
- || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
- || strncmp ("_ZTI", name, strlen ("_ZTI")) == 0 \
- || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
+#define VTABLE_NAME_P(NAME) \
+ (startswith (name, "_vt.") \
+ || startswith (name, "_ZTV") \
+ || startswith (name, "_ZTT") \
+ || startswith (name, "_ZTI") \
+ || startswith (name, "_ZTC"))
#ifdef NO_DOLLAR_IN_LABEL
/* Return a GGC-allocated character string translating dollar signs in
const char *cpu_opt = NULL;
p = NULL;
- if (strncmp (q, "cpu=", 4) == 0)
+ if (startswith (q, "cpu="))
{
int cpu_index = rs6000_cpu_name_lookup (q+4);
if (cpu_index >= 0)
cpu_opt = q+4;
}
}
- else if (strncmp (q, "tune=", 5) == 0)
+ else if (startswith (q, "tune="))
{
int tune_index = rs6000_cpu_name_lookup (q+5);
if (tune_index >= 0)
char *r = q;
error_p = true;
- if (strncmp (r, "no-", 3) == 0)
+ if (startswith (r, "no-"))
{
invert = true;
r += 3;
(has_features == 0 || has_processor == 0)
&& fgets (buf, sizeof (buf), f) != NULL; )
{
- if (has_processor == 0 && strncmp (buf, "processor", 9) == 0)
+ if (has_processor == 0 && startswith (buf, "processor"))
{
const char *p;
long machine_id;
break;
}
}
- if (has_features == 0 && strncmp (buf, "features", 8) == 0)
+ if (has_features == 0 && startswith (buf, "features"))
{
const char *p;
p++;
for (i = 0; !ISSPACE (p[i]) && p[i] != 0; i++)
;
- if (i == 3 && strncmp (p, "dfp", 3) == 0)
+ if (i == 3 && startswith (p, "dfp"))
has_dfp = 1;
- else if (i == 2 && strncmp (p, "te", 2) == 0)
+ else if (i == 2 && startswith (p, "te"))
has_te = 1;
- else if (i == 2 && strncmp (p, "vx", 2) == 0)
+ else if (i == 2 && startswith (p, "vx"))
has_vx = 1;
- else if (i == 8 && strncmp (p, "highgprs", 8) == 0)
+ else if (i == 8 && startswith (p, "highgprs"))
has_highgprs = 1;
p += i;
}
return NULL;
while (fgets (buf, sizeof (buf), f) != NULL)
- if (strncmp (buf, "cpu\t\t:", sizeof ("cpu\t\t:") - 1) == 0)
+ if (startswith (buf, "cpu\t\t:"))
{
for (i = 0; cpu_names [i].name; i++)
if (strstr (buf, cpu_names [i].name) != NULL)
be shorter (1 opcode byte + 1 addrmode byte + 8 immediate value
bytes .vs. 2 opcode bytes + 2 addrmode bytes + 8 immediate value
value bytes. */
- if ((!strncmp (pattern_lo, "movl", 4)
- && !strncmp (pattern_hi, "movl", 4))
- || (!strncmp (pattern_lo, "pushl", 5)
- && !strncmp (pattern_hi, "pushl", 5)))
+ if ((startswith (pattern_lo, "movl")
+ && startswith (pattern_hi, "movl"))
+ || (startswith (pattern_lo, "pushl")
+ && startswith (pattern_hi, "pushl")))
return "movq %1,%0";
if (MEM_P (operands[0])
#endif
\f
+/* Return 1 if STR string starts with PREFIX. */
+
+static inline int
+startswith (const char *str, const char *prefix)
+{
+ return strncmp (str, prefix, strlen (prefix)) == 0;
+}
+
/* Append STR to the command line to invoke the linker.
Expand the line as necessary to accommodate. */
for (i = 1; i < argc; i++)
{
- if (strncmp (argv[i], "-L", 2) == 0)
+ if (startswith (argv[i], "-L"))
{
search_dirs = XRESIZEVEC(const char *, search_dirs,
search_dirs_len + 1);
}
else if (strcmp (argv[i], "-g0") == 0)
addarg ("/notraceback");
- else if (strncmp (argv[i], "-g", 2) == 0)
+ else if (startswith (argv[i], "-g"))
{
addarg ("/debug");
debug = 1;
/* Already handled. */
i++;
}
- else if (arg_len > 2 && strncmp (argv[i], "-l", 2) == 0)
+ else if (arg_len > 2 && startswith (argv[i], "-l"))
{
const char *libname;
}
}
else if (strcmp (argv[i], "-v" ) == 0
- || strncmp (argv[i], "-g", 2 ) == 0
+ || startswith (argv[i], "-g")
|| strcmp (argv[i], "-static" ) == 0
|| strcmp (argv[i], "-map" ) == 0
|| strcmp (argv[i], "-save-temps") == 0
|| strcmp (argv[i], "--noinhibit-exec") == 0
- || (arg_len > 2 && strncmp (argv[i], "-L", 2) == 0)
- || (arg_len >= 6 && strncmp (argv[i], "-share", 6) == 0))
+ || (arg_len > 2 && startswith (argv[i], "-L"))
+ || (arg_len >= 6 && startswith (argv[i], "-share")))
{
/* Already handled. */
}
- else if (strncmp (argv[i], "--opt=", 6) == 0)
+ else if (startswith (argv[i], "--opt="))
fprintf (optfile, "%s\n", argv[i] + 6);
else if (arg_len > 1 && argv[i][0] == '@')
{
#if VMS_DEBUGGING_INFO
if (vms_debug_main
&& debug_info_level > DINFO_LEVEL_NONE
- && strncmp (vms_debug_main, fnname, strlen (vms_debug_main)) == 0)
+ && startswith (vms_debug_main, fnname))
{
targetm.asm_out.globalize_label (asm_out_file, VMS_DEBUG_MAIN_POINTER);
ASM_OUTPUT_DEF (asm_out_file, VMS_DEBUG_MAIN_POINTER, fnname);