Browse Source

Clear more compile warnings reported by -Wshadow flag (#899)

Wenyong Huang 4 năm trước cách đây
mục cha
commit
66e6e1f7cd

+ 1 - 1
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);

+ 31 - 31
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

+ 6 - 6
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);

+ 4 - 4
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:

+ 4 - 3
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=<cpu> to specify a cpu "
                                "or adding --disable-simd to disable SIMD");

+ 0 - 1
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)