When COMPlus_TailcallStress=1 is set, the JIT converts as many call/ret pairs as possible into tail call, which it treats as tail. prefixed "explicit" tail calls. It does not in this case run the legality checks that are run when checking to determine if implicit tailcall optimization can be done, specifically the code under FEATURE_TAILCALL_OPT in fgMorphCall() that rejects a potential tail call if any variable in the function has had its address taken, if there are pinned locals, or if there are struct promoted struct arguments.
This causes code such as this to fail:
unsafe class Program
{
static void foo(IntPtr x)
{
Console.WriteLine(*(int*)x);
}
static void Main(string[] args)
{
int x = 42;
foo((IntPtr)(&x));
}
}
category:correctness
theme:tail-call
skill-level:intermediate
cost:small