Fix the case when we replace `stmt->gtStmtExpr`.
authorSergey Andreenko <seandree@microsoft.com>
Fri, 26 Apr 2019 22:50:37 +0000 (15:50 -0700)
committerSergey Andreenko <seandree@microsoft.com>
Fri, 26 Apr 2019 22:50:37 +0000 (15:50 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/3e271954768ec502d1827c18d911d046f234c5a1

src/coreclr/src/jit/assertionprop.cpp

index d569458..5b62e88 100644 (file)
@@ -3905,9 +3905,18 @@ GenTree* Compiler::optAssertionProp_Update(GenTree* newTree, GenTree* tree, GenT
             GenTree**    useEdge  = linkData.result;
             GenTree*     parent   = linkData.parent;
             noway_assert(useEdge != nullptr);
-            assert(parent != nullptr);
 
-            parent->ReplaceOperand(useEdge, newTree);
+            if (parent != nullptr)
+            {
+                parent->ReplaceOperand(useEdge, newTree);
+            }
+            else
+            {
+                // If there's no parent, the tree being replaced is the root of the
+                // statement.
+                assert((stmt->gtStmtExpr == tree) && (&stmt->gtStmtExpr == useEdge));
+                stmt->gtStmtExpr = newTree;
+            }
 
             // We only need to ensure that the gtNext field is set as it is used to traverse
             // to the next node in the tree. We will re-morph this entire statement in