From 85030be5f185837f5c360cdab1cc5b7d4de2874f Mon Sep 17 00:00:00 2001 From: petris Date: Tue, 5 Jul 2022 14:44:16 +0200 Subject: [PATCH 1/4] Make getTypeForPrimitiveValueClass treat different sizes as different types --- src/coreclr/vm/jitinterface.cpp | 56 ++----------------- .../JitBlue/Runtime_71632/Runtime_71632.cs | 45 +++++++++++++++ .../Runtime_71632/Runtime_71632.csproj | 9 +++ 3 files changed, 60 insertions(+), 50 deletions(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_71632/Runtime_71632.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_71632/Runtime_71632.csproj diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index ea91727f15023..41863af5fe04f 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -3969,54 +3969,10 @@ CorInfoType CEEInfo::getTypeForPrimitiveValueClass( } else { - switch (th.GetInternalCorElementType()) + CorElementType elementType = th.GetInternalCorElementType(); + if (elementType >= ELEMENT_TYPE_BOOLEAN && elementType <= ELEMENT_TYPE_R8) { - case ELEMENT_TYPE_I1: - case ELEMENT_TYPE_U1: - case ELEMENT_TYPE_BOOLEAN: - result = asCorInfoType(ELEMENT_TYPE_I1); - break; - - case ELEMENT_TYPE_I2: - case ELEMENT_TYPE_U2: - case ELEMENT_TYPE_CHAR: - result = asCorInfoType(ELEMENT_TYPE_I2); - break; - - case ELEMENT_TYPE_I4: - case ELEMENT_TYPE_U4: - result = asCorInfoType(ELEMENT_TYPE_I4); - break; - - case ELEMENT_TYPE_I8: - case ELEMENT_TYPE_U8: - result = asCorInfoType(ELEMENT_TYPE_I8); - break; - - case ELEMENT_TYPE_I: - case ELEMENT_TYPE_U: - result = asCorInfoType(ELEMENT_TYPE_I); - break; - - case ELEMENT_TYPE_R4: - result = asCorInfoType(ELEMENT_TYPE_R4); - break; - - case ELEMENT_TYPE_R8: - result = asCorInfoType(ELEMENT_TYPE_R8); - break; - - case ELEMENT_TYPE_VOID: - result = asCorInfoType(ELEMENT_TYPE_VOID); - break; - - case ELEMENT_TYPE_PTR: - case ELEMENT_TYPE_FNPTR: - result = asCorInfoType(ELEMENT_TYPE_PTR); - break; - - default: - break; + result = asCorInfoType(elementType); } } @@ -13938,7 +13894,7 @@ BOOL LoadDynamicInfoEntry(Module *currentModule, { DWORD dwBlobSize = CorSigUncompressData(pBlob); const uint8_t *const pBlobStart = pBlob; - pBlob += dwBlobSize; + pBlob += dwBlobSize; StackSArray types; DWORD cTypes = CorSigUncompressData(pBlob); bool fail = false; @@ -13965,7 +13921,7 @@ BOOL LoadDynamicInfoEntry(Module *currentModule, } MethodDesc *pMDCompare = NULL; - + if (!fail) { if (kind == ENCODE_CHECK_IL_BODY) @@ -13995,7 +13951,7 @@ BOOL LoadDynamicInfoEntry(Module *currentModule, fail = fail || (pMethodMetadata->cByteData != dwBlobSize); } - + if (!fail) { fail = 0 != memcmp(pBlobStart, pMethodMetadata->pByteData, dwBlobSize); diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_71632/Runtime_71632.cs b/src/tests/JIT/Regression/JitBlue/Runtime_71632/Runtime_71632.cs new file mode 100644 index 0000000000000..73d38c3bc5f49 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_71632/Runtime_71632.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Numerics; +using System.Runtime.CompilerServices; + +public class Runtime_71632 +{ + public static int Main() + { + try + { + Problem(1); + return 101; + } + catch (InvalidCastException) {} + + try + { + Problem2(1); + return 102; + } + catch (InvalidCastException) {} + + return 100; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static sbyte Problem(byte a) + { + object box = a; + Use(ref box); + return (sbyte)box; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static sbyte Problem2(byte a) + { + object box = a; + return (sbyte)box; + } + + static void Use(ref T arg) { } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_71632/Runtime_71632.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_71632/Runtime_71632.csproj new file mode 100644 index 0000000000000..f492aeac9d056 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_71632/Runtime_71632.csproj @@ -0,0 +1,9 @@ + + + Exe + True + + + + + \ No newline at end of file From e888318fbaec39859e2e97ddcb46f36a8a892657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Petryka?= <35800402+MichalPetryka@users.noreply.github.com> Date: Tue, 5 Jul 2022 14:59:07 +0200 Subject: [PATCH 2/4] Handle missing types --- src/coreclr/vm/jitinterface.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 41863af5fe04f..7f7a00288dc06 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -3970,7 +3970,10 @@ CorInfoType CEEInfo::getTypeForPrimitiveValueClass( else { CorElementType elementType = th.GetInternalCorElementType(); - if (elementType >= ELEMENT_TYPE_BOOLEAN && elementType <= ELEMENT_TYPE_R8) + if (elementType >= ELEMENT_TYPE_BOOLEAN && elementType <= ELEMENT_TYPE_R8 + || elementType == ELEMENT_TYPE_I || elementType == ELEMENT_TYPE_U + || elementType == ELEMENT_TYPE_PTR || elementType == ELEMENT_TYPE_FNPTR + || elementType == ELEMENT_TYPE_VOID) { result = asCorInfoType(elementType); } From 4a8b6cba0d40d23b12836505afa8d7185c27e000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Petryka?= <35800402+MichalPetryka@users.noreply.github.com> Date: Tue, 5 Jul 2022 15:21:30 +0200 Subject: [PATCH 3/4] Update jitinterface.cpp --- src/coreclr/vm/jitinterface.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 7f7a00288dc06..bc72e18a61ae4 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -3970,10 +3970,8 @@ CorInfoType CEEInfo::getTypeForPrimitiveValueClass( else { CorElementType elementType = th.GetInternalCorElementType(); - if (elementType >= ELEMENT_TYPE_BOOLEAN && elementType <= ELEMENT_TYPE_R8 - || elementType == ELEMENT_TYPE_I || elementType == ELEMENT_TYPE_U - || elementType == ELEMENT_TYPE_PTR || elementType == ELEMENT_TYPE_FNPTR - || elementType == ELEMENT_TYPE_VOID) + if (CorIsPrimitiveType(elementType) || + elementType == ELEMENT_TYPE_PTR || elementType == ELEMENT_TYPE_FNPTR) { result = asCorInfoType(elementType); } From eca09002384b2babc22f7015bcb1f523d109f42d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Petryka?= <35800402+MichalPetryka@users.noreply.github.com> Date: Tue, 5 Jul 2022 19:37:20 +0200 Subject: [PATCH 4/4] Test removing pointers --- src/coreclr/vm/jitinterface.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index bc72e18a61ae4..29ba345bada96 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -3970,8 +3970,7 @@ CorInfoType CEEInfo::getTypeForPrimitiveValueClass( else { CorElementType elementType = th.GetInternalCorElementType(); - if (CorIsPrimitiveType(elementType) || - elementType == ELEMENT_TYPE_PTR || elementType == ELEMENT_TYPE_FNPTR) + if (CorIsPrimitiveType(elementType)) { result = asCorInfoType(elementType); }