[tests] Test loading references from LoadFrom and LoadFile contexts
[mono-project.git] / mono / tests / tailcall-rgctxb.il
blob950beddce9a2aa58e7e0b6629938bbe73bebcf03
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 This passes on desktop but not Mono.
18 It fails because Mono will not tailcall when "this" is a valuetype,
19 in case it is in current frame. A range check could handle this.
21 Another test tailcall-rgctxb-static should be provided.
23 using System;
24 using System.Runtime.CompilerServices;
25 using static System.Runtime.CompilerServices.MethodImplOptions;
27 unsafe struct A<T>
29     void f3 ()
30     {
31         a = b = c = d = e = f = g = h = 1;
32     }
33     public int a, b, c, d, e, f, g, h;
35     [MethodImpl (NoInlining)]
36     static int check (long stack1, long stack2)
37     {
38         return (stack1 == stack2) ? 0 : 1;
39     }
41     [MethodImpl (NoInlining)]
42     public int f1 (int counter, long initial_stack, long current_stack)
43     {
44         int local;
45         object a = new T[101];
46         if (counter > 0)
47             return f2 (counter - 1, initial_stack, (long)&local);
48         return check ((long)&local, current_stack);
49     }
51     [MethodImpl (NoInlining)]
52     public int f2 (int counter, long initial_stack, long current_stack)
53     {
54         int local;
55         object a = new T[101];
56         if (counter > 0)
57             return f1 (counter - 1, initial_stack, (long)&local);
58         return check ((long)&local, current_stack);
59     }
62 unsafe class B
64     [MethodImpl (NoInlining)]
65     public static void Main()
66     {
67         int stack;
68         Environment.Exit(new A<int>().f1 (100, (long)&stack, 0));
69     }
73 .assembly extern mscorlib { }
75 .assembly 'tailcall-rgctxb' { }
77 .class A`1<T>
79 // Remove this change the test a lot and make it pass.
80 extends [mscorlib]System.ValueType
83 .method static int32 check (int64 stack1, int64 stack2) noinlining
85         ldarg.0
86         ldarg.1
87         beq.s IL_0006
89         ldc.i4.1
90         ret
92 IL_0006:
93         ldc.i4.0
94         ret
97 .method instance int32 f1 (int32 counter, int64 initial_stack, int64 current_stack) noinlining
99         .locals init (int32 V_0)
101         ldarg.1
102         ldc.i4.0
103         ble.s IL_001b
105         ldarg.0
106         ldarg.1
107         ldc.i4.1
108         sub
109         ldarg.2
110         ldloca.s V_0
111         conv.u
112         conv.u8
113         tail. call instance int32 valuetype A`1<!T>::f2 (int32, int64, int64)
114         ret
116 IL_001b:
117         ldloca.s V_0
118         conv.u
119         conv.u8
120         ldarg.3
121         tail. call int32 valuetype A`1<!T>::check (int64, int64)
122         ret
125 .method instance int32 f2 (int32 counter, int64 initial_stack, int64 current_stack) noinlining
127         .locals init (int32 V_0)
128         ldarg.1
129         ldc.i4.0
130         ble.s IL_001b
132         ldarg.0
133         ldarg.1
134         ldc.i4.1
135         sub
136         ldarg.2
137         ldloca.s V_0
138         conv.u
139         conv.u8
140         tail. call instance int32 valuetype A`1<!T>::f1 (int32, int64, int64)
141         ret
143 IL_001b:
144         ldloca.s V_0
145         conv.u
146         conv.u8
147         ldarg.3
148         tail. call int32 valuetype A`1<!T>::check (int64, int64)
149         ret
153 .class B extends [mscorlib]System.Object
156 .method static int32 Main() noinlining
158         .entrypoint
159         .locals init (int32 V_0, valuetype A`1<int32> V_1)
160         ldloca.s V_1
161         initobj valuetype A`1<int32>
162         ldloc.1
163         stloc.1
164         ldloca.s V_1
165         ldc.i4.s 100
166         ldloca.s V_0
167         conv.u
168         conv.u8
169         ldc.i4.0
170         conv.i8
171         tail. call instance int32 valuetype A`1<int32>::f1 (int32, int64, int64)
172         ret
175 .method instance void .ctor()
177         ldarg.0
178         tail. call instance void [mscorlib]System.Object::.ctor ()
179         ret