From 58a99d1b9bbe8d194813f7440e293674ece13266 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Thu, 9 Apr 2026 17:01:03 +0300 Subject: [PATCH] Fix GC write barrier when writing async method return into continuation Previous code was only checking if the type contains GC refs, which means it would fail to add a write barrier if the method returns an object without refs. --- src/coreclr/vm/interpexec.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/coreclr/vm/interpexec.cpp b/src/coreclr/vm/interpexec.cpp index 3f4c2279c4834d..8ee7d4cddda8fe 100644 --- a/src/coreclr/vm/interpexec.cpp +++ b/src/coreclr/vm/interpexec.cpp @@ -1064,9 +1064,15 @@ extern "C" ContinuationObject* AsyncHelpers_ResumeInterpreterContinuationWorker( // We had a normal return, so copy out the return value if (returnValueSize > 0) { - if (pSuspendData->asyncMethodReturnType != NULL && pSuspendData->asyncMethodReturnType->ContainsGCPointers()) + if (pSuspendData->asyncMethodReturnType != NULL && !pSuspendData->asyncMethodReturnType->IsValueType()) { - // GC refs need to be written with write barriers + // asyncMethodReturnType is set only for CORINFO_TYPE_VALUECLASS/STRING/CLASS + // so we can make the assumption that the return is an object reference if not valuetype + SetObjectReference((OBJECTREF*)resultStorage, ObjectToOBJECTREF(*(Object**)returnValueLocation)); + } + else if (pSuspendData->asyncMethodReturnType != NULL && pSuspendData->asyncMethodReturnType->ContainsGCPointers()) + { + // ValueType containing gc refs, needs to be written with write barriers memmoveGCRefs(resultStorage, returnValueLocation, returnValueSize); } else