diff --git a/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/SpecialFiles.java b/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/SpecialFiles.java index 4cf8df0799f..2ae161aee0a 100644 --- a/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/SpecialFiles.java +++ b/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/SpecialFiles.java @@ -64,9 +64,6 @@ public class SpecialFiles { excludedFiles.add("kt684.kt"); // StackOverflow with StringBuilder (escape()) - excludedFiles.add("kt529.kt"); // Bug - excludedFiles.add("kt344.kt"); // Bug - excludedFiles.add("genericBackingFieldSignature.kt"); // Wrong signature after package renaming excludedFiles.add("genericMethodSignature.kt"); // Wrong signature after package renaming diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java index 5160b6ee94b..99a307481dc 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java @@ -562,11 +562,6 @@ public class AsmUtil { v.invokestatic(IntrinsicMethods.INTRINSICS_CLASS_NAME, "areEqual", "(Ljava/lang/Object;Ljava/lang/Object;)Z", false); } - public static void genIncrement(Type expectedType, int myDelta, InstructionAdapter v) { - numConst(myDelta, expectedType, v); - v.add(expectedType); - } - public static void numConst(int value, Type type, InstructionAdapter v) { if (type == Type.FLOAT_TYPE) { v.fconst(value); @@ -585,9 +580,11 @@ public class AsmUtil { } } - public static void genIncrement(Type expectedType, Type baseType, int myDelta, InstructionAdapter v) { - genIncrement(baseType, myDelta, v); - StackValue.coerce(baseType, expectedType, v); + public static void genIncrement(Type baseType, int myDelta, InstructionAdapter v) { + Type operationType = numberFunctionOperandType(baseType); + numConst(myDelta, operationType, v); + v.add(operationType); + StackValue.coerce(operationType, baseType, v); } public static void swap(InstructionAdapter v, Type stackTop, Type afterTop) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index ac878f2bbaa..159ce2b2b43 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -3348,7 +3348,7 @@ public class ExpressionCodegen extends KtVisitor impleme Type storeType; if (isPrimitiveNumberClassDescriptor && AsmUtil.isPrimitive(asmBaseType)) { - genIncrement(asmResultType, asmBaseType, increment, v); + genIncrement(asmBaseType, increment, v); storeType = asmBaseType; } else { diff --git a/compiler/testData/codegen/box/intrinsics/kt12125.kt b/compiler/testData/codegen/box/intrinsics/kt12125.kt new file mode 100644 index 00000000000..c45ffb3f57c --- /dev/null +++ b/compiler/testData/codegen/box/intrinsics/kt12125.kt @@ -0,0 +1,17 @@ +fun test(i: Int): Int { + return i +} + +fun box(): String { + var b = Byte.MAX_VALUE + b++ + var result = test(b.toInt()) + if (result != Byte.MIN_VALUE.toInt()) return "fail 1: $result" + + var s = Short.MIN_VALUE + s-- + result = test(s.toInt()) + if (result != Short.MAX_VALUE.toInt()) return "fail 2: $result" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/intrinsics/kt12125_2.kt b/compiler/testData/codegen/box/intrinsics/kt12125_2.kt new file mode 100644 index 00000000000..c9890efe644 --- /dev/null +++ b/compiler/testData/codegen/box/intrinsics/kt12125_2.kt @@ -0,0 +1,16 @@ +fun box(): String { + var aByte: Byte? = 0 + var bByte: Byte = 0 + + if (aByte != null) aByte-- + bByte-- + if (aByte != bByte) return "Failed post-decrement Byte: $aByte != $bByte" + + if (aByte != null) aByte++ + bByte++ + if (aByte != bByte) return "Failed post-increment Byte: $aByte != $bByte" + + aByte = null + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/intrinsics/kt12125_inc.kt b/compiler/testData/codegen/box/intrinsics/kt12125_inc.kt new file mode 100644 index 00000000000..f531e713ef5 --- /dev/null +++ b/compiler/testData/codegen/box/intrinsics/kt12125_inc.kt @@ -0,0 +1,15 @@ +fun test(i: Int): Int { + return i +} + +fun box(): String { + var b = Byte.MAX_VALUE + var result = test(b.inc().toInt()) + if (result != Byte.MIN_VALUE.toInt()) return "fail 1: $result" + + var s = Short.MAX_VALUE + result = test(s.inc().toInt()) + if (result != Short.MIN_VALUE.toInt()) return "fail 2: $result" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/intrinsics/kt12125_inc_2.kt b/compiler/testData/codegen/box/intrinsics/kt12125_inc_2.kt new file mode 100644 index 00000000000..953ccf8dc76 --- /dev/null +++ b/compiler/testData/codegen/box/intrinsics/kt12125_inc_2.kt @@ -0,0 +1,20 @@ +fun test(i: Int): Int { + return i +} + +fun box(): String { + var aByte: Byte? = 0 + var bByte: Byte = 0 + + if (aByte != null) { + if (aByte.dec() != bByte.dec()) return "Failed post-decrement Byte: ${aByte.dec()} != ${bByte.dec()}" + } + + if (aByte != null) { + if (aByte.inc() != bByte.inc()) return "Failed post-increment Byte: ${aByte.inc()} != ${bByte.inc()}" + } + + aByte = null + + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 5f2dd0ab861..9ec16eb6b8b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -7000,6 +7000,30 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt12125.kt") + public void testKt12125() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/intrinsics/kt12125.kt"); + doTest(fileName); + } + + @TestMetadata("kt12125_2.kt") + public void testKt12125_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/intrinsics/kt12125_2.kt"); + doTest(fileName); + } + + @TestMetadata("kt12125_inc.kt") + public void testKt12125_inc() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/intrinsics/kt12125_inc.kt"); + doTest(fileName); + } + + @TestMetadata("kt12125_inc_2.kt") + public void testKt12125_inc_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/intrinsics/kt12125_inc_2.kt"); + doTest(fileName); + } + @TestMetadata("kt5937.kt") public void testKt5937() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/intrinsics/kt5937.kt");