Initialize gtUseNum before use (#57256)
authorKunal Pathak <Kunal.Pathak@microsoft.com>
Tue, 17 Aug 2021 04:35:39 +0000 (21:35 -0700)
committerGitHub <noreply@github.com>
Tue, 17 Aug 2021 04:35:39 +0000 (21:35 -0700)
* Initialize gtUseNum

* Add test case

* catch the exceptions in test case

* kind of disable test

* try to exclude the test one more time

src/coreclr/jit/compiler.hpp
src/tests/JIT/Regression/JitBlue/Runtime_56953/Runtime_56953.cs [new file with mode: 0644]
src/tests/JIT/Regression/JitBlue/Runtime_56953/Runtime_56953.csproj [new file with mode: 0644]
src/tests/issues.targets

index ca9626e..ed0b094 100644 (file)
@@ -840,6 +840,7 @@ inline GenTree::GenTree(genTreeOps oper, var_types type DEBUGARG(bool largeNode)
 
 #ifdef DEBUG
     gtSeqNum = 0;
+    gtUseNum = -1;
     gtTreeID = JitTls::GetCompiler()->compGenTreeID++;
     gtVNPair.SetBoth(ValueNumStore::NoVN);
     gtRegTag   = GT_REGTAG_NONE;
diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_56953/Runtime_56953.cs b/src/tests/JIT/Regression/JitBlue/Runtime_56953/Runtime_56953.cs
new file mode 100644 (file)
index 0000000..f41e1d5
--- /dev/null
@@ -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;
+public class TestClass13
+{
+    // The test exposed a place where we were using uninitialized `gtUseNum` variable.
+    public struct S1
+    {
+        public byte byte_1;
+    }
+    public struct S2
+    {
+    }
+    public struct S3
+    {
+    }
+    public struct S5
+    {
+        public struct S5_D1_F2
+        {
+            public S1 s1_1;
+            public ushort uint16_2;
+        }
+    }
+    static ushort s_uint16_11 = 19036;
+    static S2 s_s2_15 = new S2();
+    static S3 s_s3_16 = new S3();
+    static S5.S5_D1_F2 s_s5_s5_d1_f2_18 = new S5.S5_D1_F2();
+    static S5 s_s5_19 = new S5();
+    static int s_loopInvariant = 1;
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    public ushort LeafMethod11()
+    {
+        unchecked
+        {
+            return s_s5_s5_d1_f2_18.uint16_2 <<= 15 | 4;
+        }
+    }
+    public S3 Method4(ref S2 p_s2_0, S5.S5_D1_F2 p_s5_s5_d1_f2_1, S5.S5_D1_F2 p_s5_s5_d1_f2_2, ushort p_uint16_3, ref S5 p_s5_4, S5.S5_D1_F2 p_s5_s5_d1_f2_5, short p_int16_6)
+    {
+        unchecked
+        {
+            {
+            }
+            return s_s3_16;
+        }
+    }
+    public void Method0()
+    {
+        unchecked
+        {
+            if ((s_uint16_11 %= s_s5_s5_d1_f2_18.uint16_2 <<= 15 | 4) < 15 + 4 - LeafMethod11())
+            { }
+            else
+            { }
+            { }
+            s_s3_16 = Method4(ref s_s2_15, s_s5_s5_d1_f2_18, s_s5_s5_d1_f2_18, LeafMethod11(), ref s_s5_19, s_s5_s5_d1_f2_18, 11592);
+            return;
+        }
+    }
+    public static int Main(string[] args)
+    {
+        try
+        {
+          TestClass13 objTestClass13 = new TestClass13();
+          objTestClass13.Method0();
+        }
+        catch(Exception)
+        {
+            // ignore exceptions
+        }
+        return 100;
+    }
+}
\ No newline at end of file
diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_56953/Runtime_56953.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_56953/Runtime_56953.csproj
new file mode 100644 (file)
index 0000000..049293e
--- /dev/null
@@ -0,0 +1,22 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+  </PropertyGroup>
+  <PropertyGroup>
+    <DebugType>None</DebugType>
+    <Optimize>True</Optimize>
+  </PropertyGroup>
+   <PropertyGroup>
+    <CLRTestBatchPreCommands><![CDATA[
+$(CLRTestBatchPreCommands)
+set COMPlus_JitOptRepeat=*
+]]></CLRTestBatchPreCommands>
+    <BashCLRTestPreCommands><![CDATA[
+$(BashCLRTestPreCommands)
+export COMPlus_JitOptRepeat=*
+]]></BashCLRTestPreCommands>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="$(MSBuildProjectName).cs" />
+  </ItemGroup>
+</Project>
\ No newline at end of file
index 3712feb..85efa7c 100644 (file)
         <ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/DevDiv_590771/DevDiv_590771/*">
             <Issue>needs triage</Issue>
         </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/Runtime_56953/Runtime_56953/*">
+            <Issue>https://github.com/dotnet/runtime/issues/57515</Issue>
+        </ExcludeList>
     </ItemGroup>
 
     <!-- Windows all architecture excludes -->