Skip to content

Commit

Permalink
Make getTypeForPrimitiveValueClass treat different signs as different…
Browse files Browse the repository at this point in the history
… types (#71633)

* Make getTypeForPrimitiveValueClass treat different sizes as different types

* Handle missing types

* Update jitinterface.cpp

* Test removing pointers
  • Loading branch information
MichalPetryka authored Jul 5, 2022
1 parent 2dc6b46 commit 874043b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 50 deletions.
56 changes: 6 additions & 50 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3969,54 +3969,10 @@ CorInfoType CEEInfo::getTypeForPrimitiveValueClass(
}
else
{
switch (th.GetInternalCorElementType())
CorElementType elementType = th.GetInternalCorElementType();
if (CorIsPrimitiveType(elementType))
{
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);
}
}

Expand Down Expand Up @@ -13938,7 +13894,7 @@ BOOL LoadDynamicInfoEntry(Module *currentModule,
{
DWORD dwBlobSize = CorSigUncompressData(pBlob);
const uint8_t *const pBlobStart = pBlob;
pBlob += dwBlobSize;
pBlob += dwBlobSize;
StackSArray<TypeHandle> types;
DWORD cTypes = CorSigUncompressData(pBlob);
bool fail = false;
Expand All @@ -13965,7 +13921,7 @@ BOOL LoadDynamicInfoEntry(Module *currentModule,
}

MethodDesc *pMDCompare = NULL;

if (!fail)
{
if (kind == ENCODE_CHECK_IL_BODY)
Expand Down Expand Up @@ -13995,7 +13951,7 @@ BOOL LoadDynamicInfoEntry(Module *currentModule,

fail = fail || (pMethodMetadata->cByteData != dwBlobSize);
}

if (!fail)
{
fail = 0 != memcmp(pBlobStart, pMethodMetadata->pByteData, dwBlobSize);
Expand Down
45 changes: 45 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_71632/Runtime_71632.cs
Original file line number Diff line number Diff line change
@@ -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<T>(ref T arg) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit 874043b

Please sign in to comment.