Skip to content

Commit

Permalink
fixes #23499; don't skip addr when constructing bracketExpr (#23503)
Browse files Browse the repository at this point in the history
fixes #23499

In the
8990626
the effect of `skipAddr` changed to skip `nkAddr` and `nkHiddenAddr`.
Some old code was not adapted. In the
#23477, the magic `addr` function
was handled in the semantic analysis phase, which causes it be skipped
incorrectly
  • Loading branch information
ringabout authored Apr 15, 2024
1 parent 7208a27 commit 549ef24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/semmagic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ proc semArrGet(c: PContext; n: PNode; flags: TExprFlags): PNode =
proc semArrPut(c: PContext; n: PNode; flags: TExprFlags): PNode =
# rewrite `[]=`(a, i, x) back to ``a[i] = x``.
let b = newNodeI(nkBracketExpr, n.info)
b.add(n[1].skipAddr)
b.add(n[1].skipHiddenAddr)
for i in 2..<n.len-1: b.add(n[i])
result = newNodeI(nkAsgn, n.info, 2)
result[0] = b
Expand Down
10 changes: 10 additions & 0 deletions tests/misc/taddr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,16 @@ proc test15939() = # bug #15939 (v2)
else: # can't take address of cstring element in js
when not defined(js): cstringTest()

block: # bug #23499
template volatileStore[T](dest: ptr T, val: T) =
dest[] = val

proc foo =
var ctr = 0
volatileStore(addr ctr, 0)

foo()

template main =
# xxx wrap all other tests here like that so they're also tested in VM
test14420()
Expand Down

0 comments on commit 549ef24

Please sign in to comment.