diff --git a/src/ObjCRuntime/Stret.cs b/src/ObjCRuntime/Stret.cs index 042a16ac8792..14cc5c52b187 100644 --- a/src/ObjCRuntime/Stret.cs +++ b/src/ObjCRuntime/Stret.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Reflection; #if !BGENERATOR using Generator = System.Object; @@ -185,6 +186,10 @@ public static bool X86_64NeedStret (Type returnType, Generator generator) return GetValueTypeSize (t, fieldTypes, true, generator) > 16; } +#if NET + // IL2070: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The parameter 'type' of method 'ObjCRuntime.Stret.GetValueTypeSize(Type, List, Boolean, Object)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. + [UnconditionalSuppressMessage ("", "IL2070", Justification = "Computing the size of a struct is safe, because the trimmer can't remove fields that would affect the size of a marshallable struct (it could affect marshalling behavior).")] +#endif static int GetValueTypeSize (Type type, List fieldTypes, bool is_64_bits, Generator generator) { int size = 0; @@ -290,6 +295,10 @@ static bool IsBuiltInType (Type type, bool is_64_bits, out int type_size) return false; } +#if NET + // IL2070: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The parameter 'type' of method 'ObjCRuntime.Stret.GetValueTypeSize(Type, Type, List, Boolean, Int32&, Int32&, Object)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. + [UnconditionalSuppressMessage ("", "IL2070", Justification = "Computing the size of a struct is safe, because the trimmer can't remove fields that would affect the size of a marshallable struct (it could affect marshalling behavior).")] +#endif static void GetValueTypeSize (Type original_type, Type type, List field_types, bool is_64_bits, ref int size, ref int max_element_size, Generator generator) { // FIXME: diff --git a/tests/dotnet/UnitTests/TrimmerWarningsTest.cs b/tests/dotnet/UnitTests/TrimmerWarningsTest.cs index 7b334a76f46f..055c880e4554 100644 --- a/tests/dotnet/UnitTests/TrimmerWarningsTest.cs +++ b/tests/dotnet/UnitTests/TrimmerWarningsTest.cs @@ -43,8 +43,6 @@ public void TrimmerWarningsDynamicRegistrar (ApplePlatform platform, string runt new ExpectedBuildMessage ("src/ObjCRuntime/Runtime.cs" /* line 1094 */, "ObjCRuntime.Runtime.GetBlockWrapperCreator(MethodInfo, Int32): Using member 'System.Reflection.Assembly.GetType(String, Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed."), new ExpectedBuildMessage ("src/ObjCRuntime/Runtime.cs" /* line 1085 */, "ObjCRuntime.Runtime.GetBlockWrapperCreator(MethodInfo, Int32): Value passed to implicit 'this' parameter of method 'System.Type.GetMethod(String)' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements."), new ExpectedBuildMessage ("src/ObjCRuntime/Runtime.cs" /* line 1068 */, "ObjCRuntime.Runtime.GetBlockWrapperCreator(MethodInfo, Int32): Value passed to parameter 'interfaceType' of method 'System.Type.GetInterfaceMap(Type)' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements."), - new ExpectedBuildMessage ("src/ObjCRuntime/Stret.cs" /* line 191 */, "ObjCRuntime.Stret.GetValueTypeSize(Type, List, Boolean, Object): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The parameter 'type' of method 'ObjCRuntime.Stret.GetValueTypeSize(Type, List, Boolean, Object)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to."), - new ExpectedBuildMessage ("src/ObjCRuntime/Stret.cs" /* line 303 */, "ObjCRuntime.Stret.GetValueTypeSize(Type, Type, List, Boolean, Int32&, Int32&, Object): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The parameter 'type' of method 'ObjCRuntime.Stret.GetValueTypeSize(Type, Type, List, Boolean, Int32&, Int32&, Object)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to."), }; break; case ApplePlatform.MacOSX: @@ -60,8 +58,6 @@ public void TrimmerWarningsDynamicRegistrar (ApplePlatform platform, string runt new ExpectedBuildMessage ("src/ObjCRuntime/Runtime.cs" /* line 1085 */, "ObjCRuntime.Runtime.GetBlockWrapperCreator(MethodInfo, Int32): Value passed to implicit 'this' parameter of method 'System.Type.GetMethod(String)' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements."), new ExpectedBuildMessage ("src/ObjCRuntime/Runtime.cs" /* line 1068 */, "ObjCRuntime.Runtime.GetBlockWrapperCreator(MethodInfo, Int32): Value passed to parameter 'interfaceType' of method 'System.Type.GetInterfaceMap(Type)' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements."), new ExpectedBuildMessage ("src/ObjCRuntime/Runtime.cs" /* line 648 */, "ObjCRuntime.Runtime.GetEntryAssembly(): Using member 'System.Reflection.Assembly.LoadFile(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types and members the loaded assembly depends on might be removed."), - new ExpectedBuildMessage ("src/ObjCRuntime/Stret.cs" /* line 191 */, "ObjCRuntime.Stret.GetValueTypeSize(Type, List, Boolean, Object): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The parameter 'type' of method 'ObjCRuntime.Stret.GetValueTypeSize(Type, List, Boolean, Object)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to."), - new ExpectedBuildMessage ("src/ObjCRuntime/Stret.cs" /* line 303 */, "ObjCRuntime.Stret.GetValueTypeSize(Type, Type, List, Boolean, Int32&, Int32&, Object): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The parameter 'type' of method 'ObjCRuntime.Stret.GetValueTypeSize(Type, Type, List, Boolean, Int32&, Int32&, Object)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to."), }; break; case ApplePlatform.MacCatalyst: @@ -75,8 +71,6 @@ public void TrimmerWarningsDynamicRegistrar (ApplePlatform platform, string runt new ExpectedBuildMessage ("src/ObjCRuntime/Runtime.cs" /* line 1094 */, "ObjCRuntime.Runtime.GetBlockWrapperCreator(MethodInfo, Int32): Using member 'System.Reflection.Assembly.GetType(String, Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed."), new ExpectedBuildMessage ("src/ObjCRuntime/Runtime.cs" /* line 1085 */, "ObjCRuntime.Runtime.GetBlockWrapperCreator(MethodInfo, Int32): Value passed to implicit 'this' parameter of method 'System.Type.GetMethod(String)' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements."), new ExpectedBuildMessage ("src/ObjCRuntime/Runtime.cs" /* line 1068 */, "ObjCRuntime.Runtime.GetBlockWrapperCreator(MethodInfo, Int32): Value passed to parameter 'interfaceType' of method 'System.Type.GetInterfaceMap(Type)' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements."), - new ExpectedBuildMessage ("src/ObjCRuntime/Stret.cs" /* line 191 */, "ObjCRuntime.Stret.GetValueTypeSize(Type, List, Boolean, Object): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The parameter 'type' of method 'ObjCRuntime.Stret.GetValueTypeSize(Type, List, Boolean, Object)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to."), - new ExpectedBuildMessage ("src/ObjCRuntime/Stret.cs" /* line 303 */, "ObjCRuntime.Stret.GetValueTypeSize(Type, Type, List, Boolean, Int32&, Int32&, Object): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The parameter 'type' of method 'ObjCRuntime.Stret.GetValueTypeSize(Type, Type, List, Boolean, Int32&, Int32&, Object)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to."), }; break; default: