From f8341ad7ebb1ea97ab356a38aa92998ecd67eaed Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Tue, 14 Jan 2020 11:18:27 +0300 Subject: [PATCH] JVM: Update tests for IEEE 754 comparisons --- .../intrinsicsCompare/byteSmartCast_after.kt | 18 ++++++++ ...teSmartCast.kt => byteSmartCast_before.kt} | 1 + .../intrinsicsCompare/differentTypes_after.kt | 21 +++++++++ ...erentTypes.kt => differentTypes_before.kt} | 1 + .../intrinsicsCompare/intSmartCast_after.kt | 17 +++++++ ...intSmartCast.kt => intSmartCast_before.kt} | 1 + .../intrinsicsCompare/shortSmartCast_after.kt | 18 ++++++++ ...tSmartCast.kt => shortSmartCast_before.kt} | 1 + .../ieee754/smartCastsForDouble10.kt | 1 + .../ieee754/smartCastsForFloat10.kt | 1 + .../oldLanguageVersions/ieee754/when10.kt | 1 + .../ieee754/whenNullableSmartCast10.kt | 1 + .../codegen/BytecodeTextTestGenerated.java | 44 ++++++++++++++----- .../ir/IrBytecodeTextTestGenerated.java | 44 ++++++++++++++----- 14 files changed, 146 insertions(+), 24 deletions(-) create mode 100644 compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast_after.kt rename compiler/testData/codegen/bytecodeText/intrinsicsCompare/{byteSmartCast.kt => byteSmartCast_before.kt} (93%) create mode 100644 compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes_after.kt rename compiler/testData/codegen/bytecodeText/intrinsicsCompare/{differentTypes.kt => differentTypes_before.kt} (88%) create mode 100644 compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast_after.kt rename compiler/testData/codegen/bytecodeText/intrinsicsCompare/{intSmartCast.kt => intSmartCast_before.kt} (93%) create mode 100644 compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast_after.kt rename compiler/testData/codegen/bytecodeText/intrinsicsCompare/{shortSmartCast.kt => shortSmartCast_before.kt} (93%) diff --git a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast_after.kt b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast_after.kt new file mode 100644 index 00000000000..cd1d063bb48 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast_after.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +ProperIeee754Comparisons +// IGNORE_BACKEND: JVM_IR +fun equals3(a: Byte?, b: Byte?) = a != null && b != null && a == b + +fun equals4(a: Byte?, b: Byte?) = if (a is Byte && b is Byte) a == b else null!! + +fun equals5(a: Any?, b: Any?) = if (a is Byte && b is Byte) a == b else null!! + +fun less3(a: Byte?, b: Byte?) = a != null && b != null && a < b + +fun less4(a: Byte?, b: Byte?) = if (a is Byte && b is Byte) a < b else true + +fun less5(a: Any?, b: Any?) = if (a is Byte && b is Byte) a < b else true + +// 3 Intrinsics\.areEqual +// 0 Intrinsics\.compare +// 0 IFGE +// 3 IF_ICMPGE diff --git a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast.kt b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast_before.kt similarity index 93% rename from compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast.kt rename to compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast_before.kt index 55d8f5af842..fa7d89ac58f 100644 --- a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast.kt +++ b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast_before.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: -ProperIeee754Comparisons // IGNORE_BACKEND: JVM_IR fun equals3(a: Byte?, b: Byte?) = a != null && b != null && a == b diff --git a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes_after.kt b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes_after.kt new file mode 100644 index 00000000000..13a8be1428f --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes_after.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +ProperIeee754Comparisons +fun box(): String { + val zero: Any = 0.0 + val floatZero: Any = -0.0F + if (zero is Double && floatZero is Float) { + if (zero == floatZero) return "fail 1" + + if (zero <= floatZero) return "fail 2" + + return "OK" + } + + return "fail" +} + +// 0 Intrinsics\.areEqual +// 0 Double\.compare +// 2 F2D +// 2 DCMPG +// 1 IFNE +// 1 IFGT diff --git a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes.kt b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes_before.kt similarity index 88% rename from compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes.kt rename to compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes_before.kt index e7437c18cd6..c1928da1dff 100644 --- a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes.kt +++ b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes_before.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: -ProperIeee754Comparisons fun box(): String { val zero: Any = 0.0 val floatZero: Any = -0.0F diff --git a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast_after.kt b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast_after.kt new file mode 100644 index 00000000000..ff1be5417a7 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast_after.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +ProperIeee754Comparisons +fun equals3(a: Int?, b: Int?) = a != null && b != null && a == b + +fun equals4(a: Int?, b: Int?) = if (a is Int && b is Int) a == b else null!! + +fun equals5(a: Any?, b: Any?) = if (a is Int && b is Int) a == b else null!! + +fun less3(a: Int?, b: Int?) = a != null && b != null && a < b + +fun less4(a: Int?, b: Int?) = if (a is Int && b is Int) a < b else true + +fun less5(a: Any?, b: Any?) = if (a is Int && b is Int) a < b else true + +// 3 Intrinsics\.areEqual +// 0 Intrinsics\.compare +// 0 IFGE +// 3 IF_ICMPGE diff --git a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast.kt b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast_before.kt similarity index 93% rename from compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast.kt rename to compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast_before.kt index 24a8e417951..e0d41de4841 100644 --- a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast.kt +++ b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast_before.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: -ProperIeee754Comparisons // IGNORE_BACKEND: JVM_IR fun equals3(a: Int?, b: Int?) = a != null && b != null && a == b diff --git a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast_after.kt b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast_after.kt new file mode 100644 index 00000000000..d0d6022b283 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast_after.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +ProperIeee754Comparisons +// IGNORE_BACKEND: JVM_IR +fun equals3(a: Short?, b: Short?) = a != null && b != null && a == b + +fun equals4(a: Short?, b: Short?) = if (a is Short && b is Short) a == b else null!! + +fun equals5(a: Any?, b: Any?) = if (a is Short && b is Short) a == b else null!! + +fun less3(a: Short?, b: Short?) = a != null && b != null && a < b + +fun less4(a: Short?, b: Short?) = if (a is Short && b is Short) a < b else true + +fun less5(a: Any?, b: Any?) = if (a is Short && b is Short) a < b else true + +// 3 Intrinsics\.areEqual +// 0 Intrinsics\.compare +// 0 IFGE +// 3 IF_ICMPGE diff --git a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast.kt b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast_before.kt similarity index 93% rename from compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast.kt rename to compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast_before.kt index 0b128ac3d34..7810d0cb0a7 100644 --- a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast.kt +++ b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast_before.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: -ProperIeee754Comparisons // IGNORE_BACKEND: JVM_IR fun equals3(a: Short?, b: Short?) = a != null && b != null && a == b diff --git a/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/smartCastsForDouble10.kt b/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/smartCastsForDouble10.kt index f8df33f71ce..75875819434 100644 --- a/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/smartCastsForDouble10.kt +++ b/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/smartCastsForDouble10.kt @@ -1,4 +1,5 @@ // !API_VERSION: 1.0 +// !LANGUAGE: -ProperIeee754Comparisons fun equals5(a: Any?, b: Any?) = if (a is Double && b is Double?) a == b else null!! diff --git a/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/smartCastsForFloat10.kt b/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/smartCastsForFloat10.kt index b2305921b35..7499ab00d36 100644 --- a/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/smartCastsForFloat10.kt +++ b/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/smartCastsForFloat10.kt @@ -1,4 +1,5 @@ // !API_VERSION: 1.0 +// !LANGUAGE: -ProperIeee754Comparisons fun equals5(a: Any?, b: Any?) = if (a is Float && b is Float?) a == b else null!! diff --git a/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/when10.kt b/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/when10.kt index 7e24c887fcb..ceb62e6dbe3 100644 --- a/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/when10.kt +++ b/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/when10.kt @@ -1,4 +1,5 @@ // !API_VERSION: 1.0 +// !LANGUAGE: -ProperIeee754Comparisons fun box(): String { val plusZero: Any = 0.0 diff --git a/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/whenNullableSmartCast10.kt b/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/whenNullableSmartCast10.kt index 77c857700e8..2446ec3b043 100644 --- a/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/whenNullableSmartCast10.kt +++ b/compiler/testData/codegen/bytecodeText/oldLanguageVersions/ieee754/whenNullableSmartCast10.kt @@ -1,4 +1,5 @@ // !API_VERSION: 1.0 +// !LANGUAGE: -ProperIeee754Comparisons fun box(): String { val nullValue: Any? = null diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index b6b7271428b..b4a0cbf9749 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -2891,9 +2891,14 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeText/intrinsicsCompare"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } - @TestMetadata("byteSmartCast.kt") - public void testByteSmartCast() throws Exception { - runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast.kt"); + @TestMetadata("byteSmartCast_after.kt") + public void testByteSmartCast_after() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast_after.kt"); + } + + @TestMetadata("byteSmartCast_before.kt") + public void testByteSmartCast_before() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast_before.kt"); } @TestMetadata("charSmartCast.kt") @@ -2901,14 +2906,24 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/charSmartCast.kt"); } - @TestMetadata("differentTypes.kt") - public void testDifferentTypes() throws Exception { - runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes.kt"); + @TestMetadata("differentTypes_after.kt") + public void testDifferentTypes_after() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes_after.kt"); } - @TestMetadata("intSmartCast.kt") - public void testIntSmartCast() throws Exception { - runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast.kt"); + @TestMetadata("differentTypes_before.kt") + public void testDifferentTypes_before() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes_before.kt"); + } + + @TestMetadata("intSmartCast_after.kt") + public void testIntSmartCast_after() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast_after.kt"); + } + + @TestMetadata("intSmartCast_before.kt") + public void testIntSmartCast_before() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast_before.kt"); } @TestMetadata("longSmartCast.kt") @@ -2916,9 +2931,14 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/longSmartCast.kt"); } - @TestMetadata("shortSmartCast.kt") - public void testShortSmartCast() throws Exception { - runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast.kt"); + @TestMetadata("shortSmartCast_after.kt") + public void testShortSmartCast_after() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast_after.kt"); + } + + @TestMetadata("shortSmartCast_before.kt") + public void testShortSmartCast_before() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast_before.kt"); } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java index 708e04d19fa..055320f0a26 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java @@ -2936,9 +2936,14 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeText/intrinsicsCompare"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } - @TestMetadata("byteSmartCast.kt") - public void testByteSmartCast() throws Exception { - runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast.kt"); + @TestMetadata("byteSmartCast_after.kt") + public void testByteSmartCast_after() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast_after.kt"); + } + + @TestMetadata("byteSmartCast_before.kt") + public void testByteSmartCast_before() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast_before.kt"); } @TestMetadata("charSmartCast.kt") @@ -2946,14 +2951,24 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/charSmartCast.kt"); } - @TestMetadata("differentTypes.kt") - public void testDifferentTypes() throws Exception { - runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes.kt"); + @TestMetadata("differentTypes_after.kt") + public void testDifferentTypes_after() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes_after.kt"); } - @TestMetadata("intSmartCast.kt") - public void testIntSmartCast() throws Exception { - runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast.kt"); + @TestMetadata("differentTypes_before.kt") + public void testDifferentTypes_before() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes_before.kt"); + } + + @TestMetadata("intSmartCast_after.kt") + public void testIntSmartCast_after() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast_after.kt"); + } + + @TestMetadata("intSmartCast_before.kt") + public void testIntSmartCast_before() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast_before.kt"); } @TestMetadata("longSmartCast.kt") @@ -2961,9 +2976,14 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/longSmartCast.kt"); } - @TestMetadata("shortSmartCast.kt") - public void testShortSmartCast() throws Exception { - runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast.kt"); + @TestMetadata("shortSmartCast_after.kt") + public void testShortSmartCast_after() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast_after.kt"); + } + + @TestMetadata("shortSmartCast_before.kt") + public void testShortSmartCast_before() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast_before.kt"); } }