From 68b7779bc7582ceb0bce0fd8fa79a91c17498b2d Mon Sep 17 00:00:00 2001 From: Reimer Behrends Date: Fri, 29 Nov 2013 02:21:47 +0100 Subject: [PATCH] Fixes various issues with shallow copying. * The {.shallow.} pragma is now properly respected for objects and tuples that are not handled by genGenericAsgn(). Mirroring the decision in generic assignments, whether an assignment is shallow depends on the destination of the assignment, but not the source. * String literals and complex inline constants are now properly assigned a location kind of locData. * Assignments from a locData source will now force deep copying to occur, even if shallowCopy or {.shallow.} is being used. This avoids potential crashes from `shallowCopy s, "xxx"` or from `shallowCopy t, ("a", "b")`. --- compiler/ccgexprs.nim | 46 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index c50fd4536c..15f7f0f34a 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -212,22 +212,36 @@ proc optAsgnLoc(a: TLoc, t: PType, field: PRope): TLoc = result.heapRoot = a.heapRoot proc genOptAsgnTuple(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = + let newflags = + if src.k == locData: + flags + { needToCopy } + elif tfShallow in dest.t.flags: + flags - { needToCopy } + else: + flags for i in 0 ..