mirror of
https://github.com/irmen/prog8.git
synced 2024-12-24 01:29:28 +00:00
no longer do return value optimization with tempvar, this caused invalid code sometimes.
This commit is contained in:
parent
8ab47d3321
commit
ca7932c4f0
@ -374,31 +374,4 @@ class StatementOptimizer(private val program: Program,
|
||||
|
||||
return noModifications
|
||||
}
|
||||
|
||||
override fun after(returnStmt: Return, parent: Node): Iterable<IAstModification> {
|
||||
|
||||
if(compTarget.name==VMTarget.NAME)
|
||||
return noModifications
|
||||
|
||||
val returnvalue = returnStmt.value
|
||||
if (returnvalue!=null) {
|
||||
val dt = returnvalue.inferType(program).getOr(DataType.UNDEFINED)
|
||||
if(dt!=DataType.UNDEFINED) {
|
||||
if (returnvalue is BinaryExpression || (returnvalue is TypecastExpression && !returnvalue.expression.isSimple)) {
|
||||
// first assign to intermediary variable, then return that
|
||||
val (returnVarName, _) = program.getTempVar(dt)
|
||||
val returnValueIntermediary = IdentifierReference(returnVarName, returnStmt.position)
|
||||
val tgt = AssignTarget(returnValueIntermediary, null, null, returnStmt.position)
|
||||
val assign = Assignment(tgt, returnvalue, AssignmentOrigin.OPTIMIZER, returnStmt.position)
|
||||
val returnReplacement = Return(returnValueIntermediary.copy(), returnStmt.position)
|
||||
return listOf(
|
||||
IAstModification.InsertBefore(returnStmt, assign, parent as IStatementContainer),
|
||||
IAstModification.ReplaceNode(returnStmt, returnReplacement, parent)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return noModifications
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user