fixes #24319; move doesn't work well with (deref (var array)) (#24321)

fixes #24319

`byRefLoc` (`mapType`) requires the Loc `a` to have the right type.
Without `lfEnforceDeref`, it produces the wrong type for `deref (var
array)`, which may come from `mitems`.
This commit is contained in:
ringabout
2024-10-18 10:56:37 +08:00
committed by GitHub
parent d0b6b9346e
commit 0347536ff2
2 changed files with 14 additions and 1 deletions

View File

@@ -2321,7 +2321,7 @@ proc genWasMoved(p: BProc; n: PNode) =
# [addrLoc(p.config, a), getTypeDesc(p.module, a.t)])
proc genMove(p: BProc; n: PNode; d: var TLoc) =
var a: TLoc = initLocExpr(p, n[1].skipAddr)
var a: TLoc = initLocExpr(p, n[1].skipAddr, {lfEnforceDeref})
if n.len == 4:
# generated by liftdestructors:
var src: TLoc = initLocExpr(p, n[2])

View File

@@ -16,3 +16,16 @@ block:
doAssert s == 2
foo()
import std/deques
block: # bug #24319
var queue = initDeque[array[32, byte]]()
for i in 0 ..< 5:
let element: array[32, byte] = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1,
]
queue.addLast(element)
doAssert queue.popLast[^1] == byte(1)