@@ -3385,13 +3385,16 @@ bool Compiler::impImportAndPushBoxForNullable(CORINFO_RESOLVED_TOKEN* pResolvedT
33853385 return true;
33863386 }
33873387
3388- GenTree* exprToBox = impPopStack().val;
3388+ GenTree* nullableObj = impPopStack().val;
33893389
33903390 // Decompose the Nullable<> arg into _hasValue and _value fields
33913391 // and calculate the type and layout of the 'value' field
33923392 //
3393- GenTreeFlags indirFlags = GTF_EMPTY;
3394- exprToBox = impGetNodeAddr(exprToBox, CHECK_SPILL_ALL, &indirFlags);
3393+ GenTreeFlags indirFlags = GTF_EMPTY;
3394+ nullableObj = impGetNodeAddr(nullableObj, CHECK_SPILL_ALL, &indirFlags);
3395+ GenTree* nullableObjClone;
3396+ nullableObj = impCloneExpr(nullableObj, &nullableObjClone, CHECK_SPILL_ALL, nullptr DEBUGARG("nullable obj clone"));
3397+
33953398 CORINFO_FIELD_HANDLE valueFldHnd = info.compCompHnd->getFieldInClass(nullableCls, 1);
33963399 CORINFO_CLASS_HANDLE valueStructCls = NO_CLASS_HANDLE;
33973400 static_assert(OFFSETOF__CORINFO_NullableOfT__hasValue == 0);
@@ -3400,9 +3403,9 @@ bool Compiler::impImportAndPushBoxForNullable(CORINFO_RESOLVED_TOKEN* pResolvedT
34003403 CorInfoType corFldType = info.compCompHnd->getFieldType(valueFldHnd, &valueStructCls);
34013404 var_types valueType = TypeHandleToVarType(corFldType, valueStructCls, &layout);
34023405 GenTree* valueOffset = gtNewIconNode(cnsValueOffset, TYP_I_IMPL);
3403- GenTree* valueAddr = gtNewOperNode(GT_ADD, TYP_BYREF, gtCloneExpr(exprToBox) , valueOffset);
3406+ GenTree* valueAddr = gtNewOperNode(GT_ADD, TYP_BYREF, nullableObjClone , valueOffset);
34043407 GenTree* value = gtNewLoadValueNode(valueType, layout, valueAddr);
3405- GenTree* hasValue = gtNewLoadValueNode(TYP_UBYTE, nullptr, gtCloneExpr(exprToBox) );
3408+ GenTree* hasValue = gtNewLoadValueNode(TYP_UBYTE, nullptr, nullableObj );
34063409
34073410 // Create the allocation node for the box
34083411 //
0 commit comments