From 2931c316a354e1c45e091d2ef9f2c5fe68b06066 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Mon, 9 Jan 2017 17:50:11 +0100 Subject: [PATCH] Fix for KT-15575: VerifyError: Bad type on operand stack #KT-15575 Fixed --- .../org/jetbrains/kotlin/codegen/AsmUtil.java | 3 ++- .../kotlin/codegen/intrinsics/ArraySet.kt | 2 +- .../common/OptimizationBasicInterpreter.java | 3 ++- .../codegen/box/arrays/multiDecl/kt15560.kt | 9 +++++++++ .../codegen/box/arrays/multiDecl/kt15568.kt | 13 +++++++++++++ .../codegen/box/arrays/multiDecl/kt15575.kt | 9 +++++++++ .../arrays/multiDecl/kt15560.txt | 4 ++++ .../arrays/multiDecl/kt15568.txt | 4 ++++ .../arrays/multiDecl/kt15575.txt | 5 +++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 18 ++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 18 ++++++++++++++++++ .../LightAnalysisModeCodegenTestGenerated.java | 18 ++++++++++++++++++ .../semantics/JsCodegenBoxTestGenerated.java | 18 ++++++++++++++++++ .../kotlin/kapt3/javac/KaptTreeMaker.kt | 3 ++- 14 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/codegen/box/arrays/multiDecl/kt15560.kt create mode 100644 compiler/testData/codegen/box/arrays/multiDecl/kt15568.kt create mode 100644 compiler/testData/codegen/box/arrays/multiDecl/kt15575.kt create mode 100644 compiler/testData/codegen/light-analysis/arrays/multiDecl/kt15560.txt create mode 100644 compiler/testData/codegen/light-analysis/arrays/multiDecl/kt15568.txt create mode 100644 compiler/testData/codegen/light-analysis/arrays/multiDecl/kt15575.txt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java index 2893250440f..192e4eceb11 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java @@ -161,7 +161,8 @@ public class AsmUtil { return isPrimitiveClass((ClassDescriptor) descriptor) && !isBoolean((ClassDescriptor) descriptor); } - public static Type correctElementType(Type type) { + @NotNull + public static Type correctElementType(@NotNull Type type) { String internalName = type.getInternalName(); assert internalName.charAt(0) == '['; return Type.getType(internalName.substring(1)); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArraySet.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArraySet.kt index ff1a2d7b5f0..bf8e3642e7c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArraySet.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArraySet.kt @@ -24,7 +24,7 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter class ArraySet : IntrinsicMethod() { override fun toCallable(method: CallableMethod): Callable { - val type = correctElementType(method.dispatchReceiverType) + val type = correctElementType(method.dispatchReceiverType!!) return object : IntrinsicCallable( Type.VOID_TYPE, listOf(Type.INT_TYPE, type), diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/OptimizationBasicInterpreter.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/OptimizationBasicInterpreter.java index 640bf95cdbb..7930ad52f01 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/OptimizationBasicInterpreter.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/OptimizationBasicInterpreter.java @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.codegen.optimization.common; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.kotlin.codegen.AsmUtil; import org.jetbrains.org.objectweb.asm.Handle; import org.jetbrains.org.objectweb.asm.Opcodes; import org.jetbrains.org.objectweb.asm.Type; @@ -164,7 +165,7 @@ public class OptimizationBasicInterpreter extends Interpreter implem if (insn.getOpcode() == Opcodes.AALOAD) { Type arrayType = value1.getType(); if (arrayType != null && arrayType.getSort() == Type.ARRAY) { - return new StrictBasicValue(arrayType.getElementType()); + return new StrictBasicValue(AsmUtil.correctElementType(arrayType)); } } diff --git a/compiler/testData/codegen/box/arrays/multiDecl/kt15560.kt b/compiler/testData/codegen/box/arrays/multiDecl/kt15560.kt new file mode 100644 index 00000000000..552a6653a97 --- /dev/null +++ b/compiler/testData/codegen/box/arrays/multiDecl/kt15560.kt @@ -0,0 +1,9 @@ +fun box(): String { + val array = arrayOf(doubleArrayOf(-1.0)) + for (node in array) { + node[0] += 1.0 + } + if (array[0][0] != 0.0) return "fail ${array[0][0]}" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/arrays/multiDecl/kt15568.kt b/compiler/testData/codegen/box/arrays/multiDecl/kt15568.kt new file mode 100644 index 00000000000..c030c22b217 --- /dev/null +++ b/compiler/testData/codegen/box/arrays/multiDecl/kt15568.kt @@ -0,0 +1,13 @@ +fun box(): String { + val a = Array(2) { DoubleArray(3) } + + for (i in 1..1) { + for (j in 0..2) { + a[i][j] += a[i - 1][j] + } + } + + if (a[0][0] != 0.0) return "fail ${a[0][0]}" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/arrays/multiDecl/kt15575.kt b/compiler/testData/codegen/box/arrays/multiDecl/kt15575.kt new file mode 100644 index 00000000000..16a7300358b --- /dev/null +++ b/compiler/testData/codegen/box/arrays/multiDecl/kt15575.kt @@ -0,0 +1,9 @@ +fun box(): String { + val transform = transform(Array(1) { BooleanArray(1) }) + if (!transform[0][0]) return "OK" + return "fail" +} + +fun transform(screen: Array) = Array(1) { x -> + screen[x] +} \ No newline at end of file diff --git a/compiler/testData/codegen/light-analysis/arrays/multiDecl/kt15560.txt b/compiler/testData/codegen/light-analysis/arrays/multiDecl/kt15560.txt new file mode 100644 index 00000000000..cfcf74932c5 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/arrays/multiDecl/kt15560.txt @@ -0,0 +1,4 @@ +@kotlin.Metadata +public final class Kt15560Kt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} diff --git a/compiler/testData/codegen/light-analysis/arrays/multiDecl/kt15568.txt b/compiler/testData/codegen/light-analysis/arrays/multiDecl/kt15568.txt new file mode 100644 index 00000000000..0bc07fdcfb1 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/arrays/multiDecl/kt15568.txt @@ -0,0 +1,4 @@ +@kotlin.Metadata +public final class Kt15568Kt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} diff --git a/compiler/testData/codegen/light-analysis/arrays/multiDecl/kt15575.txt b/compiler/testData/codegen/light-analysis/arrays/multiDecl/kt15575.txt new file mode 100644 index 00000000000..8c8e38e8bb7 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/arrays/multiDecl/kt15575.txt @@ -0,0 +1,5 @@ +@kotlin.Metadata +public final class Kt15575Kt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method transform(@org.jetbrains.annotations.NotNull p0: boolean[][]): boolean[][] +} 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 5b7ccb1ca5f..55f740cb4e4 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 @@ -619,6 +619,24 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/multiDecl"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("kt15560.kt") + public void testKt15560() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15560.kt"); + doTest(fileName); + } + + @TestMetadata("kt15568.kt") + public void testKt15568() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15568.kt"); + doTest(fileName); + } + + @TestMetadata("kt15575.kt") + public void testKt15575() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15575.kt"); + doTest(fileName); + } + @TestMetadata("MultiDeclFor.kt") public void testMultiDeclFor() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclFor.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index ead2492392d..b26a036dd01 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -619,6 +619,24 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/multiDecl"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("kt15560.kt") + public void testKt15560() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15560.kt"); + doTest(fileName); + } + + @TestMetadata("kt15568.kt") + public void testKt15568() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15568.kt"); + doTest(fileName); + } + + @TestMetadata("kt15575.kt") + public void testKt15575() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15575.kt"); + doTest(fileName); + } + @TestMetadata("MultiDeclFor.kt") public void testMultiDeclFor() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclFor.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java index 8afba6527ed..b6287a5507e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java @@ -619,6 +619,24 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/multiDecl"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("kt15560.kt") + public void testKt15560() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15560.kt"); + doTest(fileName); + } + + @TestMetadata("kt15568.kt") + public void testKt15568() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15568.kt"); + doTest(fileName); + } + + @TestMetadata("kt15575.kt") + public void testKt15575() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15575.kt"); + doTest(fileName); + } + @TestMetadata("MultiDeclFor.kt") public void testMultiDeclFor() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclFor.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 c3bba46ec50..d81bf539c71 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 @@ -859,6 +859,24 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/multiDecl"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); } + @TestMetadata("kt15560.kt") + public void testKt15560() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15560.kt"); + doTest(fileName); + } + + @TestMetadata("kt15568.kt") + public void testKt15568() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15568.kt"); + doTest(fileName); + } + + @TestMetadata("kt15575.kt") + public void testKt15575() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15575.kt"); + doTest(fileName); + } + @TestMetadata("MultiDeclFor.kt") public void testMultiDeclFor() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclFor.kt"); diff --git a/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/javac/KaptTreeMaker.kt b/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/javac/KaptTreeMaker.kt index 978a5d938a7..6f7ac735031 100644 --- a/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/javac/KaptTreeMaker.kt +++ b/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/javac/KaptTreeMaker.kt @@ -21,6 +21,7 @@ import com.sun.tools.javac.tree.JCTree import com.sun.tools.javac.tree.TreeMaker import com.sun.tools.javac.util.Context import com.sun.tools.javac.util.Names +import org.jetbrains.kotlin.codegen.AsmUtil import org.jetbrains.org.objectweb.asm.Type import org.jetbrains.org.objectweb.asm.Type.* @@ -30,7 +31,7 @@ class KaptTreeMaker(context: Context) : TreeMaker(context) { fun Type(type: Type): JCTree.JCExpression { convertBuiltinType(type)?.let { return it } if (type.sort == ARRAY) { - return TypeArray(Type(type.elementType)) + return TypeArray(Type(AsmUtil.correctElementType(type))) } return FqName(type.className) }