diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index 4badae442d9051..7db020168b0abb 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -1098,9 +1098,10 @@ var_types Compiler::impImportCall(OPCODE opcode, } // For opportunistic tailcalls we allow implicit widening, i.e. tailcalls from int32 -> int16, since the - // managed calling convention dictates that the callee widens the value. For explicit tailcalls we don't - // want to require this detail of the calling convention to bubble up to the tailcall helpers - bool allowWidening = isImplicitTailCall; + // managed calling convention dictates that the callee widens the value. For explicit tailcalls or async + // functions we don't want to require this detail of the calling convention to bubble up to helper + // infrastructure. + bool allowWidening = isImplicitTailCall && !call->AsCall()->IsAsync(); if (canTailCall && !impTailCallRetTypeCompatible(allowWidening, info.compRetType, info.compMethodInfo->args.retTypeClass, info.compCallConv, callRetTyp, sig->retTypeClass, diff --git a/src/tests/async/synchronization-context/synchronization-context.cs b/src/tests/async/synchronization-context/synchronization-context.cs index d1b053cd7ebf0a..3e3a3cd70d38d6 100644 --- a/src/tests/async/synchronization-context/synchronization-context.cs +++ b/src/tests/async/synchronization-context/synchronization-context.cs @@ -45,9 +45,9 @@ private static async Task TestSyncContextContinueAsync() // we check IsCompleted on the awaiter). //await WrappedYieldToThreadPool(suspend: true).ConfigureAwait(false); //Assert.Null(SynchronizationContext.Current); - - await WrappedYieldToThreadWithCustomSyncContext(); - Assert.Null(SynchronizationContext.Current); + // + //await WrappedYieldToThreadWithCustomSyncContext(); + //Assert.Null(SynchronizationContext.Current); } private static async Task WrappedYieldToThreadPool(bool suspend) diff --git a/src/tests/async/widening-tailcall/widening-tailcall.cs b/src/tests/async/widening-tailcall/widening-tailcall.cs new file mode 100644 index 00000000000000..1d3cfafc500587 --- /dev/null +++ b/src/tests/async/widening-tailcall/widening-tailcall.cs @@ -0,0 +1,29 @@ +// 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; +using System.Threading.Tasks; +using Xunit; + +public class Async2WideningTailcall +{ + [Fact] + public static void TestEntryPoint() + { + uint vr0 = (uint)M29().GetAwaiter().GetResult(); + Assert.Equal(uint.MaxValue, vr0); + } + + private static async Task M29() + { + return await M40(); + } + + private static sbyte s_38 = -1; + private static async Task M40() + { + await Task.Yield(); + return s_38; + } +} diff --git a/src/tests/async/widening-tailcall/widening-tailcall.csproj b/src/tests/async/widening-tailcall/widening-tailcall.csproj new file mode 100644 index 00000000000000..de6d5e08882e86 --- /dev/null +++ b/src/tests/async/widening-tailcall/widening-tailcall.csproj @@ -0,0 +1,8 @@ + + + True + + + + +