From 4f977fe11760d95040506d6b82f92bec37255a61 Mon Sep 17 00:00:00 2001 From: Sergey Andreenko Date: Thu, 10 May 2018 17:10:57 -0700 Subject: [PATCH] add test with tail call of VSD stub with AV. (dotnet/coreclr#17920) * add test with tail call of VSD stub with AV. * exclude new failing test * fix names/types * forbid inlining Commit migrated from https://github.com/dotnet/coreclr/commit/8a0c19ea09b2b4b0ecfa4af427ae2e4926e218f7 --- src/coreclr/tests/arm/Tests.lst | 8 + src/coreclr/tests/arm64/Tests.lst | 8 + src/coreclr/tests/issues.targets | 9 ++ .../JitBlue/GitHub_17585/GitHub_17585.il | 151 ++++++++++++++++++ .../JitBlue/GitHub_17585/GitHub_17585.ilproj | 34 ++++ 5 files changed, 210 insertions(+) create mode 100644 src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_17585/GitHub_17585.il create mode 100644 src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_17585/GitHub_17585.ilproj diff --git a/src/coreclr/tests/arm/Tests.lst b/src/coreclr/tests/arm/Tests.lst index 50ecd6be4a6..b4a1bf3325a 100644 --- a/src/coreclr/tests/arm/Tests.lst +++ b/src/coreclr/tests/arm/Tests.lst @@ -94708,3 +94708,11 @@ MaxAllowedDurationSeconds=600 Categories=EXPECTED_PASS;NEW;EXCLUDED HostStyle=0 +[GitHub_17585.cmd_11895] +RelativePath=JIT\Regression\JitBlue\GitHub_17585\GitHub_17585\GitHub_17585.cmd +WorkingDir=JIT\Regression\JitBlue\GitHub_17585\GitHub_17585 +Expected=0 +MaxAllowedDurationSeconds=600 +Categories=EXPECTED_FAIL;17585;EXCLUDED +HostStyle=0 + diff --git a/src/coreclr/tests/arm64/Tests.lst b/src/coreclr/tests/arm64/Tests.lst index a58dc6249d8..b7c7fcad19c 100644 --- a/src/coreclr/tests/arm64/Tests.lst +++ b/src/coreclr/tests/arm64/Tests.lst @@ -94731,3 +94731,11 @@ Expected=0 MaxAllowedDurationSeconds=600 Categories=EXPECTED_PASS HostStyle=0 + +[GitHub_17585.cmd_12215] +RelativePath=JIT\Regression\JitBlue\GitHub_17585\GitHub_17585\GitHub_17585.cmd +WorkingDir=JIT\Regression\JitBlue\GitHub_17585\GitHub_17585 +Expected=0 +MaxAllowedDurationSeconds=600 +Categories=EXPECTED_FAIL;17585;EXCLUDED +HostStyle=0 diff --git a/src/coreclr/tests/issues.targets b/src/coreclr/tests/issues.targets index 670a935f347..4aec0a5426c 100644 --- a/src/coreclr/tests/issues.targets +++ b/src/coreclr/tests/issues.targets @@ -214,6 +214,15 @@ 11469, The test causes OutOfMemory exception in crossgen mode. + + + + + + 17585 + + + diff --git a/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_17585/GitHub_17585.il b/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_17585/GitHub_17585.il new file mode 100644 index 00000000000..63547bea255 --- /dev/null +++ b/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_17585/GitHub_17585.il @@ -0,0 +1,151 @@ +// 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. + + +// This test shows an issue with tail call optimization of an interface call through Virtual Dispatch Stub. +// The optimized VSD checks that `this` method table is equal to the cached method table. +// If `this` is `null` then the stub throws `Acess Violation` exception that VM should +// transform into the NullReference exception. VM is not able to do that when the first frame on the stack is +// unmanaged, in this case it is JIT_TailCallHelperStub_ReturnAddress from tail call optimization. +// To repro this issue on amd64/arm64 it also requires to reject fast tail call, for this puprose +// `Interface::InterfaceMethodWithStackArgs` has several stack arguments. + +// The fix is to always generate explicit null check before calling VSD with tail call from tail call frame. + + +.assembly extern System.Runtime +{ +} +.assembly extern System.Runtime.Extensions +{ +} +.assembly GitHub_17585 +{ +} + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class interface private abstract auto ansi Interface +{ + .method public hidebysig newslot abstract virtual + instance int32 InterfaceMethodWithStackArgs(int32 a, + int32 b, + int32 c, + int32 d, + int32 e, + int32 f, + int32 g, + int32 h, + int32 i) cil managed + { + } // end of method Interface::InterfaceMethodWithStackArgs + +} // end of class Interface + +.class private auto ansi beforefieldinit InterfaceImplementation + extends [System.Runtime]System.Object + implements Interface +{ + .method public hidebysig newslot virtual final + instance int32 InterfaceMethodWithStackArgs(int32 a, + int32 b, + int32 c, + int32 d, + int32 e, + int32 f, + int32 g, + int32 h, + int32 i) cil managed noinlining + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ret + } // end of method InterfaceImplementation::InterfaceMethodWithStackArgs + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [System.Runtime]System.Object::.ctor() + IL_0006: ret + } // end of method InterfaceImplementation::.ctor + +} // end of class InterfaceImplementation + +.class private auto ansi beforefieldinit Test + extends [System.Runtime]System.Object +{ + .method public hidebysig static int32 CallInterfaceMethod(class Interface iface) cil managed noinlining + { + // Code size 17 (0x11) + .maxstack 10 + IL_0000: ldarg.0 + IL_0001: ldc.i4.1 + IL_0002: ldc.i4.2 + IL_0003: ldc.i4.3 + IL_0004: ldc.i4.4 + IL_0005: ldc.i4.5 + IL_0006: ldc.i4.6 + IL_0007: ldc.i4.7 + IL_0008: ldc.i4.8 + IL_0009: ldc.i4.s 9 + IL_000b: tail. callvirt instance int32 Interface::InterfaceMethodWithStackArgs(int32, + int32, + int32, + int32, + int32, + int32, + int32, + int32, + int32) + IL_0010: ret + } // end of method Test::CallInterfaceMethod + + .method public hidebysig static int32 Main() cil managed + { + .entrypoint + // Code size 35 (0x23) + .maxstack 1 + .locals init ([0] class InterfaceImplementation iface) + IL_0000: newobj instance void InterfaceImplementation::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: call int32 Test::CallInterfaceMethod(class Interface) + IL_000c: pop + IL_000d: ldloc.0 + IL_000e: call int32 Test::CallInterfaceMethod(class Interface) + IL_0013: pop + .try + { + IL_0014: ldnull + IL_0015: call int32 Test::CallInterfaceMethod(class Interface) + IL_001a: pop + IL_001b: leave.s IL_0020 + + } // end .try + catch [System.Runtime]System.NullReferenceException + { + IL_001d: pop + IL_001e: leave.s IL_0020 + + } // end handler + IL_0020: ldc.i4.s 100 + IL_0022: ret + } // end of method Test::Main + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [System.Runtime]System.Object::.ctor() + IL_0006: ret + } // end of method Test::.ctor + +} // end of class Test diff --git a/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_17585/GitHub_17585.ilproj b/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_17585/GitHub_17585.ilproj new file mode 100644 index 00000000000..7ec8e412330 --- /dev/null +++ b/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_17585/GitHub_17585.ilproj @@ -0,0 +1,34 @@ + + + + + Debug + AnyCPU + $(MSBuildProjectName) + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + + + + + + + False + + + + None + True + + + + + + + + + + -- 2.34.1