Skip to content

Commit

Permalink
Fix capability-to/from-integer-cast compiler warnings on CHERI
Browse files Browse the repository at this point in the history
Issue #627 (bdwgc).

Cast between numeric and pointer through GC_uintptr_t instead of word.

* cord/tests/de_win.c [CPPCHECK] (WinMain): Cast a pointer to word
through GC_uintptr_t.
* include/gc/gc.h [!__GNUC__ || __CHERI_PURE_CAPABILITY__]
(GC_ADDR_LT): Likewise.
* include/gc/gc_cpp.h (gc_cleanup::cleanup): Likewise.
* include/gc/gc_inline.h (GC_FAST_MALLOC_GRANS): Likewise.
* include/private/gc_priv.h (ADDR): Likewise.
* pthread_support.c [PARALLEL_MARK] (GC_mark_thread): Likewise.
* tests/subthreadcreate.c (entry): Likewise.
* gcj_mlc.c [FUNCPTR_IS_DATAPTR && CPPCHECK] (GC_gcj_fake_mark_proc):
Cast to word through GC_funcptr_uint.
* os_dep.c [MPROTECT_VDB && DARWIN && CPPCHECK] (GC_dirty_init):
Likewise.
* include/gc/gc.h [include/gc/gc.h [] (GC_HIDE_NZ_POINTER): Cast p to
intptr_t instead of GC_signed_word.
* include/private/gc_hdrs.h (FORWARDED_ADDR): Cast to size_t through
GC_uintptr_t.
* include/private/gc_locks.h [GC_PTHREADS && !GC_WIN32_PTHREADS]
(NUMERIC_THREAD_ID): Cast to unsigned long through GC_uintptr_t.
* include/private/gc_priv.h (NUMERIC_TO_VPTR, MAKE_CPTR): Cast to
pointer through GC_uintptr_t.
* include/private/gcconfig.h [I386 && DGUX] (MAP_FAILED): Likewise.
* pthread_stop_world.c (GC_suspend_all, GC_restart_all): Likewise.
* tests/staticroots.c (root_nz): Likewise.
* tests/staticroots_lib.c (root_nz): Likewise.
* tests/subthreadcreate.c (main): Likewise.
* include/private/gc_priv.h (CPTR_CLEAR_FLAGS, CPTR_SET_FLAGS): Cast
pointer to GC_uintptr_t instead of word.
* include/private/gcconfig.h (PTR_ALIGN_DOWN, PTR_ALIGN_UP): Likewise.
* tests/cpp.cc (D::CleanUp): Likewise.
* tests/cpp.cc [CPPCHECK] (WinMain): Likewise.
* tests/cpp.cc [!CPPCHECK] (main): Likewise.
* tests/weakmap.c (IS_FLAG_SET): Likewise.
* pthread_support.c [DEBUG_THREADS && !GC_WIN32_PTHREADS]
(GC_new_thread, GC_delete_thread, GC_unregister_my_thread_inner,
GC_thread_exit_proc): Cast to pointer through GC_uintptr_t instead of
signed_word.
* tests/gctest.c (SEXPR_TO_INT): Cast pointer to int through
GC_uintptr_t instead of GC_word.
* tests/initfromthread.c [!GC_PTHREADS] (thread): Cast to DWORD through
GC_uintptr_t instead of GC_word.
* tests/threadleak.c [!GC_PTHREADS] (test): Likewise.
* win32_threads.c (GC_win32_start): Likewise.
* win32_threads.c [GC_WINMAIN_REDIRECT] (WinMain): Likewise.
* tests/threadkey.c (on_thread_exit): Cast unused result to void.
  • Loading branch information
ivmai committed Oct 30, 2024
1 parent ec524a9 commit 5d619ee
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 52 deletions.
2 changes: 1 addition & 1 deletion cord/tests/de_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR command_line,
GC_enable_incremental();
# endif
# if defined(CPPCHECK)
GC_noop1((GC_word)&WinMain);
GC_noop1((GC_word)(GC_uintptr_t)(&WinMain));
# endif

if (!hPrevInstance) {
Expand Down
2 changes: 1 addition & 1 deletion gcj_mlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ GC_gcj_fake_mark_proc(word *addr, struct GC_ms_entry *mark_stack_top,
UNUSED_ARG(mark_stack_limit);
UNUSED_ARG(env);
# if defined(FUNCPTR_IS_DATAPTR) && defined(CPPCHECK)
GC_noop1((word)&GC_init_gcj_malloc);
GC_noop1((word)(GC_funcptr_uint)(&GC_init_gcj_malloc));
# endif
ABORT_RET("No client gcj mark proc is specified");
return mark_stack_top;
Expand Down
9 changes: 7 additions & 2 deletions include/gc/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ typedef GC_word GC_uintptr_t;
#if defined(__GNUC__) && !defined(__CHERI_PURE_CAPABILITY__)
# define GC_ADDR_LT(p, q) ((p) < (q))
#else
# define GC_ADDR_LT(p, q) ((GC_word)(p) < (GC_word)(q))
# define GC_ADDR_LT(p, q) \
((GC_word)(GC_uintptr_t)(p) < (GC_word)(GC_uintptr_t)(q))
#endif

/* Get the GC library version. The returned value is a constant in the */
Expand Down Expand Up @@ -1571,7 +1572,11 @@ typedef GC_uintptr_t GC_hidden_pointer;
/* might be useful in conjunction with GC_register_disappearing_link. */
/* Note that unlike GC_HIDE_POINTER, inversion of the least significant */
/* bit of the argument is not guaranteed. */
#define GC_HIDE_NZ_POINTER(p) ((GC_hidden_pointer)(-(GC_signed_word)(p)))
#if defined(__CHERI_PURE_CAPABILITY__)
# define GC_HIDE_NZ_POINTER(p) ((GC_hidden_pointer)(-(intptr_t)(p)))
#else
# define GC_HIDE_NZ_POINTER(p) ((GC_hidden_pointer)(-(GC_signed_word)(p)))
#endif
#define GC_REVEAL_NZ_POINTER(p) ((void *)GC_HIDE_NZ_POINTER(p))

/* The routines to acquire/release the GC (allocator) lock. */
Expand Down
10 changes: 6 additions & 4 deletions include/gc/gc_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,9 @@ inline gc_cleanup::~gc_cleanup()
inline void GC_CALLBACK
gc_cleanup::cleanup(void *obj, void *displ)
{
reinterpret_cast<gc_cleanup *>(reinterpret_cast<char *>(obj)
+ reinterpret_cast<GC_PTRDIFF_T>(displ))
reinterpret_cast<gc_cleanup *>(
reinterpret_cast<char *>(obj)
+ static_cast<GC_PTRDIFF_T>(reinterpret_cast<GC_uintptr_t>(displ)))
->~gc_cleanup();
}

Expand All @@ -632,8 +633,9 @@ inline gc_cleanup::gc_cleanup()
// Don't call the debug version, since this is a real base address.
GC_register_finalizer_ignore_self(
base, reinterpret_cast<GC_finalization_proc>(cleanup),
reinterpret_cast<void *>(reinterpret_cast<char *>(this_ptr)
- reinterpret_cast<char *>(base)),
reinterpret_cast<void *>(
static_cast<GC_uintptr_t>(reinterpret_cast<char *>(this_ptr)
- reinterpret_cast<char *>(base))),
&oldProc, &oldData);
if (oldProc != 0) {
GC_register_finalizer_ignore_self(base, oldProc, oldData, 0, 0);
Expand Down
13 changes: 7 additions & 6 deletions include/gc/gc_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void *GC_CALL
void *next; \
\
for (;;) { \
if (GC_EXPECT((GC_word)my_entry \
if (GC_EXPECT((GC_word)(GC_uintptr_t)my_entry \
> (num_direct) + GC_TINY_FREELISTS + 1, \
1)) { \
next = *(void **)(my_entry); \
Expand All @@ -172,16 +172,17 @@ GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void *GC_CALL
|| 0 /* NULL */ == ((void **)result)[1]); \
break; \
} \
/* Entry contains counter or NULL */ \
if ((GC_signed_word)my_entry - (GC_signed_word)(num_direct) \
<= 0 /* (GC_word)my_entry <= (num_direct) */ \
/* Entry contains counter or NULL. */ \
if ((GC_signed_word)(GC_uintptr_t)my_entry \
- (GC_signed_word)(num_direct) \
<= 0 /* (GC_uintptr_t)my_entry <= num_direct */ \
&& my_entry != 0 /* NULL */) { \
/* Small counter value, not NULL */ \
/* Small counter value, not NULL. */ \
GC_FAST_M_AO_STORE(my_fl, (char *)my_entry + (lg) + 1); \
result = (default_expr); \
break; \
} else { \
/* Large counter or NULL */ \
/* Large counter or NULL. */ \
GC_generic_malloc_many(0 == (lg) ? GC_GRANULE_BYTES \
: GC_RAW_BYTES_FROM_INDEX(lg), \
k, my_fl); \
Expand Down
3 changes: 2 additions & 1 deletion include/private/gc_hdrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ typedef struct bi {
/* Get an HBLKSIZE-aligned address closer to the beginning of the block */
/* h. Assumes hhdr == HDR(h), IS_FORWARDING_ADDR(hhdr) and hhdr is not */
/* NULL. HDR(result) is expected to be non-NULL. */
#define FORWARDED_ADDR(h, hhdr) ((struct hblk *)(h) - (size_t)(hhdr))
#define FORWARDED_ADDR(h, hhdr) \
((struct hblk *)(h) - (size_t)(GC_uintptr_t)(hhdr))

EXTERN_C_END

Expand Down
2 changes: 1 addition & 1 deletion include/private/gc_locks.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ EXTERN_C_BEGIN
/* as possible. */
/* Refine to exclude platforms on which pthread_t is struct. */
# if !defined(GC_WIN32_PTHREADS)
# define NUMERIC_THREAD_ID(id) ((unsigned long)(id))
# define NUMERIC_THREAD_ID(id) ((unsigned long)(GC_uintptr_t)(id))
# define THREAD_EQUAL(id1, id2) ((id1) == (id2))
# define NUMERIC_THREAD_ID_UNIQUE
# elif defined(__WINPTHREADS_VERSION_MAJOR) /* winpthreads */
Expand Down
11 changes: 6 additions & 5 deletions include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,15 @@ typedef struct hblkhdr hdr;
/* Convert an unsigned value to a void pointer. Typically used to */
/* print a numeric value using "%p" format specifier. The pointer */
/* is not supposed to be dereferenced. */
#define NUMERIC_TO_VPTR(v) ((void *)(word)(v))
#define NUMERIC_TO_VPTR(v) ((void *)(GC_uintptr_t)(v))

/* Create a ptr_t pointer from a number (of word type). */
#define MAKE_CPTR(w) ((ptr_t)(word)(w))
#define MAKE_CPTR(w) ((ptr_t)(GC_uintptr_t)(word)(w))

#define GC_WORD_MAX (~(word)0)

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

#define ADDR_LT(p, q) GC_ADDR_LT(p, q)
#define ADDR_GE(p, q) (!ADDR_LT(p, q))
Expand All @@ -359,8 +359,9 @@ typedef struct hblkhdr hdr;
#endif /* !STACK_GROWS_UP */

/* Clear/set flags (given by a mask) in a pointer. */
#define CPTR_CLEAR_FLAGS(p, mask) (ptr_t)((word)(p) & ~(word)(mask))
#define CPTR_SET_FLAGS(p, mask) (ptr_t)((word)(p) | (word)(mask))
#define CPTR_CLEAR_FLAGS(p, mask) \
(ptr_t)((GC_uintptr_t)(p) & ~(GC_uintptr_t)(word)(mask))
#define CPTR_SET_FLAGS(p, mask) (ptr_t)((GC_uintptr_t)(p) | (word)(mask))

/* Easily changeable parameters ae below. */

Expand Down
10 changes: 6 additions & 4 deletions include/private/gcconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -768,9 +768,11 @@ EXTERN_C_BEGIN
#endif

/* Align a ptr_t pointer down/up to a given boundary. */
#define PTR_ALIGN_DOWN(p, b) ((ptr_t)((word)(p) & ~(word)((b)-1)))
#define PTR_ALIGN_UP(p, b) \
((ptr_t)(((word)(p) + (word)((b)-1)) & ~(word)((b)-1)))
#define PTR_ALIGN_DOWN(p, b) \
((ptr_t)((GC_uintptr_t)(p) & ~(GC_uintptr_t)((b)-1)))
#define PTR_ALIGN_UP(p, b) \
((ptr_t)(((GC_uintptr_t)(p) + (GC_uintptr_t)((b)-1)) \
& ~(GC_uintptr_t)((b)-1)))

/* If available, we can use __builtin_unwind_init() to push the */
/* relevant registers onto the stack. */
Expand Down Expand Up @@ -1407,7 +1409,7 @@ ptr_t GC_SysVGetDataStart(size_t, ptr_t);
# ifndef USE_MMAP
# define USE_MMAP 1
# endif
# define MAP_FAILED (void *)((word)-1)
# define MAP_FAILED (void *)((GC_uintptr_t)-1)
# define HEAP_START (ptr_t)0x40000000
# endif /* DGUX */
# ifdef LINUX
Expand Down
6 changes: 3 additions & 3 deletions os_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ GC_set_and_save_fault_handler(GC_fault_handler_t h)
# endif
# endif /* !USE_SEGV_SIGACT */
# if defined(CPPCHECK) && defined(ADDRESS_SANITIZER)
GC_noop1((word)(GC_funcptr_uint)&__asan_default_options);
GC_noop1((word)(GC_funcptr_uint)(&__asan_default_options));
# endif
}
#endif /* NEED_FIND_LIMIT || UNIX_LIKE || WRAP_MARK_SOME */
Expand Down Expand Up @@ -3566,7 +3566,7 @@ GC_dirty_init(void)
# endif
# endif /* !MSWIN32 && !MSWINCE */
# if defined(CPPCHECK) && defined(ADDRESS_SANITIZER)
GC_noop1((word)(GC_funcptr_uint)&__asan_default_options);
GC_noop1((word)(GC_funcptr_uint)(&__asan_default_options));
# endif
return TRUE;
}
Expand Down Expand Up @@ -4937,7 +4937,7 @@ GC_dirty_init(void)
}
# endif /* BROKEN_EXCEPTION_HANDLING */
# if defined(CPPCHECK)
GC_noop1((word)GC_ports.os_callback[0]);
GC_noop1((word)(GC_funcptr_uint)GC_ports.os_callback[0]);
# endif
return TRUE;
}
Expand Down
4 changes: 2 additions & 2 deletions pthread_stop_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ GC_suspend_all(void)
if (GC_on_thread_event) {
/* Note: thread id might be truncated. */
GC_on_thread_event(GC_EVENT_THREAD_SUSPENDED,
(void *)(word)THREAD_SYSTEM_ID(p));
(void *)(GC_uintptr_t)THREAD_SYSTEM_ID(p));
}
break;
default:
Expand Down Expand Up @@ -1339,7 +1339,7 @@ GC_restart_all(void)
case 0:
if (GC_on_thread_event)
GC_on_thread_event(GC_EVENT_THREAD_UNSUSPENDED,
(void *)(word)THREAD_SYSTEM_ID(p));
(void *)(GC_uintptr_t)THREAD_SYSTEM_ID(p));
break;
default:
ABORT_ARG1("pthread_kill failed at resume", ": errcode= %d", result);
Expand Down
10 changes: 5 additions & 5 deletions pthread_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ unsigned __stdcall GC_mark_thread(void *id)
# endif
{
word my_mark_no = 0;
word id_n = (word)id;
word id_n = (word)(GC_uintptr_t)id;
IF_CANCEL(int cancel_state;)

if (id_n == GC_WORD_MAX)
Expand Down Expand Up @@ -763,7 +763,7 @@ GC_new_thread(thread_id_t self_id)
GC_ASSERT(I_HOLD_LOCK());
# ifdef DEBUG_THREADS
# if !defined(GC_WIN32_PTHREADS)
GC_log_printf("Creating thread %p\n", (void *)(signed_word)self_id);
GC_log_printf("Creating thread %p\n", (void *)(GC_uintptr_t)self_id);
# endif
for (result = GC_threads[hv]; result != NULL; result = result->tm.next)
if (!THREAD_ID_EQUAL(result->id, self_id)) {
Expand Down Expand Up @@ -865,7 +865,7 @@ GC_delete_thread(GC_thread t)
&& (!defined(MSWIN32) || defined(CONSOLE_LOG)) \
&& !defined(GC_WIN32_PTHREADS)
GC_log_printf("Deleting thread %p, n_threads= %d\n",
(void *)(signed_word)id, GC_count_threads());
(void *)(GC_uintptr_t)id, GC_count_threads());
# endif
for (p = GC_threads[hv]; p != t; p = p->tm.next) {
prev = p;
Expand Down Expand Up @@ -2254,7 +2254,7 @@ GC_unregister_my_thread_inner(GC_thread me)
GC_ASSERT(I_HOLD_LOCK());
# if defined(DEBUG_THREADS) && !defined(GC_WIN32_PTHREADS)
GC_log_printf("Unregistering thread %p, gc_thread= %p, n_threads= %d\n",
(void *)((signed_word)me->id), (void *)me, GC_count_threads());
(void *)(GC_uintptr_t)me->id, (void *)me, GC_count_threads());
# endif
GC_ASSERT(!KNOWN_FINISHED(me));
# if defined(THREAD_LOCAL_ALLOC)
Expand Down Expand Up @@ -2482,7 +2482,7 @@ GC_thread_exit_proc(void *arg)

# if defined(DEBUG_THREADS) && !defined(GC_WIN32_PTHREADS)
GC_log_printf("Called GC_thread_exit_proc on %p, gc_thread= %p\n",
(void *)((signed_word)me->id), (void *)me);
(void *)(GC_uintptr_t)me->id, (void *)me);
# endif
LOCK();
DISABLE_CANCEL(cancel_state);
Expand Down
8 changes: 4 additions & 4 deletions tests/cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ class D : public GC_NS_QUALIFY(gc)
{
const D *self = static_cast<D *>(obj);
nFreed++;
my_assert(static_cast<GC_word>(self->i)
== reinterpret_cast<GC_word>(data));
my_assert(static_cast<GC_uintptr_t>(self->i)
== reinterpret_cast<GC_uintptr_t>(data));
}
static void
Test()
Expand Down Expand Up @@ -304,7 +304,7 @@ WinMain(HINSTANCE /* instance */, HINSTANCE /* prev */, LPSTR cmd,
char *argv[3];

# if defined(CPPCHECK)
GC_noop1(reinterpret_cast<GC_word>(&WinMain));
GC_noop1(static_cast<GC_word>(reinterpret_cast<GC_uintptr_t>(&WinMain)));
# endif
if (cmd != 0)
for (argc = 1; argc < static_cast<int>(sizeof(argv) / sizeof(argv[0]));
Expand Down Expand Up @@ -404,7 +404,7 @@ main(int argc, const char *argv[])
#if !defined(CPPCHECK)
D *d;
d = ::new (USE_GC, D::CleanUp,
reinterpret_cast<void *>(static_cast<GC_word>(i))) D(i);
reinterpret_cast<void *>(static_cast<GC_uintptr_t>(i))) D(i);
GC_reachable_here(d);
#endif
f = new F;
Expand Down
2 changes: 1 addition & 1 deletion tests/gctest.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ struct SEXPR {
typedef struct SEXPR *sexpr;

#define INT_TO_SEXPR(v) ((sexpr)NUMERIC_TO_VPTR(v))
#define SEXPR_TO_INT(p) ((int)(GC_word)(p))
#define SEXPR_TO_INT(p) ((int)(GC_uintptr_t)(p))

#undef nil
#define nil (INT_TO_SEXPR(0))
Expand Down
2 changes: 1 addition & 1 deletion tests/initfromthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ thread(LPVOID arg)
#ifdef GC_PTHREADS
return arg;
#else
return (DWORD)(GC_word)arg;
return (DWORD)(GC_uintptr_t)arg;
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion tests/staticroots.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct treenode *root[10] = { NULL };

/* Same as "root" variable but initialized to some non-zero value (to */
/* be placed to .data section instead of .bss). */
struct treenode *root_nz[10] = { (struct treenode *)(GC_word)1 };
struct treenode *root_nz[10] = { (struct treenode *)(GC_uintptr_t)1 };

/* Note: this is static intentionally. */
static char *staticroot;
Expand Down
2 changes: 1 addition & 1 deletion tests/staticroots_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct treenode {
};

static struct treenode *root[10] = { 0 };
static struct treenode *root_nz[10] = { (struct treenode *)(GC_word)2 };
static struct treenode *root_nz[10] = { (struct treenode *)(GC_uintptr_t)2 };

/* Declare it to avoid "no previous prototype" clang warning. */
GC_TEST_EXPORT_API struct treenode **libsrl_getpelem(int i, int j);
Expand Down
4 changes: 2 additions & 2 deletions tests/subthreadcreate.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ entry(LPVOID arg)
# endif
{
int thread_num = (int)AO_fetch_and_add1(&thread_created_cnt);
GC_word my_depth = (GC_word)arg + 1;
GC_word my_depth = (GC_word)(GC_uintptr_t)arg + 1;

if (my_depth <= MAX_SUBTHREAD_DEPTH && thread_num < MAX_SUBTHREAD_COUNT
&& (thread_num % DECAY_DENOM) < DECAY_NUMER
Expand All @@ -76,7 +76,7 @@ entry(LPVOID arg)
int err;
pthread_t th;

err = pthread_create(&th, NULL, entry, (void *)my_depth);
err = pthread_create(&th, NULL, entry, (void *)(GC_uintptr_t)my_depth);
if (err != 0) {
fprintf(stderr, "Thread #%d creation failed from other thread: %s\n",
thread_num, strerror(err));
Expand Down
4 changes: 2 additions & 2 deletions tests/threadkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ on_thread_exit_inner(struct GC_stack_base *sb, void *arg)
GC_noop1_ptr(sb);
GC_noop1_ptr(arg);
# endif
return arg ? (void *)(GC_word)creation_res : 0;
return arg ? (void *)(GC_uintptr_t)creation_res : 0;
}

static void
on_thread_exit(void *v)
{
GC_call_with_stack_base(on_thread_exit_inner, v);
(void)GC_call_with_stack_base(on_thread_exit_inner, v);
}

static void
Expand Down
2 changes: 1 addition & 1 deletion tests/threadleak.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test(LPVOID arg)
#ifdef GC_PTHREADS
return arg;
#else
return (DWORD)(GC_word)arg;
return (DWORD)(GC_uintptr_t)arg;
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion tests/weakmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ static GC_RAND_STATE_T seed;
# define INVALIDATE_FLAG 0x2
#endif

#define IS_FLAG_SET(p, mask) (((GC_word)(p)&mask) != 0)
#define IS_FLAG_SET(p, mask) \
(((unsigned)(GC_uintptr_t)(p) & (unsigned)(mask)) != 0)

#define my_assert(e) \
if (!(e)) { \
Expand Down
7 changes: 4 additions & 3 deletions win32_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,8 @@ GC_win32_start_inner(struct GC_stack_base *sb, void *arg)
STATIC DWORD WINAPI
GC_win32_start(LPVOID arg)
{
return (DWORD)(word)GC_call_with_stack_base(GC_win32_start_inner, arg);
return (DWORD)(GC_uintptr_t)GC_call_with_stack_base(GC_win32_start_inner,
arg);
}

GC_API HANDLE WINAPI
Expand Down Expand Up @@ -1636,8 +1637,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, WINMAIN_LPTSTR lpCmdLine,
if (NULL == thread_h)
ABORT("GC_CreateThread(main_thread) failed");

if ((DWORD)(word)GC_do_blocking(GC_waitForSingleObjectInfinite,
(void *)thread_h)
if ((DWORD)(GC_uintptr_t)GC_do_blocking(GC_waitForSingleObjectInfinite,
(void *)thread_h)
== WAIT_FAILED)
ABORT("WaitForSingleObject(main_thread) failed");
GetExitCodeThread(thread_h, &exit_code);
Expand Down

0 comments on commit 5d619ee

Please sign in to comment.