Skip to content

Commit

Permalink
Fix "pointer cast size mismatch" warnings on 32-bit arch's
Browse files Browse the repository at this point in the history
Should hopefully resolve #444. Cast as uintptr_t from pointers and not
directly into a 64-bit type.
  • Loading branch information
samcv committed Nov 25, 2018
1 parent 514ebce commit 6ff60a3
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/core/exceptions.c
Expand Up @@ -82,8 +82,8 @@ typedef struct {
static MVMint32 handler_can_handle(MVMFrame *f, MVMFrameHandler *fh, MVMint32 cat, MVMObject *payload) {
MVMuint32 category_mask = fh->category_mask;
MVMuint64 block_has_label = category_mask & MVM_EX_CAT_LABELED;
MVMuint64 block_label = block_has_label ? (MVMuint64)(f->work[fh->label_reg].o) : 0;
MVMuint64 thrown_label = payload ? (MVMuint64)payload : 0;
MVMuint64 block_label = block_has_label ? (uintptr_t)(f->work[fh->label_reg].o) : 0;
MVMuint64 thrown_label = payload ? (uintptr_t)payload : 0;
MVMuint64 identical_label_found = thrown_label == block_label;
return ((cat & category_mask) == cat && (!(cat & MVM_EX_CAT_LABELED) || identical_label_found))
|| ((category_mask & MVM_EX_CAT_CONTROL) && cat != MVM_EX_CAT_CATCH);
Expand Down
4 changes: 2 additions & 2 deletions src/core/interp.c
Expand Up @@ -1918,7 +1918,7 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
goto NEXT;
}
OP(getwhere):
GET_REG(cur_op, 0).i64 = (MVMint64)GET_REG(cur_op, 2).o;
GET_REG(cur_op, 0).i64 = (uintptr_t)GET_REG(cur_op, 2).o;
cur_op += 4;
goto NEXT;
OP(eqaddr):
Expand Down Expand Up @@ -6302,7 +6302,7 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
MVMString *filename = MVM_cu_string(tc, cu, GET_UI32(cur_op, 0));
MVMuint32 lineno = GET_UI32(cur_op, 4);
MVMuint32 cacheidx = GET_UI32(cur_op, 8);
char *cache = (char *)MVM_BC_get_I64(cur_op, 12);
char *cache = (char *)(uintptr_t)MVM_BC_get_I64(cur_op, 12);
MVM_line_coverage_report(tc, filename, lineno, cacheidx, cache);
cur_op += 20;
goto NEXT;
Expand Down
2 changes: 1 addition & 1 deletion src/core/nativecall_libffi.c
Expand Up @@ -760,7 +760,7 @@ MVMObject * MVM_nativecall_invoke(MVMThreadContext *tc, MVMObject *res_type,
break;
case MVM_NATIVECALL_ARG_CPOINTER:
REPR(value)->box_funcs.set_int(tc, STABLE(value), value, OBJECT_BODY(value),
(MVMint64)*(void **)*(void **)values[i]);
(MVMint64)(uintptr_t)*(void **)*(void **)values[i]);
break;
default:
MVM_telemetry_interval_stop(tc, interval_id, "nativecall invoke failed");
Expand Down
4 changes: 2 additions & 2 deletions src/gc/objectid.c
Expand Up @@ -8,7 +8,7 @@ MVMuint64 MVM_gc_object_id(MVMThreadContext *tc, MVMObject *obj) {
/* If it's already in the old generation, just use memory address, as
* gen2 objects never move. */
if (obj->header.flags & MVM_CF_SECOND_GEN) {
id = (MVMuint64)obj;
id = (uintptr_t)obj;
}

/* Otherwise, see if we already have a persistent object ID. */
Expand All @@ -30,7 +30,7 @@ MVMuint64 MVM_gc_object_id(MVMThreadContext *tc, MVMObject *obj) {
sizeof(MVMObject *), entry);
obj->header.flags |= MVM_CF_HAS_OBJECT_ID;
}
id = (MVMuint64)entry->gen2_addr;
id = (uintptr_t)entry->gen2_addr;
uv_mutex_unlock(&tc->instance->mutex_object_ids);
}

Expand Down
2 changes: 1 addition & 1 deletion src/instrument/line_coverage.c
Expand Up @@ -247,7 +247,7 @@ static void instrument_graph(MVMThreadContext *tc, MVMSpeshGraph *g) {
for (fixup_idx = 0; fixup_idx < fixup_elems; fixup_idx++) {
MVMSpeshIns *ins = to_fixup[fixup_idx];

ins->operands[3].lit_i64 = (MVMint64)line_report_store;
ins->operands[3].lit_i64 = (uintptr_t)line_report_store;
}

if (array_slot == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/moar.c
Expand Up @@ -89,7 +89,7 @@ MVMInstance * MVM_vm_create_instance(void) {
/* Get the 128-bit hashSecret */
MVM_getrandom(instance->main_thread, instance->hashSecrets, sizeof(MVMuint64) * 2);
/* Just in case MVM_getrandom didn't work, XOR it with some (poorly) randomized data */
instance->hashSecrets[0] ^= ptr_hash_64_to_64((MVMuint64)instance);
instance->hashSecrets[0] ^= ptr_hash_64_to_64((uintptr_t)instance);
instance->hashSecrets[1] ^= MVM_proc_getpid(instance->main_thread) * MVM_platform_now();
instance->main_thread->thread_id = 1;

Expand Down
8 changes: 4 additions & 4 deletions src/profiler/instrument.c
Expand Up @@ -445,7 +445,7 @@ static MVMObject * dump_call_graph_node(MVMThreadContext *tc, ProfDumpStrs *pds,

/* Use static frame memory address to get a unique ID. */
MVM_repr_bind_key_o(tc, node_hash, pds->id,
box_i(tc, (MVMint64)pcn->sf));
box_i(tc, (MVMint64)(uintptr_t)pcn->sf));
} else {
MVMString *function_name_string =
MVM_string_utf8_c8_decode(tc, tc->instance->VMString,
Expand All @@ -461,7 +461,7 @@ static MVMObject * dump_call_graph_node(MVMThreadContext *tc, ProfDumpStrs *pds,

/* Use the address of the name string as unique ID. a hack, but oh well. */
MVM_repr_bind_key_o(tc, node_hash, pds->id,
box_i(tc, (MVMint64)pcn->native_target_name));
box_i(tc, (MVMint64)(uintptr_t)pcn->native_target_name));
}

/* Entry counts. */
Expand Down Expand Up @@ -509,7 +509,7 @@ static MVMObject * dump_call_graph_node(MVMThreadContext *tc, ProfDumpStrs *pds,
MVMProfileAllocationCount *alloc = &pcn->alloc[i];

MVMObject *type = pcn->alloc[i].type;
MVMObject *type_info = insert_if_not_exists(tc, pds, types_array, (MVMint64)type);
MVMObject *type_info = insert_if_not_exists(tc, pds, types_array, (MVMint64)(uintptr_t)type);

if (type_info) {
bind_extra_info(tc, type_info, pds->managed_size, box_i(tc, STABLE(type)->size));
Expand All @@ -519,7 +519,7 @@ static MVMObject * dump_call_graph_node(MVMThreadContext *tc, ProfDumpStrs *pds,
bind_extra_info(tc, type_info, pds->repr, box_s(tc, str(tc, REPR(type)->name)));
}

MVM_repr_bind_key_o(tc, alloc_info, pds->id, box_i(tc, (MVMint64)type));
MVM_repr_bind_key_o(tc, alloc_info, pds->id, box_i(tc, (MVMint64)(uintptr_t)type));
if (alloc->allocations_spesh)
MVM_repr_bind_key_o(tc, alloc_info, pds->spesh,
box_i(tc, alloc->allocations_spesh));
Expand Down
4 changes: 2 additions & 2 deletions src/profiler/log.c
Expand Up @@ -229,15 +229,15 @@ void MVM_profile_log_allocated(MVMThreadContext *tc, MVMObject *obj) {
* nursery; we may have generated some "allocated" log instructions
* after operations that may or may not allocate what they return.
*/
MVMuint32 distance = ((MVMuint64)tc->nursery_alloc - (MVMuint64)obj);
MVMuint32 distance = (uintptr_t)tc->nursery_alloc - (uintptr_t)obj;

if (!obj) {
return;
}

/* Since some ops first allocate, then call something else that may
* also allocate, we may have to allow for a bit of grace distance. */
if ((MVMuint64)obj > (MVMuint64)tc->nursery_tospace && distance <= obj->header.size && obj != ptd->last_counted_allocation) {
if ((uintptr_t)obj > (uintptr_t)tc->nursery_tospace && distance <= obj->header.size && obj != ptd->last_counted_allocation) {
/* See if there's an existing node to update. */
MVMObject *what = STABLE(obj)->WHAT;
MVMuint32 i;
Expand Down
2 changes: 1 addition & 1 deletion src/spesh/optimize.c
Expand Up @@ -2151,7 +2151,7 @@ static void optimize_plugin(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *
}

static void optimize_coverage_log(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb, MVMSpeshIns *ins) {
char *cache = (char *)ins->operands[3].lit_i64;
char *cache = (char *)(uintptr_t)ins->operands[3].lit_i64;
MVMint32 cache_idx = ins->operands[2].lit_i32;

if (cache[cache_idx] != 0) {
Expand Down

0 comments on commit 6ff60a3

Please sign in to comment.