diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 1c0351fbca9..0300956e235 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -3042,6 +3042,13 @@ standaloneTest("codegen_escapeAnalysis_string") { source = "codegen/escapeAnalysis/string.kt" } +standaloneTest("codegen_escapeAnalysis_negativeArraySize") { + disabled = (cacheTesting != null) || // Cache is not compatible with -opt. + project.globalTestArgs.contains('-g') // -g and -opt are incompatible + flags = ['-opt', '-tr', '-opt-in=kotlin.native.internal.InternalForKotlinNative'] + source = "codegen/escapeAnalysis/negativeArraySize.kt" +} + tasks.register("memory_var1", KonanLocalTest) { source = "runtime/memory/var1.kt" } diff --git a/kotlin-native/backend.native/tests/codegen/escapeAnalysis/negativeArraySize.kt b/kotlin-native/backend.native/tests/codegen/escapeAnalysis/negativeArraySize.kt new file mode 100644 index 00000000000..526839dee3d --- /dev/null +++ b/kotlin-native/backend.native/tests/codegen/escapeAnalysis/negativeArraySize.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +package codegen.escapeAnalysis.negativeArraySize + +import kotlin.test.* + +const val size = -42 + +fun foo() { + val arr = IntArray(size) { it } + for (x in arr) println(x) +} + +@Test fun runTest() { + assertFailsWith { foo() } +}