Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ObjCRuntime] Suppress trimmer warnings for certain Stret members. #20313

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/ObjCRuntime/Stret.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
#if !BGENERATOR
using Generator = System.Object;
Expand Down Expand Up @@ -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<Type>, 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<Type> fieldTypes, bool is_64_bits, Generator generator)
{
int size = 0;
Expand Down Expand Up @@ -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<Type>, 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<Type> field_types, bool is_64_bits, ref int size, ref int max_element_size, Generator generator)
{
// FIXME:
Expand Down
6 changes: 0 additions & 6 deletions tests/dotnet/UnitTests/TrimmerWarningsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type>, 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<Type>, 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<Type>, 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<Type>, 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:
Expand All @@ -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<Type>, 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<Type>, 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<Type>, 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<Type>, 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:
Expand All @@ -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<Type>, 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<Type>, 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<Type>, 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<Type>, 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:
Expand Down
Loading