Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Fix emitter::emitSplit to not create zero-sized method fragment #107568

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/coreclr/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3071,8 +3071,25 @@ void emitter::emitSplit(emitLocation* startLoc,

} // end for loop

splitIfNecessary();
assert(curSize < UW_MAX_FRAGMENT_SIZE_BYTES);
// It's possible to have zero-sized IGs at this point in the emitter.
// For example, the JIT may create an IG to align a loop,
// but then later walk back this decision after other alignment decisions,
// which means it will zero out the new IG.
// If a zero-sized IG precedes a populated IG, it will be included in the latter's fragment.
// However, if the last IG candidate is a zero-sized IG, splitting would create a zero-sized fragment,
// so skip the last split in such cases.
// (The last IG in the main method body can be zero-sized if it was created to align a loop in the first funclet.)
if ((igLastCandidate != nullptr) && (curSize == candidateSize))
{
JITDUMP("emitSplit: can't split at last candidate IG%02u because it would create a zero-sized fragment\n",
igLastCandidate->igNum);
}
else
{
splitIfNecessary();
}

assert((curSize > 0) && (curSize < UW_MAX_FRAGMENT_SIZE_BYTES));
}

/*****************************************************************************
Expand Down
Loading