Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5244,7 +5244,23 @@ void Compiler::generatePatchpointInfo()
// but would need to adjust all consumers, too.
for (unsigned lclNum = 0; lclNum < info.compLocalsCount; lclNum++)
{
LclVarDsc* const varDsc = lvaGetDesc(lclNum);
// If there are shadowed params, the patchpoint info should refer to the shadow copy.
//
unsigned varNum = lclNum;

if (gsShadowVarInfo != nullptr)
{
unsigned const shadowNum = gsShadowVarInfo[lclNum].shadowCopy;
if (shadowNum != BAD_VAR_NUM)
{
assert(shadowNum < lvaCount);
assert(shadowNum >= info.compLocalsCount);

varNum = shadowNum;
}
}

LclVarDsc* const varDsc = lvaGetDesc(varNum);

// We expect all these to have stack homes, and be FP relative
assert(varDsc->lvOnFrame);
Expand All @@ -5260,8 +5276,8 @@ void Compiler::generatePatchpointInfo()
patchpointInfo->SetIsExposed(lclNum);
}

JITDUMP("--OSR-- V%02u is at virtual offset %d%s\n", lclNum, patchpointInfo->Offset(lclNum),
patchpointInfo->IsExposed(lclNum) ? " (exposed)" : "");
JITDUMP("--OSR-- V%02u is at virtual offset %d%s%s\n", lclNum, patchpointInfo->Offset(lclNum),
patchpointInfo->IsExposed(lclNum) ? " (exposed)" : "", (varNum != lclNum) ? " (shadowed)" : "");
}

// Special offsets
Expand Down
44 changes: 44 additions & 0 deletions src/tests/JIT/opt/OSR/shadowparam.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;

// F is an OSR method with parameter shadowing

public unsafe struct ShadowParam
{
public int a;
public fixed int data[2];
public int b;

[MethodImpl(MethodImplOptions.NoInlining)]
public static int F(int x, string sa, ShadowParam u, string sb, int a, int b, int y)
{
for (int i = 0; i < a + b; i++)
{
x += u.data[0];
}

for (int i = 0; i < a + b; i++)
{
y += u.data[1];
}

return x + y + u.a + u.b + sb.Length - sa.Length;
}

public static int Main()
{
var u = new ShadowParam();
u.data[0] = 1;
u.data[1] = -1;
u.a = 3;
u.b = -3;

int r = F(0, "a", u, "b", 100_001, -1, 100);
Console.WriteLine($"Result is {r}");
return r;
}
}

11 changes: 11 additions & 0 deletions src/tests/JIT/opt/OSR/shadowparam.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<DebugType />
<Optimize>True</Optimize>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>