fixes #23499; don't skip addr when constructing bracketExpr (#23503)

fixes #23499

In the
8990626ca9
the effect of `skipAddr` changed to skip `nkAddr` and `nkHiddenAddr`.
Some old code was not adapted. In the
https://github.com/nim-lang/Nim/pull/23477, the magic `addr` function
was handled in the semantic analysis phase, which causes it be skipped
incorrectly
This commit is contained in:
ringabout
2024-04-15 23:28:14 +08:00
committed by GitHub
parent 7208a27c0f
commit 549ef24f35
2 changed files with 11 additions and 1 deletions

View File

@@ -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

View File

@@ -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()