From: Ivan Maidanski Date: Thu, 10 Sep 2015 08:48:05 +0000 (+0300) Subject: Fix 'comparison of non-null parameter is always false' warning (Clang) X-Git-Tag: gc7_6_0~142 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1ba52c166748a2712bedbdf0f74fcc222dc52c0d;p=gc Fix 'comparison of non-null parameter is always false' warning (Clang) * alloc.c (GC_set_stop_func, GC_try_to_collect): Use NONNULL_ARG_NOT_NULL to check argument marked as non-null (in function declaration) is actually non-null. * finalize.c (GC_general_register_disappearing_link, GC_register_long_link, GC_move_disappearing_link, GC_move_long_link): Likewise. * misc.c (GC_set_warn_proc, GC_set_abort_func, GC_set_oom_fn): Likewise. * include/private/gc_priv.h (NONNULL_ARG_NOT_NULL): New macro. --- diff --git a/alloc.c b/alloc.c index 7194802a..220ce866 100644 --- a/alloc.c +++ b/alloc.c @@ -152,7 +152,7 @@ STATIC GC_stop_func GC_default_stop_func = GC_never_stop_func; GC_API void GC_CALL GC_set_stop_func(GC_stop_func stop_func) { DCL_LOCK_STATE; - GC_ASSERT(stop_func != 0); + GC_ASSERT(NONNULL_ARG_NOT_NULL(stop_func)); LOCK(); GC_default_stop_func = stop_func; UNLOCK(); @@ -1079,7 +1079,7 @@ STATIC GC_bool GC_try_to_collect_general(GC_stop_func stop_func, /* Externally callable routines to invoke full, stop-the-world collection. */ GC_API int GC_CALL GC_try_to_collect(GC_stop_func stop_func) { - GC_ASSERT(stop_func != 0); + GC_ASSERT(NONNULL_ARG_NOT_NULL(stop_func)); return (int)GC_try_to_collect_general(stop_func, FALSE); } diff --git a/finalize.c b/finalize.c index 429f37ee..02b3d257 100644 --- a/finalize.c +++ b/finalize.c @@ -207,7 +207,7 @@ STATIC int GC_register_disappearing_link_inner( GC_API int GC_CALL GC_general_register_disappearing_link(void * * link, const void * obj) { - if (((word)link & (ALIGNMENT-1)) != 0 || NULL == link) + if (((word)link & (ALIGNMENT-1)) != 0 || !NONNULL_ARG_NOT_NULL(link)) ABORT("Bad arg to GC_general_register_disappearing_link"); return GC_register_disappearing_link_inner(&GC_dl_hashtbl, link, obj, "dl"); @@ -456,7 +456,7 @@ GC_API GC_await_finalize_proc GC_CALL GC_get_await_finalize_proc(void) #ifndef GC_LONG_REFS_NOT_NEEDED GC_API int GC_CALL GC_register_long_link(void * * link, const void * obj) { - if (((word)link & (ALIGNMENT-1)) != 0 || NULL == link) + if (((word)link & (ALIGNMENT-1)) != 0 || !NONNULL_ARG_NOT_NULL(link)) ABORT("Bad arg to GC_register_long_link"); return GC_register_disappearing_link_inner(&GC_ll_hashtbl, link, obj, "long dl"); @@ -536,7 +536,8 @@ GC_API GC_await_finalize_proc GC_CALL GC_get_await_finalize_proc(void) int result; DCL_LOCK_STATE; - if (((word)new_link & (ALIGNMENT-1)) != 0 || new_link == NULL) + if (((word)new_link & (ALIGNMENT-1)) != 0 + || !NONNULL_ARG_NOT_NULL(new_link)) ABORT("Bad new_link arg to GC_move_disappearing_link"); if (((word)link & (ALIGNMENT-1)) != 0) return GC_NOT_FOUND; /* Nothing to do. */ @@ -553,7 +554,8 @@ GC_API GC_await_finalize_proc GC_CALL GC_get_await_finalize_proc(void) int result; DCL_LOCK_STATE; - if (((word)new_link & (ALIGNMENT-1)) != 0 || new_link == NULL) + if (((word)new_link & (ALIGNMENT-1)) != 0 + || !NONNULL_ARG_NOT_NULL(new_link)) ABORT("Bad new_link arg to GC_move_disappearing_link"); if (((word)link & (ALIGNMENT-1)) != 0) return GC_NOT_FOUND; /* Nothing to do. */ diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 2102d627..9b060775 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -2357,6 +2357,14 @@ GC_INNER ptr_t GC_store_debug_info(ptr_t p, word sz, const char *str, # define GC_STATIC_ASSERT(expr) (void)sizeof(char[(expr)? 1 : -1]) #endif +/* Runtime check for an argument declared as non-null is actually not null. */ +#if defined(__GNUC__) && __GNUC__ >= 4 + /* Workaround tautological-pointer-compare Clang warning. */ +# define NONNULL_ARG_NOT_NULL(arg) (*(volatile void **)&(arg) != NULL) +#else +# define NONNULL_ARG_NOT_NULL(arg) (NULL != (arg)) +#endif + #define COND_DUMP_CHECKS \ do { \ GC_ASSERT(GC_compute_large_free_bytes() == GC_large_free_bytes); \ diff --git a/misc.c b/misc.c index 8b871966..cbe77edb 100644 --- a/misc.c +++ b/misc.c @@ -1675,7 +1675,7 @@ GC_API void GC_CALLBACK GC_ignore_warn_proc(char *msg, GC_word arg) GC_API void GC_CALL GC_set_warn_proc(GC_warn_proc p) { DCL_LOCK_STATE; - GC_ASSERT(p != 0); + GC_ASSERT(NONNULL_ARG_NOT_NULL(p)); # ifdef GC_WIN32_THREADS # ifdef CYGWIN32 /* Need explicit GC_INIT call */ @@ -1748,7 +1748,7 @@ GC_API GC_warn_proc GC_CALL GC_get_warn_proc(void) GC_API void GC_CALL GC_set_abort_func(GC_abort_func fn) { DCL_LOCK_STATE; - GC_ASSERT(fn != 0); + GC_ASSERT(NONNULL_ARG_NOT_NULL(fn)); LOCK(); GC_on_abort = fn; UNLOCK(); @@ -2077,7 +2077,7 @@ GC_API GC_word GC_CALL GC_get_gc_no(void) GC_API void GC_CALL GC_set_oom_fn(GC_oom_func fn) { - GC_ASSERT(fn != 0); + GC_ASSERT(NONNULL_ARG_NOT_NULL(fn)); DCL_LOCK_STATE; LOCK(); GC_oom_fn = fn;