Skip to content

Commit ea694d8

Browse files
Skip nullcheck frozen object in unbox optimization (#121709)
Fixes the build crash in #121697. Since with TrimMode=partial, we consider all static fields targets of reflection, we cannot allow inlining their contents. With full trimming allowed, the optimization is unlocked and we hit an assert when trying to nullcheck a constant.
1 parent 81856e7 commit ea694d8

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/coreclr/jit/importer.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10490,16 +10490,26 @@ void Compiler::impImportBlockCode(BasicBlock* block)
1049010490
GenTree* boxPayloadOffset = gtNewIconNode(TARGET_POINTER_SIZE, TYP_I_IMPL);
1049110491
GenTree* boxPayloadAddress =
1049210492
gtNewOperNode(GT_ADD, TYP_BYREF, cloneOperand, boxPayloadOffset);
10493-
GenTree* nullcheck = gtNewNullCheck(op1);
10494-
// Add an ordering dependency between the null
10495-
// check and forming the byref; the JIT assumes
10496-
// in many places that the only legal null
10497-
// byref is literally 0, and since the byref
10498-
// leaks out here, we need to ensure it is
10499-
// nullchecked.
10500-
nullcheck->SetHasOrderingSideEffect();
10501-
boxPayloadAddress->SetHasOrderingSideEffect();
10502-
GenTree* result = gtNewOperNode(GT_COMMA, TYP_BYREF, nullcheck, boxPayloadAddress);
10493+
10494+
GenTree* result;
10495+
if (fgAddrCouldBeNull(op1))
10496+
{
10497+
GenTree* nullcheck = gtNewNullCheck(op1);
10498+
// Add an ordering dependency between the null
10499+
// check and forming the byref; the JIT assumes
10500+
// in many places that the only legal null
10501+
// byref is literally 0, and since the byref
10502+
// leaks out here, we need to ensure it is
10503+
// nullchecked.
10504+
nullcheck->SetHasOrderingSideEffect();
10505+
boxPayloadAddress->SetHasOrderingSideEffect();
10506+
result = gtNewOperNode(GT_COMMA, TYP_BYREF, nullcheck, boxPayloadAddress);
10507+
}
10508+
else
10509+
{
10510+
// We don't need a nullcheck if this is e.g. a preinitialized value
10511+
result = boxPayloadAddress;
10512+
}
1050310513
impPushOnStack(result, tiRetVal);
1050410514
break;
1050510515
}

0 commit comments

Comments
 (0)