diff options
author | Brian Sullivan <briansul@microsoft.com> | 2018-03-30 23:50:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-30 23:50:07 -0700 |
commit | 42ae2c03de22d32f96890077e109e1f9e57451d1 (patch) | |
tree | 8c209ab483314f6e872b229587e72608f445af02 /tests | |
parent | 48ec2b058e182a0191af04ca7cb400e53e273b64 (diff) | |
parent | 6b07baf10683c84809e75ead4a4227e8e139d348 (diff) | |
download | coreclr-42ae2c03de22d32f96890077e109e1f9e57451d1.tar.gz coreclr-42ae2c03de22d32f96890077e109e1f9e57451d1.tar.bz2 coreclr-42ae2c03de22d32f96890077e109e1f9e57451d1.zip |
Merge pull request #17329 from briansull/struct-gscheck-fix
Reject struct promotion of parameters when -GS checks are enabled
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/JIT/Regression/JitBlue/GitHub_17329/GitHub_17329.cs | 108 | ||||
-rw-r--r-- | tests/src/JIT/Regression/JitBlue/GitHub_17329/GitHub_17329.csproj | 39 |
2 files changed, 147 insertions, 0 deletions
diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_17329/GitHub_17329.cs b/tests/src/JIT/Regression/JitBlue/GitHub_17329/GitHub_17329.cs new file mode 100644 index 0000000000..4d5eb802ef --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_17329/GitHub_17329.cs @@ -0,0 +1,108 @@ +// 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; + +// Having an UnsafeValueTypeAttribute on a struct causes incoming arguments to be +// spilled into shadow copies and the struct promotion optimization does not +// currently handle this properly. +// + +[UnsafeValueTypeAttribute] +struct DangerousBuffer +{ + public long a; + public long b; + public long c; +} + +struct Point1 +{ + long x; + + public Point1(long _x) + { + x = _x; + } + + public void Increase(ref Point1 s, long amount) + { + x = s.x + amount; + } + + [MethodImplAttribute(MethodImplOptions.NoInlining)] + public long Value() + { + return x; + } +} + +class TestCase +{ + static public long[] arr; + + unsafe static long Test(int size, Point1 a, Point1 b, Point1 c) + { + + // Mutate the values stored in a, b and c + // So if these have a shadow copy we will notice + // + a.Increase(ref a, arr[0]); + b.Increase(ref b, arr[1]); + c.Increase(ref c, arr[2]); + + DangerousBuffer db = new DangerousBuffer(); + db.a = -1; + db.b = -2; + db.c = -3; + + long* x1 = stackalloc long[size]; + + long sum = 0; + if (size >= 3) + { + x1[0] = a.Value(); + x1[1] = b.Value(); + x1[2] = c.Value(); + + for (int i = 0; i < size; i++) + { + sum += x1[i]; + } + } + return sum; + } + + static int Main() + { + long testResult = 0; + int mainResult = 0; + + Point1 p1 = new Point1(1); + Point1 p2 = new Point1(3); + Point1 p3 = new Point1(5); + + arr = new long[3]; + arr[0] = 9; + arr[1] = 10; + arr[2] = 11; + + + testResult = Test(3, p1, p2, p3); + + if (testResult != 39) + { + Console.WriteLine("FAILED!"); + mainResult = -1; + } + else + { + Console.WriteLine("passed"); + mainResult = 100; + } + + return mainResult; + } +} diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_17329/GitHub_17329.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_17329/GitHub_17329.csproj new file mode 100644 index 0000000000..15d1472fea --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_17329/GitHub_17329.csproj @@ -0,0 +1,39 @@ +<?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> + <AssemblyName>$(MSBuildProjectName)</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-B8089FFA8D79}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "></PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <PropertyGroup> + <DebugType></DebugType> + <Optimize>True</Optimize> + <AllowUnsafeBlocks>True</AllowUnsafeBlocks> + </PropertyGroup> + <ItemGroup> + <Compile Include="$(MSBuildProjectName).cs" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> +</Project>
\ No newline at end of file |