diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt index 68fac79ff1a..108509593fe 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt @@ -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, diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/inlineCodegenUtils.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/inlineCodegenUtils.kt index b52d770c8a4..9303bd13df6 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/inlineCodegenUtils.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/inlineCodegenUtils.kt @@ -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) {