Skip to content

Commit

Permalink
don't use a temp for addr [backport: 1.6] (nim-lang#19503)
Browse files Browse the repository at this point in the history
* don't use a temp for addr

fix nim-lang#19497

* Update compiler/ccgcalls.nim

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

* add a test

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
  • Loading branch information
2 people authored and PMunch committed Mar 28, 2022
1 parent e700082 commit 336ac6f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/ccgcalls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ proc genParams(p: BProc, ri: PNode, typ: PType): Rope =
if not needTmp[i - 1]:
needTmp[i - 1] = potentialAlias(n, potentialWrites)
getPotentialWrites(ri[i], false, potentialWrites)
if ri[i].kind == nkHiddenAddr:
# Optimization: don't use a temp, if we would only take the adress anyway
if ri[i].kind in {nkHiddenAddr, nkAddr}:
# Optimization: don't use a temp, if we would only take the address anyway
needTmp[i - 1] = false

for i in 1..<ri.len:
Expand Down
22 changes: 22 additions & 0 deletions tests/arc/tarc_orc.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
discard """
matrix: "--mm:arc; --mm:orc"
"""

block:
type
PublicKey = array[32, uint8]
PrivateKey = array[64, uint8]

proc ed25519_create_keypair(publicKey: ptr PublicKey; privateKey: ptr PrivateKey) =
publicKey[][0] = uint8(88)

type
KeyPair = object
public: PublicKey
private: PrivateKey

proc initKeyPair(): KeyPair =
ed25519_create_keypair(result.public.addr, result.private.addr)

let keys = initKeyPair()
doAssert keys.public[0] == 88

0 comments on commit 336ac6f

Please sign in to comment.