Skip to content

Commit a0bbf47

Browse files
Copilotjkotas
andauthored
Refine ILVerify permanent-home tracking for returns
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
1 parent 586109a commit a0bbf47

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/coreclr/tools/ILVerification.Tests/ILTests/ReturnTests.il

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@
127127
ret
128128
}
129129

130+
.method public hidebysig instance int32& Return.ByRefArg_Valid(int32& i) cil managed
131+
{
132+
ldarg.1
133+
ret
134+
}
135+
136+
.method public hidebysig instance int32& Return.ByRefLocal_Invalid_ReturnPtrToStack(int32 i) cil managed
137+
{
138+
.locals init (
139+
[0] int32&
140+
)
141+
ldarga.s i
142+
stloc.0
143+
ldloc.0
144+
ret
145+
}
146+
130147
.method public hidebysig instance int32& Return.InstanceFieldByRef_Valid(int32 i) cil managed
131148
{
132149
ldarg.0

src/coreclr/tools/ILVerification/ILImporter.Verify.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,8 @@ void ImportLoadVar(int index, bool argument)
14591459
CheckIsNotPointer(varType);
14601460

14611461
var stackValue = StackValue.CreateFromType(varType);
1462-
stackValue.SetIsPermanentHome();
1462+
if (varType.IsByRefLike || (argument && varType.IsByRef))
1463+
stackValue.SetIsPermanentHome();
14631464
if (index == 0 && argument && _thisType != null)
14641465
{
14651466
Debug.Assert(varType == _thisType);

0 commit comments

Comments
 (0)