diff --git a/compiler/testData/codegen/box/volatile/intrinsics.kt b/compiler/testData/codegen/box/volatile/intrinsics.kt index 04e9a7a1fc1..45f2b9c36bc 100644 --- a/compiler/testData/codegen/box/volatile/intrinsics.kt +++ b/compiler/testData/codegen/box/volatile/intrinsics.kt @@ -1,12 +1,27 @@ // TARGET_BACKEND: NATIVE -// KT-55904 -// IGNORE_BACKEND_K2: NATIVE @file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") @file:OptIn(kotlin.ExperimentalStdlibApi::class) import kotlin.native.concurrent.* import kotlin.concurrent.* +import kotlin.native.internal.* +import kotlin.reflect.KMutableProperty0 + + +// Overload resolution is not working in K2 with Supress INVISIBLE_REFERENCE. +// But resolving constants and annotations work +// So we are creating local copies of this intrinsic for test + +@TypedIntrinsic(IntrinsicType.GET_AND_ADD_FIELD) +internal external fun KMutableProperty0.getAndAddFieldLocal(delta: Short): Short +@TypedIntrinsic(IntrinsicType.GET_AND_ADD_FIELD) +internal external fun KMutableProperty0.getAndAddFieldLocal(newValue: Int): Int +@TypedIntrinsic(IntrinsicType.GET_AND_ADD_FIELD) +internal external fun KMutableProperty0.getAndAddFieldLocal(newValue: Long): Long +@TypedIntrinsic(IntrinsicType.GET_AND_ADD_FIELD) +internal external fun KMutableProperty0.getAndAddFieldLocal(newValue: Byte): Byte + interface Wrapper { fun compareAndSwap(expected: T, new: T): T @@ -26,28 +41,28 @@ class IntWrapper(@Volatile var x : Int) : IncWrapper { override fun compareAndSwap(expected: Int, new: Int) = this::x.compareAndSwapField(expected, new) override fun compareAndSet(expected: Int, new: Int) = this::x.compareAndSetField(expected, new) override fun getAndSet(new: Int) = this::x.getAndSetField(new) - override fun getAndAdd(delta: Int) = this::x.getAndAddField(delta) + override fun getAndAdd(delta: Int) = this::x.getAndAddFieldLocal(delta) } class LongWrapper(@Volatile var x : Long) : IncWrapper { override fun compareAndSwap(expected: Long, new: Long) = this::x.compareAndSwapField(expected, new) override fun compareAndSet(expected: Long, new: Long) = this::x.compareAndSetField(expected, new) override fun getAndSet(new: Long) = this::x.getAndSetField(new) - override fun getAndAdd(delta: Long) = this::x.getAndAddField(delta) + override fun getAndAdd(delta: Long) = this::x.getAndAddFieldLocal(delta) } class ShortWrapper(@Volatile var x : Short) : IncWrapper { override fun compareAndSwap(expected: Short, new: Short) = this::x.compareAndSwapField(expected, new) override fun compareAndSet(expected: Short, new: Short) = this::x.compareAndSetField(expected, new) override fun getAndSet(new: Short) = this::x.getAndSetField(new) - override fun getAndAdd(delta: Short) = this::x.getAndAddField(delta) + override fun getAndAdd(delta: Short) = this::x.getAndAddFieldLocal(delta) } class ByteWrapper(@Volatile var x : Byte) : IncWrapper { override fun compareAndSwap(expected: Byte, new: Byte) = this::x.compareAndSwapField(expected, new) override fun compareAndSet(expected: Byte, new: Byte) = this::x.compareAndSetField(expected, new) override fun getAndSet(new: Byte) = this::x.getAndSetField(new) - override fun getAndAdd(delta: Byte) = this::x.getAndAddField(delta) + override fun getAndAdd(delta: Byte) = this::x.getAndAddFieldLocal(delta) } diff --git a/compiler/testData/codegen/box/volatile/intrinsicsOnGlobal.kt b/compiler/testData/codegen/box/volatile/intrinsicsOnGlobal.kt index a724f64d291..6e621e81494 100644 --- a/compiler/testData/codegen/box/volatile/intrinsicsOnGlobal.kt +++ b/compiler/testData/codegen/box/volatile/intrinsicsOnGlobal.kt @@ -1,6 +1,4 @@ // TARGET_BACKEND: NATIVE -// KT-55904 -// IGNORE_BACKEND_K2: NATIVE @file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") @@ -8,6 +6,22 @@ import kotlin.native.concurrent.* import kotlin.concurrent.* +import kotlin.native.internal.* +import kotlin.reflect.KMutableProperty0 + +// Overload resolution is not working in K2 with Supress INVISIBLE_REFERENCE. +// But resolving constants and annotations work +// So we are creating local copies of this intrinsic for test + +@TypedIntrinsic(IntrinsicType.GET_AND_ADD_FIELD) +internal external fun KMutableProperty0.getAndAddFieldLocal(delta: Short): Short +@TypedIntrinsic(IntrinsicType.GET_AND_ADD_FIELD) +internal external fun KMutableProperty0.getAndAddFieldLocal(newValue: Int): Int +@TypedIntrinsic(IntrinsicType.GET_AND_ADD_FIELD) +internal external fun KMutableProperty0.getAndAddFieldLocal(newValue: Long): Long +@TypedIntrinsic(IntrinsicType.GET_AND_ADD_FIELD) +internal external fun KMutableProperty0.getAndAddFieldLocal(newValue: Byte): Byte + val a = "1" val b = "2" @@ -25,8 +39,8 @@ fun box() : String { if (::x.compareAndSwapField(2, 1) != 1) return "FAIL Int: 4" if (::x.getAndSetField(3) != 1) return "FAIL Int: 5" if (::x.getAndSetField(1) != 3) return "FAIL Int: 6" - if (::x.getAndAddField(1) != 1) return "FAIL Int: 7" - if (::x.getAndAddField(1) != 2) return "FAIL Int: 8" + if (::x.getAndAddFieldLocal(1) != 1) return "FAIL Int: 7" + if (::x.getAndAddFieldLocal(1) != 2) return "FAIL Int: 8" if (x != 3) return "FAIL Int: 9" if (::y.compareAndSetField(1L, 2L) != true) return "FAIL Long: 1" @@ -35,8 +49,8 @@ fun box() : String { if (::y.compareAndSwapField(2L, 1L) != 1L) return "FAIL Long: 4" if (::y.getAndSetField(3L) != 1L) return "FAIL Long: 5" if (::y.getAndSetField(1L) != 3L) return "FAIL Long: 6" - if (::y.getAndAddField(1L) != 1L) return "FAIL Long: 7" - if (::y.getAndAddField(1L) != 2L) return "FAIL Long: 8" + if (::y.getAndAddFieldLocal(1L) != 1L) return "FAIL Long: 7" + if (::y.getAndAddFieldLocal(1L) != 2L) return "FAIL Long: 8" if (y != 3L) return "FAIL Long: 9"