Просмотр исходного кода

Fix aot rotl/rotr 0 issue (#1285)

Fix the issue reported in #1282.
When i32/i64 rotate (rotl/rotr) with 0, the LLVM IRs translated are:
left<<0 | left>>64 and left >>0 | left<<64
The value of left >> 64 and left <<64 in LLVM are treated as poison,
which causes invalid result when executing the aot function.

Directly return left when right is 0 to fix the issue.
Wenyong Huang 3 лет назад
Родитель
Сommit
177aa4fc79
1 измененных файлов с 4 добавлено и 0 удалено
  1. 4 0
      core/iwasm/compilation/aot_emit_numberic.c

+ 4 - 0
core/iwasm/compilation/aot_emit_numberic.c

@@ -692,6 +692,10 @@ compile_int_rot(AOTCompContext *comp_ctx, LLVMValueRef left, LLVMValueRef right,
 
     SHIFT_COUNT_MASK;
 
+    /* rotl/rotr with 0 */
+    if (IS_CONST_ZERO(right))
+        return left;
+
     /* Calculate (bits - shif_count) */
     LLVM_BUILD_OP(Sub, is_i32 ? I32_32 : I64_64, right, bits_minus_shift_count,
                   "bits_minus_shift_count", NULL);