From 3ca60bd5dcb0e1c04fdc6459417824c05b292627 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Mon, 24 Oct 2016 11:06:33 +0300 Subject: [PATCH] Workaround 'value of macro unknown' cppcheck info messages The messages are eliminated for the macros: __int64, _SIGRTMIN, ARM_THREAD_STATE32, ARM_UNIFIED_THREAD_STATE, FIXUP_POINTER, GC_COLLECT_AT_MALLOC, GC_FREE_SPACE_DIVISOR, GC_FULL_FREQ, GC_INITIAL_HEAP_SIZE, GC_MAX_RETRIES, GC_MAXIMUM_HEAP_SIZE, GC_MIN_MARKERS, GC_SIG_SUSPEND, GC_SIG_THR_RESTART, GC_TIME_LIMIT, HEURISTIC2_LIMIT, MAP_ANONYMOUS, RTLD_DI_LINKMAP, SAVE_CALL_COUNT, SIZE_MAX. * alloc.c (GC_full_freq, GC_free_space_divisor, GC_time_limit): Define to default immediate value if CPPCHECK. * darwin_stop_world.c [ARM32 && ARM_THREAD_STATE32] (GC_ARM_UNIFIED_THREAD_STATE): New macro (defined to ARM_UNIFIED_THREAD_STATE unless CPPCHECK). * darwin_stop_world.c [ARM32 && ARM_THREAD_STATE32] (GC_stack_range_for): Use GC_ARM_UNIFIED_THREAD_STATE; do not use value of ARM_THREAD_STATE32 if CPPCHECK. * dyn_load.c [!USE_PROC_FOR_LIBRARIES] (GC_RTLD_DI_LINKMAP): New macro (defined to RTLD_DI_LINKMAP unless CPPCHECK). * dyn_load.c [!USE_PROC_FOR_LIBRARIES] (GC_FirstDLOpenedLinkMap): Use GC_RTLD_DI_LINKMAP. * include/gc.h (GC_word, GC_signed_word): Do not define to __int64 if CPPCHECK. * include/gc.h (GC_INIT_CONF_MAX_RETRIES, GC_INIT_CONF_FREE_SPACE_DIVISOR, GC_INIT_CONF_FULL_FREQ, GC_INIT_CONF_TIME_LIMIT, GC_INIT_CONF_SUSPEND_SIGNAL, GC_INIT_CONF_THR_RESTART_SIGNAL, GC_MAXIMUM_HEAP_SIZE, GC_INITIAL_HEAP_SIZE): Define to empty if CPPCHECK. * include/private/gc_priv.h [SIZE_MAX] (GC_SIZE_MAX): Do not define to SIZE_MAX if CPPCHECK. * include/private/gc_priv.h [DARWIN && ARM32 && ARM_UNIFIED_THREAD_STATE] (GC_MACH_THREAD_STATE): Do not define to ARM_UNIFIED_THREAD_STATE if CPPCHECK. * include/private/gc_priv.h [GC_PTHREADS && _SIGRTMIN] (SIG_SUSPEND): Do not define to _SIGRTMIN if CPPCHECK. * pthread_stop_world.c [!SIG_THR_RESTART && _SIGRTMIN] (SIG_THR_RESTART): Likewise. * include/private/gcconfig.h [SAVE_CALL_CHAIN && SAVE_CALL_COUNT] (NFRAMES): Define to immediate value (do not use value of SAVE_CALL_COUNT) if CPPCHECK. * include/private/gcconfig.h [!FIXUP_POINTER && POINTER_MASK] (FIXUP_POINTER): Define to a sample expression (not using values of POINTER_MASK and POINTER_SHIFT) if CPPCHECK. * malloc.c [GC_COLLECT_AT_MALLOC] (GC_dbg_collect_at_malloc_min_lb): Define to sample value (not using value of GC_COLLECT_AT_MALLOC) if CPPCHECK. * misc.c [GC_INITIAL_HEAP_SIZE] (GC_init): Define to default immediate value if CPPCHECK. * os_dep.c [!BEOS && !OS2 && !SWIN32 && !GC_OPENBSD_THREADS && !STACKBOTTOM && HEURISTIC2_LIMIT] (GC_get_main_stack_base): Do not use value of HEURISTIC2_LIMIT if CPPCHECK. * os_dep.c [USE_MMAP_ANON && MAP_ANONYMOUS] (OPT_MAP_ANON): Do not use value of MAP_ANONYMOUS if CPPCHECK. * pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD && !GC_TIME_LIMIT] (GC_TIME_LIMIT): Do not define. * pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD] (GC_brief_async_signal_safe_sleep): Do not use value of GC_TIME_LIMIT if CPPCHECK. * pthread_support.c [PARALLEL_MARK && GC_MIN_MARKERS] (GC_thr_init): Do not use value of GC_MIN_MARKERS if CPPCHECK. * win32_threads.c [PARALLEL_MARK && GC_MIN_MARKERS] (GC_thr_init): Likewise. * tests/test.c [GC_DEBUG && SAVE_CALL_CHAIN && SAVE_CALL_COUNT] (check_heap_stats): Use NFRAMES instead of SAVE_CALL_COUNT (i.e. do not use value of SAVE_CALL_COUNT). --- alloc.c | 25 +++++++++++++------------ darwin_stop_world.c | 16 +++++++++++----- dyn_load.c | 7 ++++++- include/gc.h | 18 +++++++++--------- include/private/gc_priv.h | 7 ++++--- include/private/gcconfig.h | 8 ++++++-- malloc.c | 6 +++++- misc.c | 2 +- os_dep.c | 6 +++--- pthread_stop_world.c | 12 ++++++------ pthread_support.c | 2 +- tests/test.c | 2 +- win32_threads.c | 2 +- 13 files changed, 67 insertions(+), 46 deletions(-) diff --git a/alloc.c b/alloc.c index 4712279..0db6458 100644 --- a/alloc.c +++ b/alloc.c @@ -71,14 +71,14 @@ word GC_gc_no = 0; int GC_parallel = FALSE; /* By default, parallel GC is off. */ #endif -#ifndef GC_FULL_FREQ -# define GC_FULL_FREQ 19 /* Every 20th collection is a full */ +#if defined(GC_FULL_FREQ) && !defined(CPPCHECK) + int GC_full_freq = GC_FULL_FREQ; +#else + int GC_full_freq = 19; /* Every 20th collection is a full */ /* collection, whether we need it */ /* or not. */ #endif -int GC_full_freq = GC_FULL_FREQ; - STATIC GC_bool GC_need_full_gc = FALSE; /* Need full GC do to heap growth. */ @@ -119,24 +119,25 @@ GC_API unsigned GC_CALL GC_get_version(void) int GC_dont_expand = FALSE; #endif -#ifndef GC_FREE_SPACE_DIVISOR -# define GC_FREE_SPACE_DIVISOR 3 /* must be > 0 */ +#if defined(GC_FREE_SPACE_DIVISOR) && !defined(CPPCHECK) + word GC_free_space_divisor = GC_FREE_SPACE_DIVISOR; /* must be > 0 */ +#else + word GC_free_space_divisor = 3; #endif -word GC_free_space_divisor = GC_FREE_SPACE_DIVISOR; - GC_INNER int GC_CALLBACK GC_never_stop_func(void) { return(0); } -#ifndef GC_TIME_LIMIT -# define GC_TIME_LIMIT 50 /* We try to keep pause times from exceeding */ +#if defined(GC_TIME_LIMIT) && !defined(CPPCHECK) + unsigned long GC_time_limit = GC_TIME_LIMIT; + /* We try to keep pause times from exceeding */ /* this by much. In milliseconds. */ +#else + unsigned long GC_time_limit = 50; #endif -unsigned long GC_time_limit = GC_TIME_LIMIT; - #ifndef NO_CLOCK STATIC CLOCK_TYPE GC_start_time = 0; /* Time at which we stopped world. */ diff --git a/darwin_stop_world.c b/darwin_stop_world.c index cfe2465..d829f6a 100644 --- a/darwin_stop_world.c +++ b/darwin_stop_world.c @@ -168,13 +168,19 @@ STATIC ptr_t GC_stack_range_for(ptr_t *phi, thread_act_t thread, GC_thread p, arm_unified_thread_state_t unified_state; mach_msg_type_number_t unified_thread_state_count = ARM_UNIFIED_THREAD_STATE_COUNT; - - kern_result = thread_get_state(thread, ARM_UNIFIED_THREAD_STATE, +# if defined(CPPCHECK) +# define GC_ARM_UNIFIED_THREAD_STATE 1 +# else +# define GC_ARM_UNIFIED_THREAD_STATE ARM_UNIFIED_THREAD_STATE +# endif + kern_result = thread_get_state(thread, GC_ARM_UNIFIED_THREAD_STATE, (natural_t *)&unified_state, &unified_thread_state_count); - if (unified_state.ash.flavor != ARM_THREAD_STATE32) { - ABORT("unified_state flavor should be ARM_THREAD_STATE32"); - } +# if !defined(CPPCHECK) + if (unified_state.ash.flavor != ARM_THREAD_STATE32) { + ABORT("unified_state flavor should be ARM_THREAD_STATE32"); + } +# endif state = unified_state.ts_32; } else # endif diff --git a/dyn_load.c b/dyn_load.c index 679211d..836e4bc 100644 --- a/dyn_load.c +++ b/dyn_load.c @@ -691,8 +691,13 @@ GC_FirstDLOpenedLinkMap(void) } if( cachedResult == 0 ) { # if defined(NETBSD) && defined(RTLD_DI_LINKMAP) +# if defined(CPPCHECK) +# define GC_RTLD_DI_LINKMAP 2 +# else +# define GC_RTLD_DI_LINKMAP RTLD_DI_LINKMAP +# endif struct link_map *lm = NULL; - if (!dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, &lm) && lm != NULL) { + if (!dlinfo(RTLD_SELF, GC_RTLD_DI_LINKMAP, &lm) && lm != NULL) { /* Now lm points link_map object of libgc. Since it */ /* might not be the first dynamically linked object, */ /* try to find it (object next to the main object). */ diff --git a/include/gc.h b/include/gc.h index db8de0a..2041f62 100644 --- a/include/gc.h +++ b/include/gc.h @@ -59,7 +59,7 @@ typedef void * GC_PTR; /* preserved only for backward compatibility */ /* better choices. But those had incorrect definitions on some older */ /* systems. Notably "typedef int size_t" is WRONG. */ #ifdef _WIN64 -# ifdef __int64 +# if defined(__int64) && !defined(CPPCHECK) typedef unsigned __int64 GC_word; typedef __int64 GC_signed_word; # else @@ -1824,14 +1824,14 @@ GC_API int GC_CALL GC_get_force_unmap_on_gcollect(void); /* This is for debugging only (useful if environment variables are */ /* unsupported); cannot call GC_disable as goes before GC_init. */ # define GC_INIT_CONF_MAX_RETRIES (void)(GC_dont_gc = 1) -#elif defined(GC_MAX_RETRIES) +#elif defined(GC_MAX_RETRIES) && !defined(CPPCHECK) /* Set GC_max_retries to the desired value at start-up */ # define GC_INIT_CONF_MAX_RETRIES GC_set_max_retries(GC_MAX_RETRIES) #else # define GC_INIT_CONF_MAX_RETRIES /* empty */ #endif -#ifdef GC_FREE_SPACE_DIVISOR +#if defined(GC_FREE_SPACE_DIVISOR) && !defined(CPPCHECK) /* Set GC_free_space_divisor to the desired value at start-up */ # define GC_INIT_CONF_FREE_SPACE_DIVISOR \ GC_set_free_space_divisor(GC_FREE_SPACE_DIVISOR) @@ -1839,34 +1839,34 @@ GC_API int GC_CALL GC_get_force_unmap_on_gcollect(void); # define GC_INIT_CONF_FREE_SPACE_DIVISOR /* empty */ #endif -#ifdef GC_FULL_FREQ +#if defined(GC_FULL_FREQ) && !defined(CPPCHECK) /* Set GC_full_freq to the desired value at start-up */ # define GC_INIT_CONF_FULL_FREQ GC_set_full_freq(GC_FULL_FREQ) #else # define GC_INIT_CONF_FULL_FREQ /* empty */ #endif -#ifdef GC_TIME_LIMIT +#if defined(GC_TIME_LIMIT) && !defined(CPPCHECK) /* Set GC_time_limit to the desired value at start-up */ # define GC_INIT_CONF_TIME_LIMIT GC_set_time_limit(GC_TIME_LIMIT) #else # define GC_INIT_CONF_TIME_LIMIT /* empty */ #endif -#if defined(GC_SIG_SUSPEND) && defined(GC_THREADS) +#if defined(GC_SIG_SUSPEND) && defined(GC_THREADS) && !defined(CPPCHECK) # define GC_INIT_CONF_SUSPEND_SIGNAL GC_set_suspend_signal(GC_SIG_SUSPEND) #else # define GC_INIT_CONF_SUSPEND_SIGNAL /* empty */ #endif -#if defined(GC_SIG_THR_RESTART) && defined(GC_THREADS) +#if defined(GC_SIG_THR_RESTART) && defined(GC_THREADS) && !defined(CPPCHECK) # define GC_INIT_CONF_THR_RESTART_SIGNAL \ GC_set_thr_restart_signal(GC_SIG_THR_RESTART) #else # define GC_INIT_CONF_THR_RESTART_SIGNAL /* empty */ #endif -#ifdef GC_MAXIMUM_HEAP_SIZE +#if defined(GC_MAXIMUM_HEAP_SIZE) && !defined(CPPCHECK) /* Limit the heap size to the desired value (useful for debugging). */ /* The limit could be overridden either at the program start-up by */ /* the similar environment variable or anytime later by the */ @@ -1884,7 +1884,7 @@ GC_API int GC_CALL GC_get_force_unmap_on_gcollect(void); # define GC_INIT_CONF_IGNORE_WARN /* empty */ #endif -#ifdef GC_INITIAL_HEAP_SIZE +#if defined(GC_INITIAL_HEAP_SIZE) && !defined(CPPCHECK) /* Set heap size to the desired value at start-up */ # define GC_INIT_CONF_INITIAL_HEAP_SIZE \ { size_t heap_size = GC_get_heap_size(); \ diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 4468984..8370fc7 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -93,7 +93,7 @@ typedef char * ptr_t; /* A generic pointer to which we can add */ #ifndef SIZE_MAX # include #endif -#ifdef SIZE_MAX +#if defined(SIZE_MAX) && !defined(CPPCHECK) # define GC_SIZE_MAX SIZE_MAX #else # define GC_SIZE_MAX (~(size_t)0) @@ -614,7 +614,8 @@ GC_EXTERN GC_warn_proc GC_current_warn_proc; # define GC_MACH_THREAD_STATE x86_THREAD_STATE64 # define GC_MACH_THREAD_STATE_COUNT x86_THREAD_STATE64_COUNT # endif -# elif defined(ARM32) && defined(ARM_UNIFIED_THREAD_STATE) +# elif defined(ARM32) && defined(ARM_UNIFIED_THREAD_STATE) \ + && !defined(CPPCHECK) # define GC_THREAD_STATE_T arm_unified_thread_state_t # define GC_MACH_THREAD_STATE ARM_UNIFIED_THREAD_STATE # define GC_MACH_THREAD_STATE_COUNT ARM_UNIFIED_THREAD_STATE_COUNT @@ -2463,7 +2464,7 @@ GC_INNER ptr_t GC_store_debug_info(ptr_t p, word sz, const char *str, # ifndef GC_OPENBSD_UTHREADS # define SIG_SUSPEND SIGXFSZ # endif -# elif defined(_SIGRTMIN) +# elif defined(_SIGRTMIN) && !defined(CPPCHECK) # define SIG_SUSPEND _SIGRTMIN + 6 # else # define SIG_SUSPEND SIGRTMIN + 6 diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h index 714e5d1..d45abda 100644 --- a/include/private/gcconfig.h +++ b/include/private/gcconfig.h @@ -3105,7 +3105,7 @@ # endif #endif #ifdef SAVE_CALL_CHAIN -# ifndef SAVE_CALL_COUNT +# if !defined(SAVE_CALL_COUNT) || defined(CPPCHECK) # define NFRAMES 6 /* Number of frames to save. Even for */ /* alignment reasons. */ # else @@ -3139,7 +3139,11 @@ #endif #if !defined(FIXUP_POINTER) && defined(POINTER_MASK) -# define FIXUP_POINTER(p) (p = ((p) & POINTER_MASK) << POINTER_SHIFT) +# if defined(CPPCHECK) +# define FIXUP_POINTER(p) (p = (p) << 4) /* e.g. */ +# else +# define FIXUP_POINTER(p) (p = ((p) & POINTER_MASK) << POINTER_SHIFT) +# endif #endif #if defined(FIXUP_POINTER) diff --git a/malloc.c b/malloc.c index d44c9a1..c4a5430 100644 --- a/malloc.c +++ b/malloc.c @@ -181,7 +181,11 @@ GC_INNER void * GC_generic_malloc_inner(size_t lb, int k) #ifdef GC_COLLECT_AT_MALLOC /* Parameter to force GC at every malloc of size greater or equal to */ /* the given value. This might be handy during debugging. */ - size_t GC_dbg_collect_at_malloc_min_lb = (GC_COLLECT_AT_MALLOC); +# if defined(CPPCHECK) + size_t GC_dbg_collect_at_malloc_min_lb = 16*1024; /* e.g. */ +# else + size_t GC_dbg_collect_at_malloc_min_lb = (GC_COLLECT_AT_MALLOC); +# endif #endif GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_malloc(size_t lb, int k) diff --git a/misc.c b/misc.c index 1cff9b6..5761ab5 100644 --- a/misc.c +++ b/misc.c @@ -873,7 +873,7 @@ GC_API void GC_CALL GC_init(void) } # endif -# ifdef GC_INITIAL_HEAP_SIZE +# if defined(GC_INITIAL_HEAP_SIZE) && !defined(CPPCHECK) initial_heap_sz = GC_INITIAL_HEAP_SIZE; # else initial_heap_sz = MINHINCR * HBLKSIZE; diff --git a/os_dep.c b/os_dep.c index b3e7fb5..1423f72 100644 --- a/os_dep.c +++ b/os_dep.c @@ -1212,7 +1212,7 @@ GC_INNER size_t GC_page_size = 0; ptr_t sp = GC_approx_sp(); # ifdef STACK_GROWS_DOWN result = GC_find_limit(sp, TRUE); -# ifdef HEURISTIC2_LIMIT +# if defined(HEURISTIC2_LIMIT) && !defined(CPPCHECK) if ((word)result > (word)HEURISTIC2_LIMIT && (word)sp < (word)HEURISTIC2_LIMIT) { result = HEURISTIC2_LIMIT; @@ -1220,7 +1220,7 @@ GC_INNER size_t GC_page_size = 0; # endif # else result = GC_find_limit(sp, FALSE); -# ifdef HEURISTIC2_LIMIT +# if defined(HEURISTIC2_LIMIT) && !defined(CPPCHECK) if ((word)result < (word)HEURISTIC2_LIMIT && (word)sp > (word)HEURISTIC2_LIMIT) { result = HEURISTIC2_LIMIT; @@ -2030,7 +2030,7 @@ void GC_register_data_segments(void) #ifdef USE_MMAP_ANON # define zero_fd -1 -# if defined(MAP_ANONYMOUS) +# if defined(MAP_ANONYMOUS) && !defined(CPPCHECK) # define OPT_MAP_ANON MAP_ANONYMOUS # else # define OPT_MAP_ANON MAP_ANON diff --git a/pthread_stop_world.c b/pthread_stop_world.c index 407db8f..6ee4282 100644 --- a/pthread_stop_world.c +++ b/pthread_stop_world.c @@ -136,7 +136,7 @@ STATIC volatile AO_t GC_world_is_stopped = FALSE; #ifndef SIG_THR_RESTART # if defined(GC_HPUX_THREADS) || defined(GC_OSF1_THREADS) \ || defined(GC_NETBSD_THREADS) || defined(GC_USESIGRT_SIGNALS) -# ifdef _SIGRTMIN +# if defined(_SIGRTMIN) && !defined(CPPCHECK) # define SIG_THR_RESTART _SIGRTMIN + 5 # else # define SIG_THR_RESTART SIGRTMIN + 5 @@ -388,15 +388,15 @@ STATIC void GC_restart_handler(int sig) # endif /* !USE_TKILL_ON_ANDROID */ # ifdef GC_ENABLE_SUSPEND_THREAD -# ifndef GC_TIME_LIMIT -# define GC_TIME_LIMIT 50 -# endif - STATIC void GC_brief_async_signal_safe_sleep(void) { struct timeval tv; tv.tv_sec = 0; - tv.tv_usec = 1000 * GC_TIME_LIMIT / 2; +# if defined(GC_TIME_LIMIT) && !defined(CPPCHECK) + tv.tv_usec = 1000 * GC_TIME_LIMIT / 2; +# else + tv.tv_usec = 1000 * 50 / 2; +# endif select(0, 0, 0, 0, &tv); } diff --git a/pthread_support.c b/pthread_support.c index 1db9af6..1b6a302 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -1189,7 +1189,7 @@ GC_INNER void GC_thr_init(void) } } else { markers = GC_nprocs; -# ifdef GC_MIN_MARKERS +# if defined(GC_MIN_MARKERS) && !defined(CPPCHECK) /* This is primarily for targets without getenv(). */ if (markers < GC_MIN_MARKERS) markers = GC_MIN_MARKERS; diff --git a/tests/test.c b/tests/test.c index 6c9bef4..4e00ea3 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1519,7 +1519,7 @@ void check_heap_stats(void) # ifdef SAVE_CALL_CHAIN max_heap_sz *= 3; # ifdef SAVE_CALL_COUNT - max_heap_sz += max_heap_sz * SAVE_CALL_COUNT/4; + max_heap_sz += max_heap_sz * NFRAMES / 4; # endif # endif # endif diff --git a/win32_threads.c b/win32_threads.c index 1e0d55e..14ac9d6 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -2453,7 +2453,7 @@ GC_INNER void GC_thr_init(void) } markers = ncpu; # endif -# ifdef GC_MIN_MARKERS +# if defined(GC_MIN_MARKERS) && !defined(CPPCHECK) /* This is primarily for testing on systems without getenv(). */ if (markers < GC_MIN_MARKERS) markers = GC_MIN_MARKERS; -- 2.7.4