Skip to content
Open
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
8 changes: 8 additions & 0 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,14 @@ GenTree* Compiler::fgMorphExpandCast(GenTreeCast* tree)
// we fix this by copying the GC pointer to a non-gc pointer temp.
noway_assert(!varTypeIsGC(dstType) && "How can we have a cast to a GCRef here?");

// we can just retype byref constants
if (oper->IsCnsIntOrI() && oper->TypeIs(TYP_BYREF) && varTypeIsI(dstType))
{
assert(srcType == TYP_BYREF);
oper->gtType = dstType;
return fgMorphTree(oper);
}

// We generate a store to an int and then do the cast from an int. With this we avoid
// the gc problem and we allow casts to bytes, longs, etc...
unsigned lclNum = lvaGrabTemp(true DEBUGARG("Cast away GC"));
Expand Down
Loading