From 20f9ce651f57d2226a1e47e89b87b034f6a4c1cb Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 15 Dec 2016 12:59:29 -0800 Subject: [PATCH] Make Unsafe.AsRef inlineable The JIT inliner chokes on type mismatch on return. Make the method inlineable by round-tripping the value via local that avoids the type mismatch on return. --- .../src/System.Runtime.CompilerServices.Unsafe.il | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/System.Runtime.CompilerServices.Unsafe/src/System.Runtime.CompilerServices.Unsafe.il b/src/System.Runtime.CompilerServices.Unsafe/src/System.Runtime.CompilerServices.Unsafe.il index 869537225894..0eb1aa409191 100644 --- a/src/System.Runtime.CompilerServices.Unsafe/src/System.Runtime.CompilerServices.Unsafe.il +++ b/src/System.Runtime.CompilerServices.Unsafe/src/System.Runtime.CompilerServices.Unsafe.il @@ -222,8 +222,12 @@ .method public hidebysig static !!T& AsRef(void* source) cil managed aggressiveinlining { .custom instance void System.Runtime.Versioning.NonVersionableAttribute::.ctor() = ( 01 00 00 00 ) + .locals (int32&) .maxstack 1 ldarg.0 + // Roundtrip via a local to avoid type mismatch on return that the JIT inliner chokes on. + stloc.0 + ldloc.0 ret } // end of method Unsafe::AsRef