From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 739203896823; Tue, 18 May 2021 08:38:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 739203896823 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-867] Use startswith in targets. X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/heads/master X-Git-Oldrev: c81704b359283bb54696755ead881ab04136da94 X-Git-Newrev: c0129e2d489cc0ab419c58c4f8451898c2b5e3ae Message-Id: <20210518083820.739203896823@sourceware.org> Date: Tue, 18 May 2021 08:38:20 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 May 2021 08:38:20 -0000 https://gcc.gnu.org/g:c0129e2d489cc0ab419c58c4f8451898c2b5e3ae commit r12-867-gc0129e2d489cc0ab419c58c4f8451898c2b5e3ae Author: Martin Liska Date: Fri Mar 19 10:21:35 2021 +0100 Use startswith in targets. gcc/ChangeLog: * common/config/aarch64/aarch64-common.c (aarch64_parse_extension): Use startswith function instead of strncmp. * common/config/bfin/bfin-common.c (bfin_handle_option): Likewise. * common/config/riscv/riscv-common.c (riscv_subset_list::parse): Likewise. * config/aarch64/aarch64-sve-builtins-shapes.cc (parse_type): Likewise. * config/aarch64/aarch64.c (aarch64_process_one_target_attr): Likewise. * config/alpha/alpha.c (alpha_elf_section_type_flags): Likewise. * config/arm/aarch-common.c (arm_md_asm_adjust): Likewise. * config/arm/arm.c (arm_file_start): Likewise. (arm_valid_target_attribute_rec): Likewise. (thumb1_md_asm_adjust): Likewise. * config/arm/driver-arm.c (host_detect_local_cpu): Likewise. * config/avr/avr.c (STR_PREFIX_P): Likewise. (avr_set_current_function): Likewise. (avr_handle_addr_attribute): Likewise. (avr_asm_output_aligned_decl_common): Likewise. (avr_asm_named_section): Likewise. (avr_section_type_flags): Likewise. (avr_asm_select_section): Likewise. * config/c6x/c6x.c (c6x_in_small_data_p): Likewise. (c6x_section_type_flags): Likewise. * config/darwin-c.c (darwin_cfstring_ref_p): Likewise. (darwin_objc_declare_unresolved_class_reference): Likewise. (darwin_objc_declare_class_definition): Likewise. * config/darwin.c (indirect_data): Likewise. (darwin_encode_section_info): Likewise. (darwin_objc2_section): Likewise. (darwin_objc1_section): Likewise. (machopic_select_section): Likewise. (darwin_globalize_label): Likewise. (darwin_label_is_anonymous_local_objc_name): Likewise. (darwin_asm_named_section): Likewise. (darwin_asm_output_dwarf_offset): Likewise. * config/frv/frv.c (frv_string_begins_with): Likewise. (frv_in_small_data_p): Likewise. * config/gcn/mkoffload.c (STR): Likewise. (main): Likewise. * config/i386/i386-builtins.c (get_builtin_code_for_version): Likewise. * config/i386/i386-options.c (ix86_option_override_internal): Likewise. * config/i386/i386.c (x86_64_elf_section_type_flags): Likewise. (ix86_md_asm_adjust): Likewise. * config/i386/intelmic-mkoffload.c (STR): Likewise. * config/i386/winnt.c (i386_pe_asm_named_section): Likewise. (i386_pe_file_end): Likewise. * config/ia64/ia64.c (ia64_in_small_data_p): Likewise. (ia64_section_type_flags): Likewise. * config/mips/driver-native.c (host_detect_local_cpu): Likewise. * config/mips/mips.c (mips_handle_interrupt_attr): Likewise. (mips16_stub_function_p): Likewise. (mips_function_rodata_section): Likewise. * config/msp430/msp430.c (msp430_mcu_name): Likewise. (msp430_function_section): Likewise. (msp430_section_type_flags): Likewise. (msp430_expand_helper): Likewise. * config/nios2/nios2.c (nios2_small_section_name_p): Likewise. (nios2_valid_target_attribute_rec): Likewise. * config/nvptx/mkoffload.c (process): Likewise. (STR): Likewise. * config/pa/som.h: Likewise. * config/pdp11/pdp11.c (pdp11_output_ident): Likewise. * config/riscv/riscv.c (riscv_elf_select_rtx_section): Likewise. * config/rs6000/rs6000.c (VTABLE_NAME_P): Likewise. (rs6000_inner_target_options): Likewise. * config/s390/driver-native.c (s390_host_detect_local_cpu): Likewise. * config/sparc/driver-sparc.c (host_detect_local_cpu): Likewise. * config/vax/vax.c (vax_output_int_move): Likewise. * config/vms/vms-ld.c (startswith): Likewise. (process_args): Likewise. (main): Likewise. * config/vms/vms.c: Likewise. 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/aarch-common.c | 2 +- gcc/config/arm/arm.c | 8 +- gcc/config/arm/driver-arm.c | 4 +- gcc/config/avr/avr.c | 25 ++-- gcc/config/c6x/c6x.c | 14 +-- gcc/config/darwin-c.c | 9 +- gcc/config/darwin.c | 141 +++++++++++----------- gcc/config/frv/frv.c | 16 +-- gcc/config/gcn/mkoffload.c | 10 +- gcc/config/i386/i386-builtins.c | 2 +- gcc/config/i386/i386-options.c | 2 +- gcc/config/i386/i386.c | 7 +- gcc/config/i386/intelmic-mkoffload.c | 4 +- gcc/config/i386/winnt.c | 5 +- gcc/config/ia64/ia64.c | 20 +-- gcc/config/mips/driver-native.c | 2 +- gcc/config/mips/mips.c | 10 +- gcc/config/msp430/msp430.c | 13 +- gcc/config/nios2/nios2.c | 13 +- gcc/config/nvptx/mkoffload.c | 10 +- gcc/config/pa/som.h | 13 +- gcc/config/pdp11/pdp11.c | 2 +- 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/vax/vax.c | 8 +- gcc/config/vms/vms-ld.c | 22 ++-- gcc/config/vms/vms.c | 2 +- 35 files changed, 199 insertions(+), 221 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 34b74e52a2d..d17bea687e0 100644 --- a/gcc/common/config/riscv/riscv-common.c +++ b/gcc/common/config/riscv/riscv-common.c @@ -804,12 +804,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 (startswith (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 85fd80e29bb..08356466e56 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -17377,7 +17377,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/aarch-common.c b/gcc/config/arm/aarch-common.c index 24711d5b4f7..0dbdc56f542 100644 --- a/gcc/config/arm/aarch-common.c +++ b/gcc/config/arm/aarch-common.c @@ -542,7 +542,7 @@ arm_md_asm_adjust (vec &outputs, vec & /*inputs*/, 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) diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index eee3671848f..28cfd81cca7 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -28169,7 +28169,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); @@ -33054,7 +33054,7 @@ arm_valid_target_attribute_rec (tree args, struct gcc_options *opts) 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, @@ -33073,7 +33073,7 @@ arm_valid_target_attribute_rec (tree args, struct gcc_options *opts) } 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 @@ -34105,7 +34105,7 @@ thumb1_md_asm_adjust (vec &outputs, vec & /*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 06c84d583e6..c95c436180c 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, @@ -1092,7 +1089,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 @@ -9642,7 +9639,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)) @@ -10055,7 +10052,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) @@ -10154,7 +10151,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)); @@ -10167,19 +10164,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); } @@ -10192,7 +10189,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) @@ -10402,7 +10399,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/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.c b/gcc/config/darwin-c.c index b0424a981e8..951a998775f 100644 --- a/gcc/config/darwin-c.c +++ b/gcc/config/darwin-c.c @@ -808,8 +808,7 @@ darwin_cfstring_ref_p (const_tree strp) 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. */ @@ -843,7 +842,7 @@ darwin_objc_declare_unresolved_class_reference (const char *name) 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)); @@ -856,8 +855,8 @@ darwin_objc_declare_class_definition (const char *name) 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); diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index 5d173919ee0..c4016fe20ef 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; } @@ -1284,7 +1284,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 } @@ -1443,58 +1443,58 @@ darwin_objc2_section (tree decl ATTRIBUTE_UNUSED, tree meta, section * base) /* 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. */ @@ -1515,72 +1515,72 @@ darwin_objc1_section (tree decl ATTRIBUTE_UNUSED, tree meta, section * base) 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; @@ -1747,7 +1747,7 @@ machopic_select_section (tree decl, && 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 (); @@ -1869,15 +1869,15 @@ finalize_dtors () 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); } @@ -1897,7 +1897,7 @@ darwin_label_is_anonymous_local_objc_name (const char *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 @@ -1908,36 +1908,36 @@ darwin_label_is_anonymous_local_objc_name (const char *name) 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; } @@ -2032,8 +2032,7 @@ darwin_asm_named_section (const char *name, { /* 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... */ @@ -2062,9 +2061,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); @@ -2973,9 +2972,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 8036aedebac..204e2903126 100644 --- a/gcc/config/i386/i386-builtins.c +++ b/gcc/config/i386/i386-builtins.c @@ -1992,7 +1992,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-options.c b/gcc/config/i386/i386-options.c index 64c6ef4267c..0eccb549c22 100644 --- a/gcc/config/i386/i386-options.c +++ b/gcc/config/i386/i386-options.c @@ -1904,7 +1904,7 @@ ix86_option_override_internal (bool main_args_p, /* 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") diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index befe69e5eeb..743d8a25fe3 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -752,9 +752,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; @@ -21500,7 +21499,7 @@ ix86_md_asm_adjust (vec &outputs, vec & /*inputs*/, 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) 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/i386/winnt.c b/gcc/config/i386/winnt.c index b66263ad243..4158a45ac31 100644 --- a/gcc/config/i386/winnt.c +++ b/gcc/config/i386/winnt.c @@ -505,8 +505,7 @@ i386_pe_asm_named_section (const char *name, unsigned int flags, /* 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'; @@ -797,7 +796,7 @@ i386_pe_file_end (void) 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" diff --git a/gcc/config/ia64/ia64.c b/gcc/config/ia64/ia64.c index f1a6de14cdd..632b9df1761 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..e5ba27331b0 100644 --- a/gcc/config/mips/mips.c +++ b/gcc/config/mips/mips.c @@ -1513,14 +1513,14 @@ mips_handle_interrupt_attr (tree *node ATTRIBUTE_UNUSED, tree name, tree args, *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=", 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..1cdacb7f480 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); @@ -3243,8 +3243,7 @@ msp430_expand_helper (rtx *operands, const char *helper_name, 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)); diff --git a/gcc/config/nios2/nios2.c b/gcc/config/nios2/nios2.c index bf5e2be6244..26d43331f33 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)); } @@ -4199,12 +4199,12 @@ nios2_valid_target_attribute_rec (tree args) *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) @@ -4225,13 +4225,12 @@ nios2_valid_target_attribute_rec (tree args) 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; 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..05cc315b9f9 100644 --- a/gcc/config/pa/som.h +++ b/gcc/config/pa/som.h @@ -47,32 +47,29 @@ along with GCC; see the file COPYING3. If not see 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++; \ diff --git a/gcc/config/pdp11/pdp11.c b/gcc/config/pdp11/pdp11.c index eb3bea497bf..b663b43a29c 100644 --- a/gcc/config/pdp11/pdp11.c +++ b/gcc/config/pdp11/pdp11.c @@ -2251,7 +2251,7 @@ static void pdp11_output_ident (const char *ident) { if (TARGET_DEC_ASM) { - if (strncmp (ident, "GCC:", 4) != 0) + if (!startswith (ident, "GCC:")) fprintf (asm_out_file, "\t.ident\t\"%s\"\n", ident); } diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c index 27665e5b58f..1baa2990ee2 100644 --- a/gcc/config/riscv/riscv.c +++ b/gcc/config/riscv/riscv.c @@ -3593,7 +3593,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 53a9f5411c7..c304596d54b 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -17205,12 +17205,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 @@ -24204,7 +24204,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) @@ -24215,7 +24215,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) @@ -24233,7 +24233,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/vax/vax.c b/gcc/config/vax/vax.c index 96a792593a3..3aacd1e5986 100644 --- a/gcc/config/vax/vax.c +++ b/gcc/config/vax/vax.c @@ -1325,10 +1325,10 @@ vax_output_int_move (rtx insn ATTRIBUTE_UNUSED, rtx *operands, 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]) diff --git a/gcc/config/vms/vms-ld.c b/gcc/config/vms/vms-ld.c index 451ad0d56fe..121aebdbe26 100644 --- a/gcc/config/vms/vms-ld.c +++ b/gcc/config/vms/vms-ld.c @@ -94,6 +94,14 @@ static int translate_unix (char *, int); #endif +/* 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. */ @@ -319,7 +327,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 +349,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 +662,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 +684,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);