Skip to content

Commit 73caf19

Browse files
authored
Fix compile warnings/error reported in Windows (#3616)
Clear some compile warnings and fix undefined reference error for symbol ffs in Windows platform.
1 parent 46695b9 commit 73caf19

11 files changed

Lines changed: 49 additions & 23 deletions

File tree

core/iwasm/aot/aot_runtime.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ memories_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
11391139

11401140
if (memory_inst->memory_data) {
11411141
bh_memcpy_s((uint8 *)memory_inst->memory_data + base_offset,
1142-
(uint32)memory_inst->memory_data_size - base_offset,
1142+
(uint32)(memory_inst->memory_data_size - base_offset),
11431143
data_seg->bytes, length);
11441144
}
11451145
}
@@ -1212,7 +1212,7 @@ aot_get_function_instance(AOTModuleInstance *module_inst, uint32 func_idx)
12121212
return NULL;
12131213
}
12141214

1215-
extra->function_count = func_count;
1215+
extra->function_count = (uint32)func_count;
12161216
}
12171217

12181218
/* instantiate function if needed */
@@ -1764,8 +1764,8 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
17641764
aot_get_data_section_addr(module, AOT_STACK_SIZES_SECTION_NAME, NULL);
17651765

17661766
#if WASM_ENABLE_PERF_PROFILING != 0
1767-
total_size = (uint64)sizeof(AOTFuncPerfProfInfo)
1768-
* (module->import_func_count + module->func_count);
1767+
total_size = sizeof(AOTFuncPerfProfInfo)
1768+
* ((uint64)module->import_func_count + module->func_count);
17691769
if (!(module_inst->func_perf_profilings =
17701770
runtime_malloc(total_size, error_buf, error_buf_size))) {
17711771
goto fail;
@@ -2536,7 +2536,7 @@ execute_malloc_function(AOTModuleInstance *module_inst, WASMExecEnv *exec_env,
25362536
if (ret) {
25372537
#if WASM_ENABLE_MEMORY64 != 0
25382538
if (is_memory64)
2539-
*p_result = GET_I64_FROM_ADDR(&argv.u64);
2539+
*p_result = argv.u64;
25402540
else
25412541
#endif
25422542
{

core/iwasm/common/wasm_loader_common.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ bool
104104
is_valid_func_type(const WASMFuncType *func_type)
105105
{
106106
unsigned i;
107-
for (i = 0; i < func_type->param_count + func_type->result_count; i++) {
107+
for (i = 0;
108+
i < (unsigned)(func_type->param_count + func_type->result_count);
109+
i++) {
108110
if (!is_valid_value_type(func_type->types[i]))
109111
return false;
110112
}

core/iwasm/common/wasm_memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,13 +930,13 @@ wasm_runtime_enlarge_memory(WASMModuleInstanceCommon *module_inst,
930930
#if WASM_ENABLE_AOT != 0
931931
if (module_inst->module_type == Wasm_Module_AoT) {
932932
return aot_enlarge_memory((AOTModuleInstance *)module_inst,
933-
inc_page_count);
933+
(uint32)inc_page_count);
934934
}
935935
#endif
936936
#if WASM_ENABLE_INTERP != 0
937937
if (module_inst->module_type == Wasm_Module_Bytecode) {
938938
return wasm_enlarge_memory((WASMModuleInstance *)module_inst,
939-
inc_page_count);
939+
(uint32)inc_page_count);
940940
}
941941
#endif
942942

core/iwasm/compilation/aot_emit_memory.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,23 @@ get_memory_check_bound(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
9191
return mem_check_bound;
9292
}
9393

94+
#if defined(_WIN32) || defined(_WIN32_)
95+
static inline int
96+
ffs(int n)
97+
{
98+
int pos = 0;
99+
100+
if (n == 0)
101+
return 0;
102+
103+
while (!(n & 1)) {
104+
pos++;
105+
n >>= 1;
106+
}
107+
return pos + 1;
108+
}
109+
#endif
110+
94111
static LLVMValueRef
95112
get_memory_curr_page_count(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx);
96113

@@ -198,7 +215,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
198215
* has the natural alignment. for platforms using mmap, it can
199216
* be even larger. for now, use a conservative value.
200217
*/
201-
const int max_align = 8;
218+
const unsigned int max_align = 8;
202219
int shift = ffs((int)(unsigned int)mem_offset);
203220
if (shift == 0) {
204221
*alignp = max_align;

core/iwasm/compilation/aot_llvm.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,8 @@ aot_add_llvm_func(AOTCompContext *comp_ctx, LLVMModuleRef module,
749749
* and more importantly doesn't involve relocations.
750750
*/
751751
LLVMAttributeRef attr_short_call = LLVMCreateStringAttribute(
752-
comp_ctx->context, "short-call", strlen("short-call"), "", 0);
752+
comp_ctx->context, "short-call", (unsigned)strlen("short-call"),
753+
"", 0);
753754
LLVMAddAttributeAtIndex(func, LLVMAttributeFunctionIndex,
754755
attr_short_call);
755756
}
@@ -3529,7 +3530,7 @@ aot_block_destroy(AOTCompContext *comp_ctx, AOTBlock *block)
35293530

35303531
bool
35313532
aot_checked_addr_list_add(AOTFuncContext *func_ctx, uint32 local_idx,
3532-
uint32 offset, uint32 bytes)
3533+
uint64 offset, uint32 bytes)
35333534
{
35343535
AOTCheckedAddr *node = func_ctx->checked_addr_list;
35353536

@@ -3573,7 +3574,7 @@ aot_checked_addr_list_del(AOTFuncContext *func_ctx, uint32 local_idx)
35733574

35743575
bool
35753576
aot_checked_addr_list_find(AOTFuncContext *func_ctx, uint32 local_idx,
3576-
uint32 offset, uint32 bytes)
3577+
uint64 offset, uint32 bytes)
35773578
{
35783579
AOTCheckedAddr *node = func_ctx->checked_addr_list;
35793580

core/iwasm/compilation/aot_llvm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ typedef struct AOTBlockStack {
197197
typedef struct AOTCheckedAddr {
198198
struct AOTCheckedAddr *next;
199199
uint32 local_idx;
200-
uint32 offset;
200+
uint64 offset;
201201
uint32 bytes;
202202
} AOTCheckedAddr, *AOTCheckedAddrList;
203203

@@ -574,14 +574,14 @@ wasm_type_to_llvm_type(const AOTCompContext *comp_ctx,
574574

575575
bool
576576
aot_checked_addr_list_add(AOTFuncContext *func_ctx, uint32 local_idx,
577-
uint32 offset, uint32 bytes);
577+
uint64 offset, uint32 bytes);
578578

579579
void
580580
aot_checked_addr_list_del(AOTFuncContext *func_ctx, uint32 local_idx);
581581

582582
bool
583583
aot_checked_addr_list_find(AOTFuncContext *func_ctx, uint32 local_idx,
584-
uint32 offset, uint32 bytes);
584+
uint64 offset, uint32 bytes);
585585

586586
void
587587
aot_checked_addr_list_destroy(AOTFuncContext *func_ctx);

core/iwasm/compilation/aot_llvm_extra.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ aot_compress_aot_func_names(AOTCompContext *comp_ctx, uint32 *p_size)
411411
return NULL;
412412
}
413413

414-
compressed_str_len = Result.size();
414+
compressed_str_len = (uint32)Result.size();
415415
if (!(compressed_str = (char *)wasm_runtime_malloc(compressed_str_len))) {
416416
aot_set_last_error("allocate memory failed");
417417
return NULL;

core/iwasm/compilation/aot_orc_extra.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ PartitionFunction(GlobalValueSet Requested)
189189
auto GVName = GV->getName(); /* get the function name */
190190
const char *gvname = GVName.begin(); /* C function name */
191191
const char *wrapper;
192-
uint32 prefix_len = strlen(AOT_FUNC_PREFIX);
192+
uint32 prefix_len = (uint32)strlen(AOT_FUNC_PREFIX);
193193

194194
LOG_DEBUG("requested func %s", gvname);
195195
/* Convert "aot_func#n_wrapper" to "aot_func#n" */

core/iwasm/compilation/simd/simd_load_store.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ aot_compile_simd_load_zero(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
281281
/* data_length in bytes */
282282
static bool
283283
simd_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align,
284-
uint32 offset, uint32 data_length, LLVMValueRef value,
284+
mem_offset_t offset, uint32 data_length, LLVMValueRef value,
285285
LLVMTypeRef value_ptr_type, bool enable_segue)
286286
{
287287
LLVMValueRef maddr, result;

core/iwasm/interpreter/wasm_interp_classic.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5644,8 +5644,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
56445644
#endif
56455645

56465646
/* allowing the destination and source to overlap */
5647+
#if WASM_ENABLE_MEMORY64 == 0
56475648
bh_memmove_s(mdst, (uint32)(linear_mem_size - dst),
5648-
msrc, len);
5649+
msrc, (uint32)len);
5650+
#else
5651+
/* use memmove when memory64 is enabled since len
5652+
may be larger than UINT32_MAX */
5653+
memmove(mdst, msrc, len);
5654+
#endif
56495655
break;
56505656
}
56515657
case WASM_OP_MEMORY_FILL:

0 commit comments

Comments
 (0)