You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It was noticed that Mono does not handle function pointer type equality and type compatibility the same way CoreCLR does.
There seem to be two related underlying issues:
1. Mono should ignore custom modifiers on function pointer parameters and calling convention when comparing function pointer types
2. Mono should properly implement isinst in case of testing function pointer type compatibility against array of function pointers (respecting 1. from above)
Noticed in #89712 while enabling function pointer introspection API with Mono reflection in runtime tests:
// These are runtime-specific tests not shared with MetadataLoadContext.
// Using arrays in the manner below allows for use of the "is" keyword.
// The use of 'object' will call into the runtime to compare but using a strongly-typed
// function pointer without 'object' causes C# to hard-code the result.
publicpartialclassFunctionPointerTests
Repro
Here is a sample program to illustrate the behaviours:
usingSystem;usingSystem.Reflection;usingSystem.Runtime.CompilerServices;namespaceHelloWorld{internalunsafeclassProgram{privateconstBindingFlagsBindings=BindingFlags.Public|BindingFlags.Static|BindingFlags.DeclaredOnly;publicstaticdelegate* unmanaged[Cdecl]<int>fptr1;publicstaticdelegate* unmanaged[Stdcall]<int>fptr2;privatestaticvoidMain(string[]args){FieldInfofi1=typeof(Program).GetField(nameof(Program.fptr1),Bindings);Typeft1=fi1.FieldType;FieldInfofi2=typeof(Program).GetField(nameof(Program.fptr2),Bindings);Typeft2=fi2.FieldType;if(ft1==ft2)Console.WriteLine("Function pointer types are equal");elseConsole.WriteLine("Function pointer types are not equal");objectarrayOfFptrs1=newdelegate*<int>[1];if(arrayOfFptrs1isdelegate*<int>[])Console.WriteLine("Is type compatible");elseConsole.WriteLine("Is not type compatible");objectarrayOfFptrs2=newdelegate*<refint,void>[1];if(arrayOfFptrs2isdelegate*<outint,void>[])Console.WriteLine("Is type compatible");elseConsole.WriteLine("Is not type compatible");}}}
Expected behaviour
Program should output:
Function pointer types are equal
Is type compatible
Is type compatible
Actual behaviour
Program outputs:
Function pointer types are not equal
Is not type compatible
Is not type compatible
The text was updated successfully, but these errors were encountered:
This is partly because mono detects the "unmanaged" calling convention on function pointer signatures during loading and then eagerly looks at the custom modifiers and adjusts the calling convention right away on the MonoMethodSignature. It seems that instead we should leave it as "unmanaged" and only dip into the cmods in the marshaling logic that actually needs to pick a calling convention.
Description
It was noticed that Mono does not handle function pointer type equality and type compatibility the same way CoreCLR does.
There seem to be two related underlying issues:
isinst
in case of testing function pointer type compatibility against array of function pointers (respecting 1. from above)Noticed in #89712 while enabling function pointer introspection API with Mono reflection in runtime tests:
runtime/src/libraries/System.Runtime/tests/System/Type/FunctionPointerTests.Runtime.cs
Lines 8 to 12 in b68382b
Repro
Here is a sample program to illustrate the behaviours:
Expected behaviour
Program should output:
Actual behaviour
Program outputs:
The text was updated successfully, but these errors were encountered: