Fix a tight assert for System V struct returning.
authorLubomir Litchev <lubol@microsoft.com>
Wed, 9 Dec 2015 13:52:28 +0000 (05:52 -0800)
committerLubomir Litchev <lubol@microsoft.com>
Wed, 9 Dec 2015 13:52:28 +0000 (05:52 -0800)
When having a single eightbyte structs, the type of the struct is
normalized to the type of the single eight byte, thus replacing the
TYP_STRUCT. Account for this in the importer.

src/jit/importer.cpp

index 5204abe..83600f8 100644 (file)
@@ -6999,7 +6999,6 @@ GenTreePtr          Compiler::impFixupStructReturnType(GenTreePtr op, CORINFO_CL
                 unsigned lclNum = op->gtLclVarCommon.gtLclNum;
                 // Make sure this struct type stays as struct so that we can return it in registers.
                 lvaTable[lclNum].lvDontPromote = true;
-
                 return op;
             }
 
@@ -13637,7 +13636,14 @@ bool Compiler::impReturnInstruction(BasicBlock *block, int prefixFlags, OPCODE &
                     bool restoreType = false;
                     if ((op2->OperGet() == GT_CALL) && (info.compRetType == TYP_STRUCT))
                     {
-                        noway_assert(op2->TypeGet() == TYP_STRUCT); // If not, then impFixupStructReturnType() must have touched it!
+                        // If the op2 type is not TYP_STRUCT, then the impFixupStructReturnType has changed it.
+                        // For System V a single eightbyte struct's type could be normalized to the type of the single eightbyte.
+                        bool isNormalizedType = false;
+#if defined(FEATURE_UNIX_AMD64_STRUCT_PASSING)
+                        GenTreeCall* callTreePtr = op2->AsCall();
+                        isNormalizedType = callTreePtr->structDesc.passedInRegisters && (callTreePtr->structDesc.eightByteCount == 1);
+#endif // defined(FEATURE_UNIX_AMD64_STRUCT_PASSING)
+                        noway_assert(op2->TypeGet() == TYP_STRUCT || isNormalizedType);
                         op2->gtType = info.compRetNativeType;
                         restoreType = true;
                     }