public void Compare(ref NoAliasField other) { #if UNITY_2020_1_OR_NEWER || UNITY_BURST_EXPERIMENTAL_FEATURE_ALIASING // Check that we can definitely alias with another struct of the same type as us. Unity.Burst.Aliasing.ExpectAlias(ref this, ref other); #endif }
private unsafe static void AliasInfoSubFunctionTwoSameTypedStructs(ref NoAliasField s0, ref NoAliasField s1) { // Check that they do not alias within their own structs. Unity.Burst.Aliasing.ExpectNoAlias(s0.ptr1, s0.ptr2); Unity.Burst.Aliasing.ExpectNoAlias(s1.ptr1, s1.ptr2); // But that they do alias across structs. Unity.Burst.Aliasing.ExpectAlias(s0.ptr1, s1.ptr1); Unity.Burst.Aliasing.ExpectAlias(s0.ptr1, s1.ptr2); Unity.Burst.Aliasing.ExpectAlias(s0.ptr2, s1.ptr1); Unity.Burst.Aliasing.ExpectAlias(s0.ptr2, s1.ptr2); }
private static unsafe void AliasInfoSubFunctionTwoSameTypedStructs(ref NoAliasField s0, ref NoAliasField s1) { // Check that they do not alias within their own structs. ExpectNotAliased(s0.ptr1, s0.ptr2); ExpectNotAliased(s1.ptr1, s1.ptr2); // But that they do alias across structs. ExpectAliased(s0.ptr1, s1.ptr1); ExpectAliased(s0.ptr1, s1.ptr2); ExpectAliased(s0.ptr2, s1.ptr1); ExpectAliased(s0.ptr2, s1.ptr2); }
public static unsafe void CheckNoAliasReturn(ref NoAliasField s) { int * ptr1 = NoAliasReturn(40); int * ptr2 = NoAliasReturn(4); int * ptr3 = ptr2 + 4; byte *ptr4 = (byte *)ptr3 + 1; // Obviously it still aliases with itself even it we bitcast. ExpectAliased((char *)ptr1 + 4, ptr1 + 1); // We know that both allocations can't point to the same memory as // they are derived from Malloc!). ExpectNotAliased(ptr1, ptr2); // Since ptr3 derives from ptr2 it cannot alias with ptr1. ExpectNotAliased(ptr3, ptr1); // And the derefenced memory locations at ptr3 and ptr2 cannot alias // since ptr3 does not overlap the allocation in ptr2. ExpectNotAliased(in * ptr3, in * ptr2); // The pointers pt4 and ptr3 have overlapping ranges so they do alias. ExpectAliased(in * ptr4, in * ptr3); // The pointers cannot alias with anything else too! ExpectNotAliased(ptr1, in s); ExpectNotAliased(ptr1, s.ptr1); ExpectNotAliased(ptr1, s.ptr2); ExpectNotAliased(ptr2, in s); ExpectNotAliased(ptr2, s.ptr1); ExpectNotAliased(ptr2, s.ptr2); ExpectNotAliased(ptr3, in s); ExpectNotAliased(ptr3, s.ptr1); ExpectNotAliased(ptr3, s.ptr2); ExpectNotAliased(ptr4, in s); ExpectNotAliased(ptr4, s.ptr1); ExpectNotAliased(ptr4, s.ptr2); UnsafeUtility.Free(ptr1, Allocator.Temp); UnsafeUtility.Free(ptr2, Allocator.Temp); }
public static unsafe void CheckNoAliasFieldAcrossTwoSameTypedStructs(ref NoAliasField s0, ref NoAliasField s1) { AliasInfoSubFunctionTwoSameTypedStructs(ref s0, ref s1); }
public static unsafe void CheckNoAliasFieldWithAnotherPointer(ref NoAliasField s) { // Check that they do not alias each other because of the [NoAlias] on the ptr1 field above. ExpectNotAliased(s.ptr1, s.ptr2); }
public unsafe static void CheckNoAliasFieldWithItself(ref NoAliasField s) { // Check that they correctly alias with themselves. Unity.Burst.Aliasing.ExpectAlias(s.ptr1, s.ptr1); Unity.Burst.Aliasing.ExpectAlias(s.ptr2, s.ptr2); }
public void Compare(ref NoAliasField other) { // Check that we can definitely alias with another struct of the same type as us. ExpectAliased(in this, in other); }
public static unsafe void CheckCompareWithItself(ref NoAliasField s) { s.Compare(ref s); }
public static unsafe void CheckNoAliasFieldSubFunctionWithNoAliasParameter(ref NoAliasField s) { AliasInfoSubFunctionNoAlias(s.ptr1, s.ptr1); }
public static unsafe void CheckAliasFieldWithNull(ref NoAliasField s) { // Check that comparing a pointer with null is no alias. ExpectNotAliased(s.ptr2, null); }
public static unsafe void CheckNoAliasFieldSubFunctionAlias(ref NoAliasField s) { NoAliasInfoSubFunctionAlias(s.ptr1, s.ptr1); }
public static unsafe void CheckNoAliasFieldWithItselfBadPtr2(ref NoAliasField s) { ExpectNotAliased(s.ptr2, s.ptr2); }
public static unsafe void CheckNoAliasFieldWithItself(ref NoAliasField s) { // Check that they correctly alias with themselves. ExpectAliased(s.ptr1, s.ptr1); ExpectAliased(s.ptr2, s.ptr2); }
public unsafe static void CheckNoAliasFieldWithNull(ref NoAliasField s) { // Check that comparing a pointer with null is no alias. Unity.Burst.Aliasing.ExpectNoAlias(s.ptr1, null); }
public unsafe static void CheckNoAliasFieldWithAnotherPointer(ref NoAliasField s) { // Check that they do not alias each other because of the [NoAlias] on the ptr1 field above. Unity.Burst.Aliasing.ExpectNoAlias(s.ptr1, s.ptr2); }
public unsafe static void CheckNoAliasFieldWithItselfBadPtr2(ref NoAliasField s) { Unity.Burst.Aliasing.ExpectNoAlias(s.ptr2, s.ptr2); }