Skip to content

Commit

Permalink
range check for ->Int64
Browse files Browse the repository at this point in the history
relaxing the fits_signed_bits contract to work with 64
  • Loading branch information
ggreif committed Jun 11, 2019
1 parent 76dc485 commit 393e979
Show file tree
Hide file tree
Showing 15 changed files with 613 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ sig
(* given a numeric object on the stack as skewed pointer, check whether
it can be faithfully stored in N bits, including a leading sign bit
leaves boolean result on the stack
N must be 2..63
N must be 2..64
*)
val fits_signed_bits : E.t -> int -> G.t
(* given a numeric object on the stack as skewed pointer, check whether
Expand Down Expand Up @@ -4651,8 +4651,13 @@ and compile_exp (env : E.t) ae exp =

| "Int->Int64" ->
SR.UnboxedWord64,
let (set_num, get_num) = new_local env "num" in
compile_exp_vanilla env ae e ^^
BigNum.truncate_to_word64 env (* FIXME: trap if it doesn't fit *)
set_num ^^ get_num ^^
BigNum.fits_signed_bits env 64 ^^
E.else_trap_with env "Losing precision" ^^
get_num ^^
BigNum.truncate_to_word64 env

| "Int->Int32"
| "Int->Int16"
Expand Down
10 changes: 10 additions & 0 deletions test/fail/ok/outrange-int64lower.diff-ir.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- outrange-int64lower.run
+++ outrange-int64lower.run-ir
@@ -1,6 +1,7 @@
prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed

Last environment:
+$param/8 = -9_223_372_036_854_775_809
@new_async = func
@text_of_Bool = func
@text_of_Int = func
10 changes: 10 additions & 0 deletions test/fail/ok/outrange-int64lower.diff-low.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- outrange-int64lower.run
+++ outrange-int64lower.run-low
@@ -1,6 +1,7 @@
prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed

Last environment:
+$param/8 = -9_223_372_036_854_775_809
@new_async = func
@text_of_Bool = func
@text_of_Int = func
94 changes: 94 additions & 0 deletions test/fail/ok/outrange-int64lower.run-ir.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed

Last environment:
$param/8 = -9_223_372_036_854_775_809
@new_async = func
@text_of_Bool = func
@text_of_Int = func
@text_of_Nat = func
@text_of_Text = func
@text_of_array = func
@text_of_array_mut = func
@text_of_option = func
@text_of_variant = func
Array_init = func
Array_tabulate = func
abs = func
btstWord16 = func
btstWord32 = func
btstWord64 = func
btstWord8 = func
charToText = func
charToWord32 = func
clzWord16 = func
clzWord32 = func
clzWord64 = func
clzWord8 = func
ctzWord16 = func
ctzWord32 = func
ctzWord64 = func
ctzWord8 = func
decodeUTF8 = func
hashInt = func
ignore = func
int16ToInt = func
int16ToWord16 = func
int32ToInt = func
int32ToWord32 = func
int64ToInt = func
int64ToWord64 = func
int8ToInt = func
int8ToWord8 = func
intToInt16 = func
intToInt32 = func
intToInt64 = func
intToInt8 = func
intToWord16 = func
intToWord32 = func
intToWord64 = func
intToWord8 = func
n = -9_223_372_036_854_775_809
nat16ToNat = func
nat16ToWord16 = func
nat32ToNat = func
nat32ToWord32 = func
nat64ToNat = func
nat64ToWord64 = func
nat8ToNat = func
nat8ToWord8 = func
natToNat16 = func
natToNat32 = func
natToNat64 = func
natToNat8 = func
natToWord16 = func
natToWord32 = func
natToWord64 = func
natToWord8 = func
popcntWord16 = func
popcntWord32 = func
popcntWord64 = func
popcntWord8 = func
print = func
printChar = func
printInt = func
range = func
revrange = func
rts_version = func
word16ToInt = func
word16ToInt16 = func
word16ToNat = func
word16ToNat16 = func
word32ToChar = func
word32ToInt = func
word32ToInt32 = func
word32ToNat = func
word32ToNat32 = func
word64ToInt = func
word64ToInt64 = func
word64ToNat = func
word64ToNat64 = func
word8ToInt = func
word8ToInt8 = func
word8ToNat = func
word8ToNat8 = func

94 changes: 94 additions & 0 deletions test/fail/ok/outrange-int64lower.run-low.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed

Last environment:
$param/8 = -9_223_372_036_854_775_809
@new_async = func
@text_of_Bool = func
@text_of_Int = func
@text_of_Nat = func
@text_of_Text = func
@text_of_array = func
@text_of_array_mut = func
@text_of_option = func
@text_of_variant = func
Array_init = func
Array_tabulate = func
abs = func
btstWord16 = func
btstWord32 = func
btstWord64 = func
btstWord8 = func
charToText = func
charToWord32 = func
clzWord16 = func
clzWord32 = func
clzWord64 = func
clzWord8 = func
ctzWord16 = func
ctzWord32 = func
ctzWord64 = func
ctzWord8 = func
decodeUTF8 = func
hashInt = func
ignore = func
int16ToInt = func
int16ToWord16 = func
int32ToInt = func
int32ToWord32 = func
int64ToInt = func
int64ToWord64 = func
int8ToInt = func
int8ToWord8 = func
intToInt16 = func
intToInt32 = func
intToInt64 = func
intToInt8 = func
intToWord16 = func
intToWord32 = func
intToWord64 = func
intToWord8 = func
n = -9_223_372_036_854_775_809
nat16ToNat = func
nat16ToWord16 = func
nat32ToNat = func
nat32ToWord32 = func
nat64ToNat = func
nat64ToWord64 = func
nat8ToNat = func
nat8ToWord8 = func
natToNat16 = func
natToNat32 = func
natToNat64 = func
natToNat8 = func
natToWord16 = func
natToWord32 = func
natToWord64 = func
natToWord8 = func
popcntWord16 = func
popcntWord32 = func
popcntWord64 = func
popcntWord8 = func
print = func
printChar = func
printInt = func
range = func
revrange = func
rts_version = func
word16ToInt = func
word16ToInt16 = func
word16ToNat = func
word16ToNat16 = func
word32ToChar = func
word32ToInt = func
word32ToInt32 = func
word32ToNat = func
word32ToNat32 = func
word64ToInt = func
word64ToInt64 = func
word64ToNat = func
word64ToNat64 = func
word8ToInt = func
word8ToInt8 = func
word8ToNat = func
word8ToNat8 = func

93 changes: 93 additions & 0 deletions test/fail/ok/outrange-int64lower.run.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed

Last environment:
@new_async = func
@text_of_Bool = func
@text_of_Int = func
@text_of_Nat = func
@text_of_Text = func
@text_of_array = func
@text_of_array_mut = func
@text_of_option = func
@text_of_variant = func
Array_init = func
Array_tabulate = func
abs = func
btstWord16 = func
btstWord32 = func
btstWord64 = func
btstWord8 = func
charToText = func
charToWord32 = func
clzWord16 = func
clzWord32 = func
clzWord64 = func
clzWord8 = func
ctzWord16 = func
ctzWord32 = func
ctzWord64 = func
ctzWord8 = func
decodeUTF8 = func
hashInt = func
ignore = func
int16ToInt = func
int16ToWord16 = func
int32ToInt = func
int32ToWord32 = func
int64ToInt = func
int64ToWord64 = func
int8ToInt = func
int8ToWord8 = func
intToInt16 = func
intToInt32 = func
intToInt64 = func
intToInt8 = func
intToWord16 = func
intToWord32 = func
intToWord64 = func
intToWord8 = func
n = -9_223_372_036_854_775_809
nat16ToNat = func
nat16ToWord16 = func
nat32ToNat = func
nat32ToWord32 = func
nat64ToNat = func
nat64ToWord64 = func
nat8ToNat = func
nat8ToWord8 = func
natToNat16 = func
natToNat32 = func
natToNat64 = func
natToNat8 = func
natToWord16 = func
natToWord32 = func
natToWord64 = func
natToWord8 = func
popcntWord16 = func
popcntWord32 = func
popcntWord64 = func
popcntWord8 = func
print = func
printChar = func
printInt = func
range = func
revrange = func
rts_version = func
word16ToInt = func
word16ToInt16 = func
word16ToNat = func
word16ToNat16 = func
word32ToChar = func
word32ToInt = func
word32ToInt32 = func
word32ToNat = func
word32ToNat32 = func
word64ToInt = func
word64ToInt64 = func
word64ToNat = func
word64ToNat64 = func
word8ToInt = func
word8ToInt8 = func
word8ToNat = func
word8ToNat8 = func

1 change: 1 addition & 0 deletions test/fail/ok/outrange-int64lower.wasm-run.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_out/outrange-int64lower.wasm:0x___: runtime trap: unreachable executed
10 changes: 10 additions & 0 deletions test/fail/ok/outrange-int64upper.diff-ir.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- outrange-int64upper.run
+++ outrange-int64upper.run-ir
@@ -1,6 +1,7 @@
prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed

Last environment:
+$param/8 = 9_223_372_036_854_775_808
@new_async = func
@text_of_Bool = func
@text_of_Int = func
10 changes: 10 additions & 0 deletions test/fail/ok/outrange-int64upper.diff-low.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- outrange-int64upper.run
+++ outrange-int64upper.run-low
@@ -1,6 +1,7 @@
prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed

Last environment:
+$param/8 = 9_223_372_036_854_775_808
@new_async = func
@text_of_Bool = func
@text_of_Int = func
Loading

0 comments on commit 393e979

Please sign in to comment.