From 1ae0350ca5096315b7f22b965fadd773cffebb8a Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Wed, 24 May 2023 11:30:36 +0300 Subject: [PATCH] [K/N][tests] Added some file-check tests on KT-58654 --- .../backend.native/tests/build.gradle | 5 +++ .../backend.native/tests/filecheck/kt58654.kt | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 kotlin-native/backend.native/tests/filecheck/kt58654.kt diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index f4f59f56b4d..630f2195cb8 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -6422,6 +6422,11 @@ fileCheckTest("filecheck_kt49847_generic_receiver") { enabled = project.globalTestArgs.contains('-opt') } +fileCheckTest("filecheck_kt58654") { + annotatedSource = project.file('filecheck/kt58654.kt') + enabled = project.globalTestArgs.contains('-opt') +} + fileCheckTest("filecheck_kt53261_inline_unbox") { annotatedSource = project.file('filecheck/kt53261/kt53261_inline_unbox.kt') enabled = project.globalTestArgs.contains('-opt') diff --git a/kotlin-native/backend.native/tests/filecheck/kt58654.kt b/kotlin-native/backend.native/tests/filecheck/kt58654.kt new file mode 100644 index 00000000000..3b5b64a91a7 --- /dev/null +++ b/kotlin-native/backend.native/tests/filecheck/kt58654.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +// CHECK-LABEL: define i64 @"kfun:#foo(){}kotlin.Long"() +fun foo(): Long { + // CHECK-NOT: @LONG_CACHE + val data: Map = mapOf() + return data.getOrElse("id") { 0L } as Long +} +// CHECK: ret i64 + +inline fun bar(x: T?, f: Boolean): Any { + when { + x != null -> return@bar x + f -> return@bar 0L + else -> return@bar 1UL + } +} + +// CHECK-LABEL: define i64 @"kfun:#callBar(kotlin.Boolean){}kotlin.ULong"(i1 zeroext %0) +fun callBar(f: Boolean): ULong { + // CHECK: @LONG_CACHE + val data: Map = mapOf() + val x = data["id"] + return bar(x, f) as ULong +} +// CHECK: ret i64 + +fun main() { + println(foo()) + println(callBar(true)) +}