Handle ELEMENT_TYPE_PTR in ILCodeStream::EmitLDIND/EmitSTIND (#16381)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Wed, 14 Feb 2018 10:16:09 +0000 (11:16 +0100)
committerGitHub <noreply@github.com>
Wed, 14 Feb 2018 10:16:09 +0000 (11:16 +0100)
Fixes #16371.

src/vm/stubgen.cpp
tests/src/Regressions/coreclr/16371/ptrarray.cs [new file with mode: 0644]
tests/src/Regressions/coreclr/16371/ptrarray.csproj [new file with mode: 0644]

index 18a6c19..f1690db 100644 (file)
@@ -1396,7 +1396,8 @@ void ILCodeStream::EmitLDIND_T(LocalDesc* pType)
         case ELEMENT_TYPE_U8:       EmitLDIND_I8(); break;
         case ELEMENT_TYPE_R4:       EmitLDIND_R4(); break;
         case ELEMENT_TYPE_R8:       EmitLDIND_R8(); break;
-        case ELEMENT_TYPE_FNPTR: // same as ELEMENT_TYPE_I
+        case ELEMENT_TYPE_PTR:      // same as ELEMENT_TYPE_I
+        case ELEMENT_TYPE_FNPTR:    // same as ELEMENT_TYPE_I
         case ELEMENT_TYPE_I:        EmitLDIND_I();  break;
         case ELEMENT_TYPE_U:        EmitLDIND_I();  break;
         case ELEMENT_TYPE_STRING:   // fall through
@@ -1594,7 +1595,8 @@ void ILCodeStream::EmitSTIND_T(LocalDesc* pType)
         case ELEMENT_TYPE_U8:       EmitSTIND_I8(); break;
         case ELEMENT_TYPE_R4:       EmitSTIND_R4(); break;
         case ELEMENT_TYPE_R8:       EmitSTIND_R8(); break;
-        case ELEMENT_TYPE_FNPTR: // same as ELEMENT_TYPE_I
+        case ELEMENT_TYPE_PTR:      // same as ELEMENT_TYPE_I
+        case ELEMENT_TYPE_FNPTR:    // same as ELEMENT_TYPE_I
         case ELEMENT_TYPE_I:        EmitSTIND_I();  break;
         case ELEMENT_TYPE_U:        EmitSTIND_I();  break;
         case ELEMENT_TYPE_STRING:   // fall through
diff --git a/tests/src/Regressions/coreclr/16371/ptrarray.cs b/tests/src/Regressions/coreclr/16371/ptrarray.cs
new file mode 100644 (file)
index 0000000..47537b3
--- /dev/null
@@ -0,0 +1,25 @@
+// 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.
+
+unsafe class Program
+{
+    static int*[,] s_mdArray;
+
+    static void Init(ref int* elem)
+    {
+        elem = (int*)98;
+    }
+
+    static Program()
+    {
+        s_mdArray = new int*[2,2];
+        Init(ref s_mdArray[0, 0]);
+        s_mdArray[1, 1] = (int*)2;
+    }
+
+    static int Main()
+    {
+        return (int)s_mdArray[0, 0] + (int)s_mdArray[1, 1];
+    }
+}
diff --git a/tests/src/Regressions/coreclr/16371/ptrarray.csproj b/tests/src/Regressions/coreclr/16371/ptrarray.csproj
new file mode 100644 (file)
index 0000000..756d1d3
--- /dev/null
@@ -0,0 +1,31 @@
+<?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>{CBD0D777-3583-49CC-8538-DD84447F6522}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <CLRTestKind>BuildAndRun</CLRTestKind>
+    <CLRTestPriority>1</CLRTestPriority>
+    <DebugType>None</DebugType>
+    <Optimize>False</Optimize>
+  </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>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="ptrarray.cs" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+</Project>
\ No newline at end of file