Skip to content

Commit

Permalink
Fix a potential bug with return buffer numbering
Browse files Browse the repository at this point in the history
Also address the TODO-CQ.
  • Loading branch information
SingleAccretion committed May 23, 2022
1 parent 1562d2a commit 836eac0
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9723,23 +9723,15 @@ void Compiler::fgValueNumberCall(GenTreeCall* call)

// If the call generates a definition, because it uses "return buffer", then VN the local
// as well.
GenTreeLclVarCommon* lclVarTree;
if (call->DefinesLocal(this, &lclVarTree))
GenTreeLclVarCommon* lclVarTree = nullptr;
ssize_t offset = 0;
if (call->DefinesLocal(this, &lclVarTree, /* pIsEntire */ nullptr, &offset))
{
assert((lclVarTree->gtFlags & GTF_VAR_DEF) != 0);

unsigned hiddenArgLclNum = lclVarTree->GetLclNum();
LclVarDsc* hiddenArgVarDsc = lvaGetDesc(hiddenArgLclNum);
unsigned lclDefSsaNum = GetSsaNumForLocalVarDef(lclVarTree);
ValueNumPair storeValue;
storeValue.SetBoth(vnStore->VNForExpr(compCurBB, TYP_STRUCT));
unsigned storeSize = typGetObjLayout(call->gtRetClsHnd)->GetSize();

// TODO-Bug: call "fgValueNumberLocalStore" here, currently this code fails to update
// the heap state if the local was address-exposed.
if (lclDefSsaNum != SsaConfig::RESERVED_SSA_NUM)
{
ValueNumPair newHiddenArgLclVNPair = ValueNumPair();
newHiddenArgLclVNPair.SetBoth(vnStore->VNForExpr(compCurBB, hiddenArgVarDsc->TypeGet()));
hiddenArgVarDsc->GetPerSsaData(lclDefSsaNum)->m_vnPair = newHiddenArgLclVNPair;
}
fgValueNumberLocalStore(call, lclVarTree, offset, storeSize, storeValue);
}
}

Expand Down

0 comments on commit 836eac0

Please sign in to comment.