diff options
author | Araq <rumpf_a@web.de> | 2015-04-06 23:50:09 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-04-06 23:50:09 +0200 |
commit | 5bb3534f1058d5b15f4a9488511d8e718ac7039b (patch) | |
tree | 4c68414f111dee75090653d9cc4bb72b18efc3e5 | |
parent | 05e39cf6ad431003ed7b8388b559009e88c00e47 (diff) | |
download | Nim-5bb3534f1058d5b15f4a9488511d8e718ac7039b.tar.gz |
fixes #2427
-rw-r--r-- | compiler/ccgexprs.nim | 4 | ||||
-rw-r--r-- | tests/misc/tunsignedinc.nim | 14 |
2 files changed, 16 insertions, 2 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 0a6249f8a..75c79c0e2 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1672,7 +1672,8 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = "$# = #subInt64($#, $#);$n"] const fun: array [mInc..mDec, string] = ["$# = #addInt($#, $#);$n", "$# = #subInt($#, $#);$n"] - if optOverflowCheck notin p.options: + let underlying = skipTypes(e.sons[1].typ, {tyGenericInst, tyVar, tyRange}) + if optOverflowCheck notin p.options or underlying.kind in {tyUInt..tyUInt64}: binaryStmt(p, e, d, opr[op]) else: var a, b: TLoc @@ -1681,7 +1682,6 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = initLocExpr(p, e.sons[1], a) initLocExpr(p, e.sons[2], b) - let underlying = skipTypes(e.sons[1].typ, {tyGenericInst, tyVar, tyRange}) let ranged = skipTypes(e.sons[1].typ, {tyGenericInst, tyVar}) let res = binaryArithOverflowRaw(p, ranged, a, b, if underlying.kind == tyInt64: fun64[op] else: fun[op]) diff --git a/tests/misc/tunsignedinc.nim b/tests/misc/tunsignedinc.nim new file mode 100644 index 000000000..95622156f --- /dev/null +++ b/tests/misc/tunsignedinc.nim @@ -0,0 +1,14 @@ +discard """ + output: '''253''' +""" + +# bug #2427 + +import unsigned + +var x = 0'u8 +dec x # OverflowError +x -= 1 # OverflowError +x = x - 1 # No error + +echo x |