From: Sunil Mohan Adapa <sunil@medhas.org>
Date: Wed, 21 Apr 2021 22:13:00 -0700
Subject: compiler/backend: Fix crash when generating coroutine functions

Forwarded: not-needed
Bug-Debian: https://salsa.debian.org/java-team/kotlin/-/issues/9

When generating JVM byte code for a coroutine, code is inserted to help stop
the function and continue is later. As part of this a variable with name
'$continuation' is also added. This variable is also added to the local
variable table (LVT). The entry in LVT contains that scope of the variable
represented as a starting label (inclusive) and ending label (exclusive).

Before adding a starting label, the starting label is first created. At the
time of creation of the label and at the time of assing the starting label node
to the variable in LVT, different LabelNode are created. This works in a flaky
way because of a reference (.info) in the label in LVT. It somehow does not
work when compiled in Debian due change in ASM Java library or for other
reasons.

This patch fixes the problem by using the same LabelNode at the location of the
label and in LVT. This problem was fixed in later versions of Kotlin due to
ractoring.

This patch is not needed upstream due to refactoring done in commit
d2a80e793825c16506a235a6dc61a6a052835110.
---
 .../kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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 a7a3420..d2a25bc 100644
--- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt
+++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt
@@ -459,7 +459,7 @@ class CoroutineTransformerMethodVisitor(
 
             visitLabel(afterCoroutineStateCreated)
 
-            addContinuationToLvt(methodNode, LabelNode(afterCoroutineStateCreated))
+            addContinuationToLvt(methodNode, afterCoroutineStateCreated.info as LabelNode)
 
             visitVarInsn(Opcodes.ALOAD, continuationIndex)
             getfield(classBuilderForCoroutineState.thisName, languageVersionSettings.dataFieldName(), AsmTypes.OBJECT_TYPE.descriptor)
