Skip to content

Commit 100647b

Browse files
committed
FB
1 parent 548e980 commit 100647b

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,7 @@ private static void ArrayTypeCheck_Helper(object obj, void* elementType)
523523
{
524524
Debug.Assert(srcMT->IsNullable);
525525

526-
// If 'hasValue' is false, return null.
527-
if (!Unsafe.As<byte, bool>(ref nullableData))
526+
if (nullableData == 0)
528527
return null;
529528

530529
// Allocate a new instance of the T in Nullable<T>.
@@ -541,6 +540,9 @@ internal static object Box(MethodTable* typeMT, ref byte unboxedData)
541540
Debug.Assert(typeMT != null);
542541
Debug.Assert(typeMT->IsValueType);
543542

543+
// A null can be passed for boxing of a null ref.
544+
_ = Unsafe.ReadUnaligned<byte>(ref unboxedData);
545+
544546
object boxed = RuntimeTypeHandle.InternalAllocNoChecks(typeMT);
545547
if (typeMT->ContainsGCPointers)
546548
{

src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ internal static object InternalAllocNoChecks(MethodTable* pMT)
306306
return InternalAllocNoChecks_FastPath(pMT) ?? InternalAllocNoChecksWorker(pMT);
307307

308308
[MethodImpl(MethodImplOptions.NoInlining)]
309-
static object? InternalAllocNoChecksWorker(MethodTable* pMT)
309+
static object InternalAllocNoChecksWorker(MethodTable* pMT)
310310
{
311311
object? result = null;
312312
InternalAllocNoChecks(pMT, ObjectHandleOnStack.Create(ref result));
313-
return result;
313+
return result!;
314314
}
315315
}
316316

src/coreclr/vm/object.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ void CopyValueClassUnchecked(void* dest, void* src, MethodTable *pMT)
395395
// Copy value class into the argument specified by the argDest.
396396
// The destOffset is nonzero when copying values into Nullable<T>, it is the offset
397397
// of the T value inside of the Nullable<T>
398-
void STDCALL CopyValueClassArgUnchecked(ArgDestination *argDest, void* src, MethodTable *pMT, int destOffset)
398+
void CopyValueClassArgUnchecked(ArgDestination *argDest, void* src, MethodTable *pMT, int destOffset)
399399
{
400400
STATIC_CONTRACT_NOTHROW;
401401
STATIC_CONTRACT_GC_NOTRIGGER;

src/coreclr/vm/object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ inline void ClearObjectReference(OBJECTREF* dst)
494494
// CopyValueClass sets a value class field
495495

496496
void CopyValueClassUnchecked(void* dest, void* src, MethodTable *pMT);
497-
void STDCALL CopyValueClassArgUnchecked(ArgDestination *argDest, void* src, MethodTable *pMT, int destOffset);
497+
void CopyValueClassArgUnchecked(ArgDestination *argDest, void* src, MethodTable *pMT, int destOffset);
498498

499499
inline void InitValueClass(void *dest, MethodTable *pMT)
500500
{

src/coreclr/vm/runtimehandles.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,11 @@ FCIMPL1(Object*, RuntimeTypeHandle::InternalAllocNoChecks_FastPath, MethodTable*
11541154
return NULL;
11551155
}
11561156

1157+
if (pMT->HasFinalizer())
1158+
{
1159+
return NULL;
1160+
}
1161+
11571162
#ifdef FEATURE_64BIT_ALIGNMENT
11581163
if (pMT->RequiresAlign8())
11591164
{

0 commit comments

Comments
 (0)