From b4435fe0910c903e2436c0971fe30f8f64838f2e Mon Sep 17 00:00:00 2001 From: Igor Yakovlev Date: Tue, 25 Jan 2022 13:01:43 +0100 Subject: [PATCH] [WASM] Escape wasm trap on division of s32/s64 min values on -1 --- libraries/stdlib/wasm/builtins/kotlin/Primitives.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt b/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt index f43be80ef30..06ba2f918ca 100644 --- a/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt +++ b/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt @@ -854,9 +854,8 @@ public class Int private constructor(val value: Int) : Number(), Comparable this / other.toInt() /** Divides this value by the other value. */ - @WasmOp(WasmOp.I32_DIV_S) public operator fun div(other: Int): Int = - implementedAsIntrinsic + if (this == Int.MIN_VALUE && other == -1) Int.MIN_VALUE else wasm_i32_div_s(this, other) /** Divides this value by the other value. */ public inline operator fun div(other: Long): Long = @@ -1252,9 +1251,8 @@ public class Long private constructor(val value: Long) : Number(), Comparable