[gcc(refs/users/marxin/heads/str_starts_with)] Use startswith in targets.
Martin Liska
marxin@gcc.gnu.org
Fri Mar 19 09:21:51 GMT 2021
https://gcc.gnu.org/g:43420c6868a15d4559cbe08e07afc860301cf2b6
commit 43420c6868a15d4559cbe08e07afc860301cf2b6
Author: Martin Liska <mliska@suse.cz>
Date: Fri Mar 19 10:21:35 2021 +0100
Use startswith in targets.
Diff:
---
gcc/common/config/aarch64/aarch64-common.c | 2 +-
gcc/common/config/bfin/bfin-common.c | 2 +-
gcc/common/config/riscv/riscv-common.c | 4 ++--
gcc/config/aarch64/aarch64-sve-builtins-shapes.cc | 4 ++--
gcc/config/aarch64/aarch64.c | 2 +-
gcc/config/alpha/alpha.c | 8 ++++----
gcc/config/arm/arm.c | 4 ++--
gcc/config/arm/driver-arm.c | 4 ++--
gcc/config/avr/avr.c | 25 ++++++++++-------------
gcc/config/avr/gen-avr-mmcu-texi.c | 9 +-------
gcc/config/c6x/c6x.c | 14 ++++++-------
gcc/config/darwin.c | 12 +++++------
gcc/config/frv/frv.c | 16 ++-------------
gcc/config/gcn/mkoffload.c | 10 ++++-----
gcc/config/i386/i386-builtins.c | 2 +-
gcc/config/i386/i386.c | 5 ++---
gcc/config/i386/intelmic-mkoffload.c | 4 +---
gcc/config/ia64/ia64.c | 20 +++++++++---------
gcc/config/mips/driver-native.c | 2 +-
gcc/config/mips/mips.c | 8 ++++----
gcc/config/msp430/msp430.c | 10 ++++-----
gcc/config/nios2/nios2.c | 4 ++--
gcc/config/nvptx/mkoffload.c | 10 ++++-----
gcc/config/pa/som.h | 4 ++--
gcc/config/riscv/riscv.c | 2 +-
gcc/config/rs6000/rs6000.c | 18 ++++++++--------
gcc/config/s390/driver-native.c | 12 +++++------
gcc/config/sparc/driver-sparc.c | 2 +-
gcc/config/vms/vms-ld.c | 14 ++++++-------
gcc/config/vms/vms.c | 2 +-
30 files changed, 103 insertions(+), 132 deletions(-)
diff --git a/gcc/common/config/aarch64/aarch64-common.c b/gcc/common/config/aarch64/aarch64-common.c
index 6763191af36..6d200a18660 100644
--- a/gcc/common/config/aarch64/aarch64-common.c
+++ b/gcc/common/config/aarch64/aarch64-common.c
@@ -219,7 +219,7 @@ aarch64_parse_extension (const char *str, uint64_t *isa_flags,
else
len = strlen (str);
- if (len >= 2 && strncmp (str, "no", 2) == 0)
+ if (len >= 2 && startswith (str, "no"))
{
adding_ext = 0;
len -= 2;
diff --git a/gcc/common/config/bfin/bfin-common.c b/gcc/common/config/bfin/bfin-common.c
index 48a6fe8ea0b..a3ee4b5544c 100644
--- a/gcc/common/config/bfin/bfin-common.c
+++ b/gcc/common/config/bfin/bfin-common.c
@@ -313,7 +313,7 @@ bfin_handle_option (struct gcc_options *opts,
i = 0;
while ((p = bfin_cpus[i].name) != NULL)
{
- if (strncmp (arg, p, strlen (p)) == 0)
+ if (startswith (arg, p))
break;
i++;
}
diff --git a/gcc/common/config/riscv/riscv-common.c b/gcc/common/config/riscv/riscv-common.c
index 6bbe25dba89..94d42b6604c 100644
--- a/gcc/common/config/riscv/riscv-common.c
+++ b/gcc/common/config/riscv/riscv-common.c
@@ -799,12 +799,12 @@ riscv_subset_list::parse (const char *arch, location_t loc)
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 (startswth (p, "rv64"))
{
subset_list->m_xlen = 64;
p += 4;
diff --git a/gcc/config/aarch64/aarch64-sve-builtins-shapes.cc b/gcc/config/aarch64/aarch64-sve-builtins-shapes.cc
index e16c81c30ba..2cc3fbacbac 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins-shapes.cc
+++ b/gcc/config/aarch64/aarch64-sve-builtins-shapes.cc
@@ -191,12 +191,12 @@ parse_type (const function_instance &instance, const char *&format)
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;
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 7838d99feec..53e095335d7 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -15723,7 +15723,7 @@ aarch64_process_one_target_attr (char *arg_str)
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;
diff --git a/gcc/config/alpha/alpha.c b/gcc/config/alpha/alpha.c
index 335f1db5335..c702e683c31 100644
--- a/gcc/config/alpha/alpha.c
+++ b/gcc/config/alpha/alpha.c
@@ -9457,11 +9457,11 @@ alpha_elf_section_type_flags (tree decl, const char *name, int reloc)
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);
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 49635bc2d86..0f2369b6552 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -28120,7 +28120,7 @@ arm_file_start (void)
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);
@@ -33922,7 +33922,7 @@ thumb1_md_asm_adjust (vec<rtx> &outputs, vec<rtx> & /*inputs*/,
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;
diff --git a/gcc/config/arm/driver-arm.c b/gcc/config/arm/driver-arm.c
index 21ae2d71336..247eab38780 100644
--- a/gcc/config/arm/driver-arm.c
+++ b/gcc/config/arm/driver-arm.c
@@ -82,7 +82,7 @@ host_detect_local_cpu (int argc, const char **argv)
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++)
@@ -94,7 +94,7 @@ host_detect_local_cpu (int argc, const char **argv)
}
/* Detect arch/cpu. */
- if (strncmp (buf, "CPU part", sizeof ("CPU part") - 1) == 0)
+ if (startswith (buf, "CPU part"))
{
int i;
diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c
index 3a250dfb960..3490f907c0e 100644
--- a/gcc/config/avr/avr.c
+++ b/gcc/config/avr/avr.c
@@ -63,9 +63,6 @@
/* 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,
@@ -1079,7 +1076,7 @@ avr_set_current_function (tree decl)
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
@@ -9746,7 +9743,7 @@ static tree
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))
@@ -10159,7 +10156,7 @@ avr_asm_output_aligned_decl_common (FILE * stream,
/* __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)
@@ -10258,7 +10255,7 @@ avr_asm_named_section (const char *name, unsigned int flags, tree decl)
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));
@@ -10271,19 +10268,19 @@ avr_asm_named_section (const char *name, unsigned int flags, tree decl)
}
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);
}
@@ -10296,7 +10293,7 @@ avr_section_type_flags (tree decl, const char *name, int reloc)
{
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)
@@ -10506,7 +10503,7 @@ avr_asm_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align)
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));
diff --git a/gcc/config/avr/gen-avr-mmcu-texi.c b/gcc/config/avr/gen-avr-mmcu-texi.c
index 29252a52f3b..aba7f1a3ab9 100644
--- a/gcc/config/avr/gen-avr-mmcu-texi.c
+++ b/gcc/config/avr/gen-avr-mmcu-texi.c
@@ -38,13 +38,6 @@ static int digit (char c)
return c >= '0' && c <= '9';
}
-static int
-str_prefix_p (const char *str, const char *prefix)
-{
- return strncmp (str, prefix, strlen (prefix)) == 0;
-}
-
-
/* Used by string comparator to group MCUs by their
name prefix like "attiny" or "atmega". */
@@ -59,7 +52,7 @@ c_prefix (const char *str)
int i, n = (int) (sizeof (prefixes) / sizeof (*prefixes));
for (i = 0; i < n; i++)
- if (str_prefix_p (str, prefixes[i]))
+ if (startswith (str, prefixes[i]))
return i;
return n;
diff --git a/gcc/config/c6x/c6x.c b/gcc/config/c6x/c6x.c
index f9ad1e5f6c5..e7e1d6c5d05 100644
--- a/gcc/config/c6x/c6x.c
+++ b/gcc/config/c6x/c6x.c
@@ -862,14 +862,14 @@ c6x_in_small_data_p (const_tree exp)
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
@@ -1063,7 +1063,7 @@ c6x_section_type_flags (tree decl, const char *name, int reloc)
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);
diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index e2e60bbf1b2..1863a6a5c20 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -329,7 +329,7 @@ indirect_data (rtx sym_ref)
lprefix = (((name[0] == '*' || name[0] == '&')
&& (name[1] == 'L' || (name[1] == '"' && name[2] == 'L')))
- || (strncmp (name, "_OBJC_", 6) == 0));
+ || (startswith (name, "_OBJC_")));
return ! lprefix;
}
@@ -1289,7 +1289,7 @@ darwin_encode_section_info (tree decl, rtx rtl, int first)
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
}
@@ -2067,9 +2067,9 @@ darwin_asm_named_section (const char *name,
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);
@@ -2978,9 +2978,9 @@ darwin_asm_output_dwarf_offset (FILE *file, int size, const char * lab,
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);
diff --git a/gcc/config/frv/frv.c b/gcc/config/frv/frv.c
index 8201a20e24b..a7f7f086d17 100644
--- a/gcc/config/frv/frv.c
+++ b/gcc/config/frv/frv.c
@@ -262,7 +262,6 @@ static frv_stack_t *frv_stack_cache = (frv_stack_t *)0;
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);
@@ -782,17 +781,6 @@ frv_option_override (void)
init_machine_status = frv_init_machine_status;
}
-
-/* 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);
-}
/* Implement TARGET_CONDITIONAL_REGISTER_USAGE. */
@@ -9312,9 +9300,9 @@ frv_in_small_data_p (const_tree decl)
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;
}
diff --git a/gcc/config/gcn/mkoffload.c b/gcc/config/gcn/mkoffload.c
index dc9d5180a35..5432f9591db 100644
--- a/gcc/config/gcn/mkoffload.c
+++ b/gcc/config/gcn/mkoffload.c
@@ -825,8 +825,7 @@ main (int argc, char **argv)
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;
@@ -836,7 +835,6 @@ main (int argc, char **argv)
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)
@@ -995,9 +993,9 @@ main (int argc, char **argv)
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");
diff --git a/gcc/config/i386/i386-builtins.c b/gcc/config/i386/i386-builtins.c
index 4fcdf4b89ee..4f6e1208e91 100644
--- a/gcc/config/i386/i386-builtins.c
+++ b/gcc/config/i386/i386-builtins.c
@@ -1974,7 +1974,7 @@ get_builtin_code_for_version (tree decl, tree *predicate_list)
while (token != NULL)
{
/* Do not process "arch=" */
- if (strncmp (token, "arch=", 5) == 0)
+ if (startswith (token, "arch="))
{
token = strtok (NULL, ",");
continue;
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 540d4f44517..231cdb14363 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -751,9 +751,8 @@ x86_64_elf_section_type_flags (tree decl, const char *name, int reloc)
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;
diff --git a/gcc/config/i386/intelmic-mkoffload.c b/gcc/config/i386/intelmic-mkoffload.c
index 475f071609f..cb946d61454 100644
--- a/gcc/config/i386/intelmic-mkoffload.c
+++ b/gcc/config/i386/intelmic-mkoffload.c
@@ -613,8 +613,7 @@ main (int argc, char **argv)
/* 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;
@@ -624,7 +623,6 @@ main (int argc, char **argv)
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)
diff --git a/gcc/config/ia64/ia64.c b/gcc/config/ia64/ia64.c
index f1a6de14cdd..f2c4a340d69 100644
--- a/gcc/config/ia64/ia64.c
+++ b/gcc/config/ia64/ia64.c
@@ -10007,11 +10007,11 @@ ia64_in_small_data_p (const_tree exp)
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
@@ -10869,13 +10869,13 @@ ia64_section_type_flags (tree decl, const char *name, int reloc)
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);
diff --git a/gcc/config/mips/driver-native.c b/gcc/config/mips/driver-native.c
index eaf5f7e92db..46bb3cad500 100644
--- a/gcc/config/mips/driver-native.c
+++ b/gcc/config/mips/driver-native.c
@@ -57,7 +57,7 @@ host_detect_local_cpu (int argc, const char **argv)
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
diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c
index 315545966f8..d1ba593cf4e 100644
--- a/gcc/config/mips/mips.c
+++ b/gcc/config/mips/mips.c
@@ -1520,7 +1520,7 @@ mips_handle_interrupt_attr (tree *node ATTRIBUTE_UNUSED, tree name, tree args,
"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;
@@ -1849,7 +1849,7 @@ static bool
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
@@ -9323,7 +9323,7 @@ mips_function_rodata_section (tree decl, bool)
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';
@@ -9331,7 +9331,7 @@ mips_function_rodata_section (tree decl, bool)
}
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);
diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
index 581e051f68f..ddd826d187a 100644
--- a/gcc/config/msp430/msp430.c
+++ b/gcc/config/msp430/msp430.c
@@ -122,7 +122,7 @@ msp430_mcu_name (void)
/* 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);
@@ -2466,7 +2466,7 @@ msp430_function_section (tree decl, enum node_frequency freq, bool startup,
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));
@@ -2479,11 +2479,11 @@ msp430_function_section (tree decl, enum node_frequency freq, bool startup,
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);
diff --git a/gcc/config/nios2/nios2.c b/gcc/config/nios2/nios2.c
index bf5e2be6244..18f91ae1bbf 100644
--- a/gcc/config/nios2/nios2.c
+++ b/gcc/config/nios2/nios2.c
@@ -2336,9 +2336,9 @@ static bool
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));
}
diff --git a/gcc/config/nvptx/mkoffload.c b/gcc/config/nvptx/mkoffload.c
index b0a4dfa466c..c46c85d3a7c 100644
--- a/gcc/config/nvptx/mkoffload.c
+++ b/gcc/config/nvptx/mkoffload.c
@@ -256,13 +256,13 @@ process (FILE *in, FILE *out)
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 ();
@@ -481,8 +481,7 @@ main (int argc, char **argv)
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;
@@ -492,7 +491,6 @@ main (int argc, char **argv)
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)
diff --git a/gcc/config/pa/som.h b/gcc/config/pa/som.h
index d25a2ed7b4a..0ff1da3386a 100644
--- a/gcc/config/pa/som.h
+++ b/gcc/config/pa/som.h
@@ -66,13 +66,13 @@ do { \
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++; \
diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
index fffd0814eee..485ce358726 100644
--- a/gcc/config/riscv/riscv.c
+++ b/gcc/config/riscv/riscv.c
@@ -3577,7 +3577,7 @@ riscv_elf_select_rtx_section (machine_mode mode, rtx x,
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);
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 46ddf49d34b..5bdcc53f64d 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -17065,12 +17065,12 @@ toc_hasher::equal (toc_hash_struct *h1, toc_hash_struct *h2)
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
@@ -23983,7 +23983,7 @@ rs6000_inner_target_options (tree args, bool attr_p)
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)
@@ -23994,7 +23994,7 @@ rs6000_inner_target_options (tree args, bool attr_p)
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)
@@ -24012,7 +24012,7 @@ rs6000_inner_target_options (tree args, bool attr_p)
char *r = q;
error_p = true;
- if (strncmp (r, "no-", 3) == 0)
+ if (startswith (r, "no-"))
{
invert = true;
r += 3;
diff --git a/gcc/config/s390/driver-native.c b/gcc/config/s390/driver-native.c
index c0247154c0b..71c4ff672f8 100644
--- a/gcc/config/s390/driver-native.c
+++ b/gcc/config/s390/driver-native.c
@@ -73,7 +73,7 @@ s390_host_detect_local_cpu (int argc, const char **argv)
(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;
@@ -128,7 +128,7 @@ s390_host_detect_local_cpu (int argc, const char **argv)
break;
}
}
- if (has_features == 0 && strncmp (buf, "features", 8) == 0)
+ if (has_features == 0 && startswith (buf, "features"))
{
const char *p;
@@ -144,13 +144,13 @@ s390_host_detect_local_cpu (int argc, const char **argv)
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;
}
diff --git a/gcc/config/sparc/driver-sparc.c b/gcc/config/sparc/driver-sparc.c
index f70c53fc377..698c18e65d9 100644
--- a/gcc/config/sparc/driver-sparc.c
+++ b/gcc/config/sparc/driver-sparc.c
@@ -148,7 +148,7 @@ host_detect_local_cpu (int argc, const char **argv)
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)
diff --git a/gcc/config/vms/vms-ld.c b/gcc/config/vms/vms-ld.c
index 451ad0d56fe..de18763de34 100644
--- a/gcc/config/vms/vms-ld.c
+++ b/gcc/config/vms/vms-ld.c
@@ -319,7 +319,7 @@ process_args (int argc, char **argv)
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);
@@ -341,7 +341,7 @@ process_args (int argc, char **argv)
}
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;
@@ -654,7 +654,7 @@ main (int argc, char **argv)
/* 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;
@@ -676,17 +676,17 @@ main (int argc, char **argv)
}
}
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] == '@')
{
diff --git a/gcc/config/vms/vms.c b/gcc/config/vms/vms.c
index 1ee1c86d1a4..bbf174e0dc9 100644
--- a/gcc/config/vms/vms.c
+++ b/gcc/config/vms/vms.c
@@ -302,7 +302,7 @@ vms_start_function (const char *fnname)
#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);
More information about the Gcc-cvs
mailing list