Adjust ref counts during EH normalization (dotnet/coreclr#8713)
authorAndy Ayers <andya@microsoft.com>
Tue, 3 Jan 2017 21:30:09 +0000 (13:30 -0800)
committerGitHub <noreply@github.com>
Tue, 3 Jan 2017 21:30:09 +0000 (13:30 -0800)
EH normalization can leave incorrect ref counts. This caused asserts in a few
cases with the forthcoming finally cloning, as these EH related blocks were
exposed to flow optimizations.

Commit migrated from https://github.com/dotnet/coreclr/commit/7be8f56ce218029bcd4d68f013aacd4070994b22

src/coreclr/src/jit/jiteh.cpp

index 4b3ceae..01a2fdc 100644 (file)
@@ -2426,6 +2426,11 @@ bool Compiler::fgNormalizeEHCase2()
                                 // this once per dup.
                                 fgReplaceJumpTarget(predBlock, newTryStart, insertBeforeBlk);
 
+                                // Need to adjust ref counts here since we're retargeting edges.
+                                newTryStart->bbRefs++;
+                                assert(insertBeforeBlk->countOfInEdges() > 0);
+                                insertBeforeBlk->bbRefs--;
+
 #ifdef DEBUG
                                 if (verbose)
                                 {