Fixup end label of local variable if it is before start label
In that case, put end label to next label after start label.
This commit is contained in:
+15
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.codegen.inline
|
||||
|
||||
import org.jetbrains.kotlin.codegen.optimization.boxing.isMethodInsnWith
|
||||
import org.jetbrains.kotlin.codegen.optimization.common.InsnSequence
|
||||
import org.jetbrains.kotlin.codegen.optimization.common.findNextOrNull
|
||||
import org.jetbrains.kotlin.codegen.optimization.common.removeUnusedLocalVariables
|
||||
import org.jetbrains.kotlin.codegen.optimization.common.updateMaxStack
|
||||
import org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer
|
||||
@@ -25,6 +26,8 @@ class InplaceArgumentsMethodTransformer : MethodTransformer() {
|
||||
|
||||
transformMethod(methodContext)
|
||||
|
||||
methodNode.fixupLVT()
|
||||
|
||||
methodNode.removeUnusedLocalVariables()
|
||||
methodNode.updateMaxStack()
|
||||
}
|
||||
@@ -368,4 +371,16 @@ class InplaceArgumentsMethodTransformer : MethodTransformer() {
|
||||
insn = insn.next
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HACK: if new end label is before start label, change to the next one
|
||||
private fun MethodNode.fixupLVT() {
|
||||
for (localVariable in localVariables) {
|
||||
val startIndex = instructions.indexOf(localVariable.start)
|
||||
val endIndex = instructions.indexOf(localVariable.end)
|
||||
if (endIndex < startIndex) {
|
||||
val newEnd = localVariable.start.findNextOrNull { it is LabelNode } as? LabelNode
|
||||
localVariable.end = newEnd ?: localVariable.start
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user