Skip to content

Commit

Permalink
[ObjCRuntime] Suppress trimmer warnings for certain Stret members. (#…
Browse files Browse the repository at this point in the history
…20313)

Contributes towards #10405.
  • Loading branch information
rolfbjarne authored Mar 18, 2024
1 parent 8d679b7 commit 72283a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
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

3 comments on commit 72283a0

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.