From: Koundinya Veluri Date: Tue, 7 Feb 2017 20:58:51 +0000 (-0800) Subject: Fix field type for ByReference and TypedReference (#9284) X-Git-Tag: accepted/tizen/base/20180629.140029~2337 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3c34cce7187e44c024331ad6267c6507034e48bd;p=platform%2Fupstream%2Fcoreclr.git Fix field type for ByReference and TypedReference (#9284) Fix field type for `ByReference` and `TypedReference` Fixes #7894 --- diff --git a/src/jit/lclvars.cpp b/src/jit/lclvars.cpp index cef861e..b4e4cc6 100644 --- a/src/jit/lclvars.cpp +++ b/src/jit/lclvars.cpp @@ -1591,8 +1591,10 @@ void Compiler::lvaCanPromoteStructType(CORINFO_CLASS_HANDLE typeHnd, #endif // _TARGET_ARM_ } - // If we saw any GC pointer fields above then the CORINFO_FLG_CONTAINS_GC_PTR has to be set! - noway_assert((containsGCpointers == false) || ((typeFlags & CORINFO_FLG_CONTAINS_GC_PTR) != 0)); + // If we saw any GC pointer or by-ref fields above then CORINFO_FLG_CONTAINS_GC_PTR or + // CORINFO_FLG_CONTAINS_STACK_PTR has to be set! + noway_assert((containsGCpointers == false) || + ((typeFlags & (CORINFO_FLG_CONTAINS_GC_PTR | CORINFO_FLG_CONTAINS_STACK_PTR)) != 0)); // If we have "Custom Layout" then we might have an explicit Size attribute // Managed C++ uses this for its structs, such C++ types will not contain GC pointers. diff --git a/src/mscorlib/src/System/ReadOnlySpan.cs b/src/mscorlib/src/System/ReadOnlySpan.cs index e67cc30..797eeea 100644 --- a/src/mscorlib/src/System/ReadOnlySpan.cs +++ b/src/mscorlib/src/System/ReadOnlySpan.cs @@ -281,7 +281,6 @@ namespace System /// /// Thrown when the specified index is not in range (<0 or >=Length). /// - [MethodImpl(MethodImplOptions.NoOptimization)] // TODO-SPAN: Workaround for https://github.com/dotnet/coreclr/issues/7894 public ReadOnlySpan Slice(int start) { if ((uint)start > (uint)_length) @@ -298,7 +297,6 @@ namespace System /// /// Thrown when the specified or end index is not in range (<0 or >=Length). /// - [MethodImpl(MethodImplOptions.NoOptimization)] // TODO-SPAN: Workaround for https://github.com/dotnet/coreclr/issues/7894 public ReadOnlySpan Slice(int start, int length) { if ((uint)start > (uint)_length || (uint)length > (uint)(_length - start)) diff --git a/src/mscorlib/src/System/Span.cs b/src/mscorlib/src/System/Span.cs index 5f6a7ae..31b788a 100644 --- a/src/mscorlib/src/System/Span.cs +++ b/src/mscorlib/src/System/Span.cs @@ -218,7 +218,6 @@ namespace System // Until we get over the hurdle of C# 7 tooling, this temporary method will simulate the intended "ref T" indexer for those // who need bypass the workaround for performance. //[MethodImpl(MethodImplOptions.AggressiveInlining)] - [MethodImpl(MethodImplOptions.NoOptimization)] // TODO-SPAN: Workaround for https://github.com/dotnet/coreclr/issues/7894 public ref T GetItem(int index) { if ((uint)index >= ((uint)_length)) @@ -350,7 +349,6 @@ namespace System /// /// Thrown when the specified index is not in range (<0 or >=Length). /// - [MethodImpl(MethodImplOptions.NoOptimization)] // TODO-SPAN: Workaround for https://github.com/dotnet/coreclr/issues/7894 public Span Slice(int start) { if ((uint)start > (uint)_length) @@ -367,7 +365,6 @@ namespace System /// /// Thrown when the specified or end index is not in range (<0 or >=Length). /// - [MethodImpl(MethodImplOptions.NoOptimization)] // TODO-SPAN: Workaround for https://github.com/dotnet/coreclr/issues/7894 public Span Slice(int start, int length) { if ((uint)start > (uint)_length || (uint)length > (uint)(_length - start)) diff --git a/src/vm/jitinterface.cpp b/src/vm/jitinterface.cpp index 77c572a..d80b60e 100644 --- a/src/vm/jitinterface.cpp +++ b/src/vm/jitinterface.cpp @@ -9105,10 +9105,15 @@ CorInfoType CEEInfo::getFieldTypeInternal (CORINFO_FIELD_HANDLE fieldHnd, // TODO should not burn the time to do this for anything but Value Classes _ASSERTE(type != ELEMENT_TYPE_BYREF); - // For verifying code involving generics, use the class instantiation - // of the optional owner (to provide exact, not representative, - // type information) - SigTypeContext typeContext(field, (TypeHandle) owner); + if (type == ELEMENT_TYPE_I) + { + PTR_MethodTable enclosingMethodTable = field->GetApproxEnclosingMethodTable(); + if (enclosingMethodTable->IsByRefLike() && enclosingMethodTable->HasSameTypeDefAs(g_pByReferenceClass)) + { + _ASSERTE(field->GetOffset() == 0); + return CORINFO_TYPE_BYREF; + } + } if (!CorTypeInfo::IsPrimitiveType(type)) { @@ -9118,11 +9123,16 @@ CorInfoType CEEInfo::getFieldTypeInternal (CORINFO_FIELD_HANDLE fieldHnd, field->GetSig(&sig, &sigCount); - conv = (CorCallingConvention) CorSigUncompressCallingConv(sig); + conv = (CorCallingConvention)CorSigUncompressCallingConv(sig); _ASSERTE(isCallConv(conv, IMAGE_CEE_CS_CALLCONV_FIELD)); SigPointer ptr(sig, sigCount); + // For verifying code involving generics, use the class instantiation + // of the optional owner (to provide exact, not representative, + // type information) + SigTypeContext typeContext(field, (TypeHandle)owner); + clsHnd = ptr.GetTypeHandleThrowing(field->GetModule(), &typeContext); _ASSERTE(!clsHnd.IsNull());