diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 18dccc25083..a80dd5da3a1 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -753,3 +753,23 @@ task expression_as_statement(type: RunKonanTest) { goldValue = "Ok\n" source = "codegen/basics/expression_as_statement.kt" } + +task memory_var1(type: RunKonanTest) { + disabled = true + source = "runtime/memory/var1.kt" +} + +task memory_var2(type: RunKonanTest) { + disabled = true + source = "runtime/memory/var2.kt" +} + +task memory_var3(type: RunKonanTest) { + disabled = true + source = "runtime/memory/var3.kt" +} + +task memory_var4(type: RunKonanTest) { + disabled = true + source = "runtime/memory/var4.kt" +} \ No newline at end of file diff --git a/backend.native/tests/runtime/memory/var1.kt b/backend.native/tests/runtime/memory/var1.kt new file mode 100644 index 00000000000..2969dcad805 --- /dev/null +++ b/backend.native/tests/runtime/memory/var1.kt @@ -0,0 +1,25 @@ +class Integer(val value: Int) { + operator fun inc() = Integer(value + 1) +} + +fun foo(x: Any, y: Any) { + x.use() + y.use() +} + +fun main(args : Array) { + var x = Integer(0) + + for (i in 0..1) { + val c = Integer(0) + if (i == 0) x = c + } + + // x refcount is 1. + + foo(x, ++x) +} + +fun Any?.use() { + var x = this +} \ No newline at end of file diff --git a/backend.native/tests/runtime/memory/var2.kt b/backend.native/tests/runtime/memory/var2.kt new file mode 100644 index 00000000000..aa064da42fa --- /dev/null +++ b/backend.native/tests/runtime/memory/var2.kt @@ -0,0 +1,22 @@ +fun main(args : Array) { + var x = Any() + + for (i in 0..1) { + val c = Any() + if (i == 0) x = c + } + + // x refcount is 1. + + val y = try { + x + } finally { + x = Any() + } + + y.use() +} + +fun Any?.use() { + var x = this +} \ No newline at end of file diff --git a/backend.native/tests/runtime/memory/var3.kt b/backend.native/tests/runtime/memory/var3.kt new file mode 100644 index 00000000000..81030b928bc --- /dev/null +++ b/backend.native/tests/runtime/memory/var3.kt @@ -0,0 +1,24 @@ +fun main(args : Array) { + foo().use() +} + +fun foo(): Any { + var x = Any() + + for (i in 0..1) { + val c = Any() + if (i == 0) x = c + } + + // x refcount is 1. + + try { + return x + } finally { + x = Any() + } +} + +fun Any?.use() { + var x = this +} \ No newline at end of file diff --git a/backend.native/tests/runtime/memory/var4.kt b/backend.native/tests/runtime/memory/var4.kt new file mode 100644 index 00000000000..37e3746880c --- /dev/null +++ b/backend.native/tests/runtime/memory/var4.kt @@ -0,0 +1,24 @@ +fun main(args : Array) { + var x = Error() + + for (i in 0..1) { + val c = Error() + if (i == 0) x = c + } + + // x refcount is 1. + + try { + try { + throw x + } finally { + x = Error() + } + } catch (e: Error) { + e.use() + } +} + +fun Any?.use() { + var x = this +} \ No newline at end of file