[tests] Test loading references from LoadFrom and LoadFile contexts
[mono-project.git] / mono / tests / tailcall-rgctxb-static.il
blob69f4e91c12ec5effd537ec6f7aabbc23516d61de
1 /*
2 Author:
3     Jay Krell (jaykrell@microsoft.com)
5 Copyright 2018 Microsoft
6 Licensed under the MIT license. See LICENSE file in the project root for full license information.
8 http://www.mono-project.com/docs/advanced/runtime/docs/generic-sharing/
9 1. Non-generic non-static methods of reference types have access to the
10    RGCTX via the “this” argument (this->vtable->rgctx).
11 2. a. Non-generic static methods of reference types and b. non-generic methods
12    of value types need to be passed a pointer to the caller’s class’s VTable in the MONO_ARCH_RGCTX_REG register.
13 3. Generic methods need to be passed a pointer to the MRGCTX in the MONO_ARCH_RGCTX_REG register
15 Test case 2b.
16 It uses static to avoid another problem.
18 using System;
19 using System.Runtime.CompilerServices;
20 using static System.Runtime.CompilerServices.MethodImplOptions;
22 unsafe struct A<T>
24     void f3 ()
25     {
26         a = b = c = d = e = f = g = h = 1;
27     }
28     public int a, b, c, d, e, f, g, h;
30     [MethodImpl (NoInlining)]
31     static int check (long stack1, long stack2)
32     {
33         return (stack1 == stack2) ? 0 : 1;
34     }
36     [MethodImpl (NoInlining)]
37     static public int f1 (int counter, long initial_stack, long current_stack)
38     {
39         int local;
40         object a = new T[101];
41         if (counter > 0)
42             return f2 (counter - 1, initial_stack, (long)&local);
43         return check ((long)&local, current_stack);
44     }
46     [MethodImpl (NoInlining)]
47     static public int f2 (int counter, long initial_stack, long current_stack)
48     {
49         int local;
50         object a = new T[101];
51         if (counter > 0)
52             return f1 (counter - 1, initial_stack, (long)&local);
53         return check ((long)&local, current_stack);
54     }
57 unsafe class B
59     [MethodImpl (NoInlining)]
60     public static void Main()
61     {
62         int stack;
63         Environment.Exit(A<int>().f1 (100, (long)&stack, 0));
64     }
68 .assembly extern mscorlib { }
70 .assembly 'tailcall-rgctxb' { }
72 .class A`1<T>
74 // Remove this change the test a lot and make it pass.
75 extends [mscorlib]System.ValueType
78 .method static int32 check (int64 stack1, int64 stack2) noinlining
80         ldarg 0
81         ldarg 1
82         beq IL_0006
84         ldc.i4 1
85         ret
87 IL_0006:
88         ldc.i4 0
89         ret
92 .method static int32 f1 (int32 counter, int64 initial_stack, int64 current_stack) noinlining
94         .locals (int32 V_0)
96         ldarg 0
97         ldc.i4 0
98         ble IL_001b
100         ldarg 0
101         ldc.i4 1
102         sub
103         ldarg 1
104         ldloca V_0
105         conv.u8
106         tail.
107         call int32 valuetype A`1<!T>::f2 (int32, int64, int64)
108         ret
110 IL_001b:
111         ldloca V_0
112         conv.u8
113         ldarg 2
114         call int32 valuetype A`1<!T>::check (int64, int64)
115         ret
118 .method static int32 f2 (int32 counter, int64 initial_stack, int64 current_stack) noinlining
120         .locals (int32 V_0)
121         ldarg 0
122         ldc.i4 0
123         ble IL_001b
125         ldarg 0
126         ldc.i4 1
127         sub
128         ldarg 1
129         ldloca V_0
130         conv.u8
131         tail.
132         call int32 valuetype A`1<!T>::f1 (int32, int64, int64)
133         ret
135 IL_001b:
136         ldloca V_0
137         conv.u8
138         ldarg 2
139         call int32 valuetype A`1<!T>::check (int64, int64)
140         ret
144 .class B extends [mscorlib]System.Object
147 .method static int32 Main() noinlining
149         .entrypoint
150         .locals (int32 V_0)
152         ldc.i4 100
153         ldloca V_0
154         conv.u8
155         ldc.i8 0
156         call int32 valuetype A`1<int32>::f1 (int32, int64, int64)
157         ret