From 66e6e1f7cd94e037845c962958cade8274111a2b Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Thu, 16 Dec 2021 14:47:44 +0800 Subject: [PATCH] Clear more compile warnings reported by -Wshadow flag (#899) --- core/iwasm/aot/aot_runtime.c | 2 +- core/iwasm/compilation/aot_emit_control.c | 62 +++++++++++----------- core/iwasm/compilation/aot_emit_memory.c | 12 ++--- core/iwasm/compilation/aot_emit_variable.c | 8 +-- core/iwasm/compilation/aot_llvm.c | 7 +-- core/iwasm/interpreter/wasm_loader.c | 1 - 6 files changed, 46 insertions(+), 46 deletions(-) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 0d9dd49e..e2eb9496 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -1403,7 +1403,7 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function, bool ret; if (argc < func_type->param_cell_num) { - char buf[128]; + char buf[108]; snprintf(buf, sizeof(buf), "invalid argument count %u, must be no smaller than %u", argc, func_type->param_cell_num); diff --git a/core/iwasm/compilation/aot_emit_control.c b/core/iwasm/compilation/aot_emit_control.c index 4763a9bd..9c90cd00 100644 --- a/core/iwasm/compilation/aot_emit_control.c +++ b/core/iwasm/compilation/aot_emit_control.c @@ -74,41 +74,41 @@ format_block_name(char *name, uint32 name_size, uint32 block_index, #define SET_BUILDER_POS(llvm_block) \ LLVMPositionBuilderAtEnd(comp_ctx->builder, llvm_block) -#define CREATE_RESULT_VALUE_PHIS(block) \ - do { \ - if (block->result_count && !block->result_phis) { \ - uint32 i; \ - uint64 size; \ - LLVMBasicBlockRef block_curr = CURR_BLOCK(); \ - /* Allocate memory */ \ - size = sizeof(LLVMValueRef) * (uint64)block->result_count; \ - if (size >= UINT32_MAX \ - || !(block->result_phis = \ - wasm_runtime_malloc((uint32)size))) { \ - aot_set_last_error("allocate memory failed."); \ - goto fail; \ - } \ - SET_BUILDER_POS(block->llvm_end_block); \ - for (i = 0; i < block->result_count; i++) { \ - if (!(block->result_phis[i] = LLVMBuildPhi( \ - comp_ctx->builder, \ - TO_LLVM_TYPE(block->result_types[i]), "phi"))) { \ - aot_set_last_error("llvm build phi failed."); \ - goto fail; \ - } \ - } \ - SET_BUILDER_POS(block_curr); \ - } \ +#define CREATE_RESULT_VALUE_PHIS(block) \ + do { \ + if (block->result_count && !block->result_phis) { \ + uint32 _i; \ + uint64 _size; \ + LLVMBasicBlockRef _block_curr = CURR_BLOCK(); \ + /* Allocate memory */ \ + _size = sizeof(LLVMValueRef) * (uint64)block->result_count; \ + if (_size >= UINT32_MAX \ + || !(block->result_phis = \ + wasm_runtime_malloc((uint32)_size))) { \ + aot_set_last_error("allocate memory failed."); \ + goto fail; \ + } \ + SET_BUILDER_POS(block->llvm_end_block); \ + for (_i = 0; _i < block->result_count; _i++) { \ + if (!(block->result_phis[_i] = LLVMBuildPhi( \ + comp_ctx->builder, \ + TO_LLVM_TYPE(block->result_types[_i]), "phi"))) { \ + aot_set_last_error("llvm build phi failed."); \ + goto fail; \ + } \ + } \ + SET_BUILDER_POS(_block_curr); \ + } \ } while (0) #define ADD_TO_RESULT_PHIS(block, value, idx) \ do { \ - LLVMBasicBlockRef block_curr = CURR_BLOCK(); \ + LLVMBasicBlockRef _block_curr = CURR_BLOCK(); \ LLVMTypeRef phi_ty = LLVMTypeOf(block->result_phis[idx]); \ LLVMTypeRef value_ty = LLVMTypeOf(value); \ bh_assert(LLVMGetTypeKind(phi_ty) == LLVMGetTypeKind(value_ty)); \ bh_assert(LLVMGetTypeContext(phi_ty) == LLVMGetTypeContext(value_ty)); \ - LLVMAddIncoming(block->result_phis[idx], &value, &block_curr, 1); \ + LLVMAddIncoming(block->result_phis[idx], &value, &_block_curr, 1); \ (void)phi_ty; \ (void)value_ty; \ } while (0) @@ -122,10 +122,10 @@ format_block_name(char *name, uint32 name_size, uint32 block_index, } \ } while (0) -#define ADD_TO_PARAM_PHIS(block, value, idx) \ - do { \ - LLVMBasicBlockRef block_curr = CURR_BLOCK(); \ - LLVMAddIncoming(block->param_phis[idx], &value, &block_curr, 1); \ +#define ADD_TO_PARAM_PHIS(block, value, idx) \ + do { \ + LLVMBasicBlockRef _block_curr = CURR_BLOCK(); \ + LLVMAddIncoming(block->param_phis[idx], &value, &_block_curr, 1); \ } while (0) static LLVMBasicBlockRef diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c index c089f426..2c2cc996 100644 --- a/core/iwasm/compilation/aot_emit_memory.c +++ b/core/iwasm/compilation/aot_emit_memory.c @@ -85,7 +85,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMValueRef mem_base_addr, mem_check_bound; LLVMBasicBlockRef block_curr = LLVMGetInsertBlock(comp_ctx->builder); LLVMBasicBlockRef check_succ; - AOTValue *aot_value; + AOTValue *aot_value_top; uint32 local_idx_of_aot_value = 0; bool is_target_64bit, is_local_of_aot_value = false; #if WASM_ENABLE_SHARED_MEMORY != 0 @@ -114,13 +114,13 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } } - aot_value = + aot_value_top = func_ctx->block_stack.block_list_end->value_stack.value_list_end; - if (aot_value) { - /* aot_value is freed in the following POP_I32(addr), + if (aot_value_top) { + /* aot_value_top is freed in the following POP_I32(addr), so save its fields here for further use */ - is_local_of_aot_value = aot_value->is_local; - local_idx_of_aot_value = aot_value->local_idx; + is_local_of_aot_value = aot_value_top->is_local; + local_idx_of_aot_value = aot_value_top->local_idx; } POP_I32(addr); diff --git a/core/iwasm/compilation/aot_emit_variable.c b/core/iwasm/compilation/aot_emit_variable.c index 36069f3f..7ac6645d 100644 --- a/core/iwasm/compilation/aot_emit_variable.c +++ b/core/iwasm/compilation/aot_emit_variable.c @@ -32,7 +32,7 @@ aot_compile_op_get_local(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, { char name[32]; LLVMValueRef value; - AOTValue *aot_value; + AOTValue *aot_value_top; CHECK_LOCAL(local_idx); @@ -45,10 +45,10 @@ aot_compile_op_get_local(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, PUSH(value, get_local_type(func_ctx, local_idx)); - aot_value = + aot_value_top = func_ctx->block_stack.block_list_end->value_stack.value_list_end; - aot_value->is_local = true; - aot_value->local_idx = local_idx; + aot_value_top->is_local = true; + aot_value_top->local_idx = local_idx; return true; fail: diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index a1fe757b..796def61 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -1813,7 +1813,7 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) if (option->enable_simd) { char *tmp; - bool ret; + bool check_simd_ret; comp_ctx->enable_simd = true; @@ -1822,9 +1822,10 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) goto fail; } - ret = aot_check_simd_compatibility(comp_ctx->target_arch, tmp); + check_simd_ret = + aot_check_simd_compatibility(comp_ctx->target_arch, tmp); LLVMDisposeMessage(tmp); - if (!ret) { + if (!check_simd_ret) { aot_set_last_error("SIMD compatibility check failed, " "try adding --cpu= to specify a cpu " "or adding --disable-simd to disable SIMD"); diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index de4a0381..21f828da 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -456,7 +456,6 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, #if (WASM_ENABLE_WAMR_COMPILER != 0) || (WASM_ENABLE_JIT != 0) case INIT_EXPR_TYPE_V128_CONST: { - uint8 flag; uint64 high, low; if (type != VALUE_TYPE_V128)