Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,18 @@ public override MethodIL EmitIL()

foreach (var param in _targetMethod.Signature)
{
var local = ilEmitter.NewLocal(param);
ilStream.EmitLdLoca(local);
ilStream.Emit(ILOpcode.initobj, ilEmitter.NewToken(param));
ilStream.EmitLdLoc(local);
if (param.IsByRef)
{
ilStream.EmitLdc(0);
ilStream.Emit(ILOpcode.conv_u);
}
else
{
var local = ilEmitter.NewLocal(param);
ilStream.EmitLdLoca(local);
ilStream.Emit(ILOpcode.initobj, ilEmitter.NewToken(param));
ilStream.EmitLdLoc(local);
}
}

ilStream.Emit(ILOpcode.call, ilEmitter.NewToken(_targetMethod));
Expand Down
16 changes: 12 additions & 4 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15092,10 +15092,18 @@ CORINFO_METHOD_HANDLE CEEJitInfo::getAsyncResumptionStub(void** entryPoint)
while ((ty = msig.NextArg()) != ELEMENT_TYPE_END)
{
TypeHandle tyHnd = msig.GetLastTypeHandleThrowing();
DWORD loc = pCode->NewLocal(LocalDesc(tyHnd));
pCode->EmitLDLOCA(loc);
pCode->EmitINITOBJ(pCode->GetToken(tyHnd));
pCode->EmitLDLOC(loc);
if (tyHnd.IsByRef())
{
pCode->EmitLDC(0);
pCode->EmitCONV_U();
}
else
{
DWORD loc = pCode->NewLocal(LocalDesc(tyHnd));
pCode->EmitLDLOCA(loc);
pCode->EmitINITOBJ(pCode->GetToken(tyHnd));
pCode->EmitLDLOC(loc);
}
numArgs++;
}

Expand Down
26 changes: 25 additions & 1 deletion src/tests/async/byref-param/byref-param.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Xunit;

public class Async2ByrefParam
{
[Fact]
public static int TestEntryPoint()
public static int TestByrefParam()
{
return Test().GetAwaiter().GetResult();
}
Expand All @@ -22,4 +23,27 @@ private static Task<int> HasByrefParam(out int foo)
foo = 47;
return Task.FromResult(53);
}

[Fact]
public static int TestByrefParamWithSuspension()
{
return TestWithSuspension().GetAwaiter().GetResult();
}

private static async Task<int> TestWithSuspension()
{
await Verify(new string('a', 100), out int val);
return val;
}

// NoInlining ensures a suspension point in Verify
// (otherwise this would just tail-await)
[MethodImpl(MethodImplOptions.NoInlining)]
private static Task Verify(string source, out int length)
{
length = source.Length;
return DoAsync();
}

private static async Task DoAsync() => await Task.Yield();
}
Loading