Skip to content

Commit

Permalink
ILVerify: Handle readonly references in ldfld (#64077)
Browse files Browse the repository at this point in the history
* ILVerify: Handle readonly references in ldfld

Fixes #63953

* Fix test name

Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
  • Loading branch information
jkotas and MichalStrehovsky committed Jan 21, 2022
1 parent 0240828 commit 9c8b804
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/coreclr/tools/ILVerification/ILImporter.Verify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 13 additions & 0 deletions src/tests/ilverify/ILTests/ValueTypeTests.il
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 9c8b804

Please sign in to comment.