Skip to content

Commit 7b724e2

Browse files
authored
fix(aot): ensure value_cmp does not exceed br_count in branch table compilation (#4065)
1 parent e6a47d5 commit 7b724e2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

core/iwasm/compilation/aot_emit_control.c

+22
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,28 @@ aot_compile_op_br_table(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
12181218
return aot_handle_next_reachable_block(comp_ctx, func_ctx, p_frame_ip);
12191219
}
12201220

1221+
/*
1222+
* if (value_cmp > br_count)
1223+
* value_cmp = br_count;
1224+
*/
1225+
LLVMValueRef br_count_value = I32_CONST(br_count);
1226+
CHECK_LLVM_CONST(br_count_value);
1227+
1228+
LLVMValueRef clap_value_cmp_cond =
1229+
LLVMBuildICmp(comp_ctx->builder, LLVMIntUGT, value_cmp, br_count_value,
1230+
"cmp_w_br_count");
1231+
if (!clap_value_cmp_cond) {
1232+
aot_set_last_error("llvm build icmp failed.");
1233+
return false;
1234+
}
1235+
1236+
value_cmp = LLVMBuildSelect(comp_ctx->builder, clap_value_cmp_cond,
1237+
br_count_value, value_cmp, "clap_value_cmp");
1238+
if (!value_cmp) {
1239+
aot_set_last_error("llvm build select failed.");
1240+
return false;
1241+
}
1242+
12211243
if (!LLVMIsEfficientConstInt(value_cmp)) {
12221244
if (comp_ctx->aot_frame) {
12231245
if (comp_ctx->enable_gc

0 commit comments

Comments
 (0)