fixes #23378; fixes js abs negative int64 (#23379)

fixes #23378
This commit is contained in:
ringabout
2024-03-09 18:41:39 +08:00
committed by GitHub
parent 6ebad30e7a
commit f80a5a30b4
2 changed files with 15 additions and 1 deletions

View File

@@ -788,7 +788,13 @@ proc arithAux(p: PProc, n: PNode, r: var TCompRes, op: TMagic) =
of mEqProc: applyFormat("($1 == $2)", "($1 == $2)")
of mUnaryMinusI: applyFormat("negInt($1)", "-($1)")
of mUnaryMinusI64: applyFormat("negInt64($1)", "-($1)")
of mAbsI: applyFormat("absInt($1)", "Math.abs($1)")
of mAbsI:
let typ = n[1].typ.skipTypes(abstractVarRange)
if typ.kind == tyInt64 and optJsBigInt64 in p.config.globalOptions:
useMagic(p, "absInt64")
applyFormat("absInt64($1)", "absInt64($1)")
else:
applyFormat("absInt($1)", "Math.abs($1)")
of mNot: applyFormat("!($1)", "!($1)")
of mUnaryPlusI: applyFormat("+($1)", "+($1)")
of mBitnotI:

View File

@@ -1,5 +1,6 @@
discard """
matrix: "; --backend:js --jsbigint64:off; --backend:js --jsbigint64:on"
targets: "c js"
output: '''
0 0
0 0
@@ -7,6 +8,8 @@ Success'''
"""
# Test the different integer operations
# TODO: fixme --backend:js cannot change targets!!!
import std/private/jsutils
var testNumber = 0
@@ -141,4 +144,9 @@ block: # shl
when not defined(js) or (defined(js) and compileOption("jsbigint64")):
doAssert u64 shl 1 == u64 - 1
block: # bug #23378
var neg = -1 # prevent compile-time evaluation
let n = abs BiggestInt neg
doAssert n == 1
echo("Success") #OUT Success