From 56e08e40e894e382adb951dbc9ea9dfc119d538c Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Mon, 7 Aug 2017 16:45:35 +0300 Subject: [PATCH] Added some corner tests on escape analysis --- backend.native/tests/build.gradle | 10 ++++++++ .../tests/runtime/memory/escape1.kt | 14 +++++++++++ .../tests/runtime/memory/escape2.kt | 23 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 backend.native/tests/runtime/memory/escape1.kt create mode 100644 backend.native/tests/runtime/memory/escape2.kt 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