Fix to respect readonly prefix for multidimensional array Address method (#11245)
authorKoundinya Veluri <kouvel@microsoft.com>
Thu, 27 Apr 2017 01:42:48 +0000 (18:42 -0700)
committerGitHub <noreply@github.com>
Thu, 27 Apr 2017 01:42:48 +0000 (18:42 -0700)
Fixes #9414
- Added missing 'else' back from regression in https://github.com/dotnet/coreclr/commit/97b4ff0b438261ba11b357008630076054a6f25d#diff-edc46b80f57431489a82311948a8234dL6424, which has the effect of passing null to the Address method's instParam to indicate the readonly prefix in order to bypass the type check

src/jit/importer.cpp
tests/src/Regressions/coreclr/9414/readonlyPrefix.cs [new file with mode: 0644]
tests/src/Regressions/coreclr/9414/readonlyPrefix.csproj [new file with mode: 0644]

index 9548e0a..d91537c 100644 (file)
@@ -7325,8 +7325,7 @@ var_types Compiler::impImportCall(OPCODE                  opcode,
                 // instParam.
                 instParam = gtNewIconNode(0, TYP_REF);
             }
-
-            if (!exactContextNeedsRuntimeLookup)
+            else if (!exactContextNeedsRuntimeLookup)
             {
 #ifdef FEATURE_READYTORUN_COMPILER
                 if (opts.IsReadyToRun())
diff --git a/tests/src/Regressions/coreclr/9414/readonlyPrefix.cs b/tests/src/Regressions/coreclr/9414/readonlyPrefix.cs
new file mode 100644 (file)
index 0000000..05148a1
--- /dev/null
@@ -0,0 +1,36 @@
+// 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.
+
+class Program
+{
+    interface IFrobber
+    {
+        void Frob();
+    }
+
+    class Frobber : IFrobber
+    {
+        public void Frob()
+        {
+        }
+    }
+
+    class Foo<T> where T : IFrobber
+    {
+        public static void FrobAll(T[,] arr)
+        {
+            for (int i = 0; i < arr.Length; i++)
+            {
+                // 'readonly' prefix on call to array's Address method must be respected, and the type check bypassed
+                arr[0, i].Frob();
+            }
+        }
+    }
+
+    private static int Main()
+    {
+        Foo<IFrobber>.FrobAll(new Frobber[,] { { new Frobber() } });
+        return 100;
+    }
+}
diff --git a/tests/src/Regressions/coreclr/9414/readonlyPrefix.csproj b/tests/src/Regressions/coreclr/9414/readonlyPrefix.csproj
new file mode 100644 (file)
index 0000000..560073c
--- /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>0</CLRTestPriority>
+  </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="readonlyPrefix.cs" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+</Project>
\ No newline at end of file