Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 673242e

Browse files
committed
Fix issue #11447.
This issue was caused by the code for PInvoke frame initialization reading from the stub argument register after it had been trashed by prior instructions. This change fixes this issue by inserting the PInvoke frame initialization at the beginning of the scratch block into which it is inserted rather than at the end. Note that a more correct fix here would be to represent the stub argument as a lclVar rather than a physical register; that work is tracked by #11450.
1 parent 4a9af73 commit 673242e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/jit/lower.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,8 +2872,10 @@ void Lowering::InsertPInvokeMethodProlog()
28722872
store->gtOp.gtOp1 = call;
28732873
store->gtFlags |= GTF_VAR_DEF;
28742874

2875+
GenTree* const insertionPoint = firstBlockRange.FirstNonPhiOrCatchArgNode();
2876+
28752877
comp->fgMorphTree(store);
2876-
firstBlockRange.InsertAtEnd(LIR::SeqTree(comp, store));
2878+
firstBlockRange.InsertBefore(insertionPoint, LIR::SeqTree(comp, store));
28772879
DISPTREERANGE(firstBlockRange, store);
28782880

28792881
#if !defined(_TARGET_X86_) && !defined(_TARGET_ARM_)
@@ -2887,7 +2889,7 @@ void Lowering::InsertPInvokeMethodProlog()
28872889
GenTreeLclFld(GT_STORE_LCL_FLD, TYP_I_IMPL, comp->lvaInlinedPInvokeFrameVar, callFrameInfo.offsetOfCallSiteSP);
28882890
storeSP->gtOp1 = PhysReg(REG_SPBASE);
28892891

2890-
firstBlockRange.InsertAtEnd(LIR::SeqTree(comp, storeSP));
2892+
firstBlockRange.InsertBefore(insertionPoint, LIR::SeqTree(comp, storeSP));
28912893
DISPTREERANGE(firstBlockRange, storeSP);
28922894

28932895
#endif // !defined(_TARGET_X86_) && !defined(_TARGET_ARM_)
@@ -2903,7 +2905,7 @@ void Lowering::InsertPInvokeMethodProlog()
29032905
callFrameInfo.offsetOfCalleeSavedFP);
29042906
storeFP->gtOp1 = PhysReg(REG_FPBASE);
29052907

2906-
firstBlockRange.InsertAtEnd(LIR::SeqTree(comp, storeFP));
2908+
firstBlockRange.InsertBefore(insertionPoint, LIR::SeqTree(comp, storeFP));
29072909
DISPTREERANGE(firstBlockRange, storeFP);
29082910
#endif // !defined(_TARGET_ARM_)
29092911

@@ -2918,7 +2920,7 @@ void Lowering::InsertPInvokeMethodProlog()
29182920
// Push a frame - if we are NOT in an IL stub, this is done right before the call
29192921
// The init routine sets InlinedCallFrame's m_pNext, so we just set the thead's top-of-stack
29202922
GenTree* frameUpd = CreateFrameLinkUpdate(PushFrame);
2921-
firstBlockRange.InsertAtEnd(LIR::SeqTree(comp, frameUpd));
2923+
firstBlockRange.InsertBefore(insertionPoint, LIR::SeqTree(comp, frameUpd));
29222924
DISPTREERANGE(firstBlockRange, frameUpd);
29232925
}
29242926
#endif // _TARGET_64BIT_

0 commit comments

Comments
 (0)