summaryrefslogtreecommitdiff
path: root/tests/src/JIT
diff options
context:
space:
mode:
authorEugene Rozenfeld <erozen@microsoft.com>2019-05-07 15:35:42 -0700
committerEugene Rozenfeld <erozen@microsoft.com>2019-05-09 10:30:46 -0700
commit993b7c5d4c002ff2f9f11b4ac3176baf72ec1b77 (patch)
tree5e36ec1c3c96405d215200eff17504776336641d /tests/src/JIT
parent8b6a69e71d36c26e378460c4e586593efe0b13da (diff)
downloadcoreclr-993b7c5d4c002ff2f9f11b4ac3176baf72ec1b77.tar.gz
coreclr-993b7c5d4c002ff2f9f11b4ac3176baf72ec1b77.tar.bz2
coreclr-993b7c5d4c002ff2f9f11b4ac3176baf72ec1b77.zip
Mark local struct as having overlapping fields after struct reinterpretation
Methods like System.Runtime.CompilerServices.Unsafe.As<TFrom, TTo> may have struct reinterpretation when function signature specifies Struct1& and the method returns Struct2& where Struct1 and Struct2 are different structs. This may confuse jit optimizations (in particular, value numbering) because fields of a struct of type Struct1 may be accessed using handles of Struct2. This fix marks the source local involved in such struct reinterpretation as having overlapping fields. That prevents SSA builder from inserting the local into SSA. Fixes #24159. No diffs in framework assemblies and coreclr benchmarks.
Diffstat (limited to 'tests/src/JIT')
-rw-r--r--tests/src/JIT/Regression/JitBlue/GitHub_24159/GitHub_24159.cs61
-rw-r--r--tests/src/JIT/Regression/JitBlue/GitHub_24159/GitHub_24159.csproj17
2 files changed, 78 insertions, 0 deletions
diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_24159/GitHub_24159.cs b/tests/src/JIT/Regression/JitBlue/GitHub_24159/GitHub_24159.cs
new file mode 100644
index 0000000000..8017ca5e0c
--- /dev/null
+++ b/tests/src/JIT/Regression/JitBlue/GitHub_24159/GitHub_24159.cs
@@ -0,0 +1,61 @@
+// 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;
+
+namespace GitHub_24159
+{
+
+ public struct Str1
+ {
+ public int i1;
+ public int i2;
+ public int i3;
+ public int i4;
+ public int i5;
+ }
+
+ public struct Str2
+ {
+ public int j1;
+ public int j2;
+ public int j3;
+ public int j4;
+ public int j5;
+ }
+
+ class Test
+ {
+ static int i;
+
+ public static int Main()
+ {
+ i = 0;
+
+ Str1 str1 = new Str1();
+
+ if (i != 0)
+ {
+ str1 = new Str1();
+ }
+ else
+ {
+ str1.i2 = 7;
+ }
+
+ // This call reinterprets the struct.
+ Str2 str2 = Unsafe.As<Str1, Str2>(ref str1);
+
+ // The bug was that value numbering couldn't recognize
+ // that this field has been updated on str1.
+ int k = str2.j2;
+
+ Console.WriteLine(k);
+
+ return k + 93;
+
+ }
+ }
+}
diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_24159/GitHub_24159.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_24159/GitHub_24159.csproj
new file mode 100644
index 0000000000..d86ed9f3d7
--- /dev/null
+++ b/tests/src/JIT/Regression/JitBlue/GitHub_24159/GitHub_24159.csproj
@@ -0,0 +1,17 @@
+<?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)' == '' ">Release</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+ <OutputType>Exe</OutputType>
+ <DebugType></DebugType>
+ <Optimize>True</Optimize>
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="$(MSBuildProjectName).cs" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
+</Project> \ No newline at end of file