Merge pull request #7298 from jamessan/check-array-bounds-support

cmake: Check if the compiler understands -Wno-array-bounds
This commit is contained in:
James McCoy 2017-09-23 08:30:45 -04:00 committed by GitHub
commit 4bb0e95abb
2 changed files with 45 additions and 37 deletions

View File

@ -254,7 +254,10 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8.5")
# Array-bounds testing is broken in some GCC versions before 4.8.5.
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56273
add_definitions(-Wno-array-bounds)
check_c_compiler_flag(-Wno-array-bounds HAS_NO_ARRAY_BOUNDS_FLAG)
if(HAS_NO_ARRAY_BOUNDS_FLAG)
add_definitions(-Wno-array-bounds)
endif()
endif()
endif()

View File

@ -3316,6 +3316,47 @@ bt_regexec_nl (
return (int)r;
}
/// Wrapper around strchr which accounts for case-insensitive searches and
/// non-ASCII characters.
///
/// This function is used a lot for simple searches, keep it fast!
///
/// @param s string to search
/// @param c character to find in @a s
///
/// @return NULL if no match, otherwise pointer to the position in @a s
static inline char_u *cstrchr(const char_u *const s, const int c)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
FUNC_ATTR_ALWAYS_INLINE
{
if (!rex.reg_ic) {
return vim_strchr(s, c);
}
// Use folded case for UTF-8, slow! For ASCII use libc strpbrk which is
// expected to be highly optimized.
if (c > 0x80) {
const int folded_c = utf_fold(c);
for (const char_u *p = s; *p != NUL; p += utfc_ptr2len(p)) {
if (utf_fold(utf_ptr2char(p)) == folded_c) {
return (char_u *)p;
}
}
return NULL;
}
int cc;
if (ASCII_ISUPPER(c)) {
cc = TOLOWER_ASC(c);
} else if (ASCII_ISLOWER(c)) {
cc = TOUPPER_ASC(c);
} else {
return vim_strchr(s, c);
}
char tofind[] = { (char)c, (char)cc, NUL };
return (char_u *)strpbrk((const char *)s, tofind);
}
/// Matches a regexp against multiple lines.
/// "rmp->regprog" is a compiled regexp as returned by vim_regcomp().
@ -6320,42 +6361,6 @@ static int cstrncmp(char_u *s1, char_u *s2, int *n)
return result;
}
/*
* cstrchr: This function is used a lot for simple searches, keep it fast!
*/
static inline char_u *cstrchr(const char_u *const s, const int c)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
FUNC_ATTR_ALWAYS_INLINE
{
if (!rex.reg_ic) {
return vim_strchr(s, c);
}
// Use folded case for UTF-8, slow! For ASCII use libc strpbrk which is
// expected to be highly optimized.
if (c > 0x80) {
const int folded_c = utf_fold(c);
for (const char_u *p = s; *p != NUL; p += utfc_ptr2len(p)) {
if (utf_fold(utf_ptr2char(p)) == folded_c) {
return (char_u *)p;
}
}
return NULL;
}
int cc;
if (ASCII_ISUPPER(c)) {
cc = TOLOWER_ASC(c);
} else if (ASCII_ISLOWER(c)) {
cc = TOUPPER_ASC(c);
} else {
return vim_strchr(s, c);
}
char tofind[] = { (char)c, (char)cc, NUL };
return (char_u *)strpbrk((const char *)s, tofind);
}
/***************************************************************
* regsub stuff *
***************************************************************/