Fixes Issue 42787 (#43077)
authorBrian Sullivan <briansul@microsoft.com>
Thu, 8 Oct 2020 04:31:39 +0000 (21:31 -0700)
committerGitHub <noreply@github.com>
Thu, 8 Oct 2020 04:31:39 +0000 (21:31 -0700)
* Fixes Issue 42787

The GS COOKIE phase can create a new Basic Block and this will later cause an assert failure:
Assertion failed 'topBB->bbNum <= botBB->bbNum'
Previously this was hidden by an unconditional call to fgRenumberBlocks() which was removed in PR 42664

* Add a call to fgRenumberBlocks in the morphGlobalPhase when it creates new basic blocks

src/coreclr/src/jit/compiler.cpp

index 2278404..130eb9f 100644 (file)
@@ -4600,6 +4600,7 @@ void Compiler::compCompile(void** methodCodePtr, ULONG* methodCodeSize, JitFlags
     // Morph the trees in all the blocks of the method
     //
     auto morphGlobalPhase = [this]() {
+        unsigned prevBBCount = fgBBcount;
         fgMorphBlocks();
 
         // Fix any LclVar annotations on discarded struct promotion temps for implicit by-ref args
@@ -4624,6 +4625,12 @@ void Compiler::compCompile(void** methodCodePtr, ULONG* methodCodeSize, JitFlags
         compCurBB = nullptr;
 #endif // DEBUG
 
+        // If we needed to create any new BasicBlocks then renumber the blocks
+        if (fgBBcount > prevBBCount)
+        {
+            fgRenumberBlocks();
+        }
+
         // We can now enable all phase checking
         activePhaseChecks = PhaseChecks::CHECK_ALL;
     };
@@ -4632,6 +4639,7 @@ void Compiler::compCompile(void** methodCodePtr, ULONG* methodCodeSize, JitFlags
     // GS security checks for unsafe buffers
     //
     auto gsPhase = [this]() {
+        unsigned prevBBCount = fgBBcount;
         if (getNeedsGSSecurityCookie())
         {
             gsGSChecksInitCookie();
@@ -4640,6 +4648,12 @@ void Compiler::compCompile(void** methodCodePtr, ULONG* methodCodeSize, JitFlags
             {
                 gsCopyShadowParams();
             }
+
+            // If we needed to create any new BasicBlocks then renumber the blocks
+            if (fgBBcount > prevBBCount)
+            {
+                fgRenumberBlocks();
+            }
         }
         else
         {