JIT: properly handle special-case varargs params in minopts (#19489)
authorAndy Ayers <andya@microsoft.com>
Thu, 16 Aug 2018 00:05:28 +0000 (17:05 -0700)
committerGitHub <noreply@github.com>
Thu, 16 Aug 2018 00:05:28 +0000 (17:05 -0700)
We were previously marking all lcl vars as implicitly referenced in minopts,
but there are some special varargs params that can't ever be marked as
referenced, either implicitly or explicitly.

Special case these when computing or checking ref counts in minopts.

Closes #19349.

src/jit/lclvars.cpp

index 70b6eee46c472bb50126fadf8c8b0497a9afa96a..324896b1adbdda1f70be166e48cc3be8e7825ab1 100644 (file)
@@ -4100,7 +4100,16 @@ void Compiler::lvaComputeRefCounts(bool isRecompute, bool setSlotNumbers)
             // to do something else to ensure late temps are considered.
             for (lclNum = 0, varDsc = lvaTable; lclNum < lvaCount; lclNum++, varDsc++)
             {
-                assert(varDsc->lvImplicitlyReferenced);
+                const bool isSpecialVarargsParam = varDsc->lvIsParam && raIsVarargsStackArg(lclNum);
+
+                if (isSpecialVarargsParam)
+                {
+                    assert(varDsc->lvRefCnt() == 0);
+                }
+                else
+                {
+                    assert(varDsc->lvImplicitlyReferenced);
+                }
             }
 #endif // defined (DEBUG)
 
@@ -4118,8 +4127,17 @@ void Compiler::lvaComputeRefCounts(bool isRecompute, bool setSlotNumbers)
             // unreferenced later, we'll have to explicitly clear this bit.
             varDsc->setLvRefCnt(0);
             varDsc->setLvRefCntWtd(0);
-            varDsc->lvImplicitlyReferenced = 1;
-            varDsc->lvTracked              = 0;
+
+            // Special case for some varargs params ... these must
+            // remain unreferenced.
+            const bool isSpecialVarargsParam = varDsc->lvIsParam && raIsVarargsStackArg(lclNum);
+
+            if (!isSpecialVarargsParam)
+            {
+                varDsc->lvImplicitlyReferenced = 1;
+            }
+
+            varDsc->lvTracked = 0;
 
             if (setSlotNumbers)
             {