return;
gcc_assert ((!both_p && !fallback_p)
- || !strncmp (name, "__builtin_",
- strlen ("__builtin_")));
+ || startswith (name, "__builtin_"));
libname = name + strlen ("__builtin_");
decl = add_builtin_function (name, fntype, fncode, fnclass,
/* Also support variants of these names prefixed with "_IO_". */
const char *name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
- if (strncmp (name, "_IO_", 4) == 0)
- if (fs.contains_name_p (name + 4))
- return true;
+ if (startswith (name, "_IO_") && fs.contains_name_p (name + 4))
+ return true;
return false;
}
static bool
is_builtin_name (const char *name)
{
- if (strncmp (name, "__builtin_", 10) == 0)
- return true;
- if (strncmp (name, "__sync_", 7) == 0)
- return true;
- if (strncmp (name, "__atomic_", 9) == 0)
- return true;
- return false;
+ return (startswith (name, "__builtin_")
+ || startswith (name, "__sync_")
+ || startswith (name, "__atomic_"));
}
/* Return true if NODE should be considered for inline expansion regardless
tree decl_name = DECL_NAME (TYPE_NAME (type));
pp_string (buffer, "Delete_");
- if (strncmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__dt_del", 8) == 0)
+ if (startswith (IDENTIFIER_POINTER (DECL_NAME (t)), "__dt_del"))
pp_string (buffer, "And_Free_");
pp_ada_tree_identifier (buffer, decl_name, t, false);
}
return 0;
/* Only consider complete constructors and deleting destructors. */
- if (strncmp (IDENTIFIER_POINTER (decl_name), "__ct_comp", 9) != 0
- && strncmp (IDENTIFIER_POINTER (decl_name), "__dt_comp", 9) != 0
- && strncmp (IDENTIFIER_POINTER (decl_name), "__dt_del", 8) != 0)
+ if (!startswith (IDENTIFIER_POINTER (decl_name), "__ct_comp")
+ && !startswith (IDENTIFIER_POINTER (decl_name), "__dt_comp")
+ && !startswith (IDENTIFIER_POINTER (decl_name), "__dt_del"))
return 0;
}
void
disable_builtin_function (const char *name)
{
- if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
+ if (startswith (name, "__builtin_"))
error ("cannot disable built-in function %qs", name);
else
{
return;
gcc_assert ((!both_p && !fallback_p)
- || !strncmp (name, "__builtin_",
- strlen ("__builtin_")));
+ || startswith (name, "__builtin_"));
libname = name + strlen ("__builtin_");
decl = add_builtin_function (name, fntype, fncode, fnclass,
/* Allow this ugly warning for the time being. */
if (toklen == 2
&& format_chars - orig_format_chars > 6
- && !strncmp (format_chars - 7, " count >= width of ", 19))
+ && startswith (format_chars - 7, " count >= width of "))
return format_chars + 10;
/* The token is a type if it ends in an alphabetic character. */
/* Diagnose unquoted __attribute__. Consider any parenthesized
argument to the attribute to avoid redundant warnings for
the double parentheses that might follow. */
- if (!strncmp (format_chars, "__attribute", sizeof "__attribute" - 1))
+ if (startswith (format_chars, "__attribute"))
{
unsigned nchars = sizeof "__attribute" - 1;
while ('_' == format_chars[nchars])
/* Diagnose unquoted built-ins. */
if (format_chars[0] == '_'
&& format_chars[1] == '_'
- && (!strncmp (format_chars + 2, "atomic", sizeof "atomic" - 1)
- || !strncmp (format_chars + 2, "builtin", sizeof "builtin" - 1)
- || !strncmp (format_chars + 2, "sync", sizeof "sync" - 1)))
+ && (startswith (format_chars + 2, "atomic")
+ || startswith (format_chars + 2, "builtin")
+ || startswith (format_chars + 2, "sync")))
{
format_warning_substr (format_string_loc, format_string_cst,
fmtchrpos, fmtchrpos + wlen, opt,
if (*format_chars == '%')
{
/* Diagnose %<%s%> and suggest using %qs instead. */
- if (!strncmp (format_chars, "%<%s%>", 6))
+ if (startswith (format_chars, "%<%s%>"))
format_warning_substr (format_string_loc, format_string_cst,
fmtchrpos, fmtchrpos + 6, opt,
"quoted %qs directive in format; "
if (nchars == 1)
{
- if (!strncmp (format_chars, "\"%s\"", 4))
+ if (startswith (format_chars, "\"%s\""))
{
if (format_warning_substr (format_string_loc, format_string_cst,
fmtchrpos, fmtchrpos + 4, opt,
&& format_chars[0] == '(')
; /* Text beginning in an open parenthesis. */
else if (nchars == 3
- && !strncmp (format_chars, "...", 3)
+ && startswith (format_chars, "...")
&& format_chars[3])
; /* Text beginning in an ellipsis. */
else
a period at the end of a capitalized sentence. */
else if (nchars == 3
&& format_chars - orig_format_chars > 0
- && !strncmp (format_chars, "...", 3))
+ && startswith (format_chars, "..."))
; /* Text ending in the ellipsis. */
else
format_warning_substr (format_string_loc, format_string_cst,
int i;
if (attr_name == NULL || *attr_name == 0
- || strncmp (attr_name, "gcc_", 4) == 0)
+ || startswith (attr_name, "gcc_"))
return attr_name;
#ifdef TARGET_OVERRIDES_FORMAT_INIT
TARGET_OVERRIDES_FORMAT_INIT ();
for (;;)
{
- if (!strncmp (p, "volatile ", 9))
+ if (startswith (p, "volatile "))
{
p += 9;
continue;
}
- if (!strncmp (p, "const ", 6))
+ if (startswith (p, "const "))
{
p += 6;
continue;
orig_fundecl = fundecl;
/* Atomic functions have type checking/casting already done. They are
often rewritten and don't match the original parameter list. */
- if (name && !strncmp (IDENTIFIER_POINTER (name), "__atomic_", 9))
+ if (name && startswith (IDENTIFIER_POINTER (name), "__atomic_"))
origtypes = NULL;
}
if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
nargs, argarray, &arg_loc);
if (name != NULL_TREE
- && !strncmp (IDENTIFIER_POINTER (name), "__builtin_", 10))
+ && startswith (IDENTIFIER_POINTER (name), "__builtin_"))
{
if (require_constant_value)
result
static bool
c_parser_gimple_parse_bb_spec (tree val, int *index)
{
- if (strncmp (IDENTIFIER_POINTER (val), "__BB", 4) != 0)
+ if (!startswith (IDENTIFIER_POINTER (val), "__BB"))
return false;
for (const char *p = IDENTIFIER_POINTER (val) + 4; *p; ++p)
if (!ISDIGIT (*p))
{
if (! strcmp (argv[i], "-debug"))
debug = true;
- else if (!strncmp (argv[i], "-fno-lto", 8))
+ else if (startswith (argv[i], "-fno-lto"))
lto_mode = LTO_MODE_NONE;
else if (! strcmp (argv[i], "-plugin"))
{
selected_linker = USE_GOLD_LD;
else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
selected_linker = USE_LLD_LD;
- else if (strncmp (argv[i], "-o", 2) == 0)
+ else if (startswith (argv[i], "-o"))
{
/* Parse the output filename if it's given so that we can make
meaningful temp filenames. */
/* These flags are position independent, although their order
is important - subsequent flags override earlier ones. */
else if (strcmp (argv[i], "-b64") == 0)
- aix64_flag = 1;
+ aix64_flag = 1;
/* -bexport:filename always needs the :filename */
- else if (strncmp (argv[i], "-bE:", 4) == 0
- || strncmp (argv[i], "-bexport:", 9) == 0)
- export_flag = 1;
+ else if (startswith (argv[i], "-bE:")
+ || startswith (argv[i], "-bexport:"))
+ export_flag = 1;
else if (strcmp (argv[i], "-brtl") == 0
|| strcmp (argv[i], "-bsvr4") == 0
|| strcmp (argv[i], "-G") == 0)
- aixrtl_flag = 1;
+ aixrtl_flag = 1;
else if (strcmp (argv[i], "-bnortl") == 0)
- aixrtl_flag = 0;
+ aixrtl_flag = 0;
else if (strcmp (argv[i], "-blazy") == 0)
- aixlazy_flag = 1;
+ aixlazy_flag = 1;
#endif
}
const char *q = extract_string (&p);
if (*q == '-' && (q[1] == 'm' || q[1] == 'f'))
num_c_args++;
- if (strncmp (q, "-flto-partition=none", 20) == 0)
+ if (startswith (q, "-flto-partition=none"))
no_partition = true;
- else if (strncmp (q, "-fno-lto", 8) == 0)
+ else if (startswith (q, "-fno-lto"))
lto_mode = LTO_MODE_NONE;
- else if (strncmp (q, "-save-temps", 11) == 0)
+ else if (startswith (q, "-save-temps"))
/* FIXME: Honour =obj. */
save_temps = true;
else if (strcmp (q, "-dumpdir") == 0)
(void) extract_string (&p);
#ifdef COLLECT_EXPORT_LIST
/* Detect any invocation with -fvisibility. */
- if (strncmp (q, "-fvisibility", 12) == 0)
+ if (startswith (q, "-fvisibility"))
visibility_flag = 1;
#endif
}
break;
case 'f':
- if (strncmp (arg, "-flto", 5) == 0)
+ if (startswith (arg, "-flto"))
{
#ifdef ENABLE_LTO
/* Do not pass LTO flag to the linker. */
#endif
}
else if (!use_collect_ld
- && strncmp (arg, "-fuse-ld=", 9) == 0)
+ && startswith (arg, "-fuse-ld="))
{
/* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
ld1--;
ld2--;
}
- else if (strncmp (arg, "-fno-lto", 8) == 0)
+ else if (startswith (arg, "-fno-lto"))
{
/* Do not pass -fno-lto to the linker. */
ld1--;
ld2--;
#endif
}
- else if (strncmp (arg, "--demangle", 10) == 0)
+ else if (startswith (arg, "--demangle"))
{
#ifndef HAVE_LD_DEMANGLE
no_demangle = 0;
ld2--;
#endif
}
- else if (strncmp (arg, "--sysroot=", 10) == 0)
+ else if (startswith (arg, "--sysroot="))
target_system_root = arg + 10;
else if (strcmp (arg, "--version") == 0)
verbose = true;
{
int *found = (int *) data;
- if (strncmp (name, LTO_SECTION_NAME_PREFIX,
- sizeof (LTO_SECTION_NAME_PREFIX) - 1) != 0)
- {
- if (strncmp (name, OFFLOAD_SECTION_NAME_PREFIX,
- sizeof (OFFLOAD_SECTION_NAME_PREFIX) - 1) != 0)
- return 1;
- }
+ if (!startswith (name, LTO_SECTION_NAME_PREFIX)
+ && !startswith (name, OFFLOAD_SECTION_NAME_PREFIX))
+ return 1;
*found = 1;
continue;
name = p;
- if (strncmp (name, "not found", sizeof ("not found") - 1) == 0)
+ if (startswith (name, "not found"))
fatal_error (input_location, "dynamic dependency %s not found", buf);
/* Find the end of the symbol name. */
for (i = 0; string[i]; i++)
{
int offset = 0;
- if (!strncmp (string + i, "_GLOBAL__N_", 11))
+ if (startswith (string + i, "_GLOBAL__N_"))
offset = 11;
- if (!strncmp (string + i, "_GLOBAL__", 9))
+ if (startswith (string + i, "_GLOBAL__"))
offset = 9;
/* C++ namespaces do have scheme:
filename = concat (getpwd (), separator, filename, NULL);
if (profile_prefix_path)
{
- if (!strncmp (filename, profile_prefix_path,
- strlen (profile_prefix_path)))
+ if (startswith (filename, profile_prefix_path))
{
filename += strlen (profile_prefix_path);
while (*filename == *separator)
if (name[0] == '_'
&& name[1] == '_'
- && (strncmp (name + 2, "builtin_",
- strlen ("builtin_")) == 0
+ && (startswith (name + 2, "builtin_")
|| (len = strlen (name)) <= strlen ("___chk")
|| memcmp (name + len - strlen ("_chk"),
"_chk", strlen ("_chk") + 1) != 0))
/* In the user's namespace, it must be declared before use. */
hiding = true;
else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
- && 0 != strncmp (name + 2, "builtin_", strlen ("builtin_"))
+ && !startswith (name + 2, "builtin_")
&& 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
"_chk", strlen ("_chk") + 1))
/* Treat __*_chk fortification functions as anticipated as well,
return true;
}
if (fndecl_built_in_p (variant)
- && (strncmp (varname, "__builtin_", strlen ("__builtin_")) == 0
- || strncmp (varname, "__sync_", strlen ("__sync_")) == 0
- || strncmp (varname, "__atomic_", strlen ("__atomic_")) == 0))
+ && (startswith (varname, "__builtin_")
+ || startswith (varname, "__sync_")
+ || startswith (varname, "__atomic_")))
{
error_at (varid_loc, "variant %qD is a built-in", variant);
return true;
|| (IDENTIFIER_LENGTH (declarator) > 10
&& IDENTIFIER_POINTER (declarator)[0] == '_'
&& IDENTIFIER_POINTER (declarator)[1] == '_'
- && strncmp (IDENTIFIER_POINTER (declarator)+2,
- "builtin_", 8) == 0)
+ && startswith (IDENTIFIER_POINTER (declarator) + 2,
+ "builtin_"))
|| (targetcm.cxx_implicit_extern_c
&& (targetcm.cxx_implicit_extern_c
(IDENTIFIER_POINTER (declarator))))))
}
const char *str = IDENTIFIER_POINTER (t);
- if (!strncmp (str, "_ZGR", 4))
+ if (startswith (str, "_ZGR"))
{
pp_cxx_ws_string (pp, "<temporary>");
return;
const char *p = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
const char *end = p + IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl));
bool nested = false;
- if (strncmp (p, "_Z", 2))
+ if (!startswith (p, "_Z"))
return NULL;
p += 2;
- if (!strncmp (p, "St", 2))
+ if (startswith (p, "St"))
p += 2;
else if (*p == 'N')
{
break;
}
}
- if (strncmp (p, "DC", 2))
+ if (!startswith (p, "DC"))
return NULL;
if (nested)
{
write_guarded_var_name (const tree variable)
{
if (DECL_NAME (variable)
- && strncmp (IDENTIFIER_POINTER (DECL_NAME (variable)), "_ZGR", 4) == 0)
+ && startswith (IDENTIFIER_POINTER (DECL_NAME (variable)), "_ZGR"))
/* The name of a guard variable for a reference temporary should refer
to the reference, not the temporary. */
write_string (IDENTIFIER_POINTER (DECL_NAME (variable)) + 4);
if (TREE_CODE (fn) != FUNCTION_DECL)
return false;
tree name = DECL_NAME (fn);
- return strncmp (IDENTIFIER_POINTER (name), TLS_WRAPPER_PREFIX,
- strlen (TLS_WRAPPER_PREFIX)) == 0;
+ return startswith (IDENTIFIER_POINTER (name), TLS_WRAPPER_PREFIX);
}
/* Return an identifier for the name of a temporary variable used to
decl_specs->int_n_idx = idx;
/* Check if the alternate "__intN__" form has been used instead of
"__intN". */
- if (strncmp (IDENTIFIER_POINTER (token->u.value)
- + (IDENTIFIER_LENGTH (token->u.value) - 2),
- "__", 2) == 0)
+ if (startswith (IDENTIFIER_POINTER (token->u.value)
+ + (IDENTIFIER_LENGTH (token->u.value) - 2), "__"))
decl_specs->int_n_alt = true;
}
type = int_n_trees [idx].signed_type;
tree name = token->u.value;
const char *p = IDENTIFIER_POINTER (name);
const int len = strlen ("transaction_safe");
- if (!strncmp (p, "transaction_safe", len))
+ if (startswith (p, "transaction_safe"))
{
p += len;
if (*p == '\0'
template_parm_object_p (const_tree t)
{
return (TREE_CODE (t) == VAR_DECL && DECL_ARTIFICIAL (t) && DECL_NAME (t)
- && !strncmp (IDENTIFIER_POINTER (DECL_NAME (t)), "_ZTA", 4));
+ && startswith (IDENTIFIER_POINTER (DECL_NAME (t)), "_ZTA"));
}
/* Subroutine of convert_nontype_argument, to check whether EXPR, as an
{
return (TREE_CODE (name) == IDENTIFIER_NODE
&& TREE_TYPE (name)
- && !strncmp (IDENTIFIER_POINTER (name), dguide_base,
- strlen (dguide_base)));
+ && startswith (IDENTIFIER_POINTER (name), dguide_base));
}
/* True if FN is a deduction guide. */
return;
gcc_assert ((!both_p && !fallback_p)
- || !strncmp (name, "__builtin_",
- strlen ("__builtin_")));
+ || startswith (name, "__builtin_"));
libname = name + strlen ("__builtin_");
const char *id = fd->ident->toChars();
size_t idlen = strlen(id);
if (nargs == 2 && (idlen == 10 || idlen == 11) &&
- !strncmp(id, "_aApply", 7))
+ startswith (id, "_aApply"))
{
// Functions from aApply.d and aApplyR.d in the runtime
bool rvs = (idlen == 11); // true if foreach_reverse
cd == ClassDeclaration::object ||
cd == Type::typeinfoclass ||
cd == Module::moduleinfo ||
- strncmp(cd->ident->toChars(), "TypeInfo_", 9) == 0)
+ startswith (cd->ident->toChars(), "TypeInfo_"))
{
// Don't mangle parent
ad->parent = NULL;
}
else if (p->type->ty == Tident &&
strlen(((TypeIdentifier *)p->type)->ident->toChars()) > 3 &&
- strncmp(((TypeIdentifier *)p->type)->ident->toChars(), "__T", 3) == 0)
+ startswith (((TypeIdentifier *)p->type)->ident->toChars(), "__T"))
{
// print parameter name, instead of undetermined type parameter
buf->writestring(p->ident->toChars());
{ p = toChars();
if (*p == '_')
{
- if (strncmp(p, "_staticCtor", 11) == 0)
+ if (startswith(p, "_staticCtor"))
p = "static this";
- else if (strncmp(p, "_staticDtor", 11) == 0)
+ else if (startswith(p, "_staticDtor"))
p = "static ~this";
- else if (strncmp(p, "__invariant", 11) == 0)
+ else if (startswith(p, "__invariant"))
p = "invariant";
}
}
{
const_tree context = get_ultimate_context (decl);
if (context && TRANSLATION_UNIT_LANGUAGE (context))
- return strncmp (TRANSLATION_UNIT_LANGUAGE (context), "GNU C++", 7) == 0;
+ return startswith (TRANSLATION_UNIT_LANGUAGE (context), "GNU C++");
}
return is_cxx ();
}
common_lang = TRANSLATION_UNIT_LANGUAGE (t);
else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
;
- else if (strncmp (common_lang, "GNU C", 5) == 0
- && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
+ else if (startswith (common_lang, "GNU C")
+ && startswith (TRANSLATION_UNIT_LANGUAGE (t), "GNU C"))
/* Mixing C and C++ is ok, use C++ in that case. */
common_lang = highest_c_language (common_lang,
TRANSLATION_UNIT_LANGUAGE (t));
}
language = DW_LANG_C;
- if (strncmp (language_string, "GNU C", 5) == 0
+ if (startswith (language_string, "GNU C")
&& ISDIGIT (language_string[5]))
{
language = DW_LANG_C89;
language = DW_LANG_C11;
}
}
- else if (strncmp (language_string, "GNU C++", 7) == 0)
+ else if (startswith (language_string, "GNU C++"))
{
language = DW_LANG_C_plus_plus;
if (dwarf_version >= 5 /* || !dwarf_strict */)
{
if (strcmp (language_string, "GNU Ada") == 0)
language = DW_LANG_Ada95;
- else if (strncmp (language_string, "GNU Fortran", 11) == 0)
+ else if (startswith (language_string, "GNU Fortran"))
{
language = DW_LANG_Fortran95;
if (dwarf_version >= 5 /* || !dwarf_strict */)
}
}
/* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
- else if (strncmp (language_string, "GNU Fortran", 11) == 0)
+ else if (startswith (language_string, "GNU Fortran"))
language = DW_LANG_Fortran90;
/* Likewise for Ada. */
else if (strcmp (language_string, "GNU Ada") == 0)
}
/* %FILL components may not have initializers. */
- if (gfc_str_startswith (name, "%FILL") && gfc_match_eos () != MATCH_YES)
+ if (startswith (name, "%FILL") && gfc_match_eos () != MATCH_YES)
{
gfc_error ("%qs entity cannot have an initializer at %C", "%FILL");
m = MATCH_ERROR;
{
case COMP_ASSOCIATE:
case COMP_BLOCK:
- if (gfc_str_startswith (block_name, "block@"))
+ if (startswith (block_name, "block@"))
block_name = NULL;
break;
bool gfc_ref_dimen_size (gfc_array_ref *, int dimen, mpz_t *, mpz_t *);
-
-#define gfc_str_startswith(str, pref) \
- (strncmp ((str), (pref), strlen (pref)) == 0)
-
/* interface.c -- FIXME: some of these should be in symbol.c */
void gfc_free_interface (gfc_interface *);
bool gfc_compare_derived_types (gfc_symbol *, gfc_symbol *);
mio_pool_string (&name);
gfc_clear_ts (&ts);
mio_typespec (&ts);
- if (gfc_str_startswith (name, "operator "))
+ if (startswith (name, "operator "))
{
const char *p = name + sizeof ("operator ") - 1;
if (strcmp (p, "+") == 0)
/* Exception: Always import vtabs & vtypes. */
if (p == NULL && name[0] == '_'
- && (gfc_str_startswith (name, "__vtab_")
- || gfc_str_startswith (name, "__vtype_")))
+ && (startswith (name, "__vtab_")
+ || startswith (name, "__vtype_")))
p = name;
/* Skip symtree nodes not in an ONLY clause, unless there
sym->attr.use_rename = 1;
if (name[0] != '_'
- || (!gfc_str_startswith (name, "__vtab_")
- && !gfc_str_startswith (name, "__vtype_")))
+ || (!startswith (name, "__vtab_")
+ && !startswith (name, "__vtype_")))
sym->attr.use_only = only_flag;
/* Store the symtree pointing to this symbol. */
result = 1;
break;
}
- else if (optname[n] && pos > 3 && gfc_str_startswith (arg, "no-")
+ else if (optname[n] && pos > 3 && startswith (arg, "no-")
&& strncmp (optname[n], arg+3, pos-3) == 0)
{
gfc_option.rtcheck &= ~optmask[n];
switch (name[0])
{
case 'l':
- if (gfc_str_startswith (name, "loc"))
+ if (startswith (name, "loc"))
{
result->name = "%LOC";
break;
}
/* FALLTHRU */
case 'r':
- if (gfc_str_startswith (name, "ref"))
+ if (startswith (name, "ref"))
{
result->name = "%REF";
break;
}
/* FALLTHRU */
case 'v':
- if (gfc_str_startswith (name, "val"))
+ if (startswith (name, "val"))
{
result->name = "%VAL";
break;
Marking this as artificial means that OpenMP will treat this as
predetermined shared. */
- bool def_init = gfc_str_startswith (sym->name, "__def_init");
+ bool def_init = startswith (sym->name, "__def_init");
if (sym->attr.vtab || def_init)
{
/* When calling __copy for character expressions to unlimited
polymorphic entities, the dst argument needs a string length. */
if (sym->name[0] == '_' && e && e->ts.type == BT_CHARACTER
- && gfc_str_startswith (sym->name, "__vtab_CHARACTER")
+ && startswith (sym->name, "__vtab_CHARACTER")
&& arg->next && arg->next->expr
&& (arg->next->expr->ts.type == BT_DERIVED
|| arg->next->expr->ts.type == BT_CLASS)
{
const char *name = expr->value.function.name;
- if (gfc_str_startswith (name, "_gfortran_ieee_is_nan"))
+ if (startswith (name, "_gfortran_ieee_is_nan"))
conv_intrinsic_ieee_builtin (se, expr, BUILT_IN_ISNAN, 1);
- else if (gfc_str_startswith (name, "_gfortran_ieee_is_finite"))
+ else if (startswith (name, "_gfortran_ieee_is_finite"))
conv_intrinsic_ieee_builtin (se, expr, BUILT_IN_ISFINITE, 1);
- else if (gfc_str_startswith (name, "_gfortran_ieee_unordered"))
+ else if (startswith (name, "_gfortran_ieee_unordered"))
conv_intrinsic_ieee_builtin (se, expr, BUILT_IN_ISUNORDERED, 2);
- else if (gfc_str_startswith (name, "_gfortran_ieee_is_normal"))
+ else if (startswith (name, "_gfortran_ieee_is_normal"))
conv_intrinsic_ieee_is_normal (se, expr);
- else if (gfc_str_startswith (name, "_gfortran_ieee_is_negative"))
+ else if (startswith (name, "_gfortran_ieee_is_negative"))
conv_intrinsic_ieee_is_negative (se, expr);
- else if (gfc_str_startswith (name, "_gfortran_ieee_copy_sign"))
+ else if (startswith (name, "_gfortran_ieee_copy_sign"))
conv_intrinsic_ieee_copy_sign (se, expr);
- else if (gfc_str_startswith (name, "_gfortran_ieee_scalb"))
+ else if (startswith (name, "_gfortran_ieee_scalb"))
conv_intrinsic_ieee_scalb (se, expr);
- else if (gfc_str_startswith (name, "_gfortran_ieee_next_after"))
+ else if (startswith (name, "_gfortran_ieee_next_after"))
conv_intrinsic_ieee_next_after (se, expr);
- else if (gfc_str_startswith (name, "_gfortran_ieee_rem"))
+ else if (startswith (name, "_gfortran_ieee_rem"))
conv_intrinsic_ieee_rem (se, expr);
- else if (gfc_str_startswith (name, "_gfortran_ieee_logb"))
+ else if (startswith (name, "_gfortran_ieee_logb"))
conv_intrinsic_ieee_logb_rint (se, expr, BUILT_IN_LOGB);
- else if (gfc_str_startswith (name, "_gfortran_ieee_rint"))
+ else if (startswith (name, "_gfortran_ieee_rint"))
conv_intrinsic_ieee_logb_rint (se, expr, BUILT_IN_RINT);
else
/* It is not among the functions we translate directly. We return
/* Not using getopt for now. */
for (i = 0; i < ac; i++)
- if (!strncmp (av[i], "-B", 2))
+ if (startswith (av[i], "-B"))
{
const char *arg = av[i] + 2;
const char *end;
when given the proper command line arguments. */
while (*p)
{
- if (in_sep && *p == '-' && strncmp (p, "-lgcc", 5) == 0)
+ if (in_sep && *p == '-' && startswith (p, "-lgcc"))
{
init_gcc_specs (&obstack,
"-lgcc_s"
p += 5;
in_sep = 0;
}
- else if (in_sep && *p == 'l' && strncmp (p, "libgcc.a%s", 10) == 0)
+ else if (in_sep && *p == 'l' && startswith (p, "libgcc.a%s"))
{
/* Ug. We don't know shared library extensions. Hope that
systems that use this form don't do shared libraries. */
/* Skip '\n'. */
p++;
- if (!strncmp (p1, "%include", sizeof ("%include") - 1)
+ if (startswith (p1, "%include")
&& (p1[sizeof "%include" - 1] == ' '
|| p1[sizeof "%include" - 1] == '\t'))
{
read_specs (new_filename ? new_filename : p1, false, user_p);
continue;
}
- else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1)
+ else if (startswith (p1, "%include_noerr")
&& (p1[sizeof "%include_noerr" - 1] == ' '
|| p1[sizeof "%include_noerr" - 1] == '\t'))
{
fnotice (stderr, "could not find specs file %s\n", p1);
continue;
}
- else if (!strncmp (p1, "%rename", sizeof "%rename" - 1)
+ else if (startswith (p1, "%rename")
&& (p1[sizeof "%rename" - 1] == ' '
|| p1[sizeof "%rename" - 1] == '\t'))
{
&& WEXITSTATUS (status) == ICE_EXIT_CODE
&& i == 0
&& (p = strrchr (commands[0].argv[0], DIR_SEPARATOR))
- && ! strncmp (p + 1, "cc1", 3))
+ && startswith (p + 1, "cc1"))
try_generate_repro (commands[0].argv);
if (WEXITSTATUS (status) > greatest_status)
greatest_status = WEXITSTATUS (status);
break;
case 'W': case 'f': case 'm': case 'g':
- if (! strncmp (name + 1, "no-", 3))
+ if (startswith (name + 1, "no-"))
{
/* We have Xno-YYY, search for XYYY. */
for (i = switchnum + 1; i < n_switches; i++)
write_attr_set (outf, attr, indent + 2, av->value, prefix, suffix,
known_true, -2, 0, 0);
- if (strncmp (prefix, "return", 6))
+ if (!startswith (prefix, "return"))
{
write_indent (outf, indent + 2);
fprintf (outf, "break;\n");
{
FILE *outf;
-#define IS_ATTR_GROUP(X) (!strncmp (attr->name, X, strlen (X)))
- if (IS_ATTR_GROUP ("*internal_dfa_insn_code"))
+ if (startswith(attr->name, "*internal_dfa_insn_code"))
outf = dfa_file;
- else if (IS_ATTR_GROUP ("*insn_default_latency"))
+ else if (startswith (attr->name, "*insn_default_latency"))
outf = latency_file;
else
outf = attr_file;
-#undef IS_ATTR_GROUP
if (! attr->is_special && ! attr->is_const)
write_attr_get (outf, attr);
for (unsigned int i = 0; builtin_names[i]; ++i)
{
const char *name = builtin_names[i];
- if (strncmp (name, "BUILT_IN_", 9) == 0)
+ if (startswith (name, "BUILT_IN_"))
{
const char *root = name + 9;
for (unsigned int j = 0; suffix_lists[j]; ++j)
extern GTY(()) gcc::some_type *some_ptr;
where the autogenerated functions will refer to simply "some_type",
where they can be resolved into their namespace. */
- if (strncmp (s, "gcc::", 5) == 0)
+ if (startswith (s, "gcc::"))
s += 5;
for (p = typedefs; p != NULL; p = p->next)
int k;
rtx_next_new[i] = -1;
- if (strncmp (rtx_format[i], "uu", 2) == 0)
+ if (startswith (rtx_format[i], "uu"))
rtx_next_new[i] = 1;
else if (i == COND_EXEC || i == SET || i == EXPR_LIST || i == INSN_LIST)
rtx_next_new[i] = 1;
return NULL;
lang_index = get_prefix_langdir_index (srcdir_relative_path);
- if (lang_index < 0 && strncmp (srcdir_relative_path, "c-family", 8) == 0)
+ if (lang_index < 0 && startswith (srcdir_relative_path, "c-family"))
r = "c-family";
else if (lang_index >= 0)
r = lang_dir_names[lang_index];
|| ((s)->gc_used == GC_MAYBE_POINTED_TO \
&& s->u.s.line.file != NULL) \
|| ((s)->gc_used == GC_USED \
- && strncmp (s->u.s.tag, "anonymous", strlen ("anonymous"))) \
+ && !startswith (s->u.s.tag, "anonymous")) \
|| (s->u.s.base_class && opts_have (s->u.s.opt, "tag")))))
for (unsigned int i = 0; id2[i]; ++i)
id2[i] = TOUPPER (id2[i]);
}
- else if (all_upper && strncmp (id, "IFN_", 4) == 0)
+ else if (all_upper && startswith (id, "IFN_"))
/* Try CFN_ instead of IFN_. */
id2 = ACONCAT (("CFN_", id + 4, NULL));
- else if (all_upper && strncmp (id, "BUILT_IN_", 9) == 0)
+ else if (all_upper && startswith (id, "BUILT_IN_"))
/* Try prepending CFN_. */
id2 = ACONCAT (("CFN_", id, NULL));
else
else if (*op == COND_EXPR
&& pos == 0)
return "boolean_type_node";
- else if (strncmp (op->id, "CFN_COND_", 9) == 0)
+ else if (startswith (op->id, "CFN_COND_"))
{
/* IFN_COND_* operands 1 and later by default have the same type
as the result. The type of operand 0 needs to be specified
}
else if (*opr == COND_EXPR
|| *opr == VEC_COND_EXPR
- || strncmp (opr->id, "CFN_COND_", 9) == 0)
+ || startswith (opr->id, "CFN_COND_"))
{
/* Conditions are of the same type as their first alternative. */
snprintf (optype, sizeof (optype), "TREE_TYPE (_o%d[1])", depth);
return;
/* Miscellaneous tests. */
- if (strncmp (d->name, "cstore", 6) == 0
+ if (startswith (d->name, "cstore")
&& d->name[strlen (d->name) - 1] == '4'
&& d->operand[0].mode == VOIDmode)
{
// The names in the table have "runtime." prefix. We may be
// called with a name without the prefix. Try matching
// without the prefix as well.
- if (strncmp(runtime_function_name, "runtime.", 8) == 0
+ if (startswith(runtime_function_name, "runtime.")
&& strcmp(runtime_function_name + 8, name.c_str()) == 0)
code = static_cast<Runtime::Function>(i);
}
{
if (p->name[0] == '=')
p->name = concat (sysroot, p->name + 1, NULL);
- if (strncmp (p->name, "$SYSROOT", strlen ("$SYSROOT")) == 0)
+ if (startswith (p->name, "$SYSROOT"))
p->name = concat (sysroot, p->name + strlen ("$SYSROOT"), NULL);
}
}
bool
lang_GNU_C (void)
{
- return (strncmp (lang_hooks.name, "GNU C", 5) == 0
+ return (startswith (lang_hooks.name, "GNU C")
&& (lang_hooks.name[5] == '\0' || ISDIGIT (lang_hooks.name[5])));
}
bool
lang_GNU_CXX (void)
{
- return strncmp (lang_hooks.name, "GNU C++", 7) == 0;
+ return startswith (lang_hooks.name, "GNU C++");
}
/* Returns true if the current lang_hooks represents the GNU Fortran frontend. */
bool
lang_GNU_Fortran (void)
{
- return strncmp (lang_hooks.name, "GNU Fortran", 11) == 0;
+ return startswith (lang_hooks.name, "GNU Fortran");
}
/* Returns true if the current lang_hooks represents the GNU Objective-C
bool
lang_GNU_OBJC (void)
{
- return strncmp (lang_hooks.name, "GNU Objective-C", 15) == 0;
+ return startswith (lang_hooks.name, "GNU Objective-C");
}
int consumed;
char *filename = argv[i];
- if (strncmp (argv[i], "-foffload-objects=",
- sizeof ("-foffload-objects=") - 1) == 0)
+ if (startswith (argv[i], "-foffload-objects="))
{
have_offload = true;
offload_objects_file_name
return (tmv
&& TREE_CODE (tmv) == IDENTIFIER_NODE
&& IDENTIFIER_POINTER (tmv)
- && !strncmp (IDENTIFIER_POINTER (tmv), "NSString", 8));
+ && startswith (IDENTIFIER_POINTER (tmv), "NSString"));
}
/* At present the behavior of this is undefined and it does nothing. */
char *enc = (char *) obstack_base (&util_obstack) + curtype;
/* Rewrite "in const" from "nr" to "rn". */
- if (curtype >= 1 && !strncmp (enc - 1, "nr", 2))
+ if (curtype >= 1 && startswith (enc - 1, "nr"))
memcpy (enc - 1, "rn", 2);
}
}
{
tree id = METHOD_SEL_NAME (clsmeth);
if (IDENTIFIER_LENGTH (id) == 4
- && strncmp (IDENTIFIER_POINTER (id), "load", 4) == 0)
+ && startswith (IDENTIFIER_POINTER (id), "load"))
return true;
clsmeth = DECL_CHAIN (clsmeth);
}
if (ENABLE_OFFLOADING)
for (const char *c = getenv ("OFFLOAD_TARGET_NAMES"); c;)
{
- if (!strncmp (c, "nvptx", strlen ("nvptx")))
+ if (startswith (c, "nvptx"))
return 32;
else if ((c = strchr (c, ':')))
c++;
return false;
const char *name = IDENTIFIER_POINTER (declname);
- if (strncmp (name, "omp_", 4) != 0)
+ if (!startswith (name, "omp_"))
return false;
static const char *omp_runtime_apis[] =
if (argv_storage[j] == '\0')
fatal_error (input_location,
"malformed %<COLLECT_GCC_OPTIONS%>");
- else if (strncmp (&argv_storage[j], "'\\''", 4) == 0)
+ else if (startswith (&argv_storage[j], "'\\''"))
{
argv_storage[k++] = '\'';
j += 4;
"orig:%i", ORIGINAL_REGNO (rtx).
Consume it, we don't set ORIGINAL_REGNO, since we can
get that from the 2nd copy later. */
- if (strncmp (desc, "orig:", 5) == 0)
+ if (startswith (desc, "orig:"))
{
expect_original_regno = true;
desc_start += 5;
else if (*str == '+')
str++;
- if (!strncmp (str, "QNaN", 4))
+ if (startswith (str, "QNaN"))
{
get_canonical_qnan (r, sign);
return 0;
}
- else if (!strncmp (str, "SNaN", 4))
+ else if (startswith (str, "SNaN"))
{
get_canonical_snan (r, sign);
return 0;
}
- else if (!strncmp (str, "Inf", 3))
+ else if (startswith (str, "Inf"))
{
get_inf (r, sign);
return 0;
"ASSERT_STR_STARTSWITH (%s, %s) str=\"%s\" prefix=NULL",
desc_str, desc_prefix, val_str);
- const char *test = strstr (val_str, val_prefix);
- if (test == val_str)
+ if (startswith (val_str, val_prefix))
pass (loc, "ASSERT_STR_STARTSWITH");
else
fail_formatted
#define NULL nullptr
#endif
+/* Return true if STR string starts with PREFIX. */
+
+static inline bool
+startswith (const char *str, const char *prefix)
+{
+ return strncmp (str, prefix, strlen (prefix)) == 0;
+}
+
#endif /* ! GCC_SYSTEM_H */
if (!tv->used)
continue;
- if (strncmp (tv->name, phase_prefix, sizeof phase_prefix - 1) == 0)
+ if (startswith (tv->name, phase_prefix))
{
phase_user += tv->elapsed.user;
phase_sys += tv->elapsed.sys;
We also assign sub_I and sub_D sufixes to constructors called from
the global static constructors. These are always local. */
else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
- || (strncmp (type, "sub_", 4) == 0
+ || (startswith (type, "sub_")
&& (type[4] == 'I' || type[4] == 'D')))
{
const char *file = main_input_filename;
return false;
expanded_location xloc = expand_location (loc);
- if (xloc.file == NULL || strncmp (xloc.file, "\1", 2) == 0
+ if (xloc.file == NULL || startswith (xloc.file, "\1")
|| xloc.file[0] == '\0' || xloc.file[0] == '\xff'
|| xloc.file[1] == '\xff')
return false;
/* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo or
.gnu.linkonce.d.rel.ro.local.foo if the jump table is relocatable. */
else if (DECL_COMDAT_GROUP (decl)
- && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
+ && startswith (name, ".gnu.linkonce.t."))
{
size_t len;
char *rname;
}
/* For .text.foo we want to use .rodata.foo. */
else if (flag_function_sections && flag_data_sections
- && strncmp (name, ".text.", 6) == 0)
+ && startswith (name, ".text."))
{
size_t len = strlen (name) + 1;
char *rname = (char *) alloca (len + strlen (sname) - 5);
name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
/* Atomic or sync builtins which have survived this far will be
resolved externally and therefore are not incorporeal. */
- if (strncmp (name, "__builtin_", 10) == 0)
+ if (startswith (name, "__builtin_"))
return true;
}
return false;
flags |= SECTION_TLS | SECTION_WRITE;
if (strcmp (name, ".bss") == 0
- || strncmp (name, ".bss.", 5) == 0
- || strncmp (name, ".gnu.linkonce.b.", 16) == 0
+ || startswith (name, ".bss.")
+ || startswith (name, ".gnu.linkonce.b.")
|| strcmp (name, ".persistent.bss") == 0
|| 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_BSS;
if (strcmp (name, ".tdata") == 0
- || strncmp (name, ".tdata.", 7) == 0
- || strncmp (name, ".gnu.linkonce.td.", 17) == 0)
+ || startswith (name, ".tdata.")
+ || startswith (name, ".gnu.linkonce.td."))
flags |= SECTION_TLS;
if (strcmp (name, ".tbss") == 0
- || strncmp (name, ".tbss.", 6) == 0
- || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
+ || startswith (name, ".tbss.")
+ || startswith (name, ".gnu.linkonce.tb."))
flags |= SECTION_TLS | SECTION_BSS;
if (strcmp (name, ".noinit") == 0)