* Check that we don't create null checks on an address that is not null.
* Egor's request
inline GenTree* Compiler::gtNewNullCheck(GenTree* addr, BasicBlock* basicBlock)
{
+ assert(fgAddrCouldBeNull(addr));
GenTree* nullCheck = gtNewOperNode(GT_NULLCHECK, TYP_BYTE, addr);
nullCheck->gtFlags |= GTF_EXCEPT;
basicBlock->bbFlags |= BBF_HAS_NULLCHECK;
GenTree* thisOp = impInlineFetchArg(0, inlArgInfo, lclVarInfo);
if (fgAddrCouldBeNull(thisOp))
{
- nullcheck = gtNewNullCheck(impInlineFetchArg(0, inlArgInfo, lclVarInfo), block);
+ nullcheck = gtNewNullCheck(thisOp, block);
// The NULL-check statement will be inserted to the statement list after those statements
// that assign arguments to temps and before the actual body of the inlinee method.
}
if (((treeToBox->gtFlags & GTF_SIDE_EFFECT) == GTF_EXCEPT) &&
treeToBox->OperIs(GT_OBJ, GT_BLK, GT_IND))
{
- // Yes, we just need to perform a null check.
- treeToNullcheck = treeToBox->AsOp()->gtOp1;
+ // Yes, we just need to perform a null check if needed.
+ GenTree* const addr = treeToBox->AsOp()->gtGetOp1();
+ if (fgAddrCouldBeNull(addr))
+ {
+ treeToNullcheck = addr;
+ }
}
else
{