Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build-scripts/warnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ else ()
# options benefit embedded system.
add_compile_options (
-Wdouble-promotion
-Wcast-align=strict
)

# waivers
Expand Down
42 changes: 21 additions & 21 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ exchange_uint64(uint8 *p_data)
{
uint32 value;

value = *(uint32 *)p_data;
*(uint32 *)p_data = *(uint32 *)(p_data + 4);
*(uint32 *)(p_data + 4) = value;
value = *(uint32 *)(void *)p_data;
*(uint32 *)(void *)p_data = *(uint32 *)(void *)(p_data + 4);
*(uint32 *)(void *)(p_data + 4) = value;
exchange_uint32(p_data);
exchange_uint32(p_data + 4);
}
Expand Down Expand Up @@ -204,21 +204,21 @@ GET_U16_FROM_ADDR(const uint8 *p)

#else /* else of (WASM_ENABLE_WORD_ALIGN_READ != 0) */

#define TEMPLATE_READ(p, p_end, res, type) \
do { \
if (sizeof(type) != sizeof(uint64)) \
p = (uint8 *)align_ptr(p, sizeof(type)); \
else \
/* align 4 bytes if type is uint64 */ \
p = (uint8 *)align_ptr(p, sizeof(uint32)); \
CHECK_BUF(p, p_end, sizeof(type)); \
if (sizeof(type) != sizeof(uint64)) \
res = *(type *)p; \
else \
res = (type)GET_U64_FROM_ADDR((uint32 *)p); \
if (!is_little_endian()) \
exchange_##type((uint8 *)&res); \
p += sizeof(type); \
#define TEMPLATE_READ(p, p_end, res, type) \
do { \
if (sizeof(type) != sizeof(uint64)) \
p = (uint8 *)align_ptr(p, sizeof(type)); \
else \
/* align 4 bytes if type is uint64 */ \
p = (uint8 *)align_ptr(p, sizeof(uint32)); \
CHECK_BUF(p, p_end, sizeof(type)); \
if (sizeof(type) != sizeof(uint64)) \
res = *(type *)(void *)p; \
else \
res = (type)GET_U64_FROM_ADDR((uint32 *)(void *)p); \
if (!is_little_endian()) \
exchange_##type((uint8 *)&res); \
p += sizeof(type); \
} while (0)

/* NOLINTBEGIN, disable lint for this region with clang-tidy */
Expand Down Expand Up @@ -3557,7 +3557,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,

read_uint32(buf, buf_end, symbol_count);

symbol_offsets = (uint32 *)buf;
symbol_offsets = (uint32 *)(void *)buf;
for (i = 0; i < symbol_count; i++) {
CHECK_BUF(buf, buf_end, sizeof(uint32));
buf += sizeof(uint32);
Expand Down Expand Up @@ -3709,7 +3709,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
}

group_name = symbol_buf + symbol_offsets[name_index];
group_name_len = *(uint16 *)group_name;
group_name_len = *(uint16 *)(void *)group_name;
group_name += sizeof(uint16);

read_uint32(buf, buf_end, relocation_count);
Expand All @@ -3735,7 +3735,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
}

symbol_name = symbol_buf + symbol_offsets[symbol_index];
symbol_name_len = *(uint16 *)symbol_name;
symbol_name_len = *(uint16 *)(void *)symbol_name;
symbol_name += sizeof(uint16);

bh_memcpy_s(group_name_buf, (uint32)sizeof(group_name_buf),
Expand Down
30 changes: 15 additions & 15 deletions core/shared/mem-alloc/ems/ems_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ remove_tree_node(gc_heap_t *heap, hmu_tree_node_t *p)
/* get the slot which holds pointer to node p */
if (p == p->parent->right) {
/* Don't use `slot = &p->parent->right` to avoid compiler warning */
slot = (hmu_tree_node_t **)((uint8 *)p->parent
slot = (hmu_tree_node_t **)((uintptr_t)p->parent
+ offsetof(hmu_tree_node_t, right));
}
else if (p == p->parent->left) {
/* p should be a child of its parent */
/* Don't use `slot = &p->parent->left` to avoid compiler warning */
slot = (hmu_tree_node_t **)((uint8 *)p->parent
slot = (hmu_tree_node_t **)((uintptr_t)p->parent
+ offsetof(hmu_tree_node_t, left));
}
else {
Expand Down Expand Up @@ -237,7 +237,7 @@ hmu_set_free_size(hmu_t *hmu)
bh_assert(hmu && hmu_get_ut(hmu) == HMU_FC);

size = hmu_get_size(hmu);
*((uint32 *)((char *)hmu + size) - 1) = size;
*((uint32 *)((uintptr_t)hmu + size) - 1) = size;
}

/**
Expand Down Expand Up @@ -398,15 +398,15 @@ alloc_hmu(gc_heap_t *heap, gc_size_t size)
if ((gc_size_t)node_idx != (uint32)init_node_idx
/* with bigger size*/
&& ((gc_size_t)node_idx << 3) >= size + GC_SMALLEST_SIZE) {
rest = (hmu_t *)(((char *)p) + size);
rest = (hmu_t *)(((uintptr_t)p) + size);
if (!gci_add_fc(heap, rest, (node_idx << 3) - size)) {
return NULL;
}
hmu_mark_pinuse(rest);
}
else {
size = node_idx << 3;
next = (hmu_t *)((char *)p + size);
next = (hmu_t *)((uintptr_t)p + size);
if (hmu_is_in_heap(next, base_addr, end_addr))
hmu_mark_pinuse(next);
}
Expand Down Expand Up @@ -456,14 +456,14 @@ alloc_hmu(gc_heap_t *heap, gc_size_t size)
return NULL;

if (last_tp->size >= size + GC_SMALLEST_SIZE) {
rest = (hmu_t *)((char *)last_tp + size);
rest = (hmu_t *)((uintptr_t)last_tp + size);
if (!gci_add_fc(heap, rest, last_tp->size - size))
return NULL;
hmu_mark_pinuse(rest);
}
else {
size = last_tp->size;
next = (hmu_t *)((char *)last_tp + size);
next = (hmu_t *)((uintptr_t)last_tp + size);
if (hmu_is_in_heap(next, base_addr, end_addr))
hmu_mark_pinuse(next);
}
Expand Down Expand Up @@ -658,7 +658,7 @@ gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size, const char *file,
LOCK_HEAP(heap);

if (hmu_old) {
hmu_next = (hmu_t *)((char *)hmu_old + tot_size_old);
hmu_next = (hmu_t *)((uintptr_t)hmu_old + tot_size_old);
if (hmu_is_in_heap(hmu_next, base_addr, end_addr)) {
ut = hmu_get_ut(hmu_next);
tot_size_next = hmu_get_size(hmu_next);
Expand All @@ -675,7 +675,7 @@ gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size, const char *file,
hmu_init_prefix_and_suffix(hmu_old, tot_size, file, line);
#endif
if (tot_size < tot_size_old + tot_size_next) {
hmu_next = (hmu_t *)((char *)hmu_old + tot_size);
hmu_next = (hmu_t *)((uintptr_t)hmu_old + tot_size);
tot_size_next = tot_size_old + tot_size_next - tot_size;
if (!gci_add_fc(heap, hmu_next, tot_size_next)) {
UNLOCK_HEAP(heap);
Expand Down Expand Up @@ -889,7 +889,7 @@ gc_free_vo_internal(void *vheap, gc_object_t obj, const char *file, int line)
#endif

if (!hmu_get_pinuse(hmu)) {
prev = (hmu_t *)((char *)hmu - *((int *)hmu - 1));
prev = (hmu_t *)((uintptr_t)hmu - *((int *)hmu - 1));

if (hmu_is_in_heap(prev, base_addr, end_addr)
&& hmu_get_ut(prev) == HMU_FC) {
Expand All @@ -902,15 +902,15 @@ gc_free_vo_internal(void *vheap, gc_object_t obj, const char *file, int line)
}
}

next = (hmu_t *)((char *)hmu + size);
next = (hmu_t *)((uintptr_t)hmu + size);
if (hmu_is_in_heap(next, base_addr, end_addr)) {
if (hmu_get_ut(next) == HMU_FC) {
size += hmu_get_size(next);
if (!unlink_hmu(heap, next)) {
ret = GC_ERROR;
goto out;
}
next = (hmu_t *)((char *)hmu + size);
next = (hmu_t *)((uintptr_t)hmu + size);
}
}

Expand Down Expand Up @@ -966,8 +966,8 @@ gci_dump(gc_heap_t *heap)
int i = 0, p, mark;
char inuse = 'U';

cur = (hmu_t *)heap->base_addr;
end = (hmu_t *)((char *)heap->base_addr + heap->current_size);
cur = (void *)heap->base_addr;
end = (hmu_t *)((uintptr_t)heap->base_addr + heap->current_size);

while (cur < end) {
ut = hmu_get_ut(cur);
Expand Down Expand Up @@ -1001,7 +1001,7 @@ gci_dump(gc_heap_t *heap)
}
#endif

cur = (hmu_t *)((char *)cur + size);
cur = (hmu_t *)((uintptr_t)cur + size);
i++;
}

Expand Down
4 changes: 2 additions & 2 deletions core/shared/mem-alloc/ems/ems_gc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ hmu_verify(void *vheap, hmu_t *hmu);
#define HMU_SIZE (sizeof(hmu_t))

#define hmu_to_obj(hmu) (gc_object_t)(SKIP_OBJ_PREFIX((hmu_t *)(hmu) + 1))
#define obj_to_hmu(obj) ((hmu_t *)((gc_uint8 *)(obj)-OBJ_PREFIX_SIZE) - 1)
#define obj_to_hmu(obj) ((hmu_t *)((uintptr_t)(obj)-OBJ_PREFIX_SIZE) - 1)

#define HMU_UT_SIZE 2
#define HMU_UT_OFFSET 30
Expand Down Expand Up @@ -188,7 +188,7 @@ static inline hmu_normal_node_t *
get_hmu_normal_node_next(hmu_normal_node_t *node)
{
return node->next_offset
? (hmu_normal_node_t *)((uint8 *)node + node->next_offset)
? (hmu_normal_node_t *)((uintptr_t)node + node->next_offset)
: NULL;
}

Expand Down
36 changes: 19 additions & 17 deletions core/shared/mem-alloc/ems/ems_kfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ gc_init_internal(gc_heap_t *heap, char *base_addr, gc_size_t heap_max_size)
gc_update_threshold(heap);
#endif

root = heap->kfc_tree_root = (hmu_tree_node_t *)heap->kfc_tree_root_buf;
root = heap->kfc_tree_root = (void *)(heap->kfc_tree_root_buf);
memset(root, 0, sizeof *root);
root->size = sizeof *root;
hmu_set_ut(&root->hmu_header, HMU_FC);
hmu_set_size(&root->hmu_header, sizeof *root);

q = (hmu_tree_node_t *)heap->base_addr;
q = (void *)base_addr;
memset(q, 0, sizeof *q);
hmu_set_ut(&q->hmu_header, HMU_FC);
hmu_set_size(&q->hmu_header, heap->current_size);
Expand All @@ -60,8 +60,8 @@ gc_handle_t
gc_init_with_pool(char *buf, gc_size_t buf_size)
{
char *buf_end = buf + buf_size;
char *buf_aligned = (char *)(((uintptr_t)buf + 7) & (uintptr_t)~7);
char *base_addr = buf_aligned + sizeof(gc_heap_t);
uintptr_t buf_aligned = ((uintptr_t)buf + 7) & (uintptr_t)~7;
char *base_addr = (char *)(buf_aligned + sizeof(gc_heap_t));
gc_heap_t *heap = (gc_heap_t *)buf_aligned;
gc_size_t heap_max_size;

Expand Down Expand Up @@ -89,7 +89,9 @@ gc_handle_t
gc_init_with_struct_and_pool(char *struct_buf, gc_size_t struct_buf_size,
char *pool_buf, gc_size_t pool_buf_size)
{
gc_heap_t *heap = (gc_heap_t *)struct_buf;
/*struct_buf is allocated with the size of gc_heap_t via
* gc_get_heap_struct_size() */
gc_heap_t *heap = (void *)struct_buf;
char *base_addr = pool_buf + GC_HEAD_PADDING;
char *pool_buf_end = pool_buf + pool_buf_size;
gc_size_t heap_max_size;
Expand Down Expand Up @@ -270,18 +272,18 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size)

ASSERT_TREE_NODE_ALIGNED_ACCESS(heap->kfc_tree_root);

p_left = (uint8 **)((uint8 *)heap->kfc_tree_root
p_left = (uint8 **)((uintptr_t)heap->kfc_tree_root
+ offsetof(hmu_tree_node_t, left));
p_right = (uint8 **)((uint8 *)heap->kfc_tree_root
p_right = (uint8 **)((uintptr_t)heap->kfc_tree_root
+ offsetof(hmu_tree_node_t, right));
p_parent = (uint8 **)((uint8 *)heap->kfc_tree_root
p_parent = (uint8 **)((uintptr_t)heap->kfc_tree_root
+ offsetof(hmu_tree_node_t, parent));
adjust_ptr(p_left, offset);
adjust_ptr(p_right, offset);
adjust_ptr(p_parent, offset);

cur = (hmu_t *)heap->base_addr;
end = (hmu_t *)((char *)heap->base_addr + heap->current_size);
cur = (void *)heap->base_addr;
end = (hmu_t *)((uintptr_t)heap->base_addr + heap->current_size);

while (cur < end) {
size = hmu_get_size(cur);
Expand All @@ -299,11 +301,11 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size)

ASSERT_TREE_NODE_ALIGNED_ACCESS(tree_node);

p_left = (uint8 **)((uint8 *)tree_node
p_left = (uint8 **)((uintptr_t)tree_node
+ offsetof(hmu_tree_node_t, left));
p_right = (uint8 **)((uint8 *)tree_node
p_right = (uint8 **)((uintptr_t)tree_node
+ offsetof(hmu_tree_node_t, right));
p_parent = (uint8 **)((uint8 *)tree_node
p_parent = (uint8 **)((uintptr_t)tree_node
+ offsetof(hmu_tree_node_t, parent));
adjust_ptr(p_left, offset);
adjust_ptr(p_right, offset);
Expand All @@ -312,7 +314,7 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size)
it is fixed part and isn't changed. */
adjust_ptr(p_parent, offset);
}
cur = (hmu_t *)((char *)cur + size);
cur = (hmu_t *)((uintptr_t)cur + size);
}

#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
Expand Down Expand Up @@ -366,8 +368,8 @@ gc_heap_stat(void *heap_ptr, gc_stat_t *stat)
gc_heap_t *heap = (gc_heap_t *)heap_ptr;

memset(stat, 0, sizeof(gc_stat_t));
cur = (hmu_t *)heap->base_addr;
end = (hmu_t *)((char *)heap->base_addr + heap->current_size);
cur = (void *)heap->base_addr;
end = (hmu_t *)((uintptr_t)heap->base_addr + heap->current_size);

while (cur < end) {
ut = hmu_get_ut(cur);
Expand Down Expand Up @@ -401,7 +403,7 @@ gc_heap_stat(void *heap_ptr, gc_stat_t *stat)
stat->usage_sizes[GC_HEAP_STAT_SIZE - 1] += 1;
}

cur = (hmu_t *)((char *)cur + size);
cur = (hmu_t *)((uintptr_t)cur + size);
}
}

Expand Down
Loading