diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 74da580dbae..7dc3eb650e5 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -1757,6 +1757,16 @@ task memory_throw_cleanup(type: RunKonanTest) { source = "runtime/memory/throw_cleanup.kt" } +task memory_escape1(type: RunKonanTest) { + goldValue = "zzz\n" + source = "runtime/memory/escape1.kt" +} + +task memory_escape2(type: RunKonanTest) { + goldValue = "zzz\n" + source = "runtime/memory/escape2.kt" +} + task unit1(type: RunKonanTest) { goldValue = "First\nkotlin.Unit\n" source = "codegen/basics/unit1.kt" diff --git a/backend.native/tests/runtime/memory/escape1.kt b/backend.native/tests/runtime/memory/escape1.kt new file mode 100644 index 00000000000..12f5bb91782 --- /dev/null +++ b/backend.native/tests/runtime/memory/escape1.kt @@ -0,0 +1,14 @@ +class B(val s: String) + +class A { + val b = B("zzz") +} + +fun foo(): B { + val a = A() + return a.b +} + +fun main(args: Array) { + println(foo().s) +} \ No newline at end of file diff --git a/backend.native/tests/runtime/memory/escape2.kt b/backend.native/tests/runtime/memory/escape2.kt new file mode 100644 index 00000000000..d860d23370a --- /dev/null +++ b/backend.native/tests/runtime/memory/escape2.kt @@ -0,0 +1,23 @@ +class A(val s: String) + +class B { + var a: A? = null +} + +class C(val b: B) + +fun foo(c: C) { + c.b.a = A("zzz") +} + +fun bar(b: B) { + val c = C(b) + foo(c) +} + +val global = B() + +fun main(args: Array) { + bar(global) + println(global.a!!.s) +} \ No newline at end of file