From 93112d2274e5815a1fc23576bf5a6b02473415be Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Mon, 29 Jun 2026 14:27:34 -0700 Subject: [PATCH] JIT: unpin locals fed by non-GC typed values Treat a non-GC typed def (eg a native int reinterpreted as a byref, as in a Span built from a pointer) as non-movable, so the pinned local can be unpinned. Fixes #129993. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/coreclr/jit/gentree.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index b66874618c106b..be9cab8591dc89 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -1222,6 +1222,12 @@ struct GenTree bool IsNotGcDef() const { + // A non-GC typed value (eg native int reinterpreted as byref) cannot designate a movable object. + if (!varTypeIsGC(TypeGet())) + { + return true; + } + if (IsIntegralConst(0) || OperIs(GT_LCL_ADDR, GT_LCLHEAP)) { return true;