Skip to content

Commit

Permalink
Define NOOP1_PTR() internal macro
Browse files Browse the repository at this point in the history
(refactoring)

Issue #627 (bdwgc).

* allchblk.c [VALGRIND_TRACKING] (GC_free_profiler_hook): Replace
GC_noop1((word)p) to NOOP1_PTR(p).
* alloc.c [!GC_DISABLE_INCREMENTAL && !NO_CLOCK && CPPCHECK]
(GC_timeout_stop_func): Likewise.
* alloc.c [GWW_VDB] (GC_add_to_heap): Likewise.
* alloc.c [CPPCHECK] (GC_allocobj): Likewise.
* backgraph.c [CPPCHECK] (push_in_progress, ensure_struct, add_edge,
backwards_height, update_max_height): Likewise.
* darwin_stop_world.c [!POWERPC && !ARM32 && !AARCH64 && CPPCHECK]
(GC_FindTopOfStack): Likewise.
* dyn_load.c [LINUX && !USE_PROC_FOR_LIBRARIES && CPPCHECK
&& HOST_ANDROID && !GC_DONT_DEFINE_LINK_MAP && !(__ANDROID_API__>=21)]
(GC_register_dynamic_libraries): Likewise.
* dyn_load.c [DARWIN && LINT2] (GC_init_dyld): Likewise.
* include/private/gc_priv.h [E2K && CPPCHECK] (PS_ALLOCA_BUF):
Likewise.
* mach_dep.c [!HAVE_PUSH_REGS && !EMSCRIPTEN && UNIX_LIKE
&& !NO_GETCONTEXT && GETCONTEXT_FPU_EXCMASK_BUG && X86_64 && CPPCHECK]
(GC_with_callee_saves_pushed): Likewise.
* mark.c [CPPCHECK] (GC_signal_mark_stack_overflow,
GC_steal_mark_stack): Likewise.
* misc.c [CPPCHECK] (GC_default_warn_proc, GC_call_with_gc_active):
Likewise.
* misc.c [!THREAD && CPPCHECK] (GC_do_blocking_inner): Likewise.
* os_dep.c [NEED_PROC_MAPS && LINT2] (GC_get_maps): Likewise.
* os_dep.c [(NEED_FIND_LIMIT || UNIX_LIKE || WRAP_MARK_SOME)
&& CPPCHECK && ADDRESS_SANITIZER] (GC_set_and_save_fault_handler):
Likewise.
* os_dep.c [CPPCHECK] (GC_get_register_stack_base,
GC_linux_main_stack_base): Likewise.
* os_dep.c [!ANY_MSWIN && (SVR4 || AIX || DGUX) && !PCR
&& !AO_HAVE_fetch_and_add && CPPCHECK] (GC_SysVGetDataStart): Likewise.
* os_dep.c [USE_MUNMAP && (CPPCHECK || LINT2)] (block_unmap_inner,
GC_remap): Likewise.
* os_dep.c [MPROTECT_VDB && !DARWIN && CPPCHECK && ADDRESS_SANITIZER]
(GC_dirty_init): Likewise.
* pthread_support.c [CPPCHECK] (GC_call_with_gc_active): Likewise.
* specific.c [LINT2] (GC_remove_specific_after_fork): Likewise.
* tests/gctest.c [CPPCHECK] (reverse_test_inner, test_long_mult,
warn_proc): Likewise.
* tests/gctest.c [!NO_TYPED_TEST] (typed_test): Likewise.
* tests/gctest.c (run_one_test): Likewise.
* win32_threads.c [CPPCHECK] (copy_ptr_regs, GC_win32_start_inner):
Likewise.
* include/private/gc_priv.h (NOOP1_PTR): New macro.
  • Loading branch information
ivmai committed Apr 23, 2024
1 parent c59fce2 commit 0ca8be5
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 43 deletions.
2 changes: 1 addition & 1 deletion allchblk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ STATIC struct hblk *GC_allochblk_nth(size_t lb_adjusted, int k,
GC_ASSERT(I_HOLD_LOCK());
# endif
/* Prevent treating this function by the compiler as a no-op one. */
GC_noop1((word)p);
NOOP1_PTR(p);
}
#endif /* VALGRIND_TRACKING */

Expand Down
8 changes: 4 additions & 4 deletions alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ GC_API GC_stop_func GC_CALL GC_get_stop_func(void)
time_diff = MS_TIME_DIFF(current_time, GC_start_time);
nsec_diff = NS_FRAC_TIME_DIFF(current_time, GC_start_time);
# if defined(CPPCHECK)
GC_noop1((word)(&nsec_diff));
NOOP1_PTR(&nsec_diff);
# endif
if (time_diff >= GC_time_limit
&& (time_diff > GC_time_limit || nsec_diff >= GC_time_lim_nsec)) {
Expand Down Expand Up @@ -1514,7 +1514,7 @@ STATIC void GC_add_to_heap(struct hblk *h, size_t bytes)
old_capacity * sizeof(struct HeapSect));
# else
/* TODO: implement GWW-aware recycling as in alloc_mark_stack */
GC_noop1((word)old_heap_sects);
NOOP1_PTR(old_heap_sects);
# endif
}
}
Expand Down Expand Up @@ -1833,12 +1833,12 @@ GC_INNER ptr_t GC_allocobj(size_t lg, int k)
GC_continue_reclaim(lg, k);
EXIT_GC();
# if defined(CPPCHECK)
GC_noop1((word)(&flh));
NOOP1_PTR(&flh);
# endif
if (NULL == *flh) {
GC_new_hblk(lg, k);
# if defined(CPPCHECK)
GC_noop1((word)(&flh));
NOOP1_PTR(&flh);
# endif
if (NULL == *flh) {
ENTER_GC();
Expand Down
10 changes: 5 additions & 5 deletions backgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static void push_in_progress(ptr_t p)
n_in_progress * sizeof(ptr_t));
# elif defined(LINT2)
/* TODO: implement GWW-aware recycling as in alloc_mark_stack */
GC_noop1((word)in_progress_space);
NOOP1_PTR(in_progress_space);
# endif
in_progress_space = new_in_progress_space;
}
Expand Down Expand Up @@ -195,7 +195,7 @@ static void ensure_struct(ptr_t p)

be -> flags = 0;
# if defined(CPPCHECK)
GC_noop1((word)(&old_back_ptr));
NOOP1_PTR(&old_back_ptr);
/* Workaround a false positive that old_back_ptr cannot be null. */
# endif
if (NULL == old_back_ptr) {
Expand Down Expand Up @@ -227,7 +227,7 @@ static void add_edge(ptr_t p, ptr_t q)
return;
}
# if defined(CPPCHECK)
GC_noop1((word)(&pred));
NOOP1_PTR(&pred);
# endif
if (NULL == pred) {
static unsigned random_number = 13;
Expand Down Expand Up @@ -392,7 +392,7 @@ static word backwards_height(ptr_t p)

GC_ASSERT(I_HOLD_LOCK());
# if defined(CPPCHECK)
GC_noop1((word)(&pred));
NOOP1_PTR(&pred);
# endif
if (NULL == pred)
return 1;
Expand Down Expand Up @@ -483,7 +483,7 @@ static void update_max_height(ptr_t p, size_t n_bytes, word gc_descr)
/* to p, but it can't have decreased. */
back_ptr = GET_OH_BG_PTR(p);
# if defined(CPPCHECK)
GC_noop1((word)(&back_ptr));
NOOP1_PTR(&back_ptr);
# endif
if (back_ptr != NULL && (ADDR(back_ptr) & FLAG_MANY) != 0) {
be = (back_edges *)((word)back_ptr & ~(word)FLAG_MANY);
Expand Down
2 changes: 1 addition & 1 deletion darwin_stop_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ GC_INNER ptr_t GC_FindTopOfStack(unsigned long stack_start)
frame = (StackFrame *)sp_reg;
# else
# if defined(CPPCHECK)
GC_noop1((word)&frame);
NOOP1_PTR(&frame);
# endif
ABORT("GC_FindTopOfStack(0) is not implemented");
# endif
Expand Down
8 changes: 4 additions & 4 deletions dyn_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,9 @@ GC_INNER void GC_register_dynamic_libraries(void)
}
# if defined(CPPCHECK) && defined(HOST_ANDROID) \
&& !defined(GC_DONT_DEFINE_LINK_MAP) && !(__ANDROID_API__ >= 21)
GC_noop1((word)lm->l_name);
GC_noop1((word)lm->l_ld);
GC_noop1((word)lm->l_prev);
NOOP1_PTR(lm -> l_name);
GC_noop1((word)(lm -> l_ld));
NOOP1_PTR(lm -> l_prev);
# endif
}
}
Expand Down Expand Up @@ -1495,7 +1495,7 @@ GC_INNER void GC_init_dyld(void)
ABORT("dlopen failed (to bind fully image)");
/* Note that the handle is never closed. */
# ifdef LINT2
GC_noop1((word)dl_handle);
NOOP1_PTR(dl_handle);
# endif
}
# else
Expand Down
7 changes: 6 additions & 1 deletion include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ typedef struct hblkhdr hdr;

#define GC_WORD_MAX (~(word)0)

/* A handy macro to prevent certain compiler false positive */
/* warnings and misoptimizations by making the compiler to treat */
/* the specified pointer as the one stored to some global location. */
#define NOOP1_PTR(p) GC_noop1(ADDR(p))

/* Convert given pointer to its address. Result is of word type. */
#define ADDR(p) ((word)(p))

Expand Down Expand Up @@ -2052,7 +2057,7 @@ GC_INNER void GC_with_callee_saves_pushed(GC_with_callee_saves_func fn,
/* Workaround "Uninitialized bs_lo" and "obsolete alloca() called" */
/* false positive warnings. */
# define PS_ALLOCA_BUF(pbuf, sz) \
(void)(GC_noop1((word)(pbuf)), *(pbuf) = __builtin_alloca(sz))
(void)(NOOP1_PTR(pbuf), *(pbuf) = __builtin_alloca(sz))
# else
# define PS_ALLOCA_BUF(pbuf, sz) (void)(*(pbuf) = alloca(sz))
# endif
Expand Down
2 changes: 1 addition & 1 deletion mach_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ GC_INNER void GC_with_callee_saves_pushed(GC_with_callee_saves_func fn,
unsigned short old_fcw;

# if defined(CPPCHECK)
GC_noop1((word)&old_fcw);
NOOP1_PTR(&old_fcw);
# endif
__asm__ __volatile__ ("fstcw %0" : "=m" (*&old_fcw));
# else
Expand Down
4 changes: 2 additions & 2 deletions mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ STATIC mse * GC_signal_mark_stack_overflow(mse *msp)
GC_COND_LOG_PRINTF("Mark stack overflow; current size: %lu entries\n",
(unsigned long)GC_mark_stack_size);
# if defined(CPPCHECK)
GC_noop1((word)msp);
NOOP1_PTR(msp);
# endif
return msp - GC_MARK_STACK_DISCARDS;
}
Expand Down Expand Up @@ -1003,7 +1003,7 @@ STATIC mse * GC_steal_mark_stack(mse * low, mse * high, mse * local,
}
*next = p;
# if defined(CPPCHECK)
GC_noop1((word)local);
NOOP1_PTR(local);
# endif
return top;
}
Expand Down
7 changes: 4 additions & 3 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,7 @@ STATIC void GC_CALLBACK GC_default_warn_proc(char *msg, GC_word arg)
# if defined(CPPCHECK)
/* Workaround "parameter can be declared as pointer to const" */
/* cppcheck warning. */
GC_noop1((word)msg);
NOOP1_PTR(msg);
# endif
GC_warn_printf(msg, arg);
}
Expand Down Expand Up @@ -2352,7 +2352,8 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn, void *client_data)
GC_ASSERT(GC_traced_stack_sect == &stacksect);

# if defined(CPPCHECK)
GC_noop1((word)GC_traced_stack_sect - (word)GC_blocked_sp);
NOOP1_PTR(GC_traced_stack_sect);
NOOP1_PTR(GC_blocked_sp);
# endif
/* Restore original "stack section". */
GC_traced_stack_sect = stacksect.prev;
Expand Down Expand Up @@ -2389,7 +2390,7 @@ STATIC void GC_do_blocking_inner(ptr_t data, void *context)
GC_ASSERT(GC_blocked_sp == (ptr_t)(&d));
# endif
# if defined(CPPCHECK)
GC_noop1((word)GC_blocked_sp);
NOOP1_PTR(GC_blocked_sp);
# endif
GC_blocked_sp = NULL;
}
Expand Down
20 changes: 10 additions & 10 deletions os_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ GC_INNER const char * GC_get_maps(void)
while (maps_size >= maps_buf_sz) {
# ifdef LINT2
/* Workaround passing tainted maps_buf to a tainted sink. */
GC_noop1((word)maps_buf);
NOOP1_PTR(maps_buf);
# else
GC_scratch_recycle_no_gww(maps_buf, maps_buf_sz);
# endif
Expand Down Expand Up @@ -936,7 +936,7 @@ GC_INNER void GC_setpagesize(void)
# endif
# endif /* !USE_SEGV_SIGACT */
# if defined(CPPCHECK) && defined(ADDRESS_SANITIZER)
GC_noop1((word)&__asan_default_options);
NOOP1_PTR(&__asan_default_options);
# endif
}
#endif /* NEED_FIND_LIMIT || UNIX_LIKE || WRAP_MARK_SOME */
Expand Down Expand Up @@ -1114,7 +1114,7 @@ GC_INNER void GC_setpagesize(void)
# if defined(CPPCHECK)
/* Workaround a warning that the address of the global */
/* symbol (which is a weak one) cannot be null. */
GC_noop1((word)(&p_libc_ia64_register_backing_store_base));
NOOP1_PTR(&p_libc_ia64_register_backing_store_base);
# endif
if (p_libc_ia64_register_backing_store_base != NULL
&& __libc_ia64_register_backing_store_base != NULL) {
Expand Down Expand Up @@ -1155,7 +1155,7 @@ GC_INNER void GC_setpagesize(void)
ptr_t *p_libc_stack_end = &__libc_stack_end;

# if defined(CPPCHECK)
GC_noop1((word)(&p_libc_stack_end));
NOOP1_PTR(&p_libc_stack_end);
# endif
if (p_libc_stack_end != NULL && __libc_stack_end != NULL) {
# if defined(IA64)
Expand Down Expand Up @@ -2003,7 +2003,7 @@ void GC_register_data_segments(void)
/* Fallback to non-atomic fetch-and-store. */
char v = *result;
# if defined(CPPCHECK)
GC_noop1((word)(&v));
NOOP1_PTR(&v);
# endif
*result = v;
# endif
Expand Down Expand Up @@ -2043,7 +2043,7 @@ void GC_register_data_segments(void)
GC_reset_fault_handler();
} else {
GC_reset_fault_handler();
/* As above, we go to plan B */
/* As above, we go to plan B. */
result = (ptr_t)GC_find_limit(DATAEND, FALSE);
}
return result;
Expand Down Expand Up @@ -2664,7 +2664,7 @@ static void block_unmap_inner(ptr_t start_addr, size_t len)
ABORT("unmap: mmap() result differs from start_addr");
# if defined(CPPCHECK) || defined(LINT2)
/* Explicitly store the resource handle to a global variable. */
GC_noop1((word)result);
NOOP1_PTR(result);
# endif
# endif
GC_unmapped_bytes += len;
Expand Down Expand Up @@ -2717,7 +2717,7 @@ GC_INNER void GC_remap(ptr_t start, size_t bytes)
}
}
# ifdef LINT2
GC_noop1((word)result);
NOOP1_PTR(result);
# endif
GC_ASSERT(GC_unmapped_bytes >= alloc_len);
GC_unmapped_bytes -= alloc_len;
Expand All @@ -2744,7 +2744,7 @@ GC_INNER void GC_remap(ptr_t start, size_t bytes)
if (result != start_addr)
ABORT("remap: mmap() result differs from start_addr");
# if defined(CPPCHECK) || defined(LINT2)
GC_noop1((word)result);
NOOP1_PTR(result);
# endif
# undef IGNORE_PAGES_EXECUTABLE
# else
Expand Down Expand Up @@ -3502,7 +3502,7 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void)
# endif
# endif /* !MSWIN32 && !MSWINCE */
# if defined(CPPCHECK) && defined(ADDRESS_SANITIZER)
GC_noop1((word)&__asan_default_options);
NOOP1_PTR(&__asan_default_options);
# endif
return TRUE;
}
Expand Down
2 changes: 1 addition & 1 deletion pthread_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,7 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn, void *client_data)
GC_ASSERT(me -> crtn == crtn);
GC_ASSERT(crtn -> traced_stack_sect == &stacksect);
# ifdef CPPCHECK
GC_noop1((word)(crtn -> traced_stack_sect));
NOOP1_PTR(crtn -> traced_stack_sect);
# endif
crtn -> traced_stack_sect = stacksect.prev;
# ifdef E2K
Expand Down
2 changes: 1 addition & 1 deletion specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ GC_INNER void GC_remove_specific_after_fork(tsd * key, pthread_t t)
/* This can only happen if the concurrent access is from another */
/* thread, and hence has missed the cache, but still... */
# ifdef LINT2
GC_noop1((word)entry);
NOOP1_PTR(entry);
# endif

/* With GC, we're done, since the pointers from the cache will */
Expand Down
14 changes: 7 additions & 7 deletions tests/gctest.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ static void *GC_CALLBACK reverse_test_inner(void *data)
}

# if defined(CPPCHECK)
GC_noop1((GC_word)data);
NOOP1_PTR(data);
# endif
# ifndef BIG
# if defined(MACOS) \
Expand Down Expand Up @@ -1451,7 +1451,7 @@ static void typed_test(void)
newP = (GC_word *)old[1];
}
GC_gcollect();
GC_noop1((GC_word)x);
NOOP1_PTR(x);
}
#endif /* !NO_TYPED_TEST */

Expand Down Expand Up @@ -1667,7 +1667,7 @@ static void run_one_test(void)
GC_printf("Out of memory in GC_posix_memalign\n");
exit(69);
}
GC_noop1((GC_word)p);
NOOP1_PTR(p);
AO_fetch_and_add1(&collectable_count);
}
# ifndef GC_NO_VALLOC
Expand Down Expand Up @@ -1714,7 +1714,7 @@ static void run_one_test(void)
FAIL;
}
# if defined(CPPCHECK)
GC_noop1((GC_word)x);
NOOP1_PTR(x);
# endif
# ifdef GC_REQUIRE_WCSDUP
{
Expand Down Expand Up @@ -1983,8 +1983,8 @@ static void test_long_mult(void)

LONG_MULT(hp, lp, (unsigned32)0x1234567UL, (unsigned32)0xfedcba98UL);
# if defined(CPPCHECK)
GC_noop1((GC_word)(&hp));
GC_noop1((GC_word)(&lp));
NOOP1_PTR(&hp);
NOOP1_PTR(&lp);
# endif
if (hp != (unsigned32)0x121fa00UL || lp != (unsigned32)0x23e20b28UL) {
GC_printf("LONG_MULT gives wrong result\n");
Expand Down Expand Up @@ -2221,7 +2221,7 @@ void SetMinimumStack(long minSize)
static void GC_CALLBACK warn_proc(char *msg, GC_word p)
{
# if defined(CPPCHECK)
GC_noop1((GC_word)msg);
NOOP1_PTR(msg);
# endif
GC_printf(msg, (unsigned long)p);
/*FAIL;*/
Expand Down
4 changes: 2 additions & 2 deletions win32_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ static ptr_t copy_ptr_regs(word *regs, const CONTEXT *pcontext) {
PUSH4(IntT10,IntT11,IntT12,IntAt);
sp = (ptr_t)context.IntSp;
# elif defined(CPPCHECK)
GC_noop1((word)regs);
NOOP1_PTR(regs);
sp = (ptr_t)(word)cnt; /* to workaround "cnt not used" false positive */
# else
# error Architecture is not supported
Expand Down Expand Up @@ -1402,7 +1402,7 @@ STATIC void *GC_CALLBACK GC_win32_start_inner(struct GC_stack_base *sb,
(long)GetCurrentThreadId());
# endif
# if defined(CPPCHECK)
GC_noop1((word)sb);
NOOP1_PTR(sb);
# endif
return ret;
}
Expand Down

0 comments on commit 0ca8be5

Please sign in to comment.