[JVM] Fix various undefined locals issues.

CoroutineTransformermethodVisitor attempts to extend the ranges
of local variables in various situations. Probably in an attempt
to give a better debugging experience. However, all of these
range extensions lead to invalid local variable tables where
something is in the local variable table where nothing is in the
corresponding slot.

The code that extends variables to the next suspension point
instead of ending them when they are no longer live has issues
with loops. When resuming and reentering the loop, the locals
table will mention a local that we did not spill and which
is therefore not restored when resuming.

The code that extends local variable table entries if there
are no suspension points between two entries doesn't work
for code such as:

```
var s: String
if (suspendHere() == "OK") {
  s = "OK"
} else {
  s = "FAIL"
}
```

If the local variable ranges are collapsed into one, one of
the branches will have the local defined in the local variable
table before the slot is initialized.
This commit is contained in:
Mads Ager
2021-04-09 09:19:35 +02:00
committed by Ilmir Usmanov
parent 14ed660f4f
commit d023966054
10 changed files with 52 additions and 74 deletions
@@ -15,12 +15,6 @@ fun main(args: Array<String>) {
suspend fun SequenceScope<Int>.awaitSeq(): Int = 42
// 1 LINENUMBER 9 L19
// JVM_IR_TEMPLATES
// 1 LOCALVARIABLE a I L[0-9]+ L4
// JVM_TEMPLATES
// 1 LOCALVARIABLE a I L[0-9]+ L19
// TODO: Old BE generates LINENUMBER label after suspension point, unlike JVM_BE
// 1 LOCALVARIABLE a I L[0-9]+ L18
// IGNORE_BACKEND_FIR: JVM_IR