diff options
author | Araq <rumpf_a@web.de> | 2010-09-20 00:52:22 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2010-09-20 00:52:22 +0200 |
commit | f182d8d708aa3195b87a0e732faf73d3d3fa4b24 (patch) | |
tree | 22695f4baae07337b64f2f6c5327f6009cd5fc53 | |
parent | 93b3c03dbd104786a2aaa46f924e1c2c479c1fa1 (diff) | |
download | Nim-f182d8d708aa3195b87a0e732faf73d3d3fa4b24.tar.gz |
bugfix: overflow checking for small ints; bugfix: tiny C works again
-rwxr-xr-x | rod/ccgexprs.nim | 54 | ||||
-rwxr-xr-x | rod/main.nim | 1 | ||||
-rwxr-xr-x | tests/accept/run/toverflw.nim | 2 | ||||
-rwxr-xr-x | todo.txt | 2 | ||||
-rwxr-xr-x | web/news.txt | 1 |
5 files changed, 19 insertions, 41 deletions
diff --git a/rod/ccgexprs.nim b/rod/ccgexprs.nim index da5e9b084..aaf3a51ed 100755 --- a/rod/ccgexprs.nim +++ b/rod/ccgexprs.nim @@ -350,46 +350,24 @@ proc binaryArithOverflow(p: BProc, e: PNode, d: var TLoc, m: TMagic) = InitLocExpr(p, e.sons[1], a) InitLocExpr(p, e.sons[2], b) var t = skipTypes(e.typ, abstractRange) - if getSize(t) >= platform.IntSize: - if optOverflowCheck in p.options: - putIntoDest(p, d, e.typ, ropecg(p.module, - "#$1($2, $3)", [toRope(prc[m]), rdLoc(a), rdLoc(b)])) - else: - putIntoDest(p, d, e.typ, ropef("(NI$4)($2 $1 $3)", [toRope(opr[m]), - rdLoc(a), rdLoc(b), toRope(getSize(t) * 8)])) + if optOverflowCheck notin p.options: + putIntoDest(p, d, e.typ, ropef("(NI$4)($2 $1 $3)", [toRope(opr[m]), + rdLoc(a), rdLoc(b), toRope(getSize(t) * 8)])) else: - if optOverflowCheck in p.options: - if (m == mModI) or (m == mDivI): - appcg(p, cpsStmts, "if (!$1) #raiseDivByZero();$n", [rdLoc(b)]) - a.r = ropef("((NI)($2) $1 (NI)($3))", [toRope(opr[m]), rdLoc(a), rdLoc(b)]) - if d.k == locNone: getTemp(p, getSysType(tyInt), d) - genAssignment(p, d, a, {}) - appcg(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseOverflow();$n", - [rdLoc(d), intLiteral(firstOrd(t)), intLiteral(lastOrd(t))]) - d.t = e.typ - d.r = ropef("(NI$1)($2)", [toRope(getSize(t) * 8), rdLoc(d)]) - else: - putIntoDest(p, d, e.typ, ropef("(NI$4)($2 $1 $3)", [toRope(opr[m]), - rdLoc(a), rdLoc(b), toRope(getSize(t) * 8)])) - when false: - if optOverflowCheck in p.options: - # It would be better to just implement these - if getSize(t) < 4: - var tmp = getTempName() - appcg(p, cpsLocals, "NI32 $1;", [tmp]) - appcg(p, cpsStmts, "$1 = #$2($3, $4);", [tmp, toRope(prc[m]), rdLoc(a), rdLoc(b)]) - appcg(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseOverflow();$n", - [tmp, intLiteral(firstOrd(t)), intLiteral(lastOrd(t))]) - putIntoDest(p, d, e.typ, tmp) - else: - putIntoDest(p, d, e.typ, ropecg(p.module, - "#$1($2, $3)", [toRope(prc[m]), rdLoc(a), rdLoc(b)])) - appcg(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseOverflow();$n", - [rdLoc(d), intLiteral(firstOrd(t)), intLiteral(lastOrd(t))]) + var storage: PRope + var size = getSize(t) + if size < platform.IntSize: + storage = toRope("NI") else: - putIntoDest(p, d, e.typ, ropef("(NI$4)($2 $1 $3)", [toRope(opr[m]), - rdLoc(a), rdLoc(b), toRope(getSize(t) * 8)])) - + storage = getTypeDesc(p.module, t) + var tmp = getTempName() + appcg(p, cpsLocals, "$1 $2;", [storage, tmp]) + appcg(p, cpsStmts, "$1 = #$2($3, $4);", [tmp, toRope(prc[m]), + rdLoc(a), rdLoc(b)]) + if size < platform.IntSize or t.kind in {tyRange, tyEnum, tySet}: + appcg(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseOverflow();$n", + [tmp, intLiteral(firstOrd(t)), intLiteral(lastOrd(t))]) + putIntoDest(p, d, e.typ, ropef("(NI$1)($2)", [toRope(getSize(t)*8), tmp])) proc unaryArithOverflow(p: BProc, e: PNode, d: var TLoc, m: TMagic) = const diff --git a/rod/main.nim b/rod/main.nim index 46f01ddf5..a008bcc7c 100755 --- a/rod/main.nim +++ b/rod/main.nim @@ -196,6 +196,7 @@ proc MainCommand(cmd, filename: string) = gCmd = cmdRun wantFile(filename) when hasTinyCBackend: + extccomp.setCC("tcc") CommandCompileToC(filename) else: rawMessage(errInvalidCommandX, cmd) diff --git a/tests/accept/run/toverflw.nim b/tests/accept/run/toverflw.nim index c8f194e68..3dadcf13b 100755 --- a/tests/accept/run/toverflw.nim +++ b/tests/accept/run/toverflw.nim @@ -1,4 +1,4 @@ -# Tests emc's ability to detect overflows +# Tests nimrod's ability to detect overflows {.push overflowChecks: on.} diff --git a/todo.txt b/todo.txt index bd02a31ee..1f461e255 100755 --- a/todo.txt +++ b/todo.txt @@ -2,9 +2,7 @@ For version 0.8.10 ================== - fix implicit generic routines -- bugfix: ccgexprs - bugfix: make ``finally`` more robust -- bugfix: tiny C broken again! High priority (version 0.9.0) diff --git a/web/news.txt b/web/news.txt index e806c23f7..f6ca438e0 100755 --- a/web/news.txt +++ b/web/news.txt @@ -63,6 +63,7 @@ Additions - The standard library can be built as a DLL. Generating DLLs has been improved. - Added ``expat`` module. +- Added ``json`` module. 2010-03-14 Version 0.8.8 released |