blob: 720ad738b6f8f1d1c6248ac63a1a2dad3046a9fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Text;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
{
[SkipKeptItemsValidation]
[ExpectedNoWarnings]
[KeptModuleReference ("Foo")]
class ComPInvokeWarning
{
[UnconditionalSuppressMessage ("trim", "IL2026")]
static void Main ()
{
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 ();
[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
{
}
}
}
|