Revert "fixes move for getPotentialWrites (#24753)"

This reverts commit ed57499427.
This commit is contained in:
narimiran
2025-03-18 15:17:49 +01:00
parent faa4042e26
commit bfd25121f9
3 changed files with 9 additions and 11 deletions

View File

@@ -343,7 +343,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
of tyString:
if optSeqDestructors in p.config.globalOptions:
genGenericAsgn(p, dest, src, flags)
elif (needToCopy notin flags and src.storage != OnStatic) or canMove(p, src.lode, dest):
elif ({needToCopy, needToCopySinkParam} * flags == {} and src.storage != OnStatic) or canMove(p, src.lode, dest):
genRefAssign(p, dest, src)
else:
if (dest.storage == OnStack and p.config.selectedGC != gcGo) or not usesWriteBarrier(p.config):
@@ -2363,7 +2363,13 @@ proc genMove(p: BProc; n: PNode; d: var TLoc) =
else:
linefmt(p, cpsStmts, "$1($2);$n", [rdLoc(b), byRefLoc(p, a)])
else:
genAssignment(p, d, a, {})
if n[1].kind == nkSym and isSinkParam(n[1].sym):
var tmp = getTemp(p, n[1].typ.skipTypes({tySink}))
genAssignment(p, tmp, a, {needToCopySinkParam})
genAssignment(p, d, tmp, {})
resetLoc(p, tmp)
else:
genAssignment(p, d, a, {})
resetLoc(p, a)
proc genDestroy(p: BProc; n: PNode) =

View File

@@ -412,6 +412,7 @@ proc rdCharLoc(a: TLoc): Rope =
type
TAssignmentFlag = enum
needToCopy
needToCopySinkParam
needTempForOpenArray
needAssignCall
TAssignmentFlags = set[TAssignmentFlag]

View File

@@ -69,12 +69,3 @@ test
static:
test
block:
proc say(a: int, b: int) =
doAssert a == 1
doAssert b == 0
var a = 1
var b = a
say a, (b = move a; a)