Skip to content

Commit 3dfee65

Browse files
jakobbotschjkotas
authored andcommitted
Add regression test
1 parent 9b73547 commit 3dfee65

File tree

2 files changed

+237
-72
lines changed

2 files changed

+237
-72
lines changed

src/tests/JIT/Directed/tailcall/more_tailcalls.cs

+50-6
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,26 @@ static Program()
6161
{
6262
IL.Emit.Ldftn(new MethodRef(typeof(Program), nameof(CalcStaticCalli)));
6363
IL.Pop(out IntPtr calcStaticCalli);
64+
s_calcStaticCalli = calcStaticCalli;
65+
6466
IL.Emit.Ldftn(new MethodRef(typeof(Program), nameof(CalcStaticCalliOther)));
6567
IL.Pop(out IntPtr calcStaticCalliOther);
68+
s_calcStaticCalliOther = calcStaticCalliOther;
69+
6670
IL.Emit.Ldftn(new MethodRef(typeof(Program), nameof(CalcStaticCalliRetbuf)));
6771
IL.Pop(out IntPtr calcStaticCalliRetbuf);
72+
s_calcStaticCalliRetbuf = calcStaticCalliRetbuf;
73+
6874
IL.Emit.Ldftn(new MethodRef(typeof(Program), nameof(CalcStaticCalliRetbufOther)));
6975
IL.Pop(out IntPtr calcStaticCalliRetbufOther);
76+
s_calcStaticCalliRetbufOther = calcStaticCalliRetbufOther;
77+
7078
IL.Emit.Ldftn(new MethodRef(typeof(Program), nameof(EmptyCalliOther)));
7179
IL.Pop(out IntPtr emptyCalliOther);
80+
s_emptyCalliOther = emptyCalliOther;
81+
7282
IL.Emit.Ldftn(new MethodRef(typeof(S16), nameof(S16.InstanceMethod)));
7383
IL.Pop(out IntPtr instanceMethodOnValueType);
74-
75-
s_calcStaticCalli = calcStaticCalli;
76-
s_calcStaticCalliOther = calcStaticCalliOther;
77-
s_calcStaticCalliRetbuf = calcStaticCalliRetbuf;
78-
s_calcStaticCalliRetbufOther = calcStaticCalliRetbufOther;
79-
s_emptyCalliOther = emptyCalliOther;
8084
s_instanceMethodOnValueType = instanceMethodOnValueType;
8185
}
8286

@@ -183,6 +187,10 @@ void TestCalc<T>(Func<int, int, T> f, T expected, string name)
183187
Test(() => GenAbstractGString(ga1), "System.String", "Abstract generic without generic on method 1");
184188
Test(() => GenAbstractGInt(ga2), "System.Int32", "Abstract generic without generic on method 2");
185189

190+
int[] a = new int[1_000_000];
191+
a[99] = 1;
192+
Test(() => InstantiatingStub1(0, 0, "string", a), a.Length + 1, "Instantiating stub direct");
193+
186194
if (result)
187195
Console.WriteLine("All tailcall-via-help succeeded");
188196
else
@@ -686,6 +694,42 @@ private static string GenAbstractGInt(GenAbstract<int> ga)
686694
IL.Emit.Callvirt(new MethodRef(typeof(GenAbstract<int>), nameof(GenAbstract<int>.G)));
687695
return IL.Return<string>();
688696
}
697+
698+
[MethodImpl(MethodImplOptions.NoInlining)]
699+
private static int InstantiatingStub1<T>(int a, int r, T c, Span<int> d)
700+
{
701+
IL.Push(c);
702+
IL.Push(c);
703+
IL.Push(c);
704+
IL.Push(c);
705+
IL.Push(c);
706+
IL.Push(c);
707+
IL.Push(c);
708+
IL.Push(c);
709+
IL.Push(a);
710+
IL.Push(r);
711+
IL.Emit.Ldarg(nameof(d));
712+
IL.Push(r + d[99]);
713+
IL.Emit.Tail();
714+
IL.Emit.Call(new MethodRef(typeof(Program), nameof(InstantiatingStub1Other)).MakeGenericMethod(typeof(T)));
715+
return IL.Return<int>();
716+
}
717+
718+
[MethodImpl(MethodImplOptions.NoInlining)]
719+
private static int InstantiatingStub1Other<T>(T c0, T c1, T c2, T c3, T c4, T c5, T c6, T c7, int a, int r, Span<int> d, int result)
720+
{
721+
if (a == d.Length) return result;
722+
else
723+
{
724+
IL.Push(a + 1);
725+
IL.Push(result);
726+
IL.Push(c0);
727+
IL.Emit.Ldarg(nameof(d));
728+
IL.Emit.Tail();
729+
IL.Emit.Call(new MethodRef(typeof(Program), nameof(InstantiatingStub1)).MakeGenericMethod(typeof(T)));
730+
return IL.Return<int>();
731+
}
732+
}
689733
}
690734

691735
class Instance

0 commit comments

Comments
 (0)