[K/N] Fix volatile intrinsics tests on K2
^KT-55904
This commit is contained in:
committed by
Space Team
parent
7cf70e7b15
commit
3afdce3168
+21
-6
@@ -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<Short>.getAndAddFieldLocal(delta: Short): Short
|
||||
@TypedIntrinsic(IntrinsicType.GET_AND_ADD_FIELD)
|
||||
internal external fun KMutableProperty0<Int>.getAndAddFieldLocal(newValue: Int): Int
|
||||
@TypedIntrinsic(IntrinsicType.GET_AND_ADD_FIELD)
|
||||
internal external fun KMutableProperty0<Long>.getAndAddFieldLocal(newValue: Long): Long
|
||||
@TypedIntrinsic(IntrinsicType.GET_AND_ADD_FIELD)
|
||||
internal external fun KMutableProperty0<Byte>.getAndAddFieldLocal(newValue: Byte): Byte
|
||||
|
||||
|
||||
interface Wrapper<T> {
|
||||
fun compareAndSwap(expected: T, new: T): T
|
||||
@@ -26,28 +41,28 @@ class IntWrapper(@Volatile var x : Int) : IncWrapper<Int> {
|
||||
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<Long> {
|
||||
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<Short> {
|
||||
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<Byte> {
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<Short>.getAndAddFieldLocal(delta: Short): Short
|
||||
@TypedIntrinsic(IntrinsicType.GET_AND_ADD_FIELD)
|
||||
internal external fun KMutableProperty0<Int>.getAndAddFieldLocal(newValue: Int): Int
|
||||
@TypedIntrinsic(IntrinsicType.GET_AND_ADD_FIELD)
|
||||
internal external fun KMutableProperty0<Long>.getAndAddFieldLocal(newValue: Long): Long
|
||||
@TypedIntrinsic(IntrinsicType.GET_AND_ADD_FIELD)
|
||||
internal external fun KMutableProperty0<Byte>.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"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user