Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Wrighton <davidwr@microsoft.com>2021-05-16 00:00:36 +0300
committerGitHub <noreply@github.com>2021-05-16 00:00:36 +0300
commit7db54380ddf0858aedec612a6581f8176cb861bb (patch)
treebf5f940a51755e77357c5ab283cbab1db1de2500 /src/coreclr/tools
parentce15f8982e87859539350bfe6c7751d6c784ac2d (diff)
Fix references to MDArray methods (#52796)
Diffstat (limited to 'src/coreclr/tools')
-rw-r--r--src/coreclr/tools/Common/TypeSystem/Common/ArrayType.cs10
-rw-r--r--src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs20
-rw-r--r--src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILCompiler.TypeSystem.ReadyToRun.Tests.csproj2
-rw-r--r--src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILTestAssembly/ILTestAssembly.ilproj1
-rw-r--r--src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILTestAssembly/MDArrayFunctionResolution.il41
-rw-r--r--src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/SignatureTests.cs41
6 files changed, 108 insertions, 7 deletions
diff --git a/src/coreclr/tools/Common/TypeSystem/Common/ArrayType.cs b/src/coreclr/tools/Common/TypeSystem/Common/ArrayType.cs
index 44a4ad886c9..c3e227ed3f6 100644
--- a/src/coreclr/tools/Common/TypeSystem/Common/ArrayType.cs
+++ b/src/coreclr/tools/Common/TypeSystem/Common/ArrayType.cs
@@ -233,7 +233,7 @@ namespace Internal.TypeSystem
var parameters = new TypeDesc[_owningType.Rank];
for (int i = 0; i < _owningType.Rank; i++)
parameters[i] = _owningType.Context.GetWellKnownType(WellKnownType.Int32);
- _signature = new MethodSignature(0, 0, _owningType.ElementType, parameters);
+ _signature = new MethodSignature(0, 0, _owningType.ElementType, parameters, MethodSignature.EmbeddedSignatureMismatchPermittedFlag);
break;
}
case ArrayMethodKind.Set:
@@ -242,7 +242,7 @@ namespace Internal.TypeSystem
for (int i = 0; i < _owningType.Rank; i++)
parameters[i] = _owningType.Context.GetWellKnownType(WellKnownType.Int32);
parameters[_owningType.Rank] = _owningType.ElementType;
- _signature = new MethodSignature(0, 0, this.Context.GetWellKnownType(WellKnownType.Void), parameters);
+ _signature = new MethodSignature(0, 0, this.Context.GetWellKnownType(WellKnownType.Void), parameters, MethodSignature.EmbeddedSignatureMismatchPermittedFlag);
break;
}
case ArrayMethodKind.Address:
@@ -250,7 +250,7 @@ namespace Internal.TypeSystem
var parameters = new TypeDesc[_owningType.Rank];
for (int i = 0; i < _owningType.Rank; i++)
parameters[i] = _owningType.Context.GetWellKnownType(WellKnownType.Int32);
- _signature = new MethodSignature(0, 0, _owningType.ElementType.MakeByRefType(), parameters);
+ _signature = new MethodSignature(0, 0, _owningType.ElementType.MakeByRefType(), parameters, MethodSignature.EmbeddedSignatureMismatchPermittedFlag);
}
break;
case ArrayMethodKind.AddressWithHiddenArg:
@@ -259,7 +259,7 @@ namespace Internal.TypeSystem
parameters[0] = Context.GetWellKnownType(WellKnownType.IntPtr);
for (int i = 0; i < _owningType.Rank; i++)
parameters[i + 1] = _owningType.Context.GetWellKnownType(WellKnownType.Int32);
- _signature = new MethodSignature(0, 0, _owningType.ElementType.MakeByRefType(), parameters);
+ _signature = new MethodSignature(0, 0, _owningType.ElementType.MakeByRefType(), parameters, MethodSignature.EmbeddedSignatureMismatchPermittedFlag);
}
break;
default:
@@ -277,7 +277,7 @@ namespace Internal.TypeSystem
var argTypes = new TypeDesc[numArgs];
for (int i = 0; i < argTypes.Length; i++)
argTypes[i] = _owningType.Context.GetWellKnownType(WellKnownType.Int32);
- _signature = new MethodSignature(0, 0, this.Context.GetWellKnownType(WellKnownType.Void), argTypes);
+ _signature = new MethodSignature(0, 0, this.Context.GetWellKnownType(WellKnownType.Void), argTypes, MethodSignature.EmbeddedSignatureMismatchPermittedFlag);
}
break;
}
diff --git a/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs b/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs
index 69075324862..01e6153e07e 100644
--- a/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs
+++ b/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs
@@ -60,6 +60,9 @@ namespace Internal.TypeSystem
return $"0.1.1.2.{(parameterIndex + 1).ToStringInvariant()}.1";
}
+ // Provide a means to create a MethodSignature which ignores EmbeddedSignature data in the MethodSignatures it is compared to
+ public static EmbeddedSignatureData[] EmbeddedSignatureMismatchPermittedFlag = new EmbeddedSignatureData[0];
+
public MethodSignature(MethodSignatureFlags flags, int genericParameterCount, TypeDesc returnType, TypeDesc[] parameters, EmbeddedSignatureData[] embeddedSignatureData = null)
{
_flags = flags;
@@ -168,7 +171,15 @@ namespace Internal.TypeSystem
{
get
{
- return _embeddedSignatureData != null;
+ return _embeddedSignatureData != null && _embeddedSignatureData.Length != 0;
+ }
+ }
+
+ public bool EmbeddedSignatureMismatchPermitted
+ {
+ get
+ {
+ return _embeddedSignatureData == EmbeddedSignatureMismatchPermittedFlag;
}
}
@@ -222,6 +233,13 @@ namespace Internal.TypeSystem
return true;
}
+ // Array methods do not need to have matching details for the array parameters they support
+ if (this.EmbeddedSignatureMismatchPermitted ||
+ otherSignature.EmbeddedSignatureMismatchPermitted)
+ {
+ return true;
+ }
+
if (this._embeddedSignatureData != null && otherSignature._embeddedSignatureData != null)
{
if (this._embeddedSignatureData.Length != otherSignature._embeddedSignatureData.Length)
diff --git a/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILCompiler.TypeSystem.ReadyToRun.Tests.csproj b/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILCompiler.TypeSystem.ReadyToRun.Tests.csproj
index e45bb1a4a7a..e6889937f59 100644
--- a/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILCompiler.TypeSystem.ReadyToRun.Tests.csproj
+++ b/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILCompiler.TypeSystem.ReadyToRun.Tests.csproj
@@ -12,6 +12,7 @@
included in compilation of this project -->
<EnableDefaultItems>false</EnableDefaultItems>
<Platforms>AnyCPU;x64</Platforms>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
@@ -37,6 +38,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="../../Common/TypeSystem/MetadataEmitter/TypeSystemMetadataEmitter.cs" />
+ <Compile Include="../../Common/TypeSystem/IL/ILReader.cs" />
<Compile Include="ArchitectureSpecificFieldLayoutTests.cs" />
<Compile Include="CanonicalizationTests.cs" />
<Compile Include="ConstraintsValidationTest.cs" />
diff --git a/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILTestAssembly/ILTestAssembly.ilproj b/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILTestAssembly/ILTestAssembly.ilproj
index bbba57074e9..22c49cc0676 100644
--- a/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILTestAssembly/ILTestAssembly.ilproj
+++ b/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILTestAssembly/ILTestAssembly.ilproj
@@ -18,6 +18,7 @@
<Compile Include="VirtualFunctionOverride.il" />
<Compile Include="Signature.il" />
<Compile Include="MethodImplOverride1.il" />
+ <Compile Include="MDArrayFunctionResolution.il" />
</ItemGroup>
</Project>
diff --git a/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILTestAssembly/MDArrayFunctionResolution.il b/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILTestAssembly/MDArrayFunctionResolution.il
new file mode 100644
index 00000000000..b240ec9f1e9
--- /dev/null
+++ b/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILTestAssembly/MDArrayFunctionResolution.il
@@ -0,0 +1,41 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+.class public auto ansi beforefieldinit MDArrayFunctionResolution
+ extends [CoreTestAssembly]System.Object
+{
+ .method private hidebysig static void MethodWithUseOfMDArrayFunctions() cil managed
+ {
+ .entrypoint
+ // Code size 44 (0x2c)
+ .maxstack 5
+ .locals init (int32[0...,0...][0...,0...][0...,0...] V_0)
+ IL_0000: ldc.i4.1
+ IL_0001: ldc.i4.1
+ IL_0002: newobj instance void int32[0...,0...][0...,0...][0...,0...]::.ctor(int32,
+ int32)
+ IL_0007: stloc.0
+ IL_0008: ldloc.0
+ IL_0009: ldc.i4.0
+ IL_000a: ldc.i4.0
+ IL_000b: ldc.i4.s 123
+ IL_000d: ldc.i4.2
+ IL_000e: newobj instance void int32[0...,0...][0...,0...]::.ctor(int32,
+ int32)
+ IL_0013: call instance void int32[0...,0...][0...,0...][0...,0...]::Set(int32,
+ int32,
+ int32[0...,0...][0...,0...])
+ IL_0018: ldstr "Hello world"
+ IL_001d: ldloc.0
+ IL_001e: ldc.i4.0
+ IL_001f: ldc.i4.0
+ IL_0020: call instance int32[0...,0...][0...,0...] int32[0...,0...][0...,0...][0...,0...]::Get(int32,
+ int32)
+pop
+pop
+ IL_002a: nop
+ IL_002b: ret
+} // end of method MethodWithUseOfMDArrayFunctions
+
+
+} \ No newline at end of file
diff --git a/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/SignatureTests.cs b/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/SignatureTests.cs
index cb8234e121d..0ea96171119 100644
--- a/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/SignatureTests.cs
+++ b/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/SignatureTests.cs
@@ -14,16 +14,19 @@ using Internal.TypeSystem;
using Internal.TypeSystem.Ecma;
using Xunit;
+using Xunit.Abstractions;
namespace TypeSystemTests
{
public class SignatureTests
{
+ private readonly ITestOutputHelper _output;
private TestTypeSystemContext _context;
private ModuleDesc _testModule;
- public SignatureTests()
+ public SignatureTests(ITestOutputHelper output)
{
+ _output = output;
_context = new TestTypeSystemContext(TargetArchitecture.X64);
var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly");
_context.SetSystemModule(systemModule);
@@ -177,5 +180,41 @@ namespace TypeSystemTests
Assert.Equal(typeInLookupContext, int32ArrayFromLookup);
}
+
+ [Fact]
+ public void TestMDArrayFunctionReading()
+ {
+ MetadataType mdArrayFunctionResolutionType = _testModule.GetType("", "MDArrayFunctionResolution");
+ MethodDesc methodWithMDArrayUsage = mdArrayFunctionResolutionType.GetMethods().Single(m => string.Equals(m.Name, "MethodWithUseOfMDArrayFunctions"));
+ MethodIL methodIL = EcmaMethodIL.Create((EcmaMethod)methodWithMDArrayUsage);
+ ILReader ilReader = new ILReader(methodIL.GetILBytes());
+ int failures = 0;
+ int successes = 0;
+ while (ilReader.HasNext)
+ {
+ ILOpcode opcode = ilReader.ReadILOpcode();
+ switch(opcode)
+ {
+ case ILOpcode.call:
+ case ILOpcode.newobj:
+ int token = ilReader.ReadILToken();
+ object tokenReferenceResult = methodIL.GetObject(token, NotFoundBehavior.ReturnNull);
+ if (tokenReferenceResult == null)
+ {
+ failures++;
+ tokenReferenceResult = "null";
+ }
+ else
+ {
+ successes++;
+ }
+ _output.WriteLine($"call {tokenReferenceResult.ToString()}");
+ break;
+ }
+ }
+
+ Assert.Equal(0, failures);
+ Assert.Equal(4, successes);
+ }
}
}