From 370f138ad40d1121d66cb6ff6f2ea73fc91c3706 Mon Sep 17 00:00:00 2001 From: Vladimir Sukharev Date: Wed, 7 Feb 2024 10:48:17 +0100 Subject: [PATCH] [K/N][Tests] Migrate test signext_zeroext_interop.kt ^KT-61259 --- .../cinterop}/signext_zeroext_interop.kt | 87 ++++++++++++------- .../backend.native/tests/build.gradle | 15 ---- .../signext_zeroext_interop_input.def | 20 ----- .../FirNativeCodegenBoxTestGenerated.java | 6 ++ .../FirNativeCodegenBoxTestNoPLGenerated.java | 6 ++ .../NativeCodegenBoxTestGenerated.java | 6 ++ .../NativeCodegenBoxTestNoPLGenerated.java | 6 ++ 7 files changed, 80 insertions(+), 66 deletions(-) rename {kotlin-native/backend.native/tests/filecheck => compiler/testData/codegen/box/fileCheck/cinterop}/signext_zeroext_interop.kt (64%) delete mode 100644 kotlin-native/backend.native/tests/filecheck/signext_zeroext_interop_input.def diff --git a/kotlin-native/backend.native/tests/filecheck/signext_zeroext_interop.kt b/compiler/testData/codegen/box/fileCheck/cinterop/signext_zeroext_interop.kt similarity index 64% rename from kotlin-native/backend.native/tests/filecheck/signext_zeroext_interop.kt rename to compiler/testData/codegen/box/fileCheck/cinterop/signext_zeroext_interop.kt index fc64e1548a9..b376538b177 100644 --- a/kotlin-native/backend.native/tests/filecheck/signext_zeroext_interop.kt +++ b/compiler/testData/codegen/box/fileCheck/cinterop/signext_zeroext_interop.kt @@ -3,25 +3,51 @@ * Use * of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ +// TARGET_BACKEND: NATIVE +// FILECHECK_STAGE: CStubs +// MODULE: cinterop +// FILE: signext_zeroext_interop_input.def +--- +char char_id(char c) { + return c; +} + +unsigned char unsigned_char_id(unsigned char c) { + return c; +} + +short short_id(short s) { + return s; +} + +unsigned short unsigned_short_id(unsigned short s) { + return s; +} + +int callbackUser(int (*fn)(int, short)) { + return fn(5,5); +} + +// MODULE: main(cinterop) +// FILE: main.kt + @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) import signext_zeroext_interop_input.* import kotlinx.cinterop.* -// CHECK: declare zeroext i1 @Kotlin_Char_isHighSurrogate(i16 zeroext) +// CHECK-DEFAULTABI: declare zeroext i1 @Kotlin_Char_isHighSurrogate(i16 zeroext){{.*}} // CHECK-AAPCS: declare i1 @Kotlin_Char_isHighSurrogate(i16) // CHECK-WINDOWSX64: declare zeroext i1 @Kotlin_Char_isHighSurrogate(i16) // Check that we pass attributes to functions imported from runtime. // CHECK-LABEL: void @"kfun:#checkRuntimeFunctionImport(){}"() -// CHECK-LABEL-AAPCS: void @"kfun:#checkRuntimeFunctionImport(){}"() -// CHECK-LABEL-WINDOWSX64: void @"kfun:#checkRuntimeFunctionImport(){}"() fun checkRuntimeFunctionImport() { - // CHECK: call zeroext i1 @Kotlin_Char_isHighSurrogate(i16 zeroext {{.*}}) + // CHECK-DEFAULTABI: call zeroext i1 @Kotlin_Char_isHighSurrogate(i16 zeroext {{.*}}) // CHECK-AAPCS: call i1 @Kotlin_Char_isHighSurrogate(i16 {{.*}}) // CHECK-WINDOWSX64: call zeroext i1 @Kotlin_Char_isHighSurrogate(i16 {{.*}}) 'c'.isHighSurrogate() - // CHECK: call zeroext i1 @Kotlin_Float_isNaN(float {{.*}} + // CHECK-DEFAULTABI: call zeroext i1 @Kotlin_Float_isNaN(float {{.*}} // CHECK-AAPCS: call i1 @Kotlin_Float_isNaN(float {{.*}} // CHECK-WINDOWSX64: call zeroext i1 @Kotlin_Float_isNaN(float {{.*}} 0.0f.isNaN() @@ -34,39 +60,38 @@ fun checkDirectInterop() { // compiler generates quite lovely names for bridges // (e.g. `_66696c65636865636b5f7369676e6578745f7a65726f6578745f696e7465726f70_knbridge0`), // so we don't check exact function names here. - // CHECK: invoke signext i8 [[CHAR_ID_BRIDGE:@_.*_knbridge[0-9]+]](i8 signext {{.*}}) + // CHECK-DEFAULTABI: invoke signext i8 [[CHAR_ID_BRIDGE:@_.*_knbridge[0-9]+]](i8 signext {{.*}}) // CHECK-AAPCS: invoke i8 [[CHAR_ID_BRIDGE:@_.*_knbridge[0-9]+]](i8 {{.*}}) // CHECK-WINDOWSX64: invoke i8 [[CHAR_ID_BRIDGE:@_.*_knbridge[0-9]+]](i8 {{.*}}) char_id(0.toByte()) - // CHECK: invoke zeroext i8 [[UNSIGNED_CHAR_ID_BRIDGE:@_.*_knbridge[0-9]+]](i8 zeroext {{.*}}) + // CHECK-DEFAULTABI: invoke zeroext i8 [[UNSIGNED_CHAR_ID_BRIDGE:@_.*_knbridge[0-9]+]](i8 zeroext {{.*}}) // CHECK-AAPCS: invoke i8 [[UNSIGNED_CHAR_ID_BRIDGE:@_.*_knbridge[0-9]+]](i8 {{.*}}) // CHECK-WINDOWSX64: invoke i8 [[UNSIGNED_CHAR_ID_BRIDGE:@_.*_knbridge[0-9]+]](i8 {{.*}}) unsigned_char_id(0.toUByte()) - // CHECK: invoke signext i16 [[SHORT_ID_BRIDGE:@_.*_knbridge[0-9]+]](i16 signext {{.*}}) + // CHECK-DEFAULTABI: invoke signext i16 [[SHORT_ID_BRIDGE:@_.*_knbridge[0-9]+]](i16 signext {{.*}}) // CHECK-AAPCS: invoke i16 [[SHORT_ID_BRIDGE:@_.*_knbridge[0-9]+]](i16 {{.*}}) // CHECK-WINDOWSX64: invoke i16 [[SHORT_ID_BRIDGE:@_.*_knbridge[0-9]+]](i16 {{.*}}) short_id(0.toShort()) - // CHECK: invoke zeroext i16 [[UNSIGNED_SHORT_ID_BRIDGE:@_.*_knbridge[0-9]+]](i16 zeroext {{.*}}) + // CHECK-DEFAULTABI: invoke zeroext i16 [[UNSIGNED_SHORT_ID_BRIDGE:@_.*_knbridge[0-9]+]](i16 zeroext {{.*}}) // CHECK-AAPCS: invoke i16 [[UNSIGNED_SHORT_ID_BRIDGE:@_.*_knbridge[0-9]+]](i16 {{.*}}) // CHECK-WINDOWSX64: invoke i16 [[UNSIGNED_SHORT_ID_BRIDGE:@_.*_knbridge[0-9]+]](i16 {{.*}}) unsigned_short_id(0.toUShort()) - // CHECK: invoke i32 [[CALLBACK_USER_BRIDGE:@_.*_knbridge[0-9]+]](i8* bitcast (i32 (i32, i16)* [[STATIC_C_FUNCTION_BRIDGE:@_.*_kncfun[0-9]+]] to i8*)) + // CHECK-DEFAULTABI: invoke i32 [[CALLBACK_USER_BRIDGE:@_.*_knbridge[0-9]+]](i8* bitcast (i32 (i32, i16)* [[STATIC_C_FUNCTION_BRIDGE:@_.*_kncfun[0-9]+]] to i8*)) // CHECK-AAPCS: invoke i32 [[CALLBACK_USER_BRIDGE:@_.*_knbridge[0-9]+]](i8* bitcast (i32 (i32, i16)* [[STATIC_C_FUNCTION_BRIDGE:@_.*_kncfun[0-9]+]] to i8*)) // CHECK-WINDOWSX64: invoke i32 [[CALLBACK_USER_BRIDGE:@_.*_knbridge[0-9]+]](i8* bitcast (i32 (i32, i16)* [[STATIC_C_FUNCTION_BRIDGE:@_.*_kncfun[0-9]+]] to i8*)) callbackUser(staticCFunction { int: Int, short: Short -> int + short }) } -// CHECK-LABEL: void @"kfun:#main(){}"() -// CHECK-LABEL-AAPCS: void @"kfun:#main(){}"() -// CHECK-LABEL-WINDOWSX64: void @"kfun:#main(){}"() -fun main() { +// CHECK-LABEL: define %struct.ObjHeader* @"kfun:#box(){}kotlin.String" +fun box(): String { checkRuntimeFunctionImport() checkDirectInterop() + return "OK" } -// CHECK: signext i8 [[CHAR_ID_BRIDGE]](i8 signext %0) -// CHECK: [[CHAR_ID_PTR:%[0-9]+]] = load i8 (i8)*, i8 (i8)** @{{.*char_id}} -// CHECK: call signext i8 [[CHAR_ID_PTR]](i8 signext %0) +// CHECK-DEFAULTABI: signext i8 [[CHAR_ID_BRIDGE]](i8 signext %0) +// CHECK-DEFAULTABI: [[CHAR_ID_PTR:%[0-9]+]] = load i8 (i8)*, i8 (i8)** @{{.*char_id}} +// CHECK-DEFAULTABI: call signext i8 [[CHAR_ID_PTR]](i8 signext %0) // CHECK-AAPCS: i8 [[CHAR_ID_BRIDGE]](i8 %0) // CHECK-AAPCS: [[CHAR_ID_PTR:%[0-9]+]] = load i8 (i8)*, i8 (i8)** @{{.*char_id}} @@ -77,9 +102,9 @@ fun main() { // CHECK-WINDOWSX64: call i8 [[CHAR_ID_PTR]](i8 %0) -// CHECK: zeroext i8 [[UNSIGNED_CHAR_ID_BRIDGE]](i8 zeroext %0) -// CHECK: [[UNSIGNED_CHAR_ID_PTR:%[0-9]+]] = load i8 (i8)*, i8 (i8)** @{{.*unsigned_char_id}} -// CHECK: call zeroext i8 [[UNSIGNED_CHAR_ID_PTR]](i8 zeroext %0) +// CHECK-DEFAULTABI: zeroext i8 [[UNSIGNED_CHAR_ID_BRIDGE]](i8 zeroext %0) +// CHECK-DEFAULTABI: [[UNSIGNED_CHAR_ID_PTR:%[0-9]+]] = load i8 (i8)*, i8 (i8)** @{{.*unsigned_char_id}} +// CHECK-DEFAULTABI: call zeroext i8 [[UNSIGNED_CHAR_ID_PTR]](i8 zeroext %0) // CHECK-AAPCS: i8 [[UNSIGNED_CHAR_ID_BRIDGE]](i8 %0) // CHECK-AAPCS: [[UNSIGNED_CHAR_ID_PTR:%[0-9]+]] = load i8 (i8)*, i8 (i8)** @{{.*unsigned_char_id}} @@ -90,9 +115,9 @@ fun main() { // CHECK-WINDOWSX64: call i8 [[UNSIGNED_CHAR_ID_PTR]](i8 %0) -// CHECK: signext i16 [[SHORT_ID_BRIDGE]](i16 signext %0) -// CHECK: [[SHORT_ID_PTR:%[0-9]+]] = load i16 (i16)*, i16 (i16)** @{{.*short_id}} -// CHECK: call signext i16 [[SHORT_ID_PTR]](i16 signext %0) +// CHECK-DEFAULTABI: signext i16 [[SHORT_ID_BRIDGE]](i16 signext %0) +// CHECK-DEFAULTABI: [[SHORT_ID_PTR:%[0-9]+]] = load i16 (i16)*, i16 (i16)** @{{.*short_id}} +// CHECK-DEFAULTABI: call signext i16 [[SHORT_ID_PTR]](i16 signext %0) // CHECK-AAPCS: i16 [[SHORT_ID_BRIDGE]](i16 %0) // CHECK-AAPCS: [[SHORT_ID_PTR:%[0-9]+]] = load i16 (i16)*, i16 (i16)** @{{.*short_id}} @@ -103,9 +128,9 @@ fun main() { // CHECK-WINDOWSX64: call i16 [[SHORT_ID_PTR]](i16 %0) -// CHECK: zeroext i16 [[UNSIGNED_SHORT_ID_BRIDGE]](i16 zeroext %0) -// CHECK: [[UNSIGNED_SHORT_ID_PTR:%[0-9]+]] = load i16 (i16)*, i16 (i16)** @{{.*unsigned_short_id}} -// CHECK: call zeroext i16 [[UNSIGNED_SHORT_ID_PTR]](i16 zeroext %0) +// CHECK-DEFAULTABI: zeroext i16 [[UNSIGNED_SHORT_ID_BRIDGE]](i16 zeroext %0) +// CHECK-DEFAULTABI: [[UNSIGNED_SHORT_ID_PTR:%[0-9]+]] = load i16 (i16)*, i16 (i16)** @{{.*unsigned_short_id}} +// CHECK-DEFAULTABI: call zeroext i16 [[UNSIGNED_SHORT_ID_PTR]](i16 zeroext %0) // CHECK-AAPCS: i16 [[UNSIGNED_SHORT_ID_BRIDGE]](i16 %0) // CHECK-AAPCS: [[UNSIGNED_SHORT_ID_PTR:%[0-9]+]] = load i16 (i16)*, i16 (i16)** @{{.*unsigned_short_id}} @@ -116,8 +141,8 @@ fun main() { // CHECK-WINDOWSX64: call i16 [[UNSIGNED_SHORT_ID_PTR]](i16 %0) -// CHECK: i32 [[STATIC_C_FUNCTION_BRIDGE]](i32 %0, i16 signext %1) -// CHECK: call i32 {{@_.*_knbridge[0-9]+}}(i32 %0, i16 signext %1) +// CHECK-DEFAULTABI: i32 [[STATIC_C_FUNCTION_BRIDGE]](i32 %0, i16 signext %1) +// CHECK-DEFAULTABI: call i32 {{@_.*_knbridge[0-9]+}}(i32 %0, i16 signext %1) // CHECK-AAPCS: i32 [[STATIC_C_FUNCTION_BRIDGE]](i32 %0, i16 %1) // CHECK-AAPCS: call i32 {{@_.*_knbridge[0-9]+}}(i32 %0, i16 %1) @@ -126,9 +151,9 @@ fun main() { // CHECK-WINDOWSX64: call i32 {{@_.*_knbridge[0-9]+}}(i32 %0, i16 %1) -// CHECK: i32 [[CALLBACK_USER_BRIDGE]](i8* %0) -// CHECK: [[CALLBACK_USER_PTR:%[0-9]+]] = load i32 (i8*)*, i32 (i8*)** @{{.*callbackUser}} -// CHECK: call i32 [[CALLBACK_USER_PTR]](i8* %0) +// CHECK-DEFAULTABI: i32 [[CALLBACK_USER_BRIDGE]](i8* %0) +// CHECK-DEFAULTABI: [[CALLBACK_USER_PTR:%[0-9]+]] = load i32 (i8*)*, i32 (i8*)** @{{.*callbackUser}} +// CHECK-DEFAULTABI: call i32 [[CALLBACK_USER_PTR]](i8* %0) // CHECK-AAPCS: i32 [[CALLBACK_USER_BRIDGE]](i8* %0) // CHECK-AAPCS: [[CALLBACK_USER_PTR:%[0-9]+]] = load i32 (i8*)*, i32 (i8*)** @{{.*callbackUser}} diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 7e83e5f78c8..810cfc348d9 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -2016,21 +2016,6 @@ Task fileCheckTest(String name, Closure configureClosure) { } } -createInterop("filecheck_signext_zeroext_interop_input") { - it.defFile 'filecheck/signext_zeroext_interop_input.def' -} - -fileCheckTest("filecheck_signext_zeroext_interop") { - enabled = enabled && cacheTesting == null - annotatedSource = project.file('filecheck/signext_zeroext_interop.kt') - interop = "filecheck_signext_zeroext_interop_input" - if (project.testTarget == 'mingw_x64') { - checkPrefix = "CHECK-WINDOWSX64" - } else if (!target.family.appleFamily && target.architecture == Architecture.ARM64) { - checkPrefix = "CHECK-AAPCS" - } -} - fileCheckTest("filecheck_signext_zeroext_objc_export") { annotatedSource = project.file('filecheck/signext_zeroext_objc_export.kt') generateFramework = true diff --git a/kotlin-native/backend.native/tests/filecheck/signext_zeroext_interop_input.def b/kotlin-native/backend.native/tests/filecheck/signext_zeroext_interop_input.def deleted file mode 100644 index e80d912875c..00000000000 --- a/kotlin-native/backend.native/tests/filecheck/signext_zeroext_interop_input.def +++ /dev/null @@ -1,20 +0,0 @@ ---- -char char_id(char c) { - return c; -} - -unsigned char unsigned_char_id(unsigned char c) { - return c; -} - -short short_id(short s) { - return s; -} - -unsigned short unsigned_short_id(unsigned short s) { - return s; -} - -int callbackUser(int (*fn)(int, short)) { - return fn(5,5); -} \ No newline at end of file diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java index 48829712ed3..e9453c73374 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java @@ -16353,6 +16353,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe public void testDirect() throws Exception { runTest("compiler/testData/codegen/box/fileCheck/cinterop/direct.kt"); } + + @Test + @TestMetadata("signext_zeroext_interop.kt") + public void testSignext_zeroext_interop() throws Exception { + runTest("compiler/testData/codegen/box/fileCheck/cinterop/signext_zeroext_interop.kt"); + } } @Nested diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java index 43a776cb960..5998eb0a7b7 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java @@ -16733,6 +16733,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB public void testDirect() throws Exception { runTest("compiler/testData/codegen/box/fileCheck/cinterop/direct.kt"); } + + @Test + @TestMetadata("signext_zeroext_interop.kt") + public void testSignext_zeroext_interop() throws Exception { + runTest("compiler/testData/codegen/box/fileCheck/cinterop/signext_zeroext_interop.kt"); + } } @Nested diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java index d32a01ba22f..805229298bc 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java @@ -15973,6 +15973,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest public void testDirect() throws Exception { runTest("compiler/testData/codegen/box/fileCheck/cinterop/direct.kt"); } + + @Test + @TestMetadata("signext_zeroext_interop.kt") + public void testSignext_zeroext_interop() throws Exception { + runTest("compiler/testData/codegen/box/fileCheck/cinterop/signext_zeroext_interop.kt"); + } } @Nested diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java index b7eee5a2ba1..118855f5abd 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java @@ -16354,6 +16354,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT public void testDirect() throws Exception { runTest("compiler/testData/codegen/box/fileCheck/cinterop/direct.kt"); } + + @Test + @TestMetadata("signext_zeroext_interop.kt") + public void testSignext_zeroext_interop() throws Exception { + runTest("compiler/testData/codegen/box/fileCheck/cinterop/signext_zeroext_interop.kt"); + } } @Nested