JIT: properly handle special-case varargs params in minopts (dotnet/coreclr#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 dotnet/coreclr#19349.

Commit migrated from https://github.com/dotnet/coreclr/commit/81c0e509c0e948385268e209db0696f2bbddd575

src/coreclr/src/jit/lclvars.cpp

index 70b6eee..324896b 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)
             {