KT-3706 Inconsistent stack height in try catch finally in function
KT-4134 Incorrect bytecode is generated for #KT-3706 Fixed #KT-4134 Fixed
This commit is contained in:
@@ -1528,6 +1528,15 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasFinallyBLocks() {
|
||||
for (BlockStackElement element : blockStackElements) {
|
||||
if (element instanceof FinallyBlockStackElement) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void genFinallyBlockOrGoto(
|
||||
@Nullable FinallyBlockStackElement finallyBlockStackElement,
|
||||
@Nullable Label tryCatchBlockEnd
|
||||
@@ -1566,7 +1575,14 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
JetExpression returnedExpression = expression.getReturnedExpression();
|
||||
if (returnedExpression != null) {
|
||||
gen(returnedExpression, returnType);
|
||||
doFinallyOnReturn();
|
||||
boolean hasFinallyBLocks = hasFinallyBLocks();
|
||||
if (hasFinallyBLocks) {
|
||||
int returnValIndex = myFrameMap.enterTemp(returnType);
|
||||
StackValue.local(returnValIndex, returnType).store(returnType, v);
|
||||
doFinallyOnReturn();
|
||||
StackValue.local(returnValIndex, returnType).put(returnType, v);
|
||||
myFrameMap.leaveTemp(returnType);
|
||||
}
|
||||
v.areturn(returnType);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
fun f(): Int {
|
||||
try {
|
||||
return 0
|
||||
}
|
||||
finally {
|
||||
try { // culprit ?? remove this try-catch and it works.
|
||||
} catch (ignore: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (f() != 0) return "fail1"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fun <T, R> io(s: R, a: (R) -> T): T {
|
||||
try {
|
||||
return a(s)
|
||||
} finally {
|
||||
try {
|
||||
s.toString()
|
||||
} catch(e: Exception) {
|
||||
//NOP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return io(("OK"), {it})
|
||||
}
|
||||
@@ -2544,6 +2544,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest("compiler/testData/codegen/box/finally/kt3549.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt3706.kt")
|
||||
public void testKt3706() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/finally/kt3706.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt3867.kt")
|
||||
public void testKt3867() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/finally/kt3867.kt");
|
||||
@@ -2559,6 +2564,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest("compiler/testData/codegen/box/finally/kt3894.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt4134.kt")
|
||||
public void testKt4134() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/finally/kt4134.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("loopAndFinally.kt")
|
||||
public void testLoopAndFinally() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/finally/loopAndFinally.kt");
|
||||
|
||||
Reference in New Issue
Block a user