From e8d0f1c3aedd8290cc972e3d06f642e88dbe783e Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 16 Jun 2023 20:59:59 +0200 Subject: [PATCH] =?UTF-8?q?fixes=20#16331;=20aliasing=20of=20tuple=20const?= =?UTF-8?q?ruction=20within=20a=20single=20assignme=E2=80=A6=20(#22113)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixes #16331; aliasing of tuple construction within a single assignment, great coding style * added test case --- compiler/ccgexprs.nim | 21 ++++++++++++++++++--- tests/ccgbugs/twrong_tupleconv.nim | 15 +++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 0567fbdf90ee..978ca8db8fe6 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2679,15 +2679,30 @@ proc genTupleConstr(p: BProc, n: PNode, d: var TLoc) = if not handleConstExpr(p, n, d): let t = n.typ discard getTypeDesc(p.module, t) # so that any fields are initialized - if d.k == locNone: getTemp(p, t, d) + + var tmp: TLoc + # bug #16331 + let doesAlias = lhsDoesAlias(d.lode, n) + let dest = if doesAlias: addr(tmp) else: addr(d) + if doesAlias: + getTemp(p, n.typ, tmp) + elif d.k == locNone: + getTemp(p, n.typ, d) + for i in 0..