From 3c712b4edebc46b599319af234484477e5017514 Mon Sep 17 00:00:00 2001 From: Jarret Shook Date: Thu, 18 Jul 2019 21:07:08 -0700 Subject: Fail to explicitly tail call on x86 unix. (#25032) * Fail to explicitly tail call on x86 unix. * Correctly return 100 * Correct return value * Add noway assert in morphTailCall to avoid morphing slow tail calls on unix. * Address feedback --- src/jit/morph.cpp | 8 ++++-- .../JitBlue/GitHub_25020/GitHub_25020.cs | 32 ++++++++++++++++++++++ .../JitBlue/GitHub_25020/GitHub_25020.csproj | 17 ++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_25020/GitHub_25020.cs create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_25020/GitHub_25020.csproj diff --git a/src/jit/morph.cpp b/src/jit/morph.cpp index c087fb069f..5450b4396c 100644 --- a/src/jit/morph.cpp +++ b/src/jit/morph.cpp @@ -7351,6 +7351,10 @@ bool Compiler::fgCanFastTailCall(GenTreeCall* callee) */ void Compiler::fgMorphTailCall(GenTreeCall* call, void* pfnCopyArgs) { +#if defined(_TARGET_UNIX_) + noway_assert(!"Slow tail calls not supported on non-Windows platforms."); +#endif + JITDUMP("fgMorphTailCall (before):\n"); DISPTREE(call); @@ -8275,7 +8279,7 @@ GenTree* Compiler::fgMorphCall(GenTreeCall* call) } void* pfnCopyArgs = nullptr; -#if !defined(_TARGET_X86_) +#if !defined(_TARGET_X86_) || defined(_TARGET_UNIX_) if (!canFastTailCall && szFailReason == nullptr) { pfnCopyArgs = @@ -8295,7 +8299,7 @@ GenTree* Compiler::fgMorphCall(GenTreeCall* call) } } } -#endif // !_TARGET_X86_ +#endif // !defined(_TARGET_X86_) || defined(_TARGET_UNIX_) if (szFailReason != nullptr) { diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_25020/GitHub_25020.cs b/tests/src/JIT/Regression/JitBlue/GitHub_25020/GitHub_25020.cs new file mode 100644 index 0000000000..89d54315e8 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_25020/GitHub_25020.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Reflection; +using System.Reflection.Emit; + +namespace GitHub_25020 +{ + class Program + { + static int Main(string[] args) + { + DynamicMethod dm = new DynamicMethod("MyMethod", typeof(string), new Type[] { typeof(string), typeof(string) }); + + ILGenerator generator = dm.GetILGenerator(); + generator.Emit(OpCodes.Ldarg_0); + generator.Emit(OpCodes.Ldarg_1); + generator.Emit(OpCodes.Tailcall); + generator.EmitCall(OpCodes.Call, typeof(String).GetMethod("Concat", new Type[] { typeof(string), typeof(string) }), null); + generator.Emit(OpCodes.Ret); + + string a = "1234"; + string b = "abcd"; + + Console.WriteLine(dm.Invoke(null, BindingFlags.Default, null, new object[] {a, b}, null)); + + return 100; + } + } +} \ No newline at end of file diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_25020/GitHub_25020.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_25020/GitHub_25020.csproj new file mode 100644 index 0000000000..c24f74b865 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_25020/GitHub_25020.csproj @@ -0,0 +1,17 @@ + + + + + Release + AnyCPU + $(MSBuildProjectName) + Exe + + True + + + + + + + -- cgit v1.2.3