diff --git a/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/MulticastDelegate.cs b/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/MulticastDelegate.cs index 9b098a069274..f6bb551c275f 100644 --- a/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/MulticastDelegate.cs +++ b/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/MulticastDelegate.cs @@ -107,7 +107,7 @@ public override sealed int GetHashCode() // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator ==(MulticastDelegate d1, MulticastDelegate d2) + public static bool operator ==(MulticastDelegate? d1, MulticastDelegate? d2) { // Test d2 first to allow branch elimination when inlined for null checks (== null) // so it can become a simple test @@ -122,7 +122,7 @@ public override sealed int GetHashCode() // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator !=(MulticastDelegate d1, MulticastDelegate d2) + public static bool operator !=(MulticastDelegate? d1, MulticastDelegate? d2) { // Can't call the == operator as it will call object== diff --git a/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs b/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs index 194a5f710775..a36114cdf971 100644 --- a/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs +++ b/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs @@ -60,28 +60,28 @@ public bool Equals(RuntimeTypeHandle handle) } } - public static bool operator ==(object left, RuntimeTypeHandle right) + public static bool operator ==(object? left, RuntimeTypeHandle right) { if (left is RuntimeTypeHandle) return right.Equals((RuntimeTypeHandle)left); return false; } - public static bool operator ==(RuntimeTypeHandle left, object right) + public static bool operator ==(RuntimeTypeHandle left, object? right) { if (right is RuntimeTypeHandle) return left.Equals((RuntimeTypeHandle)right); return false; } - public static bool operator !=(object left, RuntimeTypeHandle right) + public static bool operator !=(object? left, RuntimeTypeHandle right) { if (left is RuntimeTypeHandle) return !right.Equals((RuntimeTypeHandle)left); return true; } - public static bool operator !=(RuntimeTypeHandle left, object right) + public static bool operator !=(RuntimeTypeHandle left, object? right) { if (right is RuntimeTypeHandle) return !left.Equals((RuntimeTypeHandle)right); diff --git a/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/Threading/Interlocked.cs b/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/Threading/Interlocked.cs index 97ba82912292..86a408204294 100644 --- a/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/Threading/Interlocked.cs +++ b/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/Threading/Interlocked.cs @@ -3,6 +3,7 @@ using System.Runtime; using System.Runtime.CompilerServices; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using Internal.Runtime.CompilerServices; @@ -49,13 +50,15 @@ public static unsafe double CompareExchange(ref double location1, double value, [Intrinsic] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T CompareExchange(ref T location1, T value, T comparand) where T : class + [return: NotNullIfNotNull("location1")] + public static T CompareExchange(ref T location1, T value, T comparand) where T : class? { return Unsafe.As(RuntimeImports.InterlockedCompareExchange(ref Unsafe.As(ref location1), value, comparand)); } [Intrinsic] - public static object CompareExchange(ref object location1, object value, object comparand) + [return: NotNullIfNotNull("location1")] + public static object? CompareExchange(ref object? location1, object? value, object? comparand) { return RuntimeImports.InterlockedCompareExchange(ref location1, value, comparand); } @@ -121,13 +124,15 @@ public static unsafe double Exchange(ref double location1, double value) [Intrinsic] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T Exchange(ref T location1, T value) where T : class + [return: NotNullIfNotNull("location1")] + public static T Exchange([NotNullIfNotNull("value")] ref T location1, T value) where T : class? { - return Unsafe.As(RuntimeImports.InterlockedExchange(ref Unsafe.As(ref location1), value)); + return Unsafe.As(RuntimeImports.InterlockedExchange(ref Unsafe.As(ref location1!), value)); } [Intrinsic] - public static object Exchange(ref object location1, object value) + [return: NotNullIfNotNull("location1")] + public static object? Exchange([NotNullIfNotNull("value")] ref object? location1, object? value) { return RuntimeImports.InterlockedExchange(ref location1, value); } diff --git a/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/Type.CoreRT.cs b/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/Type.CoreRT.cs index 737c8b248b67..0b3437640cf7 100644 --- a/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/Type.CoreRT.cs +++ b/src/coreclr/src/nativeaot/System.Private.CoreLib/src/System/Type.CoreRT.cs @@ -84,7 +84,7 @@ private static Type GetTypeFromEETypePtrSlow(EETypePtr eeType, ref GCHandle hand public static Type GetType(string typeName, Func assemblyResolver, Func typeResolver, bool throwOnError, bool ignoreCase) => RuntimeAugments.Callbacks.GetType(typeName, assemblyResolver, typeResolver, throwOnError: throwOnError, ignoreCase: ignoreCase, defaultAssembly: null); [Intrinsic] - public static bool operator ==(Type left, Type right) + public static bool operator ==(Type? left, Type? right) { if (object.ReferenceEquals(left, right)) return true; @@ -102,7 +102,7 @@ private static Type GetTypeFromEETypePtrSlow(EETypePtr eeType, ref GCHandle hand } [Intrinsic] - public static bool operator !=(Type left, Type right) => !(left == right); + public static bool operator !=(Type? left, Type? right) => !(left == right); public bool IsRuntimeImplemented() => this is IRuntimeImplemented; // Not an api but needs to be public because of Reflection.Core/CoreLib divide. }