Skip to content

Commit 5a2df34

Browse files
author
Sergey Andreenko
authored
Fix JITEEInterface::IsValueClass to return false for pointers. (#50749)
* lets VM return `isValueClass=false` for pointers. * fix assert and add a comment. * fix diffs. * fix crossgen2 part. * Update JITEEVersionIdentifier.
1 parent f9fcb8b commit 5a2df34

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

src/coreclr/inc/jiteeversionguid.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// Note that this file is parsed by some tools, namely superpmi.py, so make sure the first line is exactly
1717
// of the form:
1818
//
19-
// constexpr GUID JITEEVersionIdentifier = { /* a7bb194e-4e7c-4850-af12-ea9f30ea5a13 */
19+
// constexpr GUID JITEEVersionIdentifier = { /* 1776ab48-edfa-49be-a11f-ec216b28174c */
2020
//
2121
// (without the leading slashes or spaces).
2222
//
@@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
4343
#define GUID_DEFINED
4444
#endif // !GUID_DEFINED
4545

46-
constexpr GUID JITEEVersionIdentifier = { /* a1f5e9a1-ee44-42f9-9319-e2a2dbf8c5c9 */
47-
0xa1f5e9a1,
48-
0xee44,
49-
0x42f9,
50-
{0x93, 0x19, 0xe2, 0xa2, 0xdb, 0xf8, 0xc5, 0xc9}
46+
constexpr GUID JITEEVersionIdentifier = { /* 1776ab48-edfa-49be-a11f-ec216b28174c */
47+
0x1776ab48,
48+
0xedfa,
49+
0x49be,
50+
{0xa1, 0x1f, 0xec, 0x21, 0x6b, 0x28, 0x17, 0x4c}
5151
};
5252

5353
//////////////////////////////////////////////////////////////////////////////////////////////////////////

src/coreclr/jit/importer.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16841,9 +16841,10 @@ bool Compiler::impReturnInstruction(int prefixFlags, OPCODE& opcode)
1684116841
impBashVarAddrsToI(op2);
1684216842
op2 = impImplicitIorI4Cast(op2, info.compRetType);
1684316843
op2 = impImplicitR4orR8Cast(op2, info.compRetType);
16844+
// Note that we allow TYP_I_IMPL<->TYP_BYREF transformation, but only TYP_I_IMPL<-TYP_REF.
1684416845
assertImp((genActualType(op2->TypeGet()) == genActualType(info.compRetType)) ||
16845-
((op2->TypeGet() == TYP_I_IMPL) && (info.compRetType == TYP_BYREF)) ||
16846-
((op2->TypeGet() == TYP_BYREF) && (info.compRetType == TYP_I_IMPL)) ||
16846+
((op2->TypeGet() == TYP_I_IMPL) && TypeIs(info.compRetType, TYP_BYREF)) ||
16847+
(op2->TypeIs(TYP_BYREF, TYP_REF) && (info.compRetType == TYP_I_IMPL)) ||
1684716848
(varTypeIsFloating(op2->gtType) && varTypeIsFloating(info.compRetType)) ||
1684816849
(varTypeIsStruct(op2) && varTypeIsStruct(info.compRetType)));
1684916850

@@ -16892,9 +16893,10 @@ bool Compiler::impReturnInstruction(int prefixFlags, OPCODE& opcode)
1689216893

1689316894
if (returnType != originalCallType)
1689416895
{
16895-
// Allow TYP_BYREF to be returned as TYP_I_IMPL and vice versa
16896-
if (((returnType == TYP_BYREF) && (originalCallType == TYP_I_IMPL)) ||
16897-
((returnType == TYP_I_IMPL) && (originalCallType == TYP_BYREF)))
16896+
// Allow TYP_BYREF to be returned as TYP_I_IMPL and vice versa.
16897+
// Allow TYP_REF to be returned as TYP_I_IMPL and NOT vice verse.
16898+
if ((TypeIs(returnType, TYP_BYREF, TYP_REF) && (originalCallType == TYP_I_IMPL)) ||
16899+
((returnType == TYP_I_IMPL) && TypeIs(originalCallType, TYP_BYREF)))
1689816900
{
1689916901
JITDUMP("Allowing return type mismatch: have %s, needed %s\n", varTypeName(returnType),
1690016902
varTypeName(originalCallType));

src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,8 +1580,7 @@ private int appendClassName(char** ppBuf, ref int pnBufLen, CORINFO_CLASS_STRUCT
15801580

15811581
private bool isValueClass(CORINFO_CLASS_STRUCT_* cls)
15821582
{
1583-
TypeDesc type = HandleToObject(cls);
1584-
return type.IsValueType || type.IsPointer || type.IsFunctionPointer;
1583+
return HandleToObject(cls).IsValueType;
15851584
}
15861585

15871586
private CorInfoInlineTypeCheck canInlineTypeCheck(CORINFO_CLASS_STRUCT_* cls, CorInfoInlineTypeCheckSource source)
@@ -1603,10 +1602,6 @@ private uint getClassAttribsInternal(TypeDesc type)
16031602

16041603
CorInfoFlag result = (CorInfoFlag)0;
16051604

1606-
// CoreCLR uses UIntPtr in place of pointers here
1607-
if (type.IsPointer || type.IsFunctionPointer)
1608-
type = _compilation.TypeSystemContext.GetWellKnownType(WellKnownType.UIntPtr);
1609-
16101605
var metadataType = type as MetadataType;
16111606

16121607
// The array flag is used to identify the faked-up methods on

src/coreclr/vm/jitinterface.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3772,11 +3772,7 @@ bool CEEInfo::isValueClass(CORINFO_CLASS_HANDLE clsHnd)
37723772

37733773
_ASSERTE(clsHnd);
37743774

3775-
// Note that clsHnd.IsValueType() would not return what the JIT expects
3776-
// for corner cases like ELEMENT_TYPE_FNPTR
3777-
TypeHandle VMClsHnd(clsHnd);
3778-
MethodTable * pMT = VMClsHnd.GetMethodTable();
3779-
ret = (pMT != NULL) ? pMT->IsValueType() : false;
3775+
ret = TypeHandle(clsHnd).IsValueType();
37803776

37813777
EE_TO_JIT_TRANSITION_LEAF();
37823778

@@ -3888,7 +3884,7 @@ uint32_t CEEInfo::getClassAttribsInternal (CORINFO_CLASS_HANDLE clsHnd)
38883884
if (pMT->HasComponentSize())
38893885
ret |= CORINFO_FLG_VAROBJSIZE;
38903886

3891-
if (pMT->IsValueType())
3887+
if (VMClsHnd.IsValueType())
38923888
{
38933889
ret |= CORINFO_FLG_VALUECLASS;
38943890

0 commit comments

Comments
 (0)