Skip to content

Commit 8ccce49

Browse files
committed
Compiler (wasm): fix int division return type to Unnormalized
min_int / (-1) produces 0x40000000 as i32 which is not a valid normalized 31-bit value. Declaring the return type as Normalized caused mismatches when the value was compared after an (ref i31) round-trip (e.g. function return).
1 parent ba1c6f8 commit 8ccce49

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

compiler/lib-wasm/generate.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,18 @@ module Generate (Target : Target_sig.S) = struct
415415
register_arith_bin_prim "%int_sub" `Pure ~typ:int_u Value.int_sub;
416416
register_arith_bin_prim "%int_mul" `Pure ~typ:int_u Value.int_mul;
417417
register_arith_bin_prim "%direct_int_mul" `Pure ~typ:int_u Value.int_mul;
418-
register_arith_bin_prim "%direct_int_div" `Pure ~typ:int_n Value.int_div;
418+
register_bin_prim
419+
"%direct_int_div"
420+
`Pure
421+
~tx:int_n
422+
~ty:int_n
423+
~ret_typ:int_u
424+
Value.int_div;
419425
register_bin_prim_ctx
420426
"%int_div"
421427
~tx:int_n
422428
~ty:int_n
423-
~ret_typ:int_n
429+
~ret_typ:int_u
424430
(fun context x y ->
425431
seq
426432
(let* cond = Arith.eqz y in

0 commit comments

Comments
 (0)