From 2bdf68ad675ffc3fb47168b80e1e77f71188c6c8 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Thu, 10 Jan 2019 13:57:39 +0100 Subject: [PATCH] Delete dead code on last optimization step, otherwise ASM will split exception table on it. ASM has logic that splits exception tables in MethodWriter.computeAllFrames: // Loop over all the basic blocks and visit the stack map frames that must be stored in the // StackMapTable attribute. Also replace unreachable code with NOP* ATHROW, and remove it from // exception handler ranges. ... firstHandler = Handler.removeRange(firstHandler, basicBlock, nextBasicBlock); ... https://gitlab.ow2.org/asm/asm/issues/317867 #KT-28546 Fixed --- .../optimization/OptimizationMethodVisitor.kt | 2 ++ .../nonLocalReturns/tryFinally/kt28546.kt | 35 +++++++++++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 5 +++ ...otlinAgainstInlineKotlinTestGenerated.java | 5 +++ .../IrBlackBoxInlineCodegenTestGenerated.java | 5 +++ .../IrNonLocalReturnsTestGenerated.java | 5 +++ .../NonLocalReturnsTestGenerated.java | 5 +++ 7 files changed, 62 insertions(+) create mode 100644 compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt28546.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/OptimizationMethodVisitor.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/OptimizationMethodVisitor.kt index 2524643485b..cb83708349d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/OptimizationMethodVisitor.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/OptimizationMethodVisitor.kt @@ -66,6 +66,8 @@ class OptimizationMethodVisitor( optimizationTransformer.transform("fake", methodNode) } + DeadCodeEliminationMethodTransformer().transform("fake", methodNode) + methodNode.prepareForEmitting() } diff --git a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt28546.kt b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt28546.kt new file mode 100644 index 00000000000..5318e79ce96 --- /dev/null +++ b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt28546.kt @@ -0,0 +1,35 @@ +// IGNORE_BACKEND: JVM_IR +// NO_CHECK_LAMBDA_INLINING +// FILE: 1.kt + +package test + +inline fun takeWhileSize(initialSize: Int , block: (String) -> Int) { + val current = "PARAM" + + try { + if (1 >= initialSize) { + try { + block(current) + } finally { + val i = "INNER FINALLY" + } + } else { + val e = "ELSE" + } + } finally { + val o = "OUTER FINALLY" + } +} + +// FILE: 2.kt +import test.* + + +fun box(): String { + takeWhileSize(1) { + return "OK" + } + + return "fail" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 76133edb41f..76fbb64d72e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -2060,6 +2060,11 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt26384_2.kt"); } + @TestMetadata("kt28546.kt") + public void testKt28546() throws Exception { + runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt28546.kt"); + } + @TestMetadata("kt6956.kt") public void testKt6956() throws Exception { runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt6956.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 2b78cff1ea8..a40bb1dfb5e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -2060,6 +2060,11 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt26384_2.kt"); } + @TestMetadata("kt28546.kt") + public void testKt28546() throws Exception { + runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt28546.kt"); + } + @TestMetadata("kt6956.kt") public void testKt6956() throws Exception { runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt6956.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index 7973e3909e3..e3f4ba18b87 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -2060,6 +2060,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt26384_2.kt"); } + @TestMetadata("kt28546.kt") + public void testKt28546() throws Exception { + runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt28546.kt"); + } + @TestMetadata("kt6956.kt") public void testKt6956() throws Exception { runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt6956.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrNonLocalReturnsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrNonLocalReturnsTestGenerated.java index 26c5ec5661c..bed4063f509 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrNonLocalReturnsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrNonLocalReturnsTestGenerated.java @@ -164,6 +164,11 @@ public class IrNonLocalReturnsTestGenerated extends AbstractIrNonLocalReturnsTes runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt26384_2.kt"); } + @TestMetadata("kt28546.kt") + public void testKt28546() throws Exception { + runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt28546.kt"); + } + @TestMetadata("kt6956.kt") public void testKt6956() throws Exception { runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt6956.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/NonLocalReturnsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/NonLocalReturnsTestGenerated.java index 9321824d1d3..3815681ae9c 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/NonLocalReturnsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/NonLocalReturnsTestGenerated.java @@ -164,6 +164,11 @@ public class NonLocalReturnsTestGenerated extends AbstractNonLocalReturnsTest { runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt26384_2.kt"); } + @TestMetadata("kt28546.kt") + public void testKt28546() throws Exception { + runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt28546.kt"); + } + @TestMetadata("kt6956.kt") public void testKt6956() throws Exception { runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt6956.kt");