From fd63fed8b4d1a482007b11b33a6db450187f606c Mon Sep 17 00:00:00 2001 From: Pavel Kunyavskiy Date: Tue, 21 Dec 2021 16:21:55 +0300 Subject: [PATCH] [K/N] Filecheck test for EnumWhenLowering --- .../backend.native/tests/build.gradle | 4 +++ .../tests/filecheck/enum_when.kt | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 kotlin-native/backend.native/tests/filecheck/enum_when.kt diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 6a4637d66f7..ad6cbbff42a 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -6019,6 +6019,10 @@ fileCheckTest("filecheck_escape_analysis_enabled") { checkPrefix = "CHECK-OPT" } +fileCheckTest("filecheck_enum_when") { + annotatedSource = project.file('filecheck/enum_when.kt') +} + fileCheckTest("filecheck_escape_analysis_disabled") { annotatedSource = project.file('filecheck/escape_analysis.kt') enabled = project.globalTestArgs.contains('-g') diff --git a/kotlin-native/backend.native/tests/filecheck/enum_when.kt b/kotlin-native/backend.native/tests/filecheck/enum_when.kt new file mode 100644 index 00000000000..ea59eaecb34 --- /dev/null +++ b/kotlin-native/backend.native/tests/filecheck/enum_when.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2010-2021 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. + */ + +enum class COLOR { + RED, + GREEN, + BLUE +} + +// CHECK-LABEL: "kfun:#main(){}" +fun main() { + for (i in COLOR.values()) { + // CHECK: = call i32 @"kfun:kotlin.Enum#(){}kotlin.Int"( + print(when (i) { + // we can't check the register is same, because it can be saved on stack and loaded back + // CHECK: icmp eq i32 %{{[0-9a-z]*}}, 0 + COLOR.RED -> 0xff0000 + // CHECK: icmp eq i32 %{{[0-9a-z]*}}, 1 + COLOR.GREEN -> 0x00ff00 + // CHECK: icmp eq i32 %{{[0-9a-z]*}}, 2 + COLOR.BLUE -> 0x0000ff + }) + } + // CHECK-LABEL: epilogue: +} \ No newline at end of file