Skip to content

Commit

Permalink
fix nim-lang#13902 distinct uint64 type corruption on 32-bit with borrow
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothee Cour committed Apr 7, 2020
1 parent 92c4aad commit 5535a33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
const opr: array[mInc..mDec, string] = ["+=", "-="]
const fun64: array[mInc..mDec, string] = ["nimAddInt64", "nimSubInt64"]
const fun: array[mInc..mDec, string] = ["nimAddInt","nimSubInt"]
let underlying = skipTypes(e[1].typ, {tyGenericInst, tyAlias, tySink, tyVar, tyLent, tyRange})
let underlying = skipTypes(e[1].typ, {tyGenericInst, tyAlias, tySink, tyVar, tyLent, tyRange, tyDistinct})
if optOverflowCheck notin p.options or underlying.kind in {tyUInt..tyUInt64}:
binaryStmt(p, e, d, opr[op])
else:
Expand Down
16 changes: 16 additions & 0 deletions tests/ccgbugs/t13902.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
discard """
cmd: "nim c -r --skipParentCfg --skipUserCfg --cpu:i386 --passC:-m32 --passL:-m32 --stacktrace:off --hints:off $file"
action: run
"""

#issue #13902
when defined(linux):
block:
type Slot = distinct uint64
var s = Slot(1)
proc `$`(x: Slot): string {.borrow.}
proc `+=`(x: var Slot, y: uint64) {.borrow.}
echo "s = ", s
s += 1
echo "s = ", s
doAssert s.uint64 == 2, $s # was failing, showing 18419607611339964418

0 comments on commit 5535a33

Please sign in to comment.