This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17329 from briansull/struct-gscheck-fix
Reject struct promotion of parameters when -GS checks are enabled
- Loading branch information
Showing
3 changed files
with
160 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
tests/src/JIT/Regression/JitBlue/GitHub_17329/GitHub_17329.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/src/JIT/Regression/JitBlue/GitHub_17329/GitHub_17329.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |