From 2d0e02d665c54b654b7775d15e7f5abf9e6d9852 Mon Sep 17 00:00:00 2001 From: Koundinya Veluri Date: Wed, 26 Apr 2017 18:42:48 -0700 Subject: [PATCH] Fix to respect readonly prefix for multidimensional array Address method (dotnet/coreclr#11245) Fixes dotnet/coreclr#9414 - Added missing 'else' back from regression in https://github.com/dotnet/coreclr/commit/dotnet/coreclr@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 Commit migrated from https://github.com/dotnet/coreclr/commit/0b3b3534c9a37732951d0540758d8fe722c8e974 --- src/coreclr/src/jit/importer.cpp | 3 +- .../src/Regressions/coreclr/9414/readonlyPrefix.cs | 36 ++++++++++++++++++++++ .../Regressions/coreclr/9414/readonlyPrefix.csproj | 31 +++++++++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 src/coreclr/tests/src/Regressions/coreclr/9414/readonlyPrefix.cs create mode 100644 src/coreclr/tests/src/Regressions/coreclr/9414/readonlyPrefix.csproj diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index 9548e0a..d91537c 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -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/src/coreclr/tests/src/Regressions/coreclr/9414/readonlyPrefix.cs b/src/coreclr/tests/src/Regressions/coreclr/9414/readonlyPrefix.cs new file mode 100644 index 0000000..05148a1 --- /dev/null +++ b/src/coreclr/tests/src/Regressions/coreclr/9414/readonlyPrefix.cs @@ -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 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.FrobAll(new Frobber[,] { { new Frobber() } }); + return 100; + } +} diff --git a/src/coreclr/tests/src/Regressions/coreclr/9414/readonlyPrefix.csproj b/src/coreclr/tests/src/Regressions/coreclr/9414/readonlyPrefix.csproj new file mode 100644 index 0000000..560073c --- /dev/null +++ b/src/coreclr/tests/src/Regressions/coreclr/9414/readonlyPrefix.csproj @@ -0,0 +1,31 @@ + + + + + Debug + AnyCPU + 2.0 + {CBD0D777-3583-49CC-8538-DD84447F6522} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + true + BuildAndRun + 0 + + + + + + + + + False + + + + + + + + \ No newline at end of file -- 2.7.4