Skip to content

Commit

Permalink
JIT: fix double reporting of some GC frame slots
Browse files Browse the repository at this point in the history
If there is a gc struct local that is dependently promoted, the struct
local may be untracked while the promoted gc fields of the struct are
tracked.

If so, the jit will double report the stack offset for the gc field,
first as an untracked slot, and then as a tracked slot.

Detect this case and report the slot as tracked only.

Closes #71005.
  • Loading branch information
AndyAyersMS committed Jun 24, 2022
1 parent d17741d commit 6bc83f1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/coreclr/jit/gcencode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4226,7 +4226,30 @@ void GCInfo::gcMakeRegPtrTable(
continue;
}

int offset = varDsc->GetStackOffset() + i * TARGET_POINTER_SIZE;
const unsigned int fieldOffset = i * TARGET_POINTER_SIZE;

if (varDsc->lvPromoted)
{
assert(compiler->lvaGetPromotionType(varDsc) == Compiler::PROMOTION_TYPE_DEPENDENT);

// See if this untracked dependently promoted struct has
// a tracked field at this offset.
//
unsigned const fieldLclNum = compiler->lvaGetFieldLocal(varDsc, fieldOffset);
LclVarDsc* const fieldVarDsc = compiler->lvaGetDesc(fieldLclNum);
assert(varTypeIsGC(fieldVarDsc->TypeGet()));

if (fieldVarDsc->lvTracked)
{
JITDUMP("Untracked GC struct V%02 has tracked gc ref at + 0x%x (P-DEP promoted V%02u); will "
"report slot as tracked",
varNum, fieldOffset, fieldLclNum);
continue;
}
}

int const offset = varDsc->GetStackOffset() + fieldOffset;

#if DOUBLE_ALIGN
// For genDoubleAlign(), locals are addressed relative to ESP and
// arguments are addressed relative to EBP.
Expand Down

0 comments on commit 6bc83f1

Please sign in to comment.