summaryrefslogtreecommitdiff
path: root/tests/src/JIT
diff options
context:
space:
mode:
authorAndy Ayers <andya@microsoft.com>2019-04-12 00:44:39 -0700
committerGitHub <noreply@github.com>2019-04-12 00:44:39 -0700
commit72d49127a0c25e4b931c81e621c2411bfb6633a5 (patch)
treefe079e9ca55688827fd69817b9822b644a711778 /tests/src/JIT
parent1660956bca91b93259393419cb169a10df088926 (diff)
downloadcoreclr-72d49127a0c25e4b931c81e621c2411bfb6633a5.tar.gz
coreclr-72d49127a0c25e4b931c81e621c2411bfb6633a5.tar.bz2
coreclr-72d49127a0c25e4b931c81e621c2411bfb6633a5.zip
JIT: update byref null check logic to handle field chains (#23850)
The jit was not properly accumulating offsets when figuring out if a byref should be null checked. Use a non-null MorphAddressContext as indication that GT_FIELD and GT_IND nodes are actually part of an ongoing address computation. During field morphing propagate the current address context to the child node, instead of starting a new one. Fixes #23791.
Diffstat (limited to 'tests/src/JIT')
-rw-r--r--tests/src/JIT/Regression/JitBlue/GitHub_23791/GitHub_23791.cs41
-rw-r--r--tests/src/JIT/Regression/JitBlue/GitHub_23791/GitHub_23791.csproj34
2 files changed, 75 insertions, 0 deletions
diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_23791/GitHub_23791.cs b/tests/src/JIT/Regression/JitBlue/GitHub_23791/GitHub_23791.cs
new file mode 100644
index 0000000000..e724823c34
--- /dev/null
+++ b/tests/src/JIT/Regression/JitBlue/GitHub_23791/GitHub_23791.cs
@@ -0,0 +1,41 @@
+// 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;
+
+// The jit should null check 'this' in NextElement
+
+unsafe struct GitHub_23791
+{
+ fixed byte A[10];
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ byte NextElement(int i) => A[1+i];
+
+ static int Main()
+ {
+ int result = -1;
+ GitHub_23791* x = null;
+ bool threw = true;
+
+ try
+ {
+ byte t = x->NextElement(100000);
+ threw = false;
+ }
+ catch (NullReferenceException)
+ {
+ result = 100;
+ }
+
+ if (!threw)
+ {
+ Console.WriteLine($"FAIL: did not throw an exception");
+ }
+
+ return result;
+ }
+}
diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_23791/GitHub_23791.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_23791/GitHub_23791.csproj
new file mode 100644
index 0000000000..7198ed8b5b
--- /dev/null
+++ b/tests/src/JIT/Regression/JitBlue/GitHub_23791/GitHub_23791.csproj
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{2649FAFE-07BF-4F93-8120-BA9A69285ABB}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "></PropertyGroup>
+ <PropertyGroup>
+ <DebugType>None</DebugType>
+ <Optimize>True</Optimize>
+ <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="$(MSBuildProjectName).cs" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
+</Project>