From 751f1a3b91b32abbe8096c597aef33aca6a8dc71 Mon Sep 17 00:00:00 2001 From: Elena Lepilkina Date: Mon, 25 Oct 2021 16:56:56 +0300 Subject: [PATCH] [K/N] Added FileCheck for noreturn attribute absence for suspend functions --- .../backend.native/tests/build.gradle | 4 ++ .../tests/filecheck/suspend_returnNothing.kt | 42 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 kotlin-native/backend.native/tests/filecheck/suspend_returnNothing.kt diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index b15b9933dff..079f987d95f 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -5894,6 +5894,10 @@ fileCheckTest("filecheck_escape_analysis_disabled") { checkPrefix = "CHECK-DEBUG" } +fileCheckTest("filecheck_suspend_returnNothing") { + annotatedSource = project.file('filecheck/suspend_returnNothing.kt') +} + fileCheckTest("filecheck_bce") { annotatedSource = project.file('filecheck/bce.kt') } diff --git a/kotlin-native/backend.native/tests/filecheck/suspend_returnNothing.kt b/kotlin-native/backend.native/tests/filecheck/suspend_returnNothing.kt new file mode 100644 index 00000000000..7ec9ff31bed --- /dev/null +++ b/kotlin-native/backend.native/tests/filecheck/suspend_returnNothing.kt @@ -0,0 +1,42 @@ +/* + * 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. + */ + +import kotlin.test.* + +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { + companion object : EmptyContinuation() + override fun resumeWith(result: Result) { result.getOrThrow() } +} + +suspend fun suspendForever(): Int = suspendCoroutineUninterceptedOrReturn { + COROUTINE_SUSPENDED +} +// CHECK-LABEL: define %struct.ObjHeader* @"kfun:$fooCOROUTINE + +// CHECK-NOT: ; Function Attrs: noreturn +// CHECK-LABEL: define %struct.ObjHeader* @"kfun:#foo(){}kotlin.Nothing" +suspend fun foo(): Nothing { + suspendForever() + throw Error() +} + +suspend fun bar() { + foo() +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun main() { + builder { + bar() + } + println("OK") +} +