From 9dd8266bee9fed737c515255edf957c9ddac3e5c Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Mon, 23 Aug 2021 17:04:18 +0700 Subject: [PATCH] [K/N] Add trivial test for `llvm.objc.clang.arc.use` lowering --- .../backend.native/tests/build.gradle | 13 ++++++++++ .../tests/interop/objc_arc_contract/main.kt | 10 +++++++ .../tests/interop/objc_arc_contract/main.ll | 9 +++++++ .../kotlin/org/jetbrains/kotlin/ExecLlvm.kt | 26 +++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 kotlin-native/backend.native/tests/interop/objc_arc_contract/main.kt create mode 100644 kotlin-native/backend.native/tests/interop/objc_arc_contract/main.ll diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 41a7a652833..c00bafbc431 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -4862,6 +4862,19 @@ if (PlatformInfo.isAppleTarget(project)) { } } } + + standaloneTest("objc_arc_contract") { + doBeforeBuild { + mkdir(buildDir) + ExecLlvmKt.execLlvmUtility(project, "llvm-as") { + args "$projectDir/interop/objc_arc_contract/main.ll" + args "-o", "$buildDir/objc_arc_contract.bc" + } + } + source = "interop/objc_arc_contract/main.kt" + goldValue = "ok\n" + flags = ["-native-library", "$buildDir/objc_arc_contract.bc"] + } } standaloneTest("jsinterop_math") { diff --git a/kotlin-native/backend.native/tests/interop/objc_arc_contract/main.kt b/kotlin-native/backend.native/tests/interop/objc_arc_contract/main.kt new file mode 100644 index 00000000000..fdcff2a96ec --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc_arc_contract/main.kt @@ -0,0 +1,10 @@ +/* + * 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. + */ + +// We don't do anything meaningful here, because the test is actually checks +// how compiler handles external bitcode (see main.ll). So this file is needed only for compiler invocation. +fun main() { + println("ok") +} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/objc_arc_contract/main.ll b/kotlin-native/backend.native/tests/interop/objc_arc_contract/main.ll new file mode 100644 index 00000000000..eaec06b0622 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc_arc_contract/main.ll @@ -0,0 +1,9 @@ +; Prevent function from DCE +@llvm.compiler.used = appending global [1 x i8*] [ i8* bitcast (void (i8*, i8*)* @test to i8*) ], section "llvm.metadata" + +declare void @llvm.objc.clang.arc.use(...) nounwind + +define void @test(i8* %a, i8* %b) { + call void (...) @llvm.objc.clang.arc.use(i8* %a, i8* %b) nounwind + ret void +} \ No newline at end of file diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/ExecLlvm.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/ExecLlvm.kt index e69de29bb2d..852527f7862 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/ExecLlvm.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/ExecLlvm.kt @@ -0,0 +1,26 @@ +/* + * 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. + */ + +package org.jetbrains.kotlin + +import groovy.lang.Closure +import org.gradle.api.Action +import org.gradle.api.Project +import org.gradle.process.ExecResult +import org.gradle.process.ExecSpec +import org.gradle.util.ConfigureUtil +import org.jetbrains.kotlin.konan.util.DependencyProcessor + +fun execLlvmUtility(project: Project, utility: String, action: Action): ExecResult { + val llvmBinDirectory = "${project.platformManager.hostPlatform.absoluteLlvmHome}/bin" + return project.exec(Action { + action.execute(this) + executable = "$llvmBinDirectory/$utility" + }) +} + +fun execLlvmUtility(project: Project, utility: String, closure: Closure): ExecResult { + return execLlvmUtility(project, utility, ConfigureUtil.configureUsing(closure)) +}