diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index ab9c191e2f3..4c6a5b0b77b 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -18313,6 +18313,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ieee754"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("anyCastToPrimitiveCompareTo1.kt") + public void testAnyCastToPrimitiveCompareTo1() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo1.kt"); + } + + @Test + @TestMetadata("anyCastToPrimitiveCompareTo2.kt") + public void testAnyCastToPrimitiveCompareTo2() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo2.kt"); + } + @Test @TestMetadata("anyToReal.kt") public void testAnyToReal() throws Exception { diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt index 305dfe47637..51106210d70 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt @@ -99,7 +99,7 @@ private class TypeOperatorLowering(private val backendContext: JvmBackendContext // We have to generate a null check here, because even if argument is of non-null type, // it can be uninitialized value, which is 'null' for reference types in JMM. // Most of such null checks will never actually throw, but we can't do anything about it. - irBlock { + irBlock(resultType = type) { +irCall(backendContext.ir.symbols.checkNotNullWithMessage).apply { putValueArgument(0, irGet(tmp.owner)) putValueArgument(1, message) diff --git a/compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo1.kt b/compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo1.kt new file mode 100644 index 00000000000..178261a8653 --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo1.kt @@ -0,0 +1,9 @@ +class C(val value: Any) + +fun box(): String { + val c1 = C(-0.0) + val c2 = C(0.toByte()) + val cmp = (c1.value as Double).compareTo(c2.value as Byte) + if (cmp != -1) return "Failed: cmp=$cmp" + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo2.kt b/compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo2.kt new file mode 100644 index 00000000000..846debe6bc2 --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo2.kt @@ -0,0 +1,9 @@ +class C(val value: Any) + +fun box(): String { + val c1 = C(1.1) + val c2 = C(1) + val cmp = (c1.value as Double).compareTo(c2.value as Int) + if (cmp != 1) return "Failed: cmp=$cmp" + return "OK" +} \ No newline at end of file diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index c4cac5cee96..3ad26964f2d 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -17917,6 +17917,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ieee754"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @Test + @TestMetadata("anyCastToPrimitiveCompareTo1.kt") + public void testAnyCastToPrimitiveCompareTo1() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo1.kt"); + } + + @Test + @TestMetadata("anyCastToPrimitiveCompareTo2.kt") + public void testAnyCastToPrimitiveCompareTo2() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo2.kt"); + } + @Test @TestMetadata("anyToReal.kt") public void testAnyToReal() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index ddd34d1108b..4a7947433ad 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -18313,6 +18313,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ieee754"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("anyCastToPrimitiveCompareTo1.kt") + public void testAnyCastToPrimitiveCompareTo1() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo1.kt"); + } + + @Test + @TestMetadata("anyCastToPrimitiveCompareTo2.kt") + public void testAnyCastToPrimitiveCompareTo2() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo2.kt"); + } + @Test @TestMetadata("anyToReal.kt") public void testAnyToReal() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index d25d0b9dc60..15f9e4d27eb 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -14873,6 +14873,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ieee754"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @TestMetadata("anyCastToPrimitiveCompareTo1.kt") + public void testAnyCastToPrimitiveCompareTo1() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo1.kt"); + } + + @TestMetadata("anyCastToPrimitiveCompareTo2.kt") + public void testAnyCastToPrimitiveCompareTo2() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo2.kt"); + } + @TestMetadata("anyToReal.kt") public void testAnyToReal() throws Exception { runTest("compiler/testData/codegen/box/ieee754/anyToReal.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index f70e9f00d1f..06000acf06a 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -13941,6 +13941,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ieee754"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); } + @Test + @TestMetadata("anyCastToPrimitiveCompareTo1.kt") + public void testAnyCastToPrimitiveCompareTo1() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo1.kt"); + } + + @Test + @TestMetadata("anyCastToPrimitiveCompareTo2.kt") + public void testAnyCastToPrimitiveCompareTo2() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo2.kt"); + } + @Test @TestMetadata("anyToReal.kt") public void testAnyToReal() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index 3a9a9054b02..4aef55e6eb7 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -13983,6 +13983,18 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ieee754"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test + @TestMetadata("anyCastToPrimitiveCompareTo1.kt") + public void testAnyCastToPrimitiveCompareTo1() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo1.kt"); + } + + @Test + @TestMetadata("anyCastToPrimitiveCompareTo2.kt") + public void testAnyCastToPrimitiveCompareTo2() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo2.kt"); + } + @Test @TestMetadata("anyToReal.kt") public void testAnyToReal() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index c4cde0eb24a..733f02b0a58 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -11710,6 +11710,16 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ieee754"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); } + @TestMetadata("anyCastToPrimitiveCompareTo1.kt") + public void testAnyCastToPrimitiveCompareTo1() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo1.kt"); + } + + @TestMetadata("anyCastToPrimitiveCompareTo2.kt") + public void testAnyCastToPrimitiveCompareTo2() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo2.kt"); + } + @TestMetadata("anyToReal.kt") public void testAnyToReal() throws Exception { runTest("compiler/testData/codegen/box/ieee754/anyToReal.kt"); diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/ExternalTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/ExternalTestGenerated.java index 17818fb6a7c..e33012a31b9 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/ExternalTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/ExternalTestGenerated.java @@ -14971,6 +14971,18 @@ public class ExternalTestGenerated extends AbstractExternalNativeBlackBoxTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ieee754"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); } + @Test + @TestMetadata("anyCastToPrimitiveCompareTo1.kt") + public void testAnyCastToPrimitiveCompareTo1() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo1.kt"); + } + + @Test + @TestMetadata("anyCastToPrimitiveCompareTo2.kt") + public void testAnyCastToPrimitiveCompareTo2() throws Exception { + runTest("compiler/testData/codegen/box/ieee754/anyCastToPrimitiveCompareTo2.kt"); + } + @Test @TestMetadata("anyToReal.kt") public void testAnyToReal() throws Exception {