Do not add duplicate $completion when compiling JVM against JVM_IR

This change fixes JvmOldAgainstIrBoxInlineTestGenerated.Suspend and
JvmIrAgainstOldBoxInlineTestGenerated.Suspend tests.
This commit is contained in:
Alexander Udalov
2020-09-01 19:27:17 +02:00
parent ae448ececb
commit 669fda6b77
2 changed files with 13 additions and 0 deletions
@@ -230,6 +230,16 @@ class CoroutineTransformerMethodVisitor(
if (last is LabelNode) last as LabelNode
else LabelNode().also { insert(last, it) }
}
// When compiling with the old backend against the bytecode generated by JVM IR, $completion may already be in LVT.
if (methodNode.localVariables.any {
it.name == SUSPEND_FUNCTION_COMPLETION_PARAMETER_NAME &&
areLabelsBeforeSameInsn(startLabel, it.start) &&
areLabelsBeforeSameInsn(endLabel, it.end)
}) {
return
}
methodNode.localVariables.add(
LocalVariableNode(
SUSPEND_FUNCTION_COMPLETION_PARAMETER_NAME,
@@ -317,6 +317,9 @@ internal fun firstLabelInChain(node: LabelNode): LabelNode {
return curNode
}
internal fun areLabelsBeforeSameInsn(first: LabelNode, second: LabelNode): Boolean =
firstLabelInChain(first) == firstLabelInChain(second)
internal val MethodNode?.nodeText: String
get() {
if (this == null) {