Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,11 @@ proc genAddr(p: BProc, e: PNode, d: var TLoc) =
var a: TLoc = initLocExpr(p, e[0])
if e[0].kind in {nkHiddenStdConv, nkHiddenSubConv, nkConv} and not ignoreConv(e[0]):
# addr (conv x) introduces a temp because `conv x` is not a rvalue
putIntoDest(p, d, e, addrLoc(p.config, expressionsNeedsTmp(p, a)), a.storage)
# transform addr ( conv ( x ) ) -> conv ( addr ( x ) )
var exprLoc: TLoc = initLocExpr(p, e[0][1])
var tmp = getTemp(p, e.typ, needsInit=false)
putIntoDest(p, tmp, e, cCast(getTypeDesc(p.module, e.typ), addrLoc(p.config, exprLoc)))
putIntoDest(p, d, e, rdLoc(tmp))
else:
putIntoDest(p, d, e, addrLoc(p.config, a), a.storage)

Expand Down
20 changes: 20 additions & 0 deletions tests/ccgbugs/taddrconvs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,23 @@ block:
var m = uint64(12)
foo(culonglong(m))
main()

block: # bug #25109
type T = culonglong
proc r(c: var T) = c = 1
proc h(a: var culonglong) = r(T(a))
var a: culonglong
h(a)
doAssert a == 1

block: # bug #25111
type T = culonglong
proc r(c: var T) = c = 1

proc foo =
var a: uint64
r(T(a))
doAssert a == 1

foo()

Loading