* fixes #15210 [backport:1.2] * use patched version of bigints library
This commit is contained in:
parent
a76ae8f795
commit
ff13f8cc3c
4 changed files with 38 additions and 21 deletions
|
|
@ -1996,25 +1996,30 @@ proc genRangeChck(p: BProc, n: PNode, d: var TLoc) =
|
||||||
checkUnsignedConversions notin p.config.legacyFeatures):
|
checkUnsignedConversions notin p.config.legacyFeatures):
|
||||||
discard "no need to generate a check because it was disabled"
|
discard "no need to generate a check because it was disabled"
|
||||||
else:
|
else:
|
||||||
let raiser =
|
|
||||||
case skipTypes(n.typ, abstractVarRange).kind
|
|
||||||
of tyUInt..tyUInt64, tyChar: "raiseRangeErrorU"
|
|
||||||
of tyFloat..tyFloat128: "raiseRangeErrorF"
|
|
||||||
else: "raiseRangeErrorI"
|
|
||||||
discard cgsym(p.module, raiser)
|
|
||||||
# This seems to be bug-compatible with Nim version 1 but what we
|
|
||||||
# should really do here is to check if uint64Value < high(int)
|
|
||||||
let n0t = n[0].typ
|
let n0t = n[0].typ
|
||||||
let boundaryCast =
|
|
||||||
if n0t.skipTypes(abstractVarRange).kind in {tyUInt, tyUInt32, tyUInt64} or
|
|
||||||
(n0t.sym != nil and sfSystemModule in n0t.sym.owner.flags and n0t.sym.name.s == "csize"):
|
|
||||||
"(NI64)"
|
|
||||||
else:
|
|
||||||
""
|
|
||||||
# emit range check:
|
# emit range check:
|
||||||
linefmt(p, cpsStmts, "if ($6($1) < $2 || $6($1) > $3){ $4($1, $2, $3); $5}$n",
|
if n0t.kind in {tyUInt, tyUInt64}:
|
||||||
[rdCharLoc(a), genLiteral(p, n[1], dest), genLiteral(p, n[2], dest),
|
linefmt(p, cpsStmts, "if ($1 > ($6)($3)){ #raiseRangeErrorNoArgs(); $5}$n",
|
||||||
raiser, raiseInstr(p), boundaryCast])
|
[rdCharLoc(a), genLiteral(p, n[1], dest), genLiteral(p, n[2], dest),
|
||||||
|
raiser, raiseInstr(p), getTypeDesc(p.module, n0t)])
|
||||||
|
else:
|
||||||
|
let raiser =
|
||||||
|
case skipTypes(n.typ, abstractVarRange).kind
|
||||||
|
of tyUInt..tyUInt64, tyChar: "raiseRangeErrorU"
|
||||||
|
of tyFloat..tyFloat128: "raiseRangeErrorF"
|
||||||
|
else: "raiseRangeErrorI"
|
||||||
|
discard cgsym(p.module, raiser)
|
||||||
|
|
||||||
|
let boundaryCast =
|
||||||
|
if n0t.skipTypes(abstractVarRange).kind in {tyUInt, tyUInt32, tyUInt64} or
|
||||||
|
(n0t.sym != nil and sfSystemModule in n0t.sym.owner.flags and n0t.sym.name.s == "csize"):
|
||||||
|
"(NI64)"
|
||||||
|
else:
|
||||||
|
""
|
||||||
|
linefmt(p, cpsStmts, "if ($6($1) < $2 || $6($1) > $3){ $4($1, $2, $3); $5}$n",
|
||||||
|
[rdCharLoc(a), genLiteral(p, n[1], dest), genLiteral(p, n[2], dest),
|
||||||
|
raiser, raiseInstr(p), boundaryCast])
|
||||||
putIntoDest(p, d, n, "(($1) ($2))" %
|
putIntoDest(p, d, n, "(($1) ($2))" %
|
||||||
[getTypeDesc(p.module, dest), rdCharLoc(a)], a.storage)
|
[getTypeDesc(p.module, dest), rdCharLoc(a)], a.storage)
|
||||||
|
|
||||||
|
|
@ -2690,9 +2695,7 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
|
||||||
expr(p, n[1][0], d)
|
expr(p, n[1][0], d)
|
||||||
of nkObjDownConv: downConv(p, n, d)
|
of nkObjDownConv: downConv(p, n, d)
|
||||||
of nkObjUpConv: upConv(p, n, d)
|
of nkObjUpConv: upConv(p, n, d)
|
||||||
of nkChckRangeF: genRangeChck(p, n, d)
|
of nkChckRangeF, nkChckRange64, nkChckRange: genRangeChck(p, n, d)
|
||||||
of nkChckRange64: genRangeChck(p, n, d)
|
|
||||||
of nkChckRange: genRangeChck(p, n, d)
|
|
||||||
of nkStringToCString: convStrToCStr(p, n, d)
|
of nkStringToCString: convStrToCStr(p, n, d)
|
||||||
of nkCStringToString: convCStrToStr(p, n, d)
|
of nkCStringToString: convCStrToStr(p, n, d)
|
||||||
of nkLambdaKinds:
|
of nkLambdaKinds:
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,9 @@ proc raiseRangeErrorU(i, a, b: uint64) {.compilerproc, noinline.} =
|
||||||
# todo: better error reporting
|
# todo: better error reporting
|
||||||
sysFatal(RangeDefect, "value out of range")
|
sysFatal(RangeDefect, "value out of range")
|
||||||
|
|
||||||
|
proc raiseRangeErrorNoArgs() {.compilerproc, noinline.} =
|
||||||
|
sysFatal(RangeDefect, "value out of range")
|
||||||
|
|
||||||
proc raiseObjectConversionError() {.compilerproc, noinline.} =
|
proc raiseObjectConversionError() {.compilerproc, noinline.} =
|
||||||
sysFatal(ObjectConversionDefect, "invalid object conversion")
|
sysFatal(ObjectConversionDefect, "invalid object conversion")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ pkg1 "argparse"
|
||||||
pkg1 "arraymancer", true, "nim c tests/tests_cpu.nim"
|
pkg1 "arraymancer", true, "nim c tests/tests_cpu.nim"
|
||||||
#pkg1 "ast_pattern_matching", false, "nim c -r --oldgensym:on tests/test1.nim"
|
#pkg1 "ast_pattern_matching", false, "nim c -r --oldgensym:on tests/test1.nim"
|
||||||
pkg1 "awk", true
|
pkg1 "awk", true
|
||||||
pkg1 "bigints"
|
pkg1 "bigints", url = "https://github.com/Araq/nim-bigints"
|
||||||
pkg1 "binaryheap", false, "nim c -r binaryheap.nim"
|
pkg1 "binaryheap", false, "nim c -r binaryheap.nim"
|
||||||
pkg1 "BipBuffer"
|
pkg1 "BipBuffer"
|
||||||
# pkg1 "blscurve", true # pending https://github.com/status-im/nim-blscurve/issues/39
|
# pkg1 "blscurve", true # pending https://github.com/status-im/nim-blscurve/issues/39
|
||||||
|
|
|
||||||
|
|
@ -69,3 +69,14 @@ let rangeVar = 0'u64 ..< limit
|
||||||
doAssert repr(rangeVar) == """[a = 0,
|
doAssert repr(rangeVar) == """[a = 0,
|
||||||
b = 0]
|
b = 0]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# bug #15210
|
||||||
|
|
||||||
|
let a3 = not 0'u64
|
||||||
|
var success = false
|
||||||
|
try:
|
||||||
|
discard a3.int64
|
||||||
|
except RangeDefect:
|
||||||
|
success = true
|
||||||
|
|
||||||
|
doAssert success, "conversion should fail at runtime"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue