Fix a rare JitStress assert. (dotnet/coreclr#23116)
authorSergey Andreenko <seandree@microsoft.com>
Fri, 8 Mar 2019 03:43:37 +0000 (19:43 -0800)
committerGitHub <noreply@github.com>
Fri, 8 Mar 2019 03:43:37 +0000 (19:43 -0800)
* Fix undefined behaviour when we check `this==nullptr`.

* Fix ifdef comment.

* Fix rare jit stress assert.

flowgraph.cpp: !IsUninitialized(tree) can fail if `UninitializedWord` returns a valid pointer value.

Commit migrated from https://github.com/dotnet/coreclr/commit/24d05f5e6cb905da8d2bf84d0b1525586152c908

src/coreclr/src/jit/compiler.cpp
src/coreclr/src/jit/compiler.h
src/coreclr/src/jit/ee_il_dll.cpp
src/coreclr/src/jit/jit.h

index cef3083..4892188 100644 (file)
@@ -2135,14 +2135,15 @@ void Compiler::compDoComponentUnitTestsOnce()
 //    Note that we can't use small values like zero, because we have some
 //    asserts that can fire for such values.
 //
-unsigned char Compiler::compGetJitDefaultFill()
+// static
+unsigned char Compiler::compGetJitDefaultFill(Compiler* comp)
 {
     unsigned char defaultFill = (unsigned char)JitConfig.JitDefaultFill();
 
-    if ((this != nullptr) && (compStressCompile(STRESS_GENERIC_VARN, 50)))
+    if (comp != nullptr && comp->compStressCompile(STRESS_GENERIC_VARN, 50))
     {
         unsigned temp;
-        temp = info.compMethodHash();
+        temp = comp->info.compMethodHash();
         temp = (temp >> 16) ^ temp;
         temp = (temp >> 8) ^ temp;
         temp = temp & 0xff;
@@ -2153,6 +2154,11 @@ unsigned char Compiler::compGetJitDefaultFill()
         {
             temp |= 0x80;
         }
+
+        // Make a misaligned pointer value to reduce probability of getting a valid value and firing
+        // assert(!IsUninitialized(pointer)).
+        temp |= 0x1;
+
         defaultFill = (unsigned char)temp;
     }
 
index e39c44f..e390fd5 100644 (file)
@@ -8851,8 +8851,8 @@ public:
     bool compDonotInline();
 
 #ifdef DEBUG
-    unsigned char compGetJitDefaultFill(); // Get the default fill char value
-                                           // we randomize this value when JitStress is enabled
+    // Get the default fill char value we randomize this value when JitStress is enabled.
+    static unsigned char compGetJitDefaultFill(Compiler* comp);
 
     const char* compLocalVarName(unsigned varNum, unsigned offs);
     VarName compVarName(regNumber reg, bool isFloatReg = false);
index 8b2f29e..410ef6c 100644 (file)
@@ -270,7 +270,7 @@ void JitTls::SetCompiler(Compiler* compiler)
     reinterpret_cast<JitTls*>(GetJitTls())->m_compiler = compiler;
 }
 
-#else // defined(DEBUG)
+#else // !defined(DEBUG)
 
 JitTls::JitTls(ICorJitInfo* jitInfo)
 {
index 5cdb1fd..5157d66 100644 (file)
@@ -867,7 +867,7 @@ inline T UninitializedWord(Compiler* comp)
     {
         comp = JitTls::GetCompiler();
     }
-    defaultFill = comp->compGetJitDefaultFill();
+    defaultFill = Compiler::compGetJitDefaultFill(comp);
     assert(defaultFill <= 0xff);
     __int64 word = 0x0101010101010101LL * defaultFill;
     return (T)word;