-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert invalid C# uses of UnmanagedCallersOnly to IL. (#42146)
* Convert invalid C# uses of UnmanagedCallersOnly to IL for negative testing.
- Loading branch information
1 parent
c867337
commit b910310
Showing
4 changed files
with
107 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.IL"> | ||
<PropertyGroup> | ||
<OutputType>library</OutputType> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="InvalidCallbacks.il" /> | ||
</ItemGroup> | ||
</Project> |
75 changes: 75 additions & 0 deletions
75
src/tests/Interop/UnmanagedCallersOnly/InvalidCallbacks.il
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
.assembly extern System.Runtime { } | ||
.assembly extern System.Runtime.InteropServices { } | ||
|
||
.assembly InvalidCSharp { } | ||
|
||
.class public auto ansi beforefieldinit InvalidCSharp.GenericClass`1<T> | ||
extends System.Object | ||
{ | ||
.method public hidebysig static | ||
void CallbackMethod ( | ||
int32 n | ||
) cil managed preservesig | ||
{ | ||
.custom instance void [System.Runtime.InteropServices]System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute::.ctor() = ( | ||
01 00 00 00 | ||
) | ||
.maxstack 8 | ||
IL_0000: ldstr "Functions with attribute UnmanagedCallersOnlyAttribute within a generic type are invalid" | ||
IL_0005: newobj instance void [System.Runtime]System.Exception::.ctor(string) | ||
IL_000a: throw | ||
} | ||
|
||
.method public hidebysig specialname rtspecialname | ||
instance void .ctor () cil managed | ||
{ | ||
.maxstack 8 | ||
IL_0000: ldarg.0 | ||
IL_0001: call instance void [System.Runtime]System.Object::.ctor() | ||
IL_0006: ret | ||
} | ||
} | ||
|
||
.class public auto ansi beforefieldinit InvalidCSharp.Callbacks | ||
extends [System.Runtime]System.Object | ||
{ | ||
.method public hidebysig static | ||
int32 CallbackMethodGeneric<T> ( | ||
!!T arg | ||
) cil managed preservesig | ||
{ | ||
.custom instance void [System.Runtime.InteropServices]System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute::.ctor() = ( | ||
01 00 00 00 | ||
) | ||
.maxstack 8 | ||
IL_0000: ldstr "Functions with attribute UnmanagedCallersOnlyAttribute cannot have generic arguments" | ||
IL_0005: newobj instance void [System.Runtime]System.Exception::.ctor(string) | ||
IL_000a: throw | ||
} | ||
|
||
.method public hidebysig | ||
instance int32 CallbackNonStatic ( | ||
int32 val | ||
) cil managed preservesig | ||
{ | ||
.custom instance void [System.Runtime.InteropServices]System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute::.ctor() = ( | ||
01 00 00 00 | ||
) | ||
.maxstack 8 | ||
IL_0000: ldstr "Instance functions with attribute UnmanagedCallersOnlyAttribute are invalid" | ||
IL_0005: newobj instance void [System.Runtime]System.Exception::.ctor(string) | ||
IL_000a: throw | ||
} | ||
|
||
.method public hidebysig specialname rtspecialname | ||
instance void .ctor () cil managed | ||
{ | ||
.maxstack 8 | ||
IL_0000: ldarg.0 | ||
IL_0001: call instance void [System.Runtime]System.Object::.ctor() | ||
IL_0006: ret | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters