Remove variables with empty ranges from local vars table

As their ranges may intersect after dead code elimination that leads to VerifyError
This commit is contained in:
Denis Zharkov
2015-06-03 15:02:54 +03:00
parent 310babefdf
commit 9802931a90
9 changed files with 54 additions and 2 deletions
@@ -51,7 +51,7 @@ fun MethodNode.prepareForEmitting() {
// local variables with live ranges starting after last meaningful instruction lead to VerifyError
localVariables = localVariables.filter { lv ->
InsnSequence(lv.start, instructions.getLast()).any { insn ->
InsnSequence(lv.start, lv.end).any { insn ->
insn.isMeaningful
}
}
+2 -1
View File
@@ -1,7 +1,8 @@
class A {
fun foo() {
try {
val a = 1
var a = 1
a++
}
catch(e : Throwable) {
@@ -6,6 +6,7 @@ class A {
fun foo() {
inlineFun ({
var zzz = it;
zzz++
})
}
}
@@ -8,6 +8,7 @@ class A {
fun foo() {
inlineFun ({ l ->
var zzz = l;
zzz++
}, 11)
}
}
@@ -7,6 +7,7 @@ class A {
var s = 1;
inlineFun ({
var zzz = 2;
zzz++
})
}
}
@@ -7,9 +7,11 @@ class A {
var s = 0;
inlineFun {
var z = 1;
z++
inlineFun {
var zz2 = 2;
zz2++
}
}
}
@@ -0,0 +1,13 @@
fun box(): String {
try {
return "OK"
if (1 == 1) {
val z = 2
}
if (3 == 3) {
val z = 4
}
} finally {
}
}
@@ -0,0 +1,12 @@
fun box(): String {
try {
return "OK"
} finally {
if (1 == 1) {
val z = 2
}
if (3 == 3) {
val z = 4
}
}
}
@@ -2180,6 +2180,27 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
}
}
@TestMetadata("compiler/testData/codegen/box/deadCodeElimination")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class DeadCodeElimination extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInDeadCodeElimination() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/deadCodeElimination"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("intersectingVariableRange.kt")
public void testIntersectingVariableRange() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/deadCodeElimination/intersectingVariableRange.kt");
doTest(fileName);
}
@TestMetadata("intersectingVariableRangeInFinally.kt")
public void testIntersectingVariableRangeInFinally() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/deadCodeElimination/intersectingVariableRangeInFinally.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/defaultArguments")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)