Add a test case for a test optimization
authorCarol Eidt <carol.eidt@microsoft.com>
Tue, 24 Jan 2017 00:23:29 +0000 (16:23 -0800)
committerCarol Eidt <carol.eidt@microsoft.com>
Tue, 24 Jan 2017 00:23:29 +0000 (16:23 -0800)
Commit migrated from https://github.com/dotnet/coreclr/commit/1a0e8a72f50905a564b4efcacd0785cd859c544d

src/coreclr/tests/src/JIT/Regression/JitBlue/DevDiv_1206929/DevDiv_1206929.cs [new file with mode: 0644]
src/coreclr/tests/src/JIT/Regression/JitBlue/DevDiv_1206929/DevDiv_1206929.csproj [new file with mode: 0644]

diff --git a/src/coreclr/tests/src/JIT/Regression/JitBlue/DevDiv_1206929/DevDiv_1206929.cs b/src/coreclr/tests/src/JIT/Regression/JitBlue/DevDiv_1206929/DevDiv_1206929.cs
new file mode 100644 (file)
index 0000000..d363360
--- /dev/null
@@ -0,0 +1,50 @@
+using System;
+using System.Runtime.CompilerServices;
+
+namespace ReadMemBytes
+{
+    class Program
+    {
+        static int Pass = 100;
+        static int Fail = -1;
+
+        [MethodImpl(MethodImplOptions.NoInlining)]
+        static unsafe int TestMemBytesNotReadPastTheLimit(byte *p, int byteLength)
+        {
+            int count = 0;
+            for (int i= 0; i< byteLength; ++i)
+            {
+                // RyuJIT lowering has an optimization to recognize the condition in
+                // "If" stmnt and generate "test byte ptr [p+i], 0" instruction. Due
+                // to a bug that has been fixed it will end up generating "test dword ptr [p+i], 0"
+                // that will lead to reading 4 bytes instead of a single byte.
+                if ((p[i] & 0xffffff00) != 0)
+                {
+                    ++count;
+                }
+            }
+
+            return count;
+        }
+        static unsafe int Main(string[] args)
+        {
+            byte* buffer = stackalloc byte[4];
+            buffer[0] = 0;
+            buffer[1] = buffer[2] = buffer[3] = 0xff;
+
+            int result = TestMemBytesNotReadPastTheLimit(buffer, 1);
+            if (result != 0)
+            {
+                Console.WriteLine("Failed: Read past the end of buffer");
+                return Fail;
+            }
+            else
+            {
+                Console.WriteLine("Pass");
+            }
+
+            return Pass;
+
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/JIT/Regression/JitBlue/DevDiv_1206929/DevDiv_1206929.csproj b/src/coreclr/tests/src/JIT/Regression/JitBlue/DevDiv_1206929/DevDiv_1206929.csproj
new file mode 100644 (file)
index 0000000..a1f7eaa
--- /dev/null
@@ -0,0 +1,47 @@
+<?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-E94EE1F7140D}</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="DevDiv_1206929.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>