Skip to content

Commit

Permalink
Fix lifetime1 test (#55371)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BruceForstall authored Jul 9, 2021
1 parent b814a97 commit d5aa75c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/tests/JIT/Directed/lifetime/lifetime1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public static int f2()
{
A a = new A();
a.F();
a = null;

// Testcase 3
Console.WriteLine();
Expand All @@ -63,6 +62,7 @@ public static int f2()
Console.WriteLine("Testcase 3 FAILED");
return -1;
}
GC.KeepAlive(a);
return 100;
}

Expand Down

0 comments on commit d5aa75c

Please sign in to comment.