-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/tests/JIT/opt/ValueNumbering/StaticReadonlyStructWithGC.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// 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; | ||
|
||
class StaticReadonlyStructWithGC | ||
{ | ||
static int Main() | ||
{ | ||
for (int i = 0; i < 100; i++) | ||
{ | ||
if (!Test1()) throw new Exception("Test1 failed"); | ||
if (!Test2()) throw new Exception("Test2 failed"); | ||
if (!Test3()) throw new Exception("Test3 failed"); | ||
if (!Test4()) throw new Exception("Test4 failed"); | ||
if (!Test5()) throw new Exception("Test5 failed"); | ||
if (!Test6()) throw new Exception("Test6 failed"); | ||
if (!Test7()) throw new Exception("Test7 failed"); | ||
if (!Test8()) throw new Exception("Test8 failed"); | ||
if (!Test9()) throw new Exception("Test9 failed"); | ||
|
||
GC.Collect(); | ||
GC.WaitForPendingFinalizers(); | ||
GC.Collect(); | ||
Thread.Sleep(16); | ||
} | ||
return 100; | ||
} | ||
|
||
static readonly MyStruct MyStructFld = new() | ||
{ | ||
A = "A", | ||
B = 111111.ToString(), // non-literal | ||
C = new MyStruct2 { A = "AA" }, | ||
D = typeof(int), | ||
E = () => 42, | ||
F = new MyStruct3 { A = typeof(double), B = typeof(string) }, | ||
G = new int[0], | ||
H = null | ||
}; | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test1() => MyStructFld.A == "A"; | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test2() => MyStructFld.B == "111111"; | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test3() => MyStructFld.C.A == "AA"; | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test4() => MyStructFld.D == typeof(int); | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test5() => MyStructFld.E() == 42; | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test6() => MyStructFld.F.A == typeof(double); | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test7() => MyStructFld.F.B == typeof(string); | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test8() => MyStructFld.G.Length == 0; | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test9() => MyStructFld.H == null; | ||
|
||
struct MyStruct | ||
{ | ||
public string A; | ||
public string B; | ||
public MyStruct2 C; | ||
public Type D; | ||
public Func<int> E; | ||
public MyStruct3 F; | ||
public int[] G; | ||
public object H; | ||
} | ||
|
||
struct MyStruct2 | ||
{ | ||
public string A; | ||
} | ||
|
||
struct MyStruct3 | ||
{ | ||
public Type A; | ||
public Type B; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/tests/JIT/opt/ValueNumbering/StaticReadonlyStructWithGC.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |