[jit] Run static cctors for inlined methods, the cctor might not have ran in AOT...
authormonojenkins <jo.shields+jenkins@xamarin.com>
Mon, 17 Feb 2020 14:15:23 +0000 (09:15 -0500)
committerGitHub <noreply@github.com>
Mon, 17 Feb 2020 14:15:23 +0000 (15:15 +0100)
Co-authored-by: Zoltan Varga <vargaz@gmail.com>
src/mono/mono/mini/method-to-ir.c
src/mono/mono/mini/objects.cs

index f764888..350ce3e 100644 (file)
@@ -6516,6 +6516,14 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
                        }
                }
 
+               /*
+                * Methods with AggressiveInline flag could be inlined even if the class has a cctor.
+                * This might create a branch so emit it in the first code bblock instead of into initlocals_bb.
+                */
+               if (ip - header->code == 0 && cfg->method != method && cfg->compile_aot && (method->iflags & METHOD_IMPL_ATTRIBUTE_AGGRESSIVE_INLINING) && mono_class_needs_cctor_run (method->klass, method)) {
+                       emit_class_init (cfg, method->klass);
+               }
+
                if (skip_dead_blocks) {
                        int ip_offset = ip - header->code;
 
index 4d52944..c2131dd 100644 (file)
@@ -2050,6 +2050,23 @@ ncells ) {
                var old = System.Threading.Interlocked.CompareExchange(ref variable_with_constant_address, 1, 0);
                return old == 0 && variable_with_constant_address == 1 ? 0 : 1;
        }
+
+       static bool cctor_called;
+
+       class ClassAggressiveInline {
+               static ClassAggressiveInline () {
+                       cctor_called = true;
+               }
+
+               [MethodImpl(MethodImplOptions.AggressiveInlining)]
+               public static void inlined () {
+               }
+       }
+
+       public static int test_0_aggressive_inline_cctor () {
+               ClassAggressiveInline.inlined ();
+               return cctor_called ? 0 : 1;
+       }
 }
 
 #if __MOBILE__