[JVM_IR] Keep track of catch variable gaps.

This ensures that catch variables are not visible in duplicated
finally blocks generated at an exit within the catch variable
scope.

^KT-46449 Fixed
This commit is contained in:
Mads Ager
2021-06-14 13:16:41 +02:00
committed by max-kammerer
parent 6aba6ea670
commit ae03e2983d
5 changed files with 15 additions and 18 deletions
@@ -1159,18 +1159,17 @@ class ExpressionCodegen(
val afterStore = markNewLabel() val afterStore = markNewLabel()
val catchBody = clause.result val catchBody = clause.result
val catchResult = catchBody.accept(this, data) var catchBlockInfo = BlockInfo(data)
catchBlockInfo.variables.add(VariableInfo(parameter, index, descriptorType, afterStore))
val catchResult = catchBody.accept(this, catchBlockInfo)
if (savedValue != null) { if (savedValue != null) {
catchResult.materializeAt(tryAsmType, aTry.type, true) catchResult.materializeAt(tryAsmType, aTry.type, true)
mv.store(savedValue, tryAsmType) mv.store(savedValue, tryAsmType)
} else { } else {
catchResult.discard() catchResult.discard()
} }
writeLocalVariablesInTable(catchBlockInfo, markNewLabel())
frameMap.leave(clause.catchParameter)
val clauseEnd = markNewLabel()
mv.visitLocalVariable(parameter.name.asString(), descriptorType.descriptor, null, afterStore, clauseEnd, index)
if (tryInfo is TryWithFinallyInfo) { if (tryInfo is TryWithFinallyInfo) {
data.handleBlock { genFinallyBlock(tryInfo, tryCatchBlockEnd, null, data) } data.handleBlock { genFinallyBlock(tryInfo, tryCatchBlockEnd, null, data) }
+2 -2
View File
@@ -11,7 +11,7 @@ fun box(): String {
val z = "z" val z = "z"
break // TODO: why does the break not have a line number so we can stop on it? break // TODO: why does the break not have a line number so we can stop on it?
} finally { } finally {
throw RuntimeException("$i") // TODO: `e` should not be visible here throw RuntimeException("$i")
} }
} }
} finally { } finally {
@@ -32,5 +32,5 @@ fun box(): String {
// test.kt:9 box: i:int=0:int // test.kt:9 box: i:int=0:int
// test.kt:10 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException // test.kt:10 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException
// test.kt:11 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException, y:java.lang.String="y":java.lang.String // test.kt:11 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException, y:java.lang.String="y":java.lang.String
// test.kt:14 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException // test.kt:14 box: i:int=0:int
// test.kt:18 box: // test.kt:18 box:
+2 -3
View File
@@ -11,7 +11,7 @@ fun box(): String {
val z = "z" val z = "z"
continue // TODO: why does the continue not have a line number so we stop here? continue // TODO: why does the continue not have a line number so we stop here?
} finally { } finally {
throw RuntimeException("$i") // TODO: `e` should not be visible here throw RuntimeException("$i")
} }
} }
} finally { } finally {
@@ -32,6 +32,5 @@ fun box(): String {
// test.kt:9 box: i:int=0:int // test.kt:9 box: i:int=0:int
// test.kt:10 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException // test.kt:10 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException
// test.kt:11 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException, y:java.lang.String="y":java.lang.String // test.kt:11 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException, y:java.lang.String="y":java.lang.String
// test.kt:14 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException // test.kt:14 box: i:int=0:int
// test.kt:18 box: // test.kt:18 box:
+4 -5
View File
@@ -10,11 +10,11 @@ fun box(): String {
val y = "y" val y = "y"
return "FAIL1" return "FAIL1"
} finally { } finally {
return "FAIL2" // TODO: `e` should not be visible here. return "FAIL2"
} }
} }
} finally { } finally {
return "OK" // TODO: `e` should not be visible here. return "OK"
} }
return "FAIL3" return "FAIL3"
} }
@@ -31,6 +31,5 @@ fun box(): String {
// test.kt:9 box: i:int=0:int // test.kt:9 box: i:int=0:int
// test.kt:10 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException // test.kt:10 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException
// test.kt:11 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException, y:java.lang.String="y":java.lang.String // test.kt:11 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException, y:java.lang.String="y":java.lang.String
// test.kt:13 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException // test.kt:13 box: i:int=0:int
// test.kt:17 box: e:java.lang.Exception=java.lang.RuntimeException // test.kt:17 box:
+2 -2
View File
@@ -20,7 +20,7 @@ fun compute(): String {
} }
} }
} finally { } finally {
x = "OK" // TODO: `e` should not be visible here. x = "OK"
} }
return "FAIL" return "FAIL"
} }
@@ -45,7 +45,7 @@ fun box() {
// test.kt:18 compute: e:java.lang.Exception=java.lang.RuntimeException, y:int=32:int, j:int=0:int // test.kt:18 compute: e:java.lang.Exception=java.lang.RuntimeException, y:int=32:int, j:int=0:int
// test.kt:4 compute: e:java.lang.Exception=java.lang.RuntimeException, y:int=32:int, j:int=0:int, $i$f$f:int=0:int // test.kt:4 compute: e:java.lang.Exception=java.lang.RuntimeException, y:int=32:int, j:int=0:int, $i$f$f:int=0:int
// test.kt:19 compute: e:java.lang.Exception=java.lang.RuntimeException, y:int=32:int, j:int=0:int, $i$f$f:int=0:int, $i$a$-f-TestKt$compute$1:int=0:int // test.kt:19 compute: e:java.lang.Exception=java.lang.RuntimeException, y:int=32:int, j:int=0:int, $i$f$f:int=0:int, $i$a$-f-TestKt$compute$1:int=0:int
// test.kt:23 compute: e:java.lang.Exception=java.lang.RuntimeException // test.kt:23 compute:
// test.kt:29 box: // test.kt:29 box:
// test.kt:30 box: result:java.lang.String="NON_LOCAL_RETURN":java.lang.String // test.kt:30 box: result:java.lang.String="NON_LOCAL_RETURN":java.lang.String
// test.kt:31 box: result:java.lang.String="NON_LOCAL_RETURN":java.lang.String, localX:java.lang.String="OK":java.lang.String // test.kt:31 box: result:java.lang.String="NON_LOCAL_RETURN":java.lang.String, localX:java.lang.String="OK":java.lang.String