From 7a76f99d740dca7aa7d4b5f6eb3c2b76dfd27c8b Mon Sep 17 00:00:00 2001 From: Sergey Andreenko Date: Thu, 7 Mar 2019 19:43:37 -0800 Subject: [PATCH] Fix a rare JitStress assert. (dotnet/coreclr#23116) * 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 | 12 +++++++++--- src/coreclr/src/jit/compiler.h | 4 ++-- src/coreclr/src/jit/ee_il_dll.cpp | 2 +- src/coreclr/src/jit/jit.h | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/coreclr/src/jit/compiler.cpp b/src/coreclr/src/jit/compiler.cpp index cef3083..4892188 100644 --- a/src/coreclr/src/jit/compiler.cpp +++ b/src/coreclr/src/jit/compiler.cpp @@ -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; } diff --git a/src/coreclr/src/jit/compiler.h b/src/coreclr/src/jit/compiler.h index e39c44f..e390fd5 100644 --- a/src/coreclr/src/jit/compiler.h +++ b/src/coreclr/src/jit/compiler.h @@ -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); diff --git a/src/coreclr/src/jit/ee_il_dll.cpp b/src/coreclr/src/jit/ee_il_dll.cpp index 8b2f29e..410ef6c 100644 --- a/src/coreclr/src/jit/ee_il_dll.cpp +++ b/src/coreclr/src/jit/ee_il_dll.cpp @@ -270,7 +270,7 @@ void JitTls::SetCompiler(Compiler* compiler) reinterpret_cast(GetJitTls())->m_compiler = compiler; } -#else // defined(DEBUG) +#else // !defined(DEBUG) JitTls::JitTls(ICorJitInfo* jitInfo) { diff --git a/src/coreclr/src/jit/jit.h b/src/coreclr/src/jit/jit.h index 5cdb1fd..5157d66 100644 --- a/src/coreclr/src/jit/jit.h +++ b/src/coreclr/src/jit/jit.h @@ -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; -- 2.7.4