From 9cc6ffdf2f911c53fee3b4ff73b06af65ee41971 Mon Sep 17 00:00:00 2001 From: Bruce Forstall Date: Thu, 8 Jul 2021 14:57:44 -0700 Subject: [PATCH] Fix lifetime1 test The test assumed that a GC didn't occur between the last use of a variable and a check of a value set in the finalizer. This presumably worked up until now because the test is set to build in debuggable code mode. But R2R compilations ignore that and build with optimization enabled, and GCStress exposes the issue. Fix the test by explicitly marking a variable as KeepAlive until after the requisite check. Fixes #54042 --- src/tests/JIT/Directed/lifetime/lifetime1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/JIT/Directed/lifetime/lifetime1.cs b/src/tests/JIT/Directed/lifetime/lifetime1.cs index 02834ffc99a2d..c463fa38a297a 100644 --- a/src/tests/JIT/Directed/lifetime/lifetime1.cs +++ b/src/tests/JIT/Directed/lifetime/lifetime1.cs @@ -53,7 +53,6 @@ public static int f2() { A a = new A(); a.F(); - a = null; // Testcase 3 Console.WriteLine(); @@ -63,6 +62,7 @@ public static int f2() Console.WriteLine("Testcase 3 FAILED"); return -1; } + GC.KeepAlive(a); return 100; }