Add -Wimplicit-fallthrough checks if supported
Clang since r369414 (clang-10) can now check -Wimplicit-fallthrough for C code, and use the GNU C style attribute to denote fallthrough. Move the test from header only to autoconf. The previous test used brittle version detection which did not work for newer clang that supported this feature. The attribute has to be its own statement, hence the added `;`. It also can only precede case statements, so the final cases should be explicitly terminated with break statements. Fixes commit3d29d11ac2
("Clean compilation -Wextra") Link:1e0affb6e5
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
This commit is contained in:
parent
a8b578d538
commit
d01b425e5d
20
configure.ac
20
configure.ac
@ -866,6 +866,26 @@ if test "x${je_cv_format_arg}" = "xyes" ; then
|
||||
AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_ARG], [ ])
|
||||
fi
|
||||
|
||||
dnl Check for fallthrough attribute support.
|
||||
JE_CFLAGS_SAVE()
|
||||
JE_CFLAGS_ADD([-Wimplicit-fallthrough])
|
||||
JE_COMPILABLE([fallthrough attribute],
|
||||
[#if !__has_attribute(fallthrough)
|
||||
#error "foo"
|
||||
#endif],
|
||||
[int x = 0;
|
||||
switch (x) {
|
||||
case 0: __attribute__((__fallthrough__));
|
||||
case 1: return 1;
|
||||
}],
|
||||
[je_cv_fallthrough])
|
||||
JE_CFLAGS_RESTORE()
|
||||
if test "x${je_cv_fallthrough}" = "xyes" ; then
|
||||
AC_DEFINE([JEMALLOC_HAVE_ATTR_FALLTHROUGH], [ ])
|
||||
JE_CFLAGS_ADD([-Wimplicit-fallthrough])
|
||||
JE_CXXFLAGS_ADD([-Wimplicit-fallthrough])
|
||||
fi
|
||||
|
||||
dnl Support optional additions to rpath.
|
||||
AC_ARG_WITH([rpath],
|
||||
[AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
|
||||
|
@ -104,8 +104,8 @@ hash_x86_32(const void *key, int len, uint32_t seed) {
|
||||
uint32_t k1 = 0;
|
||||
|
||||
switch (len & 3) {
|
||||
case 3: k1 ^= tail[2] << 16; JEMALLOC_FALLTHROUGH
|
||||
case 2: k1 ^= tail[1] << 8; JEMALLOC_FALLTHROUGH
|
||||
case 3: k1 ^= tail[2] << 16; JEMALLOC_FALLTHROUGH;
|
||||
case 2: k1 ^= tail[1] << 8; JEMALLOC_FALLTHROUGH;
|
||||
case 1: k1 ^= tail[0]; k1 *= c1; k1 = hash_rotl_32(k1, 15);
|
||||
k1 *= c2; h1 ^= k1;
|
||||
}
|
||||
@ -177,29 +177,29 @@ hash_x86_128(const void *key, const int len, uint32_t seed,
|
||||
uint32_t k4 = 0;
|
||||
|
||||
switch (len & 15) {
|
||||
case 15: k4 ^= tail[14] << 16; JEMALLOC_FALLTHROUGH
|
||||
case 14: k4 ^= tail[13] << 8; JEMALLOC_FALLTHROUGH
|
||||
case 15: k4 ^= tail[14] << 16; JEMALLOC_FALLTHROUGH;
|
||||
case 14: k4 ^= tail[13] << 8; JEMALLOC_FALLTHROUGH;
|
||||
case 13: k4 ^= tail[12] << 0;
|
||||
k4 *= c4; k4 = hash_rotl_32(k4, 18); k4 *= c1; h4 ^= k4;
|
||||
JEMALLOC_FALLTHROUGH
|
||||
case 12: k3 ^= tail[11] << 24; JEMALLOC_FALLTHROUGH
|
||||
case 11: k3 ^= tail[10] << 16; JEMALLOC_FALLTHROUGH
|
||||
case 10: k3 ^= tail[ 9] << 8; JEMALLOC_FALLTHROUGH
|
||||
JEMALLOC_FALLTHROUGH;
|
||||
case 12: k3 ^= tail[11] << 24; JEMALLOC_FALLTHROUGH;
|
||||
case 11: k3 ^= tail[10] << 16; JEMALLOC_FALLTHROUGH;
|
||||
case 10: k3 ^= tail[ 9] << 8; JEMALLOC_FALLTHROUGH;
|
||||
case 9: k3 ^= tail[ 8] << 0;
|
||||
k3 *= c3; k3 = hash_rotl_32(k3, 17); k3 *= c4; h3 ^= k3;
|
||||
JEMALLOC_FALLTHROUGH
|
||||
case 8: k2 ^= tail[ 7] << 24; JEMALLOC_FALLTHROUGH
|
||||
case 7: k2 ^= tail[ 6] << 16; JEMALLOC_FALLTHROUGH
|
||||
case 6: k2 ^= tail[ 5] << 8; JEMALLOC_FALLTHROUGH
|
||||
JEMALLOC_FALLTHROUGH;
|
||||
case 8: k2 ^= tail[ 7] << 24; JEMALLOC_FALLTHROUGH;
|
||||
case 7: k2 ^= tail[ 6] << 16; JEMALLOC_FALLTHROUGH;
|
||||
case 6: k2 ^= tail[ 5] << 8; JEMALLOC_FALLTHROUGH;
|
||||
case 5: k2 ^= tail[ 4] << 0;
|
||||
k2 *= c2; k2 = hash_rotl_32(k2, 16); k2 *= c3; h2 ^= k2;
|
||||
JEMALLOC_FALLTHROUGH
|
||||
case 4: k1 ^= tail[ 3] << 24; JEMALLOC_FALLTHROUGH
|
||||
case 3: k1 ^= tail[ 2] << 16; JEMALLOC_FALLTHROUGH
|
||||
case 2: k1 ^= tail[ 1] << 8; JEMALLOC_FALLTHROUGH
|
||||
JEMALLOC_FALLTHROUGH;
|
||||
case 4: k1 ^= tail[ 3] << 24; JEMALLOC_FALLTHROUGH;
|
||||
case 3: k1 ^= tail[ 2] << 16; JEMALLOC_FALLTHROUGH;
|
||||
case 2: k1 ^= tail[ 1] << 8; JEMALLOC_FALLTHROUGH;
|
||||
case 1: k1 ^= tail[ 0] << 0;
|
||||
k1 *= c1; k1 = hash_rotl_32(k1, 15); k1 *= c2; h1 ^= k1;
|
||||
JEMALLOC_FALLTHROUGH
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,24 +261,25 @@ hash_x64_128(const void *key, const int len, const uint32_t seed,
|
||||
uint64_t k2 = 0;
|
||||
|
||||
switch (len & 15) {
|
||||
case 15: k2 ^= ((uint64_t)(tail[14])) << 48; JEMALLOC_FALLTHROUGH
|
||||
case 14: k2 ^= ((uint64_t)(tail[13])) << 40; JEMALLOC_FALLTHROUGH
|
||||
case 13: k2 ^= ((uint64_t)(tail[12])) << 32; JEMALLOC_FALLTHROUGH
|
||||
case 12: k2 ^= ((uint64_t)(tail[11])) << 24; JEMALLOC_FALLTHROUGH
|
||||
case 11: k2 ^= ((uint64_t)(tail[10])) << 16; JEMALLOC_FALLTHROUGH
|
||||
case 10: k2 ^= ((uint64_t)(tail[ 9])) << 8; JEMALLOC_FALLTHROUGH
|
||||
case 15: k2 ^= ((uint64_t)(tail[14])) << 48; JEMALLOC_FALLTHROUGH;
|
||||
case 14: k2 ^= ((uint64_t)(tail[13])) << 40; JEMALLOC_FALLTHROUGH;
|
||||
case 13: k2 ^= ((uint64_t)(tail[12])) << 32; JEMALLOC_FALLTHROUGH;
|
||||
case 12: k2 ^= ((uint64_t)(tail[11])) << 24; JEMALLOC_FALLTHROUGH;
|
||||
case 11: k2 ^= ((uint64_t)(tail[10])) << 16; JEMALLOC_FALLTHROUGH;
|
||||
case 10: k2 ^= ((uint64_t)(tail[ 9])) << 8; JEMALLOC_FALLTHROUGH;
|
||||
case 9: k2 ^= ((uint64_t)(tail[ 8])) << 0;
|
||||
k2 *= c2; k2 = hash_rotl_64(k2, 33); k2 *= c1; h2 ^= k2;
|
||||
JEMALLOC_FALLTHROUGH
|
||||
case 8: k1 ^= ((uint64_t)(tail[ 7])) << 56; JEMALLOC_FALLTHROUGH
|
||||
case 7: k1 ^= ((uint64_t)(tail[ 6])) << 48; JEMALLOC_FALLTHROUGH
|
||||
case 6: k1 ^= ((uint64_t)(tail[ 5])) << 40; JEMALLOC_FALLTHROUGH
|
||||
case 5: k1 ^= ((uint64_t)(tail[ 4])) << 32; JEMALLOC_FALLTHROUGH
|
||||
case 4: k1 ^= ((uint64_t)(tail[ 3])) << 24; JEMALLOC_FALLTHROUGH
|
||||
case 3: k1 ^= ((uint64_t)(tail[ 2])) << 16; JEMALLOC_FALLTHROUGH
|
||||
case 2: k1 ^= ((uint64_t)(tail[ 1])) << 8; JEMALLOC_FALLTHROUGH
|
||||
JEMALLOC_FALLTHROUGH;
|
||||
case 8: k1 ^= ((uint64_t)(tail[ 7])) << 56; JEMALLOC_FALLTHROUGH;
|
||||
case 7: k1 ^= ((uint64_t)(tail[ 6])) << 48; JEMALLOC_FALLTHROUGH;
|
||||
case 6: k1 ^= ((uint64_t)(tail[ 5])) << 40; JEMALLOC_FALLTHROUGH;
|
||||
case 5: k1 ^= ((uint64_t)(tail[ 4])) << 32; JEMALLOC_FALLTHROUGH;
|
||||
case 4: k1 ^= ((uint64_t)(tail[ 3])) << 24; JEMALLOC_FALLTHROUGH;
|
||||
case 3: k1 ^= ((uint64_t)(tail[ 2])) << 16; JEMALLOC_FALLTHROUGH;
|
||||
case 2: k1 ^= ((uint64_t)(tail[ 1])) << 8; JEMALLOC_FALLTHROUGH;
|
||||
case 1: k1 ^= ((uint64_t)(tail[ 0])) << 0;
|
||||
k1 *= c1; k1 = hash_rotl_64(k1, 31); k1 *= c2; h1 ^= k1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,13 +40,6 @@
|
||||
#define JEMALLOC_VA_ARGS_HEAD(head, ...) head
|
||||
#define JEMALLOC_VA_ARGS_TAIL(head, ...) __VA_ARGS__
|
||||
|
||||
#if (defined(__GNUC__) || defined(__GNUG__)) && !defined(__clang__) \
|
||||
&& defined(JEMALLOC_HAVE_ATTR) && (__GNUC__ >= 7)
|
||||
#define JEMALLOC_FALLTHROUGH JEMALLOC_ATTR(fallthrough);
|
||||
#else
|
||||
#define JEMALLOC_FALLTHROUGH /* falls through */
|
||||
#endif
|
||||
|
||||
/* Diagnostic suppression macros */
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
# define JEMALLOC_DIAGNOSTIC_PUSH __pragma(warning(push))
|
||||
|
@ -13,6 +13,9 @@
|
||||
/* Defined if format(printf, ...) attribute is supported. */
|
||||
#undef JEMALLOC_HAVE_ATTR_FORMAT_PRINTF
|
||||
|
||||
/* Defined if fallthrough attribute is supported. */
|
||||
#undef JEMALLOC_HAVE_ATTR_FALLTHROUGH
|
||||
|
||||
/*
|
||||
* Define overrides for non-standard allocator-related functions if they are
|
||||
* present on the system.
|
||||
|
@ -71,6 +71,7 @@
|
||||
# endif
|
||||
# define JEMALLOC_FORMAT_ARG(i)
|
||||
# define JEMALLOC_FORMAT_PRINTF(s, i)
|
||||
# define JEMALLOC_FALLTHROUGH
|
||||
# define JEMALLOC_NOINLINE __declspec(noinline)
|
||||
# ifdef __cplusplus
|
||||
# define JEMALLOC_NOTHROW __declspec(nothrow)
|
||||
@ -109,6 +110,11 @@
|
||||
# else
|
||||
# define JEMALLOC_FORMAT_PRINTF(s, i)
|
||||
# endif
|
||||
# ifdef JEMALLOC_HAVE_ATTR_FALLTHROUGH
|
||||
# define JEMALLOC_FALLTHROUGH JEMALLOC_ATTR(fallthrough)
|
||||
# else
|
||||
# define JEMALLOC_FALLTHROUGH
|
||||
# endif
|
||||
# define JEMALLOC_NOINLINE JEMALLOC_ATTR(noinline)
|
||||
# define JEMALLOC_NOTHROW JEMALLOC_ATTR(nothrow)
|
||||
# define JEMALLOC_SECTION(s) JEMALLOC_ATTR(section(s))
|
||||
@ -121,6 +127,7 @@
|
||||
# define JEMALLOC_ALLOC_SIZE2(s1, s2)
|
||||
# define JEMALLOC_EXPORT
|
||||
# define JEMALLOC_FORMAT_PRINTF(s, i)
|
||||
# define JEMALLOC_FALLTHROUGH
|
||||
# define JEMALLOC_NOINLINE
|
||||
# define JEMALLOC_NOTHROW
|
||||
# define JEMALLOC_SECTION(s)
|
||||
|
@ -874,7 +874,7 @@ arena_decay_stashed(tsdn_t *tsdn, arena_t *arena,
|
||||
arena, is_background_thread);
|
||||
break;
|
||||
}
|
||||
/* Fall through. */
|
||||
JEMALLOC_FALLTHROUGH;
|
||||
case extent_state_muzzy:
|
||||
extent_dalloc_wrapper(tsdn, arena, r_extent_hooks,
|
||||
extent);
|
||||
|
@ -135,10 +135,10 @@ malloc_strtoumax(const char *restrict nptr, char **restrict endptr, int base) {
|
||||
break;
|
||||
case '-':
|
||||
neg = true;
|
||||
/* Fall through. */
|
||||
JEMALLOC_FALLTHROUGH;
|
||||
case '+':
|
||||
p++;
|
||||
/* Fall through. */
|
||||
JEMALLOC_FALLTHROUGH;
|
||||
default:
|
||||
goto label_prefix;
|
||||
}
|
||||
@ -289,7 +289,7 @@ d2s(intmax_t x, char sign, char *s, size_t *slen_p) {
|
||||
if (!neg) {
|
||||
break;
|
||||
}
|
||||
/* Fall through. */
|
||||
JEMALLOC_FALLTHROUGH;
|
||||
case ' ':
|
||||
case '+':
|
||||
s--;
|
||||
|
Loading…
Reference in New Issue
Block a user