diff options
author | Michael Mayr <mayr_michael@gmx.at> | 2017-07-03 17:24:37 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2017-07-03 17:24:37 +0300 |
commit | a8531bb64e6634a4b645ee0ca60b30a93067d293 (patch) | |
tree | 5f9e48e6fc8e8e59a0e5e7288b671bf8afc9711d /src/ILVerify | |
parent | 477ca0d52ca39635075b206542b10749d0cac727 (diff) |
[ILVerify]Convert _thisType to managed pointer, if it is a value type (#4055)
Diffstat (limited to 'src/ILVerify')
-rw-r--r-- | src/ILVerify/src/ILImporter.Verify.cs | 30 | ||||
-rw-r--r-- | src/ILVerify/tests/ILTests/ValueTypeTests.il | 29 |
2 files changed, 49 insertions, 10 deletions
diff --git a/src/ILVerify/src/ILImporter.Verify.cs b/src/ILVerify/src/ILImporter.Verify.cs index 30cf77cca..6d15215b1 100644 --- a/src/ILVerify/src/ILImporter.Verify.cs +++ b/src/ILVerify/src/ILImporter.Verify.cs @@ -38,18 +38,18 @@ namespace Internal.IL partial class ILImporter { - MethodDesc _method; - MethodSignature _methodSignature; - TypeSystemContext _typeSystemContext; + readonly MethodDesc _method; + readonly MethodSignature _methodSignature; + readonly TypeSystemContext _typeSystemContext; - TypeDesc _thisType; + readonly TypeDesc _thisType; - MethodIL _methodIL; - byte[] _ilBytes; - LocalVariableDefinition[] _locals; + readonly MethodIL _methodIL; + readonly byte[] _ilBytes; + readonly LocalVariableDefinition[] _locals; - bool _initLocals; - int _maxStack; + readonly bool _initLocals; + readonly int _maxStack; bool[] _instructionBoundaries; // For IL verification @@ -123,7 +123,17 @@ namespace Internal.IL _typeSystemContext = method.Context; if (!_methodSignature.IsStatic) - _thisType = method.OwningType.InstantiateAsOpen(); + { + var thisType = method.OwningType.InstantiateAsOpen(); + + // ECMA-335 II.13.3 Methods of value types, P. 164: + // ... By contrast, instance and virtual methods of value types shall be coded to expect a + // managed pointer(see Partition I) to an unboxed instance of the value type. ... + if (thisType.IsValueType) + thisType = thisType.MakeByRefType(); + + _thisType = thisType; + } _methodIL = methodIL; diff --git a/src/ILVerify/tests/ILTests/ValueTypeTests.il b/src/ILVerify/tests/ILTests/ValueTypeTests.il new file mode 100644 index 000000000..c5ea61af0 --- /dev/null +++ b/src/ILVerify/tests/ILTests/ValueTypeTests.il @@ -0,0 +1,29 @@ +// 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. + +.assembly extern System.Runtime +{ +} + +.assembly ValueType +{ +} + +.class public sequential ansi sealed beforefieldinit ValueTypeTests + extends [System.Runtime]System.ValueType +{ + .size 1 + .method public instance void CallThis() cil managed + { + ret + } + + .method public instance void ValueType.CallMethod_Valid() cil managed + { + ldarg.0 + call instance void ValueTypeTests::CallThis() + ret + } +} + |