KT-14839 Do not coerce after remapped variable store.

This commit is contained in:
Dmitry Petrov
2016-11-17 16:42:21 +03:00
parent 4b23c50bf8
commit 8b99141030
7 changed files with 46 additions and 5 deletions
@@ -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 "<null>";
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
@@ -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);
}
}
@@ -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<V : Value>(
}
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)
}
}
@@ -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
@@ -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");
@@ -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");
@@ -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");