JVM: Check for multiple {POP, Unit} sequences in suspend function TCO

We already check for {POP, Unit} sequence before ARETURN, but if the
there are multiple sequence before ARETURN, the compiler assumes, that
TCO misses.

The fix is to check, that the instruction after the sequence is either
ARETURN or another {POP, Unit} sequence.

 #KT-50835
 #KT-54152 Fixed
This commit is contained in:
Ilmir Usmanov
2022-09-14 21:26:11 +02:00
parent 45b608e195
commit 3ee09f05ef
6 changed files with 96 additions and 1 deletions
@@ -87,7 +87,7 @@ private val AbstractInsnNode.nextMeaningful: AbstractInsnNode?
get() = next.skipUntilMeaningful()
private val AbstractInsnNode.isReturnUnit: Boolean
get() = isUnitInstance() && nextMeaningful?.opcode == Opcodes.ARETURN
get() = isUnitInstance() && nextMeaningful?.let { it.opcode == Opcodes.ARETURN || it.isPopBeforeReturnUnit } == true
private val AbstractInsnNode.isPopBeforeReturnUnit: Boolean
get() = opcode == Opcodes.POP && nextMeaningful?.isReturnUnit == true