Skip to content

Commit

Permalink
JIT: properly scrub SSA from return address buffers (dotnet#85746)
Browse files Browse the repository at this point in the history
These can be in SSA and were not getting their SSA numbers cleaned by
`fgResetForSsa`, so in repeat mode they might trigger SSA check failures.

Also changed it so you can dump the SSA number without triggering an
assert.

Fixes dotnet#85629
  • Loading branch information
AndyAyersMS committed May 4, 2023
1 parent 1774bdf commit 1a51420
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,12 @@ class LclVarDsc

SsaDefArray<LclSsaVarDsc> lvPerSsaData;

// True if ssaNum is a viable ssaNum for this local.
bool IsValidSsaNum(unsigned ssaNum) const
{
return lvPerSsaData.IsValidSsaNum(ssaNum);
}

// Returns the address of the per-Ssa data for the given ssaNum (which is required
// not to be the SsaConfig::RESERVED_SSA_NUM, which indicates that the variable is
// not an SSA variable).
Expand Down
29 changes: 20 additions & 9 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11583,20 +11583,31 @@ static const char* InsCflagsToString(insCflags flags)
//
void Compiler::gtDispSsaName(unsigned lclNum, unsigned ssaNum, bool isDef)
{
if (ssaNum != SsaConfig::RESERVED_SSA_NUM)
if (ssaNum == SsaConfig::RESERVED_SSA_NUM)
{
if (isDef)
return;
}

LclVarDsc* const lclDsc = lvaGetDesc(lclNum);
bool const isValid = lclDsc->IsValidSsaNum(ssaNum);

if (isDef)
{
if (!isValid)
{
unsigned oldDefSsaNum = lvaGetDesc(lclNum)->GetPerSsaData(ssaNum)->GetUseDefSsaNum();
if (oldDefSsaNum != SsaConfig::RESERVED_SSA_NUM)
{
printf("ud:%d->%d", oldDefSsaNum, ssaNum);
return;
}
printf("?d:%d", ssaNum);
return;
}

printf("%s:%d", isDef ? "d" : "u", ssaNum);
unsigned oldDefSsaNum = lclDsc->GetPerSsaData(ssaNum)->GetUseDefSsaNum();
if (oldDefSsaNum != SsaConfig::RESERVED_SSA_NUM)
{
printf("ud:%d->%d", oldDefSsaNum, ssaNum);
return;
}
}

printf("%s%s:%d", isValid ? "" : "?", isDef ? "d" : "u", ssaNum);
}

//------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1958,6 +1958,11 @@ struct GenTree
return OperIsLocal(OperGet());
}

bool IsAnyLocal() const
{
return OperIsAnyLocal(OperGet());
}

bool IsLclVarAddr() const;

// Returns "true" iff 'this' is a GT_LCL_FLD or GT_STORE_LCL_FLD on which the type
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/ssabuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void Compiler::fgResetForSsa()
{
for (GenTree* const tree : stmt->TreeList())
{
if (tree->IsLocal())
if (tree->IsAnyLocal())
{
tree->AsLclVarCommon()->SetSsaNum(SsaConfig::RESERVED_SSA_NUM);
}
Expand Down

0 comments on commit 1a51420

Please sign in to comment.