Correct indirect P/Invoke call prlogs on x86.
authorPat Gavlin <pagavlin@microsoft.com>
Wed, 26 Oct 2016 21:40:59 +0000 (14:40 -0700)
committerPat Gavlin <pagavlin@microsoft.com>
Wed, 26 Oct 2016 21:40:59 +0000 (14:40 -0700)
32-bit targets require the size of the stack argument area in
InlinedCallFrame.m_Datum rather than the stub argument (as on 64-bit
targets).

src/jit/lower.cpp

index dbe4b5d..743e359 100644 (file)
@@ -2784,11 +2784,18 @@ void Lowering::InsertPInvokeCallProlog(GenTreeCall* call)
 
     if (callType == CT_INDIRECT)
     {
+#if !defined(_TARGET_64BIT_)
+        // On 32-bit targets, indirect calls need the size of the stack args in InlinedCallFrame.m_Datum.
+        const unsigned numStkArgBytes = call->fgArgInfo->GetNextSlotNum() * TARGET_POINTER_SIZE;
+        src = comp->gtNewIconNode(numStkArgBytes, TYP_INT);
+#else
+        // On 64-bit targets, indirect calls may need the stub parameter value in InlinedCallFrame.m_Datum.
         if (comp->info.compPublishStubParam)
         {
-            src = new (comp, GT_LCL_VAR) GenTreeLclVar(TYP_I_IMPL, comp->lvaStubArgumentVar, BAD_IL_OFFSET);
+            src = comp->gtNewLclvNode(comp->lvaStubArgumentVar, TYP_I_IMPL);
         }
         // else { If we don't have secret parameter, m_Datum will be initialized by VM code }
+#endif // !defined(_TARGET_64BIT_)
     }
     else
     {