Fix for wrong local variable table at inlining lambda with finallies

This commit is contained in:
Michael Bogdanov
2015-10-02 11:50:59 +03:00
parent 8ab746d6a3
commit e91c556d06
6 changed files with 65 additions and 6 deletions
@@ -121,6 +121,13 @@ class IntervalMetaInfo<T : SplittableInterval<T>> {
return currentIntervals.map { split(it, by, keepStart) }
}
fun splitAndRemoveIntervalsFromCurrents(by : Interval) {
val copies = ArrayList(currentIntervals)
copies.forEach {
splitAndRemoveInterval(it, by, true)
}
}
fun processCurrent(curIns: LabelNode, directOrder: Boolean) {
getInterval(curIns, directOrder).forEach {
val added = currentIntervals.add(it)
@@ -193,16 +200,16 @@ public class LocalVarNodeWrapper(val node: LocalVariableNode) : Interval, Splitt
override val endLabel: LabelNode
get() = node.end
override fun split(split: Interval, keepStart: Boolean): SplitPair<LocalVarNodeWrapper> {
override fun split(splitBy: Interval, keepStart: Boolean): SplitPair<LocalVarNodeWrapper> {
val newPartInterval = if (keepStart) {
val oldEnd = endLabel
node.end = split.startLabel
Pair(split.endLabel, oldEnd)
node.end = splitBy.startLabel
Pair(splitBy.endLabel, oldEnd)
}
else {
val oldStart = startLabel
node.start = split.endLabel
Pair(oldStart, split.startLabel)
node.start = splitBy.endLabel
Pair(oldStart, splitBy.startLabel)
}
return SplitPair(this, LocalVarNodeWrapper(
@@ -700,7 +700,7 @@ public class InlineCodegen extends CallGenerator {
SimpleInterval splitBy = new SimpleInterval((LabelNode) start.info, extension.finallyIntervalEnd);
processor.getTryBlocksMetaInfo().splitCurrentIntervals(splitBy, true);
processor.getLocalVarsMetaInfo().splitCurrentIntervals(splitBy, true);
//processor.getLocalVarsMetaInfo().splitAndRemoveIntervalsFromCurrents(splitBy);
mark.dropTo();
}
@@ -0,0 +1,35 @@
import test.*
fun test1(): String {
try {
doCall {
try {
doCall {
val a = 1
if (1 == 1) {
return "a"
}
else if (2 == 2) {
return "b"
}
}
return "d"
}
finally {
"1"
}
}
}
finally {
"2"
}
return "f"
}
fun box(): String {
test1()
return "OK"
}
@@ -0,0 +1,5 @@
package test
public inline fun <R> doCall(block: ()-> R) : R {
return block()
}
@@ -658,6 +658,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite/finallyInFinally.1.kt");
doTestMultiFileWithInlineCheck(fileName);
}
@TestMetadata("wrongVarInterval.1.kt")
public void testWrongVarInterval() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite/wrongVarInterval.1.kt");
doTestMultiFileWithInlineCheck(fileName);
}
}
@TestMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained")
@@ -658,6 +658,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite/finallyInFinally.1.kt");
doBoxTestWithInlineCheck(fileName);
}
@TestMetadata("wrongVarInterval.1.kt")
public void testWrongVarInterval() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite/wrongVarInterval.1.kt");
doBoxTestWithInlineCheck(fileName);
}
}
@TestMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained")