From 95bef03d3ea186da944f4b89429d391dcac3b1b8 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Mon, 19 Jun 2023 18:17:25 +0300 Subject: [PATCH] [K/N][tests] Added a reproducer for KT-59501 --- .../backend.native/tests/build.gradle | 7 +++++++ .../escapeAnalysis/negativeArraySize.kt | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 kotlin-native/backend.native/tests/codegen/escapeAnalysis/negativeArraySize.kt 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() } +}