bugfix: overflow checking for small ints; bugfix: tiny C works again
This commit is contained in:
parent
93b3c03dbd
commit
f182d8d708
5 changed files with 19 additions and 41 deletions
|
|
@ -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[1], a)
|
||||||
InitLocExpr(p, e.sons[2], b)
|
InitLocExpr(p, e.sons[2], b)
|
||||||
var t = skipTypes(e.typ, abstractRange)
|
var t = skipTypes(e.typ, abstractRange)
|
||||||
if getSize(t) >= platform.IntSize:
|
if optOverflowCheck notin p.options:
|
||||||
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]),
|
putIntoDest(p, d, e.typ, ropef("(NI$4)($2 $1 $3)", [toRope(opr[m]),
|
||||||
rdLoc(a), rdLoc(b), toRope(getSize(t) * 8)]))
|
rdLoc(a), rdLoc(b), toRope(getSize(t) * 8)]))
|
||||||
else:
|
else:
|
||||||
if optOverflowCheck in p.options:
|
var storage: PRope
|
||||||
if (m == mModI) or (m == mDivI):
|
var size = getSize(t)
|
||||||
appcg(p, cpsStmts, "if (!$1) #raiseDivByZero();$n", [rdLoc(b)])
|
if size < platform.IntSize:
|
||||||
a.r = ropef("((NI)($2) $1 (NI)($3))", [toRope(opr[m]), rdLoc(a), rdLoc(b)])
|
storage = toRope("NI")
|
||||||
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:
|
else:
|
||||||
putIntoDest(p, d, e.typ, ropef("(NI$4)($2 $1 $3)", [toRope(opr[m]),
|
storage = getTypeDesc(p.module, t)
|
||||||
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()
|
var tmp = getTempName()
|
||||||
appcg(p, cpsLocals, "NI32 $1;", [tmp])
|
appcg(p, cpsLocals, "$1 $2;", [storage, tmp])
|
||||||
appcg(p, cpsStmts, "$1 = #$2($3, $4);", [tmp, toRope(prc[m]), rdLoc(a), rdLoc(b)])
|
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",
|
appcg(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseOverflow();$n",
|
||||||
[tmp, intLiteral(firstOrd(t)), intLiteral(lastOrd(t))])
|
[tmp, intLiteral(firstOrd(t)), intLiteral(lastOrd(t))])
|
||||||
putIntoDest(p, d, e.typ, tmp)
|
putIntoDest(p, d, e.typ, ropef("(NI$1)($2)", [toRope(getSize(t)*8), 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))])
|
|
||||||
else:
|
|
||||||
putIntoDest(p, d, e.typ, ropef("(NI$4)($2 $1 $3)", [toRope(opr[m]),
|
|
||||||
rdLoc(a), rdLoc(b), toRope(getSize(t) * 8)]))
|
|
||||||
|
|
||||||
|
|
||||||
proc unaryArithOverflow(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
|
proc unaryArithOverflow(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
|
||||||
const
|
const
|
||||||
|
|
|
||||||
|
|
@ -196,6 +196,7 @@ proc MainCommand(cmd, filename: string) =
|
||||||
gCmd = cmdRun
|
gCmd = cmdRun
|
||||||
wantFile(filename)
|
wantFile(filename)
|
||||||
when hasTinyCBackend:
|
when hasTinyCBackend:
|
||||||
|
extccomp.setCC("tcc")
|
||||||
CommandCompileToC(filename)
|
CommandCompileToC(filename)
|
||||||
else:
|
else:
|
||||||
rawMessage(errInvalidCommandX, cmd)
|
rawMessage(errInvalidCommandX, cmd)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
# Tests emc's ability to detect overflows
|
# Tests nimrod's ability to detect overflows
|
||||||
|
|
||||||
{.push overflowChecks: on.}
|
{.push overflowChecks: on.}
|
||||||
|
|
||||||
|
|
|
||||||
2
todo.txt
2
todo.txt
|
|
@ -2,9 +2,7 @@ For version 0.8.10
|
||||||
==================
|
==================
|
||||||
|
|
||||||
- fix implicit generic routines
|
- fix implicit generic routines
|
||||||
- bugfix: ccgexprs
|
|
||||||
- bugfix: make ``finally`` more robust
|
- bugfix: make ``finally`` more robust
|
||||||
- bugfix: tiny C broken again!
|
|
||||||
|
|
||||||
|
|
||||||
High priority (version 0.9.0)
|
High priority (version 0.9.0)
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ Additions
|
||||||
- The standard library can be built as a DLL. Generating DLLs has been
|
- The standard library can be built as a DLL. Generating DLLs has been
|
||||||
improved.
|
improved.
|
||||||
- Added ``expat`` module.
|
- Added ``expat`` module.
|
||||||
|
- Added ``json`` module.
|
||||||
|
|
||||||
|
|
||||||
2010-03-14 Version 0.8.8 released
|
2010-03-14 Version 0.8.8 released
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue