diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 29e11db1..ca8e3cea 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -215,13 +215,11 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module, module_inst->mem_cur_page_count = module->mem_init_page_count; module_inst->mem_max_page_count = module->mem_max_page_count; - module_inst->mem_bound_check_heap_base = module_inst->heap_base_offset; - if (module_inst->memory_data_size > 0) { - module_inst->mem_bound_check_1byte = module_inst->memory_data_size - 1; - module_inst->mem_bound_check_2bytes = module_inst->memory_data_size - 2; - module_inst->mem_bound_check_4bytes = module_inst->memory_data_size - 4; - module_inst->mem_bound_check_8bytes = module_inst->memory_data_size - 8; - } + module_inst->mem_bound_check_heap_base = (int64)module_inst->heap_base_offset; + module_inst->mem_bound_check_1byte = (int64)module_inst->memory_data_size - 1; + module_inst->mem_bound_check_2bytes = (int64)module_inst->memory_data_size - 2; + module_inst->mem_bound_check_4bytes = (int64)module_inst->memory_data_size - 4; + module_inst->mem_bound_check_8bytes = (int64)module_inst->memory_data_size - 8; for (i = 0; i < module->mem_init_data_count; i++) { data_seg = module->mem_init_data_list[i]; diff --git a/core/iwasm/aot/aot_runtime.h b/core/iwasm/aot/aot_runtime.h index b42f12a2..a2f4908a 100644 --- a/core/iwasm/aot/aot_runtime.h +++ b/core/iwasm/aot/aot_runtime.h @@ -211,7 +211,7 @@ typedef struct AOTModuleInstance { uint32 default_wasm_stack_size; /* reserved */ - uint32 reserved[12]; + uint32 reserved[11]; union { uint64 _make_it_8_byte_aligned_; diff --git a/core/iwasm/compilation/aot_emit_control.c b/core/iwasm/compilation/aot_emit_control.c index 4dbaabb0..bbb470a2 100644 --- a/core/iwasm/compilation/aot_emit_control.c +++ b/core/iwasm/compilation/aot_emit_control.c @@ -144,10 +144,23 @@ handle_next_reachable_block(AOTCompContext *comp_ctx, block_prev = block->prev; block = aot_block_stack_pop(&func_ctx->block_stack); - if (block->block_type == BLOCK_TYPE_IF - && block->llvm_end_block) { - LLVMDeleteBasicBlock(block->llvm_end_block); - block->llvm_end_block = NULL; + if (block->block_type == BLOCK_TYPE_IF) { + if (block->llvm_else_block + && !block->skip_wasm_code_else + && *p_frame_ip <= block->wasm_code_else) { + /* Clear value stack and start to translate else branch */ + aot_value_stack_destroy(&block->value_stack); + SET_BUILDER_POS(block->llvm_else_block); + *p_frame_ip = block->wasm_code_else + 1; + /* Push back the block */ + aot_block_stack_push(&func_ctx->block_stack, block); + return true; + } + else if (block->llvm_end_block) { + /* Remove unreachable basic block */ + LLVMDeleteBasicBlock(block->llvm_end_block); + block->llvm_end_block = NULL; + } } frame_ip = block->wasm_code_end; diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c index 46292660..b6d49758 100644 --- a/core/iwasm/compilation/aot_emit_memory.c +++ b/core/iwasm/compilation/aot_emit_memory.c @@ -111,7 +111,7 @@ check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, && mem_offset <= mem_data_size - bytes) { /* inside memory space */ offset1 = I32_CONST((uint32)mem_offset); - CHECK_LLVM_CONST(offset_const); + CHECK_LLVM_CONST(offset1); if (!(maddr = LLVMBuildInBoundsGEP(comp_ctx->builder, mem_base_addr, &offset1, 1, "maddr"))) { aot_set_last_error("llvm build add failed.");