From ea12523aaca4f8dd2f2e877d0998b72d9a34de91 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Wed, 17 Apr 2019 14:23:11 -0700 Subject: [PATCH] JIT: ignore pinning of non-gc types (#24010) We may see pin modifiers on locals that are not gc types. Ignore these modifiers. Closes #23950. Also added a missing copyright header on an unrelated test. --- src/jit/importer.cpp | 24 +++++++---- src/jit/lclvars.cpp | 14 ++++++- .../JitBlue/GitHub_23411/GitHub_23411.il | 4 ++ .../JitBlue/GitHub_23950/GitHub_23950.il | 49 ++++++++++++++++++++++ .../JitBlue/GitHub_23950/GitHub_23950.ilproj | 25 +++++++++++ 5 files changed, 106 insertions(+), 10 deletions(-) create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_23950/GitHub_23950.il create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_23950/GitHub_23950.ilproj diff --git a/src/jit/importer.cpp b/src/jit/importer.cpp index 78c0b4f..db6b6df 100644 --- a/src/jit/importer.cpp +++ b/src/jit/importer.cpp @@ -18932,22 +18932,28 @@ void Compiler::impInlineInitVars(InlineInfo* pInlineInfo) var_types type = (var_types)eeGetArgType(localsSig, &methInfo->locals, &isPinned); lclVarInfo[i + argCnt].lclHasLdlocaOp = false; - lclVarInfo[i + argCnt].lclIsPinned = isPinned; lclVarInfo[i + argCnt].lclTypeInfo = type; if (varTypeIsGC(type)) { + if (isPinned) + { + JITDUMP("Inlinee local #%02u is pinned\n", i); + lclVarInfo[i + argCnt].lclIsPinned = true; + + // Pinned locals may cause inlines to fail. + inlineResult->Note(InlineObservation::CALLEE_HAS_PINNED_LOCALS); + if (inlineResult->IsFailure()) + { + return; + } + } + pInlineInfo->numberOfGcRefLocals++; } - - if (isPinned) + else if (isPinned) { - // Pinned locals may cause inlines to fail. - inlineResult->Note(InlineObservation::CALLEE_HAS_PINNED_LOCALS); - if (inlineResult->IsFailure()) - { - return; - } + JITDUMP("Ignoring pin on inlinee local #%02u -- not a GC type\n", i); } lclVarInfo[i + argCnt].lclVerTypeInfo = verParseArgSigToTypeInfo(&methInfo->locals, localsSig); diff --git a/src/jit/lclvars.cpp b/src/jit/lclvars.cpp index 515e934..6b26b5d 100644 --- a/src/jit/lclvars.cpp +++ b/src/jit/lclvars.cpp @@ -255,7 +255,19 @@ void Compiler::lvaInitTypeRef() lvaInitVarDsc(varDsc, varNum, corInfoType, typeHnd, localsSig, &info.compMethodInfo->locals); - varDsc->lvPinned = ((corInfoTypeWithMod & CORINFO_TYPE_MOD_PINNED) != 0); + if ((corInfoTypeWithMod & CORINFO_TYPE_MOD_PINNED) != 0) + { + if ((corInfoType == CORINFO_TYPE_CLASS) || (corInfoType == CORINFO_TYPE_BYREF)) + { + JITDUMP("Setting lvPinned for V%02u\n", varNum); + varDsc->lvPinned = 1; + } + else + { + JITDUMP("Ignoring pin for non-GC type V%02u\n", varNum); + } + } + varDsc->lvOnFrame = true; // The final home for this local variable might be our local stack frame if (corInfoType == CORINFO_TYPE_CLASS) diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_23411/GitHub_23411.il b/tests/src/JIT/Regression/JitBlue/GitHub_23411/GitHub_23411.il index e6e508f..e561026 100644 --- a/tests/src/JIT/Regression/JitBlue/GitHub_23411/GitHub_23411.il +++ b/tests/src/JIT/Regression/JitBlue/GitHub_23411/GitHub_23411.il @@ -1,3 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + .assembly extern System.Runtime { } .assembly extern System.Console { } .assembly extern System.Globalization { } diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_23950/GitHub_23950.il b/tests/src/JIT/Regression/JitBlue/GitHub_23950/GitHub_23950.il new file mode 100644 index 0000000..f96e2cd --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_23950/GitHub_23950.il @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern mscorlib {} + +.assembly GitHub_23970 {} + +// Test that jit can inline method with a pinned pointer + +.class public sequential ansi sealed beforefieldinit Program + extends [mscorlib]System.Object +{ + .method private hidebysig static + int32 Main ( + string[] args + ) cil managed + { + + .maxstack 1 + .entrypoint + .locals init ( + [0] int32 + ) + nop + ldc.i4.s 100 + stloc.0 + ldloca.s 0 + call int32 Program::GetValueUnsafe(int32&) + ret + } + + .method private hidebysig + static int32 GetValueUnsafe ( + int32& buffer + ) cil managed + { + .maxstack 3 + .locals init ( + [0] int32* pinned + ) + + ldarg.0 + stloc.0 + ldloc.0 + ldind.i4 + ret + } +} \ No newline at end of file diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_23950/GitHub_23950.ilproj b/tests/src/JIT/Regression/JitBlue/GitHub_23950/GitHub_23950.ilproj new file mode 100644 index 0000000..43c02b9 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_23950/GitHub_23950.ilproj @@ -0,0 +1,25 @@ + + + + + Debug + AnyCPU + $(MSBuildProjectName) + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + ..\..\ + 0 + + + + + None + True + + + + + + + + -- 2.7.4