diff --git a/src/jit/compiler.hpp b/src/jit/compiler.hpp index 545f311ab35e..c1b050cc4f00 100644 --- a/src/jit/compiler.hpp +++ b/src/jit/compiler.hpp @@ -1682,13 +1682,22 @@ inline unsigned Compiler::lvaGrabTemp(bool shortLifetime DEBUGARG(const char* re lvaTable = newLvaTable; } - lvaTable[lvaCount].lvType = TYP_UNDEF; // Initialize lvType, lvIsTemp and lvOnFrame - lvaTable[lvaCount].lvIsTemp = shortLifetime; - lvaTable[lvaCount].lvOnFrame = true; + const unsigned tempNum = lvaCount; + lvaCount++; - unsigned tempNum = lvaCount; + lvaTable[tempNum].lvType = TYP_UNDEF; // Initialize lvType, lvIsTemp and lvOnFrame + lvaTable[tempNum].lvIsTemp = shortLifetime; + lvaTable[tempNum].lvOnFrame = true; - lvaCount++; + // If we've started normal ref counting and are in minopts or debug + // mark this variable as implictly referenced. + if (lvaLocalVarRefCounted()) + { + if (opts.MinOpts() || opts.compDbgCode) + { + lvaTable[tempNum].lvImplicitlyReferenced = 1; + } + } #ifdef DEBUG if (verbose)