Skip to content

Commit 327374c

Browse files
authored
Fix some compile warnings and typos (#3854)
- Clear some compile warnings - Fix some typos - Fix llvm LICENSE link error - Remove unused aot file and binarydump bin - Add checks when loading AOT exports
1 parent b038f27 commit 327374c

File tree

17 files changed

+94
-29
lines changed

17 files changed

+94
-29
lines changed

ATTRIBUTIONS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the
6060

6161
### llvm
6262

63-
[LICENSE](./LICENCE.txt)
63+
[LICENSE](./LICENSE)
6464

6565
### wasm-c-api
6666

core/iwasm/aot/aot_loader.c

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,7 +2760,7 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
27602760
const uint8 *buf = *p_buf;
27612761
AOTExport *exports;
27622762
uint64 size;
2763-
uint32 i;
2763+
uint32 i, j;
27642764

27652765
/* Allocate memory */
27662766
size = sizeof(AOTExport) * (uint64)module->export_count;
@@ -2774,14 +2774,60 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
27742774
read_uint32(buf, buf_end, exports[i].index);
27752775
read_uint8(buf, buf_end, exports[i].kind);
27762776
read_string(buf, buf_end, exports[i].name);
2777-
#if 0 /* TODO: check kind and index */
2778-
if (export_funcs[i].index >=
2779-
module->func_count + module->import_func_count) {
2780-
set_error_buf(error_buf, error_buf_size,
2781-
"function index is out of range");
2782-
return false;
2777+
2778+
for (j = 0; j < i; j++) {
2779+
if (!strcmp(exports[i].name, exports[j].name)) {
2780+
set_error_buf(error_buf, error_buf_size,
2781+
"duplicate export name");
2782+
return false;
2783+
}
27832784
}
2785+
2786+
/* Check export kind and index */
2787+
switch (exports[i].kind) {
2788+
case EXPORT_KIND_FUNC:
2789+
if (exports[i].index
2790+
>= module->import_func_count + module->func_count) {
2791+
set_error_buf(error_buf, error_buf_size,
2792+
"unknown function");
2793+
return false;
2794+
}
2795+
break;
2796+
case EXPORT_KIND_TABLE:
2797+
if (exports[i].index
2798+
>= module->import_table_count + module->table_count) {
2799+
set_error_buf(error_buf, error_buf_size, "unknown table");
2800+
return false;
2801+
}
2802+
break;
2803+
case EXPORT_KIND_MEMORY:
2804+
if (exports[i].index
2805+
>= module->import_memory_count + module->memory_count) {
2806+
set_error_buf(error_buf, error_buf_size, "unknown memory");
2807+
return false;
2808+
}
2809+
break;
2810+
case EXPORT_KIND_GLOBAL:
2811+
if (exports[i].index
2812+
>= module->import_global_count + module->global_count) {
2813+
set_error_buf(error_buf, error_buf_size, "unknown global");
2814+
return false;
2815+
}
2816+
break;
2817+
#if WASM_ENABLE_TAGS != 0
2818+
/* TODO
2819+
case EXPORT_KIND_TAG:
2820+
if (index >= module->import_tag_count + module->tag_count) {
2821+
set_error_buf(error_buf, error_buf_size, "unknown tag");
2822+
return false;
2823+
}
2824+
break;
2825+
*/
27842826
#endif
2827+
default:
2828+
set_error_buf(error_buf, error_buf_size, "invalid export kind");
2829+
return false;
2830+
}
27852831
}
27862832

27872833
*p_buf = buf;

core/iwasm/aot/aot_runtime.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ is_frame_per_function(WASMExecEnv *exec_env)
137137
return module->feature_flags & WASM_FEATURE_FRAME_PER_FUNCTION;
138138
}
139139

140+
#if WASM_ENABLE_DUMP_CALL_STACK != 0
140141
static bool
141142
is_frame_func_idx_disabled(WASMExecEnv *exec_env)
142143
{
@@ -145,6 +146,7 @@ is_frame_func_idx_disabled(WASMExecEnv *exec_env)
145146

146147
return module->feature_flags & WASM_FEATURE_FRAME_NO_FUNC_IDX;
147148
}
149+
#endif
148150

149151
static void *
150152
get_top_frame(WASMExecEnv *exec_env)
@@ -1478,9 +1480,7 @@ create_exports(AOTModuleInstance *module_inst, AOTModule *module,
14781480
}
14791481
}
14801482

1481-
#if WASM_ENABLE_MULTI_MEMORY == 0
1482-
bh_assert(module_inst->export_memory_count <= 1);
1483-
#else
1483+
#if WASM_ENABLE_MULTI_MEMORY != 0
14841484
if (module_inst->export_memory_count) {
14851485
module_inst->export_memories = export_memories_instantiate(
14861486
module, module_inst, module_inst->export_memory_count, error_buf,

core/iwasm/common/wasm_runtime_common.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3610,7 +3610,8 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
36103610
char mapping_copy_buf[256];
36113611
char *mapping_copy = mapping_copy_buf;
36123612
char *map_mapped = NULL, *map_host = NULL;
3613-
const unsigned long max_len = strlen(map_dir_list[i]) * 2 + 3;
3613+
const unsigned long max_len =
3614+
(unsigned long)strlen(map_dir_list[i]) * 2 + 3;
36143615

36153616
/* Allocation limit for runtime environments with reduced stack size */
36163617
if (max_len > 256) {

core/iwasm/compilation/aot_emit_control.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ check_suspend_flags(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
912912
aot_set_last_error("llvm build LOAD failed");
913913
return false;
914914
}
915-
/* Set terminate_flags memory accecc to volatile, so that the value
915+
/* Set terminate_flags memory access to volatile, so that the value
916916
will always be loaded from memory rather than register */
917917
LLVMSetVolatile(terminate_flags, true);
918918

core/iwasm/compilation/aot_emit_function.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
20902090
LLVMValueRef *param_values = NULL, *value_rets = NULL;
20912091
LLVMValueRef *result_phis = NULL, value_ret, import_func_count;
20922092
#if WASM_ENABLE_MEMORY64 != 0
2093-
LLVMValueRef u32_max, u32_cmp_result;
2093+
LLVMValueRef u32_max, u32_cmp_result = NULL;
20942094
#endif
20952095
LLVMTypeRef *param_types = NULL, ret_type;
20962096
LLVMTypeRef llvm_func_type, llvm_func_ptr_type;

core/iwasm/compilation/aot_emit_table.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "aot_emit_gc.h"
1111
#endif
1212

13+
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
14+
#if WASM_ENABLE_MEMORY64 != 0
1315
static bool
1416
zero_extend_u64(AOTCompContext *comp_ctx, LLVMValueRef *value, const char *name)
1517
{
@@ -23,17 +25,18 @@ zero_extend_u64(AOTCompContext *comp_ctx, LLVMValueRef *value, const char *name)
2325
}
2426
return true;
2527
}
28+
#endif
2629

2730
/* check whether a table64 elem idx is greater than UINT32_MAX, if so, throw
2831
* exception, otherwise trunc it to uint32 */
2932
static bool
3033
check_tbl_elem_idx_and_trunc(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
3134
LLVMValueRef *elem_idx, uint32 tbl_idx)
3235
{
36+
#if WASM_ENABLE_MEMORY64 != 0
3337
LLVMValueRef u32_max, u32_cmp_result;
3438
LLVMBasicBlockRef check_elem_idx_succ;
3539

36-
#if WASM_ENABLE_MEMORY64 != 0
3740
if (!IS_TABLE64(tbl_idx)) {
3841
return true;
3942
}
@@ -69,12 +72,15 @@ check_tbl_elem_idx_and_trunc(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
6972
EXCE_OUT_OF_BOUNDS_TABLE_ACCESS, true,
7073
u32_cmp_result, check_elem_idx_succ)))
7174
goto fail;
72-
#endif
7375

7476
return true;
7577
fail:
7678
return false;
79+
#else
80+
return true;
81+
#endif
7782
}
83+
#endif /* WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC !=0 */
7884

7985
uint64
8086
get_tbl_inst_offset(const AOTCompContext *comp_ctx,
@@ -738,4 +744,4 @@ aot_compile_op_table_fill(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
738744
return false;
739745
}
740746

741-
#endif /* WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC !=0 */
747+
#endif /* WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC !=0 */

core/iwasm/include/wasm_export.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,8 +1166,8 @@ wasm_application_execute_main(wasm_module_inst_t module_inst, int32_t argc,
11661166
char *argv[]);
11671167

11681168
/**
1169-
* Find the specified function in argv[0] from a WASM module instance
1170-
* and execute that function.
1169+
* Find the specified function from a WASM module instance and execute
1170+
* that function.
11711171
*
11721172
* @param module_inst the WASM module instance
11731173
* @param name the name of the function to execute.

core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,8 @@ execute_interruptible_poll_oneoff(
10221022
uint32 i;
10231023

10241024
const __wasi_timestamp_t timeout = get_timeout_for_poll_oneoff(
1025-
in, nsubscriptions),
1026-
time_quant = 1e9;
1025+
in, (uint32)nsubscriptions),
1026+
time_quant = (__wasi_timestamp_t)1e9;
10271027
const uint64 size_to_copy =
10281028
nsubscriptions * (uint64)sizeof(wasi_subscription_t);
10291029
__wasi_subscription_t *in_copy = NULL;
@@ -1034,12 +1034,13 @@ execute_interruptible_poll_oneoff(
10341034
return __WASI_ENOMEM;
10351035
}
10361036

1037-
bh_memcpy_s(in_copy, size_to_copy, in, size_to_copy);
1037+
bh_memcpy_s(in_copy, (uint32)size_to_copy, in, (uint32)size_to_copy);
10381038

10391039
while (timeout == (__wasi_timestamp_t)-1 || elapsed <= timeout) {
10401040
/* update timeout for clock subscription events */
10411041
update_clock_subscription_data(
1042-
in_copy, nsubscriptions, min_uint64(time_quant, timeout - elapsed));
1042+
in_copy, (uint32)nsubscriptions,
1043+
min_uint64(time_quant, timeout - elapsed));
10431044
err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in_copy, out,
10441045
nsubscriptions, nevents);
10451046
elapsed += time_quant;

core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3130,7 +3130,7 @@ compare_address(const struct addr_pool *addr_pool_entry,
31303130
}
31313131
addr_size = 16;
31323132
}
3133-
max_addr_mask = addr_size * 8;
3133+
max_addr_mask = (uint8)(addr_size * 8);
31343134

31353135
/* IPv4 0.0.0.0 or IPv6 :: means any address */
31363136
if (basebuf[0] == 0 && !memcmp(basebuf, basebuf + 1, addr_size - 1)) {

0 commit comments

Comments
 (0)