Skip to content

Commit

Permalink
Eliminate 'compound assignment with volatile left operand' g++ warning
Browse files Browse the repository at this point in the history
* include/private/gc_priv.h [MPROTECT_VDB]
(set_pht_entry_from_index_concurrent_volatile): New macro.
* os_dep.c [OPENBSD] (GC_skip_hole_openbsd): Replace result+=v to
result=result+v; update comment.
* os_dep.c [NEED_FIND_LIMIT || USE_PROC_FOR_LIBRARIES && THREADS]
(GC_find_limit_with_bound): Likewise.
* os_dep.c [NEED_FIND_LIMIT || USE_PROC_FOR_LIBRARIES && THREADS]
(GC_find_limit_with_bound): Replace result-=v to result=result-v.
* os_dep.c [(!THREADS || HAVE_LOCKFREE_AO_OR) && MPROTECT_VDB]
(async_set_pht_entry_from_index): Redirect to
set_pht_entry_from_index_concurrent_volatile().
* tests/gctest.c (uncollectable_count, collectable_count, atomic_count,
realloc_count, extra_count): Remove volatile qualifier.
* tests/gctest.c [!DBG_HDRS_ALL] (fail_count): Likewise.
* tests/weakmap.c (stat_added, stat_found, stat_removed,
stat_skip_locked, stat_skip_marked): Likewise.
* tests/gctest.c (run_one_test): Remove unneeded no-volatile cast for
atomic_count.
* tests/gctest.c [GC_PTHREADS] (main): Likewise.
  • Loading branch information
ivmai committed Jan 1, 2024
1 parent 0fee898 commit 54c7a2d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 24 deletions.
12 changes: 11 additions & 1 deletion include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1061,12 +1061,22 @@ typedef word page_hash_table[PHT_SIZE];
# define set_pht_entry_from_index_concurrent(bl, index) \
AO_or((volatile AO_t *)&(bl)[divWORDSZ(index)], \
(AO_t)((word)1 << modWORDSZ(index)))
# ifdef MPROTECT_VDB
# define set_pht_entry_from_index_concurrent_volatile(bl, index) \
set_pht_entry_from_index_concurrent(bl, index)
# endif
#else
# define set_pht_entry_from_index_concurrent(bl, index) \
set_pht_entry_from_index(bl, index)
# ifdef MPROTECT_VDB
/* Same as set_pht_entry_from_index() but avoiding the compound */
/* assignment for a volatile array. */
# define set_pht_entry_from_index_concurrent_volatile(bl, index) \
(void)((bl)[divWORDSZ(index)] \
= (bl)[divWORDSZ(index)] | ((word)1 << modWORDSZ(index)))
# endif
#endif


/********************************************/
/* */
/* H e a p B l o c k s */
Expand Down
26 changes: 17 additions & 9 deletions os_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,9 @@ GC_INNER const char * GC_get_maps(void)
if ((word)result >= (word)bound - pgsz) {
result = bound;
} else {
result += pgsz; /* no overflow expected */
result = result + pgsz;
/* no overflow expected; do not use compound */
/* assignment with volatile-qualified left operand */
GC_noop1((word)(*result));
}
}
Expand Down Expand Up @@ -1000,7 +1002,9 @@ GC_INNER void GC_setpagesize(void)
result = bound;
break;
}
result += MIN_PAGE_SIZE; /* no overflow expected */
result = result + MIN_PAGE_SIZE;
/* no overflow expected; do not use compound */
/* assignment with volatile-qualified left operand */
} else {
if ((word)result <= (word)bound + MIN_PAGE_SIZE) {
result = bound - MIN_PAGE_SIZE;
Expand All @@ -1011,16 +1015,15 @@ GC_INNER void GC_setpagesize(void)
/* by setjmp otherwise). */
break;
}
result -= MIN_PAGE_SIZE; /* no underflow expected */
result = result - MIN_PAGE_SIZE;
/* no underflow expected; do not use compound */
/* assignment with volatile-qualified left operand */
}
GC_noop1((word)(*result));
}
}
GC_reset_fault_handler();
if (!up) {
result += MIN_PAGE_SIZE;
}
return result;
return up ? result : result + MIN_PAGE_SIZE;
}

void * GC_find_limit(void * p, int up)
Expand Down Expand Up @@ -3056,8 +3059,13 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void)

#if !defined(NO_MANUAL_VDB) || defined(MPROTECT_VDB)
# if !defined(THREADS) || defined(HAVE_LOCKFREE_AO_OR)
# define async_set_pht_entry_from_index(db, index) \
set_pht_entry_from_index_concurrent(db, index)
# ifdef MPROTECT_VDB
# define async_set_pht_entry_from_index(db, index) \
set_pht_entry_from_index_concurrent_volatile(db, index)
# else
# define async_set_pht_entry_from_index(db, index) \
set_pht_entry_from_index_concurrent(db, index)
# endif
# elif defined(AO_HAVE_test_and_set_acquire)
/* We need to lock around the bitmap update (in the write fault */
/* handler or GC_dirty) in order to avoid the risk of losing a bit. */
Expand Down
17 changes: 8 additions & 9 deletions tests/gctest.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,12 @@ static void *checkOOM(void *p)
#endif

/* Allocation Statistics. Synchronization is not strictly necessary. */
static volatile AO_t uncollectable_count = 0;
static volatile AO_t collectable_count = 0;
static volatile AO_t atomic_count = 0;
static volatile AO_t realloc_count = 0;
static AO_t uncollectable_count = 0;
static AO_t collectable_count = 0;
static AO_t atomic_count = 0;
static AO_t realloc_count = 0;

static volatile AO_t extra_count = 0;
/* Amount of space wasted in cons node; */
static AO_t extra_count = 0; /* Amount of space wasted in cons node; */
/* also used in gcj_cons, mktree and */
/* chktree (for other purposes). */

Expand Down Expand Up @@ -1454,7 +1453,7 @@ static void typed_test(void)
#ifdef DBG_HDRS_ALL
# define set_print_procs() (void)(A.dummy = 17)
#else
static volatile AO_t fail_count = 0;
static AO_t fail_count = 0;

static void GC_CALLBACK fail_proc1(void *arg)
{
Expand Down Expand Up @@ -1908,7 +1907,7 @@ static void run_one_test(void)
/* Run reverse_test a second time, so we hopefully notice corruption. */
reverse_test();
# ifndef NO_DEBUGGING
(void)GC_is_tmp_root((/* no volatile */ void *)(GC_word)&atomic_count);
(void)GC_is_tmp_root(&atomic_count);
# endif
# ifndef NO_CLOCK
if (print_stats) {
Expand Down Expand Up @@ -2700,7 +2699,7 @@ int main(void)
set_print_procs();

/* Minimal testing of some API functions. */
GC_exclude_static_roots((/* no volatile */ void *)(GC_word)&atomic_count,
GC_exclude_static_roots(&atomic_count,
(void *)((GC_word)&atomic_count + sizeof(atomic_count)));
GC_register_has_static_roots_callback(has_static_roots);
GC_register_describe_type_fn(GC_I_NORMAL, describe_norm_type);
Expand Down
10 changes: 5 additions & 5 deletions tests/weakmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ static unsigned memhash(void *src, size_t len)
return acc;
}

static volatile AO_t stat_added;
static volatile AO_t stat_found;
static volatile AO_t stat_removed;
static volatile AO_t stat_skip_locked;
static volatile AO_t stat_skip_marked;
static AO_t stat_added;
static AO_t stat_found;
static AO_t stat_removed;
static AO_t stat_skip_locked;
static AO_t stat_skip_marked;

struct weakmap_link {
GC_hidden_pointer obj;
Expand Down

0 comments on commit 54c7a2d

Please sign in to comment.