Emit an explicit null check for some calls made out from gshared code.
authorZoltan Varga <vargaz@gmail.com>
Thu, 28 Feb 2013 22:17:20 +0000 (23:17 +0100)
committerZoltan Varga <vargaz@gmail.com>
Thu, 28 Feb 2013 22:19:57 +0000 (23:19 +0100)
mono/mini/gshared.cs
mono/mini/method-to-ir.c

index ff62cddbc5cf2075194f8987f8266ffa64562cc2..79a1906c51ed6a5a619726b2e372b819a0f282de 100644 (file)
@@ -1040,4 +1040,22 @@ public class Tests
                        return 1;
                return 0;
        }
+
+       public class Enumbers<T> {
+               public object Enumerate (List<KeyValuePair<T, string>> alist)
+               {
+                       return alist.ToArray ();
+               }
+       }
+
+       public static int test_0_checkthis_gshared_call () {
+               Enumbers<string> e = new Enumbers<string> ();
+               try {
+                       e.Enumerate (null);
+                       return 1;
+               }
+               catch (NullReferenceException) {
+               }
+               return 0;
+       }
 }
index bc0cea88016da355f7591e8d6845d88235cc37df..dc64d7de9c8051e7e0c1ed783bafa98e8d636a05 100644 (file)
@@ -7730,6 +7730,9 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
                                 * the method in the rgctx and do an
                                 * indirect call.
                                 */
+                               if (fsig->hasthis)
+                                       MONO_EMIT_NEW_CHECK_THIS (cfg, sp [0]->dreg);
+
                                addr = emit_get_rgctx_method (cfg, context_used, cmethod, MONO_RGCTX_INFO_GENERIC_METHOD_CODE);
                                ins = (MonoInst*)mono_emit_calli (cfg, fsig, sp, addr, imt_arg, vtable_arg);
                                goto call_end;