From ffc9de03302c2170af3790d6141ed38283228e62 Mon Sep 17 00:00:00 2001 From: Carol Eidt Date: Fri, 14 Aug 2020 14:17:00 -0700 Subject: [PATCH] Fix GC liveness check in ByRefLocals test Fix #40751 --- .../ByRefLocals/ByRefLocals.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/tests/Loader/CollectibleAssemblies/ByRefLocals/ByRefLocals.cs b/src/tests/Loader/CollectibleAssemblies/ByRefLocals/ByRefLocals.cs index fb2bd10771824..bad11ae9f9cf7 100644 --- a/src/tests/Loader/CollectibleAssemblies/ByRefLocals/ByRefLocals.cs +++ b/src/tests/Loader/CollectibleAssemblies/ByRefLocals/ByRefLocals.cs @@ -54,13 +54,17 @@ static int HoldAssembliesAliveThroughByRefFields(out GCHandle gch1, out GCHandle Console.WriteLine(span2[0]); GC.Collect(2); GC.WaitForPendingFinalizers(); - if (gch1.Target == null) + // The loop may be unrolled, in which case things won't be live on the final iteration. + if (i < 9) { - return 1; - } - if (gch2.Target == null) - { - return 2; + if (gch1.Target == null) + { + return 1; + } + if (gch2.Target == null) + { + return 2; + } } } @@ -110,4 +114,4 @@ private static ReadOnlySpan CreateAssemblyDynamically(out GCHandle gchToAs return spanAccessor.GetSpan(); } -} \ No newline at end of file +}