Merge pull request #1060 from EXetoC/vm-arithmetic-overflow
Arithmetic underflow/overflow checking for the VM
This commit is contained in:
commit
e810c760fd
6 changed files with 105 additions and 6 deletions
11
tests/vm/toverflowopcaddimmint.nim
Normal file
11
tests/vm/toverflowopcaddimmint.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
discard """
|
||||
errormsg: "over- or underflow"
|
||||
"""
|
||||
|
||||
static:
|
||||
proc p =
|
||||
var
|
||||
x = int64.high
|
||||
discard x + 1
|
||||
assert false
|
||||
p()
|
||||
12
tests/vm/toverflowopcaddint.nim
Normal file
12
tests/vm/toverflowopcaddint.nim
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
discard """
|
||||
errormsg: "over- or underflow"
|
||||
"""
|
||||
|
||||
static:
|
||||
proc p =
|
||||
var
|
||||
x = int64.high
|
||||
y = 1
|
||||
discard x + y
|
||||
assert false
|
||||
p()
|
||||
11
tests/vm/toverflowopcmulint.nim
Normal file
11
tests/vm/toverflowopcmulint.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
discard """
|
||||
errormsg: "over- or underflow"
|
||||
"""
|
||||
|
||||
static:
|
||||
proc p =
|
||||
var
|
||||
x = 1 shl 62
|
||||
discard x * 2
|
||||
assert false
|
||||
p()
|
||||
10
tests/vm/toverflowopcsubimmint.nim
Normal file
10
tests/vm/toverflowopcsubimmint.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
discard """
|
||||
errormsg: "over- or underflow"
|
||||
"""
|
||||
|
||||
static:
|
||||
proc p =
|
||||
var x = int64.low
|
||||
discard x - 1
|
||||
assert false
|
||||
p()
|
||||
12
tests/vm/toverflowopcsubint.nim
Normal file
12
tests/vm/toverflowopcsubint.nim
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
discard """
|
||||
errormsg: "over- or underflow"
|
||||
"""
|
||||
|
||||
static:
|
||||
proc p =
|
||||
var
|
||||
x = int64.low
|
||||
y = 1
|
||||
discard x - y
|
||||
assert false
|
||||
p()
|
||||
Loading…
Add table
Add a link
Reference in a new issue