diff options
-rw-r--r-- | compiler/vmgen.nim | 8 | ||||
-rw-r--r-- | tests/vm/tmisc_vm.nim | 14 |
2 files changed, 20 insertions, 2 deletions
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 09e02f818..b528ff7be 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -948,9 +948,13 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = c.genAddSubInt(n, dest, opcAddInt) of mInc, mDec: unused(c, n, dest) - let opc = if m == mInc: opcAddInt else: opcSubInt + let isUnsigned = n.sons[1].typ.skipTypes(abstractVarRange).kind in {tyUInt..tyUInt64} + let opc = if not isUnsigned: + if m == mInc: opcAddInt else: opcSubInt + else: + if m == mInc: opcAddu else: opcSubu let d = c.genx(n.sons[1]) - if n.sons[2].isInt8Lit: + if n.sons[2].isInt8Lit and not isUnsigned: c.gABI(n, succ(opc), d, d, n.sons[2].intVal) else: let tmp = c.genx(n.sons[2]) diff --git a/tests/vm/tmisc_vm.nim b/tests/vm/tmisc_vm.nim index 7d7275426..57dc526c5 100644 --- a/tests/vm/tmisc_vm.nim +++ b/tests/vm/tmisc_vm.nim @@ -200,3 +200,17 @@ const vmCrash = oh_no() debugEcho vmCrash + + +# bug #12310 + +proc someTransform(s: var array[8, uint64]) = + var s1 = 5982491417506315008'u64 + s[1] += s1 + +static: + var state: array[8, uint64] + state[1] = 7105036623409894663'u64 + someTransform(state) + + doAssert state[1] == 13087528040916209671'u64 |