fix regression in semfold for old right shift (#11477)
This commit is contained in:
parent
c07973e313
commit
e4d0f4fee0
1 changed files with 16 additions and 1 deletions
|
|
@ -248,8 +248,23 @@ proc evalOp(m: TMagic, n, a, b, c: PNode; g: ModuleGraph): PNode =
|
||||||
result = doAndFit(newIntNodeT(`shl`(getInt(a), getInt(b)), n, g))
|
result = doAndFit(newIntNodeT(`shl`(getInt(a), getInt(b)), n, g))
|
||||||
else: internalError(g.config, n.info, "constant folding for shl")
|
else: internalError(g.config, n.info, "constant folding for shl")
|
||||||
of mShrI:
|
of mShrI:
|
||||||
let a = cast[uint64](getInt(a))
|
var a = cast[uint64](getInt(a))
|
||||||
let b = cast[uint64](getInt(b))
|
let b = cast[uint64](getInt(b))
|
||||||
|
# To support the ``-d:nimOldShiftRight`` flag, we need to mask the
|
||||||
|
# signed integers to cut off the extended sign bit in the internal
|
||||||
|
# representation.
|
||||||
|
if 0'u64 < b: # do not cut off the sign extension, when there is
|
||||||
|
# no bit shifting happening.
|
||||||
|
case skipTypes(n.typ, abstractRange).kind
|
||||||
|
of tyInt8: a = a and 0xff'u64
|
||||||
|
of tyInt16: a = a and 0xffff'u64
|
||||||
|
of tyInt32: a = a and 0xffffffff'u64
|
||||||
|
of tyInt:
|
||||||
|
if g.config.target.intSize == 4:
|
||||||
|
a = a and 0xffffffff'u64
|
||||||
|
else:
|
||||||
|
# unsigned and 64 bit integers don't need masking
|
||||||
|
discard
|
||||||
let c = cast[BiggestInt](a shr b)
|
let c = cast[BiggestInt](a shr b)
|
||||||
result = newIntNodeT(c, n, g)
|
result = newIntNodeT(c, n, g)
|
||||||
of mAshrI:
|
of mAshrI:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue