Skip to content

Commit 9b0602a

Browse files
Fix dataflow analysis of lambdas in async methods (#122623)
To the same tune as #122450. This is a bug farm, as expected, but likely still better than trying to teach the code that is shared with ILLink and Roslyn analyzer about async variants. Cc @dotnet/ilc-contrib
1 parent 9d5b35d commit 9b0602a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedState.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,10 @@ public bool TryGetUserMethodForCompilerGeneratedMember(TypeSystemEntity sourceMe
737737
if (sourceMember == null)
738738
return false;
739739

740+
Debug.Assert(sourceMember is not MethodDesc sourceMethod || sourceMethod.IsTypicalMethodDefinition);
741+
if (sourceMember is AsyncMethodVariant asyncVariant)
742+
sourceMember = asyncVariant.Target;
743+
740744
TypeSystemEntity member = sourceMember;
741745
MethodDesc? userMethodCandidate;
742746
while (TryGetOwningMethodForCompilerGeneratedMember(member, out userMethodCandidate))

src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/RuntimeAsyncMethods.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Diagnostics.CodeAnalysis;
6+
using System.Reflection;
67
using System.Runtime.CompilerServices;
78
using System.Threading.Tasks;
89
using Mono.Linker.Tests.Cases.Expectations.Assertions;
@@ -28,6 +29,7 @@ public static async Task Main()
2829
await RuntimeAsyncWithCorrectParameter(null);
2930
await RuntimeAsyncWithLocalAll();
3031
await RuntimeAsyncWithLambda();
32+
await RuntimeAsyncWithAwaitedLocalMethod();
3133
}
3234

3335
static async Task BasicRuntimeAsyncMethod()
@@ -116,5 +118,16 @@ static async Task RuntimeAsyncWithLambda()
116118
{
117119
await Task.Run([ExpectedWarning("IL2026", nameof(TypeWithRucMethod.RucMethod))] () => typeof(TypeWithRucMethod).GetMethods());
118120
}
121+
122+
static async Task RuntimeAsyncWithAwaitedLocalMethod()
123+
{
124+
await GetTheMethods();
125+
126+
[ExpectedWarning("IL2026", nameof(TypeWithRucMethod.RucMethod))]
127+
static async Task<MethodInfo[]> GetTheMethods()
128+
{
129+
return typeof(TypeWithRucMethod).GetMethods();
130+
}
131+
}
119132
}
120133
}

0 commit comments

Comments
 (0)