diff options
author | Lakshan Fernando <lakshanf@microsoft.com> | 2021-06-17 00:54:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-17 00:54:53 +0300 |
commit | fb9ef5b60a953842a597f0c71ffb862ecaae4af7 (patch) | |
tree | 8e1235d65f5eef7bc94c0efa9ed17cef2e3beb57 /test/Mono.Linker.Tests.Cases | |
parent | b5dac5914f8ca1d91047f52d771051ea638cecc7 (diff) |
Handle PInvoke analysis similar to other methods (#2091)
* PInvoke fix
* FB
* FB
* FB2
Diffstat (limited to 'test/Mono.Linker.Tests.Cases')
-rw-r--r-- | test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs | 173 |
1 files changed, 166 insertions, 7 deletions
diff --git a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs index 40e661340..720ad738b 100644 --- a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs +++ b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs @@ -15,39 +15,198 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings [UnconditionalSuppressMessage ("trim", "IL2026")] static void Main () { - SomeMethodTakingInterface (null); - SomeMethodTakingObject (null); - GetInterface (); - CanSuppressWarningOnParameter (null); - CanSuppressWarningOnReturnType (); - CanSuppressWithRequiresUnreferencedCode (null); + Call_SomeMethodTakingInterface (); + Call_SomeMethodTakingObject (); + Call_SomeMethodTakingArray (); + Call_SomeMethodTakingString (); + Call_SomeMethodTakingStringBuilder (); + Call_SomeMethodTakingCriticalHandle (); + Call_SomeMethodTakingSafeHandle (); + Call_SomeMethodTakingExplicitLayoutClass (); + Call_SomeMethodTakingSequentialLayoutClass (); + Call_SomeMethodTakingAutoLayoutClass (); + Call_GetInterface (); + Call_CanSuppressWarningOnParameter (); + Call_CanSuppressWarningOnReturnType (); + Call_CanSuppressWithRequiresUnreferencedCode (); + Call_CanSuppressPInvokeWithRequiresUnreferencedCode (); + Call_PInvokeWithRequiresUnreferencedCode (); } [ExpectedWarning ("IL2050")] + static void Call_SomeMethodTakingInterface () + { + SomeMethodTakingInterface (null); + } [DllImport ("Foo")] static extern void SomeMethodTakingInterface (IFoo foo); [ExpectedWarning ("IL2050")] + static void Call_SomeMethodTakingObject () + { + SomeMethodTakingObject (null); + } [DllImport ("Foo")] static extern void SomeMethodTakingObject ([MarshalAs (UnmanagedType.IUnknown)] object obj); [ExpectedWarning ("IL2050")] + static void Call_SomeMethodTakingArray () + { + SomeMethodTakingArray (null); + } + [DllImport ("Foo")] + static extern void SomeMethodTakingArray (Array array); + + static void Call_SomeMethodTakingStringBuilder () + { + SomeMethodTakingStringBuilder (null); + } + [DllImport ("Foo")] + static extern void SomeMethodTakingStringBuilder (StringBuilder str); + + static void Call_SomeMethodTakingCriticalHandle () + { + SomeMethodTakingCriticalHandle (null); + } + [DllImport ("Foo")] + static extern void SomeMethodTakingCriticalHandle (MyCriticalHandle handle); + + + static void Call_SomeMethodTakingSafeHandle () + { + SomeMethodTakingSafeHandle (null); + } + [DllImport ("Foo")] + static extern void SomeMethodTakingSafeHandle (TestSafeHandle handle); + + static void Call_SomeMethodTakingExplicitLayoutClass () + { + SomeMethodTakingExplicitLayout (null); + } + [DllImport ("Foo")] + static extern void SomeMethodTakingExplicitLayout (ExplicitLayout _class); + + static void Call_SomeMethodTakingSequentialLayoutClass () + { + SomeMethodTakingSequentialLayout (null); + } + [DllImport ("Foo")] + static extern void SomeMethodTakingSequentialLayout (SequentialLayout _class); + + [ExpectedWarning ("IL2050")] + static void Call_SomeMethodTakingAutoLayoutClass () + { + SomeMethodTakingAutoLayout (null); + } + [DllImport ("Foo")] + static extern void SomeMethodTakingAutoLayout (AutoLayout _class); + + + static void Call_SomeMethodTakingString () + { + SomeMethodTakingString (null); + } + [DllImport ("Foo")] + static extern void SomeMethodTakingString (String str); + + [ExpectedWarning ("IL2050")] + static void Call_GetInterface () + { + GetInterface (); + } [DllImport ("Foo")] static extern IFoo GetInterface (); [UnconditionalSuppressMessage ("trim", "IL2050")] + static void Call_CanSuppressWarningOnParameter () + { + CanSuppressWarningOnParameter (null); + } [DllImport ("Foo")] static extern void CanSuppressWarningOnParameter ([MarshalAs (UnmanagedType.IUnknown)] object obj); [UnconditionalSuppressMessage ("trim", "IL2050")] + static void Call_CanSuppressWarningOnReturnType () + { + CanSuppressWarningOnReturnType (); + } [DllImport ("Foo")] static extern IFoo CanSuppressWarningOnReturnType (); - [ExpectedWarning ("IL2050")] // Issue https://github.com/mono/linker/issues/1989 [RequiresUnreferencedCode ("test")] + static void Call_CanSuppressWithRequiresUnreferencedCode () + { + CanSuppressWithRequiresUnreferencedCode (null); + } + [DllImport ("Foo")] static extern void CanSuppressWithRequiresUnreferencedCode (IFoo foo); + [RequiresUnreferencedCode ("test")] + static void Call_CanSuppressPInvokeWithRequiresUnreferencedCode () + { + CanSuppressPInvokeWithRequiresUnreferencedCode (null); + } + + [RequiresUnreferencedCode ("test")] + [DllImport ("Foo")] + static extern void CanSuppressPInvokeWithRequiresUnreferencedCode (IFoo foo); + + [ExpectedWarning ("IL2050")] + [ExpectedWarning ("IL2026")] + static void Call_PInvokeWithRequiresUnreferencedCode () + { + PInvokeWithRequiresUnreferencedCode (null); + } + + [RequiresUnreferencedCode ("test")] + [DllImport ("Foo")] + static extern void PInvokeWithRequiresUnreferencedCode (IFoo foo); + interface IFoo { } + + class TestSafeHandle : SafeHandle + { + public TestSafeHandle () + : base (IntPtr.Zero, true) + { } + + public override bool IsInvalid => handle == IntPtr.Zero; + + protected override bool ReleaseHandle () + { + return true; + } + } + + class MyCriticalHandle : CriticalHandle + { + public MyCriticalHandle () : base (new IntPtr (-1)) { } + + public override bool IsInvalid { + get { return false; } + } + + protected override bool ReleaseHandle () + { + return false; + } + } + + [StructLayout (LayoutKind.Explicit)] + public class ExplicitLayout + { + } + + [StructLayout (LayoutKind.Sequential)] + public class SequentialLayout + { + } + + [StructLayout (LayoutKind.Auto)] + public class AutoLayout + { + } + } } |