A long standing issue in the Compiler::fgInsertTreeInListBefore method was
found where the gtStmtList of a statement was not updated when a tree is
inserted before the first statement in the list (stmt->gtStmtList ==
insertionPoint). In such case the gtStmtList is not updated to include the
new tree(s) inserted.
After talking to few people offline to understand where this fix should be made
and realizing that the comment on Compiler::fgMakeEmbeddedStmt is
incorrect, I made the necessary fix in Compiler::fgInsertTreeInListBefore
so the newly inserted tree(s) in includedin the gtStmtList of the updated
stmt.
Fixes 3618.
Commit migrated from https://github.com/dotnet/coreclr/commit/
e59013a59744d05fa4c60570f25198c160ba3582
if (beforeTree != nullptr)
{
beforeTree->gtNext = first;
+
+ // If the insertionPoint is the gtStatementList,
+ // update the gtStatemenList to include the newly inserted tree.
+ if (stmt->gtStmtList == insertionPoint)
+ {
+ stmt->gtStmtList = first;
+ }
}
else
{
}
//------------------------------------------------------------------------------
-// fgMakeEmbeddedStmt: insert the given subtree as an embedded statement
+// fgMakeEmbeddedStmt: insert the given subtree as an embedded statement
//
// Arguments:
// block - The block containing the parentStmt, into which the new embedded
// statement will go
// tree - The tree that will be the gtStmtExpr of the new embedded statement
-// parentStmt - The top-level statement that 'tree' is embedded in
+// parentStmt - A statement (top-level or embedded) that 'tree' is fully contained in
//
// Return Value:
// A pointer to the new statement.