From 533b3162a85d4bbda50338c07d3cec308c9d2d6b Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Thu, 8 Jul 2021 20:16:06 +0300 Subject: [PATCH 1/2] [interp] Fix open delegates used with virtual methods of valuetypes We were trying to resolve the virtual method on the this pointer (which is a managed pointer and not an object). If the delegate target method is declared on a valuetype, the method does not need resolving. Fixes https://github.com/dotnet/runtime/issues/49839 --- src/mono/mono/mini/interp/interp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/mini/interp/interp.c b/src/mono/mono/mini/interp/interp.c index dad5f095b0026..1ee5428442d1f 100644 --- a/src/mono/mono/mini/interp/interp.c +++ b/src/mono/mono/mini/interp/interp.c @@ -3433,7 +3433,7 @@ interp_exec_method (InterpFrame *frame, ThreadContext *context, FrameClauseArgs del_imethod = mono_interp_get_imethod (mono_marshal_get_native_wrapper (del_imethod->method, FALSE, FALSE), error); mono_error_assert_ok (error); del->interp_invoke_impl = del_imethod; - } else if (del_imethod->method->flags & METHOD_ATTRIBUTE_VIRTUAL && !del->target) { + } else if (del_imethod->method->flags & METHOD_ATTRIBUTE_VIRTUAL && !del->target && !m_class_is_valuetype (del_imethod->method->klass)) { // 'this' is passed dynamically, we need to recompute the target method // with each call del_imethod = get_virtual_method (del_imethod, LOCAL_VAR (call_args_offset + MINT_STACK_SLOT_SIZE, MonoObject*)->vtable); From bf82e5d9ec3e222762d2a0abda0d027b65f843bc Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Thu, 8 Jul 2021 20:30:29 +0300 Subject: [PATCH 2/2] Re-enable tests --- src/libraries/System.Runtime/tests/System/DelegateTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System/DelegateTests.cs b/src/libraries/System.Runtime/tests/System/DelegateTests.cs index 269b5f7b218af..9a3658457c10d 100644 --- a/src/libraries/System.Runtime/tests/System/DelegateTests.cs +++ b/src/libraries/System.Runtime/tests/System/DelegateTests.cs @@ -1118,7 +1118,6 @@ public static void CreateDelegate9_Type_Null() Assert.NotNull(ex.Message); } - [ActiveIssue("https://github.com/dotnet/runtime/issues/49839", TestRuntimes.Mono)] [Fact] public static void CreateDelegate10_Nullable_Method() { @@ -1130,7 +1129,6 @@ public static void CreateDelegate10_Nullable_Method() Assert.Equal(num.ToString(), s); } - [ActiveIssue("https://github.com/dotnet/runtime/issues/49839", TestRuntimes.Mono)] [Fact] public static void CreateDelegate10_Nullable_ClosedDelegate() {