From 0402229da18652194566372993f46e29c7125443 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Tue, 14 Jan 2020 10:35:50 -0800 Subject: Release/3.1 port of dotnet/runtime#239 (#27973) Fix for #27923 The jit might fail to locate a class handle for a ref class, leading to an unexpected crash while jitting. ## Customer Impact Unexpected and hard to diagnose crash/exception ## Regression? Yes, introduced during the development 3.0 cycle. 2.x behaves correctly. ## Testing Verified the user's test case now passes; no diffs seen in any existing framework or test code. ## Risk **Low**: the jit will now fall back to using the handle for System.Object if no better option can be found. cc @BruceForstall ____ In some cases we may end up in lvaSetClass without a valid ref class handle from either the IR or the stack. Use the handle for object as a conservative fallback. --- .../JitBlue/GitHub_27923/GitHub_27923.cs | 34 ++++++++++++++++++++++ .../JitBlue/GitHub_27923/GitHub_27923.csproj | 34 ++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_27923/GitHub_27923.cs create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_27923/GitHub_27923.csproj (limited to 'tests') diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_27923/GitHub_27923.cs b/tests/src/JIT/Regression/JitBlue/GitHub_27923/GitHub_27923.cs new file mode 100644 index 0000000000..9ac2283299 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_27923/GitHub_27923.cs @@ -0,0 +1,34 @@ +// 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.Runtime.CompilerServices; + +class Writer +{ + public object Data { get; set; } + public int Position { get; set; } + + [MethodImpl(MethodImplOptions.NoInlining)] + Writer() + { + Data = new int[] { 100, -1, -2, -3 }; + Position = 4; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ArraySegment Test() + { + var writer = new Writer(); + object temp = writer.Data; + byte[] data = Unsafe.As(ref temp); + return new ArraySegment(data, 0, writer.Position); + } + + public static int Main() + { + var x = Test(); + return x[0]; + } +} diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_27923/GitHub_27923.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_27923/GitHub_27923.csproj new file mode 100644 index 0000000000..95aba995a2 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_27923/GitHub_27923.csproj @@ -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 + + + + + True + + + + + + + + + + -- cgit v1.2.3