From 9c8b804099ce79f44733c23d4fc59801ab03f86d Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 21 Jan 2022 08:22:51 -0800 Subject: [PATCH] ILVerify: Handle readonly references in ldfld (#64077) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ILVerify: Handle readonly references in ldfld Fixes #63953 * Fix test name Co-authored-by: Michal Strehovský --- .../tools/ILVerification/ILImporter.Verify.cs | 2 +- src/tests/ilverify/ILTests/ValueTypeTests.il | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/coreclr/tools/ILVerification/ILImporter.Verify.cs b/src/coreclr/tools/ILVerification/ILImporter.Verify.cs index d1b3d10ed5a3f..258a005ffdd09 100644 --- a/src/coreclr/tools/ILVerification/ILImporter.Verify.cs +++ b/src/coreclr/tools/ILVerification/ILImporter.Verify.cs @@ -2060,7 +2060,7 @@ void ImportLoadField(int token, bool isStatic) actualThis = StackValue.CreateByRef(actualThis.Type); var declaredThis = owningType.IsValueType ? - StackValue.CreateByRef(owningType) : StackValue.CreateObjRef(owningType); + StackValue.CreateByRef(owningType, readOnly : true) : StackValue.CreateObjRef(owningType); CheckIsAssignable(actualThis, declaredThis); diff --git a/src/tests/ilverify/ILTests/ValueTypeTests.il b/src/tests/ilverify/ILTests/ValueTypeTests.il index a52cb76522464..8eb3aac002de8 100644 --- a/src/tests/ilverify/ILTests/ValueTypeTests.il +++ b/src/tests/ilverify/ILTests/ValueTypeTests.il @@ -26,3 +26,16 @@ } } +.class public sequential ansi sealed beforefieldinit ValueTypeFieldTests + extends [System.Runtime]System.ValueType +{ + .field public int32 InstanceField + + .method public static int32 ValueType.UnboxLdfld_Valid(object o) cil managed + { + ldarg.0 + unbox ValueTypeFieldTests + ldfld int32 ValueTypeFieldTests::InstanceField + ret + } +}