summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Regression/JitBlue/Runtime_1241/Runtime_1241.cs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/JIT/Regression/JitBlue/Runtime_1241/Runtime_1241.cs')
-rw-r--r--tests/src/JIT/Regression/JitBlue/Runtime_1241/Runtime_1241.cs95
1 files changed, 95 insertions, 0 deletions
diff --git a/tests/src/JIT/Regression/JitBlue/Runtime_1241/Runtime_1241.cs b/tests/src/JIT/Regression/JitBlue/Runtime_1241/Runtime_1241.cs
new file mode 100644
index 0000000000..02c21ce5eb
--- /dev/null
+++ b/tests/src/JIT/Regression/JitBlue/Runtime_1241/Runtime_1241.cs
@@ -0,0 +1,95 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Linq;
+using System.Numerics;
+using System.Runtime.CompilerServices;
+
+namespace Runtime_1241
+{
+
+ public struct Vertex
+ {
+ public Vector3 Position;
+ public Vector2 TexCoords;
+
+ public Vertex(Vector3 pos, Vector2 tex)
+ {
+ Position = pos;
+ TexCoords = tex;
+ }
+ }
+
+ class Program
+ {
+ static int Main()
+ {
+ int returnVal = 100;
+
+ // This prints all zeros in the failure case.
+ Console.WriteLine("Replacing array element with new struct directly");
+ {
+ var bug = Bug.Create();
+ bug.MutateBroken();
+
+ Console.WriteLine(bug.Vertices[0].Position);
+ if ((bug.Vertices[0].Position.X != 1) || (bug.Vertices[0].Position.Y != 1) || (bug.Vertices[0].Position.Z != 1))
+ {
+ returnVal = -1;
+ }
+ }
+
+ // Works
+ Console.WriteLine("Replacing array element with new struct, stored in a local variable first");
+ {
+ var bug = Bug.Create();
+ bug.MutateWorks();
+
+ Console.WriteLine(bug.Vertices[0].Position);
+ if ((bug.Vertices[0].Position.X != 1) || (bug.Vertices[0].Position.Y != 1) || (bug.Vertices[0].Position.Z != 1))
+ {
+ returnVal = -1;
+ }
+ }
+
+ return returnVal;
+ }
+ }
+
+ public class Bug
+ {
+ public static Bug Create()
+ {
+ return new Bug
+ {
+ Vertices = Enumerable.Range(1, 100).Select(i => new Vertex(new Vector3(i), Vector2.One)).ToArray()
+ };
+ }
+
+ public Vertex[] Vertices { get; set; }
+
+ public void MutateBroken()
+ {
+ for (var i = 0; i < Vertices.Length; i++)
+ {
+ var vert = Vertices[i];
+
+ Vertices[i] = new Vertex(vert.Position, vert.TexCoords);
+ }
+ }
+
+ public void MutateWorks()
+ {
+ for (var i = 0; i < Vertices.Length; i++)
+ {
+ var vert = Vertices[i];
+
+ var newVert = new Vertex(vert.Position, vert.TexCoords);
+
+ Vertices[i] = newVert;
+ }
+ }
+ }
+}