Fix handling of struct setup assignments
authorCarol Eidt <carol.eidt@microsoft.com>
Fri, 8 Mar 2019 21:09:41 +0000 (13:09 -0800)
committerCarol Eidt <carol.eidt@microsoft.com>
Fri, 8 Mar 2019 21:09:41 +0000 (13:09 -0800)
In dotnet/coreclr#22791 I was creating struct assignments with COMMAs on the rhs, but that isn't handled downstream.

Fix dotnet/coreclr#23059

Commit migrated from https://github.com/dotnet/coreclr/commit/384eefbd899ced778d99314df0d9e76fdccf71a4

src/coreclr/src/jit/flowgraph.cpp
src/coreclr/src/jit/importer.cpp

index 2207a07..4888ce2 100644 (file)
@@ -21152,7 +21152,8 @@ void Compiler::fgDebugCheckFlags(GenTree* tree)
         // If parent is a TYP_VOID, we don't no need to propagate TYP_INT up. We are fine.
         if (op2 && op2->gtOper == GT_ASG)
         {
-            assert(tree->gtType == TYP_VOID);
+            // We can have ASGs on the RHS of COMMAs in setup arguments to a call.
+            assert(tree->gtType == TYP_VOID || tree->gtOper == GT_COMMA);
         }
 
         switch (oper)
index 4399381..9c2236d 100644 (file)
@@ -1359,14 +1359,24 @@ GenTree* Compiler::impAssignStructPtr(GenTree*             destAddr,
         {
             // Insert op1 after '*pAfterStmt'
             *pAfterStmt = fgInsertStmtAfter(block, *pAfterStmt, gtNewStmt(src->gtOp.gtOp1, ilOffset));
-            // Evaluate the second thing using recursion.
-            return impAssignStructPtr(destAddr, src->gtOp.gtOp2, structHnd, curLevel, pAfterStmt, ilOffset, block);
+        }
+        else if (impTreeLast != nullptr)
+        {
+            // Do the side-effect as a separate statement.
+            impAppendTree(src->gtOp.gtOp1, curLevel, ilOffset);
         }
         else
         {
-            // We don't have an instruction to insert after, so use the entire comma expression as our rhs.
-            asgType = impNormStructType(structHnd);
+            // In this case we have neither been given a statement to insert after, nor are we
+            // in the importer where we can append the side effect.
+            // Instead, we're going to sink the assignment below the COMMA.
+            src->gtOp.gtOp2 =
+                impAssignStructPtr(destAddr, src->gtOp.gtOp2, structHnd, curLevel, pAfterStmt, ilOffset, block);
+            return src;
         }
+
+        // Evaluate the second thing using recursion.
+        return impAssignStructPtr(destAddr, src->gtOp.gtOp2, structHnd, curLevel, pAfterStmt, ilOffset, block);
     }
     else if (src->IsLocal())
     {