Fix and Test case for #27924 (#1059)
authorCarol Eidt <carol.eidt@microsoft.com>
Fri, 10 Jan 2020 17:09:00 +0000 (09:09 -0800)
committerGitHub <noreply@github.com>
Fri, 10 Jan 2020 17:09:00 +0000 (09:09 -0800)
Fix and Test case for #27924

src/coreclr/src/jit/codegenxarch.cpp
src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_27924/GitHub_27924.cs [new file with mode: 0644]
src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_27924/GitHub_27924.csproj [new file with mode: 0644]

index 66bc4fe..ef37c0d 100644 (file)
@@ -954,9 +954,10 @@ void CodeGen::genCodeForBinary(GenTreeOp* treeNode)
     // reg3 = reg3 op reg2
     else
     {
-        inst_RV_RV(ins_Copy(targetType), targetReg, op1reg, targetType);
+        var_types op1Type = op1->TypeGet();
+        inst_RV_RV(ins_Copy(op1Type), targetReg, op1reg, op1Type);
         regSet.verifyRegUsed(targetReg);
-        gcInfo.gcMarkRegPtrVal(targetReg, targetType);
+        gcInfo.gcMarkRegPtrVal(targetReg, op1Type);
         dst = treeNode;
         src = op2;
     }
diff --git a/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_27924/GitHub_27924.cs b/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_27924/GitHub_27924.cs
new file mode 100644 (file)
index 0000000..c4b8cf5
--- /dev/null
@@ -0,0 +1,53 @@
+// 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.Threading;
+using System.Runtime.CompilerServices;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+class Program
+{
+    static int returnVal = 100;
+    static byte[][] s = new byte[1000][];
+
+    static void Work()
+    {
+        for (uint i = 0; i < 1000000; i++)
+        {
+            var a = s[i++ % s.Length];
+
+            ref byte p = ref a[0];
+            ref byte q = ref a[1];
+
+            if (Unsafe.ByteOffset(ref p, ref q) != new IntPtr(1))
+            {
+                Console.WriteLine("ERROR: i = " + i);
+                returnVal = -1;
+            }
+            p = 1; q = 2;
+        }
+    }
+
+    static int Main(string[] args)
+    {
+        for(int i = 0; i < s.Length; i++) s[i] = new byte[2];
+
+        List<Task> tasks = new List<Task>();
+        for(int i = 0; i < 5; i++)
+        {
+            tasks.Add(Task.Run(Work));
+        }
+
+        Random r = new Random();
+        for (uint i = 0; i < 10000; i++)
+        {
+            s[r.Next(s.Length)] = new byte[3 + r.Next(100)];
+        }
+        Task t = Task.WhenAll(tasks);
+        t.Wait();
+        return returnVal;
+    }
+}
diff --git a/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_27924/GitHub_27924.csproj b/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_27924/GitHub_27924.csproj
new file mode 100644 (file)
index 0000000..f4f4f47
--- /dev/null
@@ -0,0 +1,23 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <CLRTestPriority>0</CLRTestPriority>
+  </PropertyGroup>
+  <PropertyGroup>
+    <DebugType>None</DebugType>
+    <Optimize>True</Optimize>
+  </PropertyGroup>
+  <PropertyGroup>
+    <CLRTestBatchPreCommands><![CDATA[
+$(CLRTestBatchPreCommands)
+set COMPlus_GcStress=0xc
+]]></CLRTestBatchPreCommands>
+    <BashCLRTestPreCommands><![CDATA[
+$(BashCLRTestPreCommands)
+export COMPlus_GcStress=0xc
+]]></BashCLRTestPreCommands>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="$(MSBuildProjectName).cs" />
+  </ItemGroup>
+</Project>