@@ -2089,6 +2089,9 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
20892089 LLVMValueRef ext_ret_offset , ext_ret_ptr , ext_ret , res ;
20902090 LLVMValueRef * param_values = NULL , * value_rets = NULL ;
20912091 LLVMValueRef * result_phis = NULL , value_ret , import_func_count ;
2092+ #if WASM_ENABLE_MEMORY64 != 0
2093+ LLVMValueRef u32_max , u32_cmp_result ;
2094+ #endif
20922095 LLVMTypeRef * param_types = NULL , ret_type ;
20932096 LLVMTypeRef llvm_func_type , llvm_func_ptr_type ;
20942097 LLVMTypeRef ext_ret_ptr_type ;
@@ -2153,7 +2156,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
21532156 func_param_count = func_type -> param_count ;
21542157 func_result_count = func_type -> result_count ;
21552158
2156- POP_I32 (elem_idx );
2159+ POP_TBL_ELEM_IDX (elem_idx );
21572160
21582161 /* get the cur size of the table instance */
21592162 if (!(offset = I32_CONST (get_tbl_inst_offset (comp_ctx , func_ctx , tbl_idx )
@@ -2182,14 +2185,47 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
21822185 goto fail ;
21832186 }
21842187
2188+ #if WASM_ENABLE_MEMORY64 != 0
2189+ /* Check if elem index >= UINT32_MAX */
2190+ if (IS_TABLE64 (tbl_idx )) {
2191+ if (!(u32_max = I64_CONST (UINT32_MAX ))) {
2192+ aot_set_last_error ("llvm build const failed" );
2193+ goto fail ;
2194+ }
2195+ if (!(u32_cmp_result =
2196+ LLVMBuildICmp (comp_ctx -> builder , LLVMIntUGE , elem_idx ,
2197+ u32_max , "cmp_elem_idx_u32_max" ))) {
2198+ aot_set_last_error ("llvm build icmp failed." );
2199+ goto fail ;
2200+ }
2201+ if (!(elem_idx = LLVMBuildTrunc (comp_ctx -> builder , elem_idx , I32_TYPE ,
2202+ "elem_idx_i32" ))) {
2203+ aot_set_last_error ("llvm build trunc failed." );
2204+ goto fail ;
2205+ }
2206+ }
2207+ #endif
2208+
21852209 /* Check if (uint32)elem index >= table size */
21862210 if (!(cmp_elem_idx = LLVMBuildICmp (comp_ctx -> builder , LLVMIntUGE , elem_idx ,
21872211 table_size_const , "cmp_elem_idx" ))) {
21882212 aot_set_last_error ("llvm build icmp failed." );
21892213 goto fail ;
21902214 }
21912215
2192- /* Throw exception if elem index >= table size */
2216+ #if WASM_ENABLE_MEMORY64 != 0
2217+ if (IS_TABLE64 (tbl_idx )) {
2218+ if (!(cmp_elem_idx =
2219+ LLVMBuildOr (comp_ctx -> builder , cmp_elem_idx , u32_cmp_result ,
2220+ "larger_than_u32_max_or_cur_size" ))) {
2221+ aot_set_last_error ("llvm build or failed." );
2222+ goto fail ;
2223+ }
2224+ }
2225+ #endif
2226+
2227+ /* Throw exception if elem index >= table size or elem index >= UINT32_MAX
2228+ */
21932229 if (!(check_elem_idx_succ = LLVMAppendBasicBlockInContext (
21942230 comp_ctx -> context , func_ctx -> func , "check_elem_idx_succ" ))) {
21952231 aot_set_last_error ("llvm add basic block failed." );
0 commit comments