diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 8360414fb2d46..2021950e7be63 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -2814,6 +2814,20 @@ standaloneTest("devirtualization_anonymousObject") { source = "codegen/devirtualization/anonymousObject.kt" } +standaloneTest("devirtualization_kt67281c") { + disabled = (cacheTesting != null) // Cache is not compatible with -opt. + useGoldenData = true + flags = ["-opt"] + source = "codegen/devirtualization/kt67218c.kt" +} + +standaloneTest("devirtualization_kt67281i") { + disabled = (cacheTesting != null) // Cache is not compatible with -opt. + useGoldenData = true + flags = ["-opt"] + source = "codegen/devirtualization/kt67218i.kt" +} + tasks.register("interfaceCallsNCasts_conservativeItable", KonanLocalTest) { useGoldenData = true source = "codegen/interfaceCallsNCasts/conservativeItable.kt" diff --git a/kotlin-native/backend.native/tests/codegen/devirtualization/kt67218c.kt b/kotlin-native/backend.native/tests/codegen/devirtualization/kt67218c.kt new file mode 100644 index 0000000000000..462c327148ea8 --- /dev/null +++ b/kotlin-native/backend.native/tests/codegen/devirtualization/kt67218c.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +open class A { + open fun foo() = 42 +} + +open class B : A() { + override fun foo() = 117 +} + +class C : A() + +class D : A() + +class E : B() + +class F : B() + +class G : B() + +fun foo(a: A) = a.foo() + +fun box(): String { + if (foo(E()) != 117) return "fail 1" + if (foo(F()) != 117) return "fail 2" + if (foo(G()) != 117) return "fail 3" + if (foo(C()) != 42) return "fail 4" + if (foo(D()) != 42) return "fail 5" + + return "OK" +} + +fun main() = println(box()) \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/codegen/devirtualization/kt67218c.out b/kotlin-native/backend.native/tests/codegen/devirtualization/kt67218c.out new file mode 100644 index 0000000000000..d86bac9de59ab --- /dev/null +++ b/kotlin-native/backend.native/tests/codegen/devirtualization/kt67218c.out @@ -0,0 +1 @@ +OK diff --git a/kotlin-native/backend.native/tests/codegen/devirtualization/kt67218i.kt b/kotlin-native/backend.native/tests/codegen/devirtualization/kt67218i.kt new file mode 100644 index 0000000000000..37831f4091447 --- /dev/null +++ b/kotlin-native/backend.native/tests/codegen/devirtualization/kt67218i.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +interface I { + fun foo() = 42 +} + +open class B : I { + override fun foo() = 117 +} + +class C : I + +class D : I + +class E : B() + +class F : B() + +class G : B() + +fun foo(i: I) = i.foo() + +fun box(): String { + if (foo(E()) != 117) return "fail 1" + if (foo(F()) != 117) return "fail 2" + if (foo(G()) != 117) return "fail 3" + if (foo(C()) != 42) return "fail 4" + if (foo(D()) != 42) return "fail 5" + + return "OK" +} + +fun main() = println(box()) \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/codegen/devirtualization/kt67218i.out b/kotlin-native/backend.native/tests/codegen/devirtualization/kt67218i.out new file mode 100644 index 0000000000000..d86bac9de59ab --- /dev/null +++ b/kotlin-native/backend.native/tests/codegen/devirtualization/kt67218i.out @@ -0,0 +1 @@ +OK