From 0b84de31b7b0d24ce53a9353815f6bfb02717656 Mon Sep 17 00:00:00 2001 From: Mads Ager Date: Thu, 19 Aug 2021 13:51:27 +0200 Subject: [PATCH] [JVM IR] Generate line number for exception store for finally. ^KT-46451 Fixed --- .../backend/jvm/codegen/ExpressionCodegen.kt | 4 ++++ .../debug/localVariables/tryFinally11.kt | 1 + .../debug/localVariables/tryFinally12.kt | 1 + .../debug/localVariables/tryFinally17.kt | 22 +++++++++++++++++++ .../testData/debug/stepping/tryFinally.kt | 5 +++-- .../IrLocalVariableTestGenerated.java | 6 +++++ .../LocalVariableTestGenerated.java | 6 +++++ 7 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/debug/localVariables/tryFinally17.kt diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index 35d541f6b55..3028818acf9 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -1244,6 +1244,10 @@ class ExpressionCodegen( // Generate `try { ... } catch (e: Any?) { ; throw e }` around every part of // the try-catch that is not a copy-pasted `finally` block. val defaultCatchStart = markNewLabel() + // Make sure the ASTORE generated below has the line number of the + // finally block and does not take over the line number of whatever + // was generated before. + tryInfo.onExit.markLineNumber(true) // While keeping this value on the stack should be enough, the bytecode validator will // complain if a catch block does not start with ASTORE. val savedException = frameMap.enterTemp(AsmTypes.JAVA_THROWABLE_TYPE) diff --git a/compiler/testData/debug/localVariables/tryFinally11.kt b/compiler/testData/debug/localVariables/tryFinally11.kt index 9ccb579fc4b..4fd36cc4286 100644 --- a/compiler/testData/debug/localVariables/tryFinally11.kt +++ b/compiler/testData/debug/localVariables/tryFinally11.kt @@ -34,4 +34,5 @@ fun box(): 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:12 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException, y:java.lang.String="y":java.lang.String, z:java.lang.String="z":java.lang.String // test.kt:14 box: i:int=0:int +// test.kt:17 box: // test.kt:18 box: diff --git a/compiler/testData/debug/localVariables/tryFinally12.kt b/compiler/testData/debug/localVariables/tryFinally12.kt index 933033865cf..f17db5026ca 100644 --- a/compiler/testData/debug/localVariables/tryFinally12.kt +++ b/compiler/testData/debug/localVariables/tryFinally12.kt @@ -34,4 +34,5 @@ fun box(): 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:12 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException, y:java.lang.String="y":java.lang.String, z:java.lang.String="z":java.lang.String // test.kt:14 box: i:int=0:int +// test.kt:17 box: // test.kt:18 box: diff --git a/compiler/testData/debug/localVariables/tryFinally17.kt b/compiler/testData/debug/localVariables/tryFinally17.kt new file mode 100644 index 00000000000..d35a789450b --- /dev/null +++ b/compiler/testData/debug/localVariables/tryFinally17.kt @@ -0,0 +1,22 @@ +// FILE: test.kt + +fun box(): String { + try { + val x = "x" + throw RuntimeException(x) + } finally { + return "OK" + } + return "FAIL" +} + +// IGNORE_BACKEND: JVM +// The old backend steps on line 4, 5, 9, and 8. No step on the throw, and a step on the end +// brace of the finally before going into the actual finally code. + +// LOCAL VARIABLES +// test.kt:4 box: +// test.kt:5 box: +// test.kt:6 box: x:java.lang.String="x":java.lang.String +// test.kt:7 box: +// test.kt:8 box: diff --git a/compiler/testData/debug/stepping/tryFinally.kt b/compiler/testData/debug/stepping/tryFinally.kt index 8f1137243bf..97a036d60f0 100644 --- a/compiler/testData/debug/stepping/tryFinally.kt +++ b/compiler/testData/debug/stepping/tryFinally.kt @@ -69,8 +69,9 @@ fun box() { // test.kt:10 foo // test.kt:11 foo // test.kt:25 mightThrow2 -// test.kt:14 foo // LINENUMBERS JVM +// test.kt:14 foo // test.kt:10 foo // LINENUMBERS JVM_IR -// test.kt:13 foo \ No newline at end of file +// test.kt:12 foo +// test.kt:13 foo diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/IrLocalVariableTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/IrLocalVariableTestGenerated.java index 7c7ad32392a..0122e8f0178 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/IrLocalVariableTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/IrLocalVariableTestGenerated.java @@ -134,6 +134,12 @@ public class IrLocalVariableTestGenerated extends AbstractIrLocalVariableTest { runTest("compiler/testData/debug/localVariables/tryFinally16.kt"); } + @Test + @TestMetadata("tryFinally17.kt") + public void testTryFinally17() throws Exception { + runTest("compiler/testData/debug/localVariables/tryFinally17.kt"); + } + @Test @TestMetadata("tryFinally2.kt") public void testTryFinally2() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/LocalVariableTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/LocalVariableTestGenerated.java index c1419b2eaf6..370ed0a21fb 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/LocalVariableTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/LocalVariableTestGenerated.java @@ -134,6 +134,12 @@ public class LocalVariableTestGenerated extends AbstractLocalVariableTest { runTest("compiler/testData/debug/localVariables/tryFinally16.kt"); } + @Test + @TestMetadata("tryFinally17.kt") + public void testTryFinally17() throws Exception { + runTest("compiler/testData/debug/localVariables/tryFinally17.kt"); + } + @Test @TestMetadata("tryFinally2.kt") public void testTryFinally2() throws Exception {