From a8cec11772cd2a8334f171a862edb87be0471258 Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Thu, 7 Sep 2023 13:11:20 +0200 Subject: [PATCH] [K/N] Protect filecheck tests for KT-53261 from DCE. --- .../filecheck/kt53261/kt53261_inline_unbox.kt | 36 ++++++++++++++++++- .../kt53261/kt53261_noinline_CPointer.kt | 12 +++++-- .../kt53261/kt53261_noinline_NativePointed.kt | 11 ++++-- .../kt53261_noinline_NonNullNativePtr.kt | 13 +++++-- .../kt53261/kt53261_noinline_StableRef.kt | 14 ++++++-- .../kt53261/kt53261_noinline_UByteArray.kt | 10 ++++-- .../kt53261/kt53261_noinline_UIntArray.kt | 10 ++++-- .../kt53261/kt53261_noinline_ULongArray.kt | 10 ++++-- .../kt53261/kt53261_noinline_UShortArray.kt | 10 ++++-- .../kt53261/kt53261_noinline_value_unbox.kt | 13 +++---- 10 files changed, 106 insertions(+), 33 deletions(-) diff --git a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_inline_unbox.kt b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_inline_unbox.kt index e0599425cae..73bb35b4c12 100644 --- a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_inline_unbox.kt +++ b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_inline_unbox.kt @@ -3,8 +3,42 @@ * 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.native.concurrent.* +import kotlinx.cinterop.* + fun main(arr: Array) { - println(arr[0].toInt() + 1) + println(arr.size.toByte() == arr[0].toByte()) + println(arr.size.toUByte() == arr[0].toUByte()) + println(arr.size.toShort() == arr[0].toShort()) + println(arr.size.toUShort() == arr[0].toUShort()) + println(arr.size.toInt() == arr[0].toInt()) + println(arr.size.toUInt() == arr[0].toUInt()) + println(arr.size.toLong() == arr[0].toLong()) + println(arr.size.toULong() == arr[0].toULong()) + println(arr.size.toFloat() == arr[0].toFloat()) + println(arr.size.toDouble() == arr[0].toDouble()) + println(Char(arr.size) == arr[0][0]) + println((arr.size == 1) == (arr[0] == "1")) // Boolean + + memScoped { + val var1: IntVar = alloc() + val var2: IntVar = alloc() + println(var1.ptr.rawValue == var2.ptr.rawValue) + } + + println(Result.success(arr.size) == Result.success(arr[0].toInt())) + println(vectorOf(arr.size, arr.size, arr.size, arr.size) == vectorOf(arr[0].toInt(), arr[0].toInt(), arr[0].toInt(), arr[0].toInt())) + + val w1 = Worker.start() + val w2 = Worker.start() + println(w1 == w2) + + val f1 = w1.requestTermination() + val f2 = w2.requestTermination() + println(f1 == f2) + + f1.result + f2.result } // CHECK-NOT: {{call|invoke}} i64 @"kfun:kotlin# // CHECK-NOT: {{call|invoke}} i64 @"kfun:kotlin# diff --git a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_CPointer.kt b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_CPointer.kt index 942b81b8f86..4832367ca27 100644 --- a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_CPointer.kt +++ b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_CPointer.kt @@ -3,7 +3,13 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -fun main(arr: Array) { - println(arr[0].toInt() + 1) +import kotlinx.cinterop.* + +// CHECK-LABEL: define zeroext i1 @"kfun:kotlinx.cinterop.CPointer#equals(kotlin.Any?){}kotlin.Boolean"(i8* %0, %struct.ObjHeader* %1) +// CHECK: call i8* @"kfun:kotlinx.cinterop#(kotlin.Any?){}kotlinx.cinterop.CPointer<-1:0>?" + +fun main() = memScoped { + val var1: IntVar = alloc() + val var2: IntVar = alloc() + println(var1.ptr == var2.ptr) } -// CHECK: {{call|invoke}} i8* @"kfun:kotlinx.cinterop# diff --git a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_NativePointed.kt b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_NativePointed.kt index ea8d69d6f25..b0e3f51aad3 100644 --- a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_NativePointed.kt +++ b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_NativePointed.kt @@ -3,7 +3,12 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -fun main(arr: Array) { - println(arr[0].toInt() + 1) +import kotlinx.cinterop.* + +// CHECK-LABEL: define i8* @"kfun:kotlinx.cinterop#interpretOpaquePointed(kotlin.native.internal.NativePtr){}kotlinx.cinterop.NativePointed"(i8* %0) +// CHECK: call i8* @"kfun:kotlinx.cinterop#(kotlin.Any?){}kotlinx.cinterop.NativePointed?" + +fun main() = memScoped { + val var1: NativePointed = alloc(4, 4) + println(interpretOpaquePointed(var1.rawPtr)) } -// CHECK: {{call|invoke}} i8* @"kfun:kotlinx.cinterop# diff --git a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_NonNullNativePtr.kt b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_NonNullNativePtr.kt index ab068b70ec4..1d747491f18 100644 --- a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_NonNullNativePtr.kt +++ b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_NonNullNativePtr.kt @@ -3,7 +3,14 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -fun main(arr: Array) { - println(arr[0].toInt() + 1) +import kotlinx.cinterop.* + +// CHECK-LABEL: define zeroext i1 @"kfun:kotlin.native.internal.NonNullNativePtr#equals(kotlin.Any?){}kotlin.Boolean"(i8* %0, %struct.ObjHeader* %1) +// CHECK: call i8* @"kfun:kotlin.native.internal#(kotlin.Any?){}kotlin.native.internal.NonNullNativePtr?" + +fun main() = memScoped { + val var1: IntVar = alloc() + val var2: IntVar = alloc() + @Suppress("INVISIBLE_MEMBER") + println(var1.ptr.value as Any == var2.ptr.value as Any) } -// CHECK: {{call|invoke}} i8* @"kfun:kotlin.native.internal# diff --git a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_StableRef.kt b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_StableRef.kt index a85f3539f13..ecd3d2cc844 100644 --- a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_StableRef.kt +++ b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_StableRef.kt @@ -3,7 +3,15 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -fun main(arr: Array) { - println(arr[0].toInt() + 1) +import kotlinx.cinterop.* + +// CHECK-LABEL: define zeroext i1 @"kfun:kotlinx.cinterop.StableRef#equals(kotlin.Any?){}kotlin.Boolean"(i8* %0, %struct.ObjHeader* %1) +// CHECK: call i8* @"kfun:kotlinx.cinterop#(kotlin.Any?){}kotlinx.cinterop.StableRef<-1:0>?" + +fun main() { + val ref1 = StableRef.create(Any()) + val ref2 = StableRef.create(Any()) + println(ref1 == ref2) + ref2.dispose() + ref1.dispose() } -// CHECK: {{call|invoke}} i8* @"kfun:kotlinx.cinterop# diff --git a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_UByteArray.kt b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_UByteArray.kt index 5130c48a817..d06d30e1535 100644 --- a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_UByteArray.kt +++ b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_UByteArray.kt @@ -3,7 +3,11 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -fun main(arr: Array) { - println(arr[0].toInt() + 1) +// CHECK-LABEL: define zeroext i1 @"kfun:kotlin.UByteArray#equals(kotlin.Any?){}kotlin.Boolean"(%struct.ObjHeader* %0, %struct.ObjHeader* %1) +// CHECK: call %struct.ObjHeader* @"kfun:kotlin#(kotlin.Any?){}kotlin.UByteArray?" + +fun main() { + val arr1 = UByteArray(10) { it.toUByte() } + val arr2 = UByteArray(10) { (it / 2).toUByte() } + println(arr1 == arr2) } -// CHECK: {{call|invoke}} %struct.ObjHeader* @"kfun:kotlin# diff --git a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_UIntArray.kt b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_UIntArray.kt index 3ed4130c6e2..0d35fbd60e2 100644 --- a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_UIntArray.kt +++ b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_UIntArray.kt @@ -3,7 +3,11 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -fun main(arr: Array) { - println(arr[0].toInt() + 1) +// CHECK-LABEL: define zeroext i1 @"kfun:kotlin.UIntArray#equals(kotlin.Any?){}kotlin.Boolean"(%struct.ObjHeader* %0, %struct.ObjHeader* %1) +// CHECK: call %struct.ObjHeader* @"kfun:kotlin#(kotlin.Any?){}kotlin.UIntArray?" + +fun main() { + val arr1 = UIntArray(10) { it.toUInt() } + val arr2 = UIntArray(10) { (it / 2).toUInt() } + println(arr1 == arr2) } -// CHECK: {{call|invoke}} %struct.ObjHeader* @"kfun:kotlin# diff --git a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_ULongArray.kt b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_ULongArray.kt index ccb1eb02019..3f5cf723314 100644 --- a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_ULongArray.kt +++ b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_ULongArray.kt @@ -3,7 +3,11 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -fun main(arr: Array) { - println(arr[0].toInt() + 1) +// CHECK-LABEL: define zeroext i1 @"kfun:kotlin.ULongArray#equals(kotlin.Any?){}kotlin.Boolean"(%struct.ObjHeader* %0, %struct.ObjHeader* %1) +// CHECK: call %struct.ObjHeader* @"kfun:kotlin#(kotlin.Any?){}kotlin.ULongArray?" + +fun main() { + val arr1 = ULongArray(10) { it.toULong() } + val arr2 = ULongArray(10) { (it / 2).toULong() } + println(arr1 == arr2) } -// CHECK: {{call|invoke}} %struct.ObjHeader* @"kfun:kotlin# diff --git a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_UShortArray.kt b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_UShortArray.kt index d456731f57e..229030205b1 100644 --- a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_UShortArray.kt +++ b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_UShortArray.kt @@ -3,7 +3,11 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -fun main(arr: Array) { - println(arr[0].toInt() + 1) +// CHECK-LABEL: define zeroext i1 @"kfun:kotlin.UShortArray#equals(kotlin.Any?){}kotlin.Boolean"(%struct.ObjHeader* %0, %struct.ObjHeader* %1) +// CHECK: call %struct.ObjHeader* @"kfun:kotlin#(kotlin.Any?){}kotlin.UShortArray?" + +fun main() { + val arr1 = UShortArray(10) { it.toUShort() } + val arr2 = UShortArray(10) { (it / 2).toUShort() } + println(arr1 == arr2) } -// CHECK: {{call|invoke}} %struct.ObjHeader* @"kfun:kotlin# diff --git a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_value_unbox.kt b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_value_unbox.kt index 2773d4396e8..6e3921ebe64 100644 --- a/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_value_unbox.kt +++ b/kotlin-native/backend.native/tests/filecheck/kt53261/kt53261_noinline_value_unbox.kt @@ -3,15 +3,12 @@ * 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 zeroext i1 @"kfun:C#equals(kotlin.Any?){}kotlin.Boolean"(%struct.ObjHeader* %0, %struct.ObjHeader* %1) +// CHECK: call %struct.ObjHeader* @"kfun:#(kotlin.Any?){}C?" value class C(val x: Any) -val c = C(42) +// Note: is also called from bridges for equals, hashCode and toString. fun main() { - println(c.x) + println(C(42) == C(13)) } -// CHECK: {{call|invoke}} %struct.ObjHeader* @"kfun:# - -// Note: is called from IR of generated methods like -// FUN BRIDGE_METHOD(target=FUN GENERATED_SINGLE_FIELD_VALUE_CLASS_MEMBER name:equals -// FUN BRIDGE_METHOD(target=FUN GENERATED_SINGLE_FIELD_VALUE_CLASS_MEMBER name:hashCode -// FUN BRIDGE_METHOD(target=FUN GENERATED_SINGLE_FIELD_VALUE_CLASS_MEMBER name:toString