diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenUtil.java index 400e18669df..a46c446468d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenUtil.java @@ -388,6 +388,17 @@ public class InlineCodegenUtil { return node.name + " " + node.desc + ":\n" + sw.getBuffer().toString(); } + @NotNull + public static String getInsnText(@Nullable AbstractInsnNode node) { + if (node == null) return ""; + Textifier textifier = new Textifier(); + node.accept(new TraceMethodVisitor(textifier)); + StringWriter sw = new StringWriter(); + textifier.print(new PrintWriter(sw)); + sw.flush(); + return sw.toString().trim(); + } + @NotNull /* package */ static ClassReader buildClassReaderByInternalName(@NotNull GenerationState state, @NotNull String internalName) { //try to find just compiled classes then in dependencies diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LocalVarRemapper.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LocalVarRemapper.java index 8228d694ac2..a5adc7d770a 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LocalVarRemapper.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LocalVarRemapper.java @@ -118,15 +118,16 @@ public class LocalVarRemapper { RemapInfo remapInfo = remap(var); StackValue value = remapInfo.value; if (value instanceof StackValue.Local) { + boolean isStore = InlineCodegenUtil.isStoreInstruction(opcode); if (remapInfo.parameterInfo != null) { //All remapped value parameters can't be rewritten except case of default ones. //On remapping default parameter to actual value there is only one instruction that writes to it according to mask value //but if such parameter remapped then it passed and this mask branch code never executed //TODO add assertion about parameter default value: descriptor is required - opcode = value.type.getOpcode(InlineCodegenUtil.isStoreInstruction(opcode) ? Opcodes.ISTORE : Opcodes.ILOAD); + opcode = value.type.getOpcode(isStore ? Opcodes.ISTORE : Opcodes.ILOAD); } mv.visitVarInsn(opcode, ((StackValue.Local) value).index); - if (remapInfo.parameterInfo != null) { + if (remapInfo.parameterInfo != null && !isStore) { StackValue.coerce(value.type, remapInfo.parameterInfo.type, mv); } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/MethodAnalyzer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/MethodAnalyzer.kt index ddf706171ef..5b48e5597cd 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/MethodAnalyzer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/MethodAnalyzer.kt @@ -46,6 +46,7 @@ package org.jetbrains.kotlin.codegen.optimization.common +import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil import org.jetbrains.org.objectweb.asm.Opcodes import org.jetbrains.org.objectweb.asm.Type import org.jetbrains.org.objectweb.asm.tree.* @@ -56,7 +57,7 @@ import org.jetbrains.org.objectweb.asm.tree.analysis.Value import java.util.* /** - * This class is a slightly version of `org.objectweb.asm.tree.analysis.Analyzer` + * This class is a modified version of `org.objectweb.asm.tree.analysis.Analyzer` * @author Eric Bruneton * @author Dmitry Petrov */ @@ -145,10 +146,10 @@ open class MethodAnalyzer( } catch (e: AnalyzerException) { - throw AnalyzerException(e.node, "Error at instruction " + insn + ": " + e.message, e) + throw AnalyzerException(e.node, "Error at instruction #" + insn + " ${InlineCodegenUtil.getInsnText(insnNode)}: " + e.message, e) } catch (e: Exception) { - throw AnalyzerException(insnNode, "Error at instruction " + insn + ": " + e.message, e) + throw AnalyzerException(insnNode, "Error at instruction #" + insn + " ${InlineCodegenUtil.getInsnText(insnNode)}: " + e.message, e) } } diff --git a/compiler/testData/codegen/box/controlStructures/kt14839.kt b/compiler/testData/codegen/box/controlStructures/kt14839.kt new file mode 100644 index 00000000000..c76925da31f --- /dev/null +++ b/compiler/testData/codegen/box/controlStructures/kt14839.kt @@ -0,0 +1,10 @@ +fun box(): String { + try { + } catch (e: Exception) { + inlineFunctionWithDefaultArguments(e) + } + return "OK" +} + +inline fun inlineFunctionWithDefaultArguments(t: Throwable? = null, bug: Boolean = true) = + Unit \ No newline at end of file diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 26e52582789..6d0530c5ea1 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -3932,6 +3932,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("kt14839.kt") + public void testKt14839() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt14839.kt"); + doTest(fileName); + } + @TestMetadata("kt1688.kt") public void testKt1688() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt1688.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index ebdcb61dfce..fec2b59a73b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -3932,6 +3932,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt14839.kt") + public void testKt14839() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt14839.kt"); + doTest(fileName); + } + @TestMetadata("kt1688.kt") public void testKt1688() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt1688.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 5524c10e1d3..14edfec19a0 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -4946,6 +4946,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("kt14839.kt") + public void testKt14839() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt14839.kt"); + doTest(fileName); + } + @TestMetadata("kt1688.kt") public void testKt1688() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt1688.kt");