From 9e2b8a2aa9c5486b0e7b863476d79e543c573ccc Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 2 Apr 2021 19:01:46 +0200 Subject: [PATCH] fix ast node duplication/reference bug in certain optimizers --- compiler/src/prog8/optimizer/StatementOptimizer.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/prog8/optimizer/StatementOptimizer.kt b/compiler/src/prog8/optimizer/StatementOptimizer.kt index 8dead3956..51110704c 100644 --- a/compiler/src/prog8/optimizer/StatementOptimizer.kt +++ b/compiler/src/prog8/optimizer/StatementOptimizer.kt @@ -403,7 +403,7 @@ internal class StatementOptimizer(private val program: Program, // replace by several INCs if it's not a memory address (inc on a memory mapped register doesn't work very well) val incs = AnonymousScope(mutableListOf(), assignment.position) repeat(rightCv.toInt()) { - incs.statements.add(PostIncrDecr(assignment.target, "++", assignment.position)) + incs.statements.add(PostIncrDecr(assignment.target.copy(), "++", assignment.position)) } return listOf(IAstModification.ReplaceNode(assignment, incs, parent)) } @@ -417,7 +417,7 @@ internal class StatementOptimizer(private val program: Program, // replace by several DECs if it's not a memory address (dec on a memory mapped register doesn't work very well) val decs = AnonymousScope(mutableListOf(), assignment.position) repeat(rightCv.toInt()) { - decs.statements.add(PostIncrDecr(assignment.target, "--", assignment.position)) + decs.statements.add(PostIncrDecr(assignment.target.copy(), "--", assignment.position)) } return listOf(IAstModification.ReplaceNode(assignment, decs, parent)) }