Disallow statics of spans and class instance members of span (#9061)
authorKoundinya Veluri <kouvel@microsoft.com>
Tue, 24 Jan 2017 07:13:26 +0000 (23:13 -0800)
committerJan Kotas <jkotas@microsoft.com>
Tue, 24 Jan 2017 07:13:26 +0000 (23:13 -0800)
Functional fix for #8516 to cover some additional cases. IL tests will be coming later in a separate PR.

src/dlls/mscorrc/mscorrc.rc
src/dlls/mscorrc/resource.h
src/vm/methodtablebuilder.cpp

index be9fb1cfa688395919b4772d933da91eee5e5a9e..138db55b66189281c540c2f84f9da74b0474160b 100644 (file)
@@ -1230,6 +1230,9 @@ BEGIN
     IDS_CLASSLOAD_NOTINTERFACE              "Could not load type '%1' from assembly '%2' because it attempts to implement a class as an interface."
     IDS_CLASSLOAD_VALUEINSTANCEFIELD        "Could not load the value type '%1' from assembly '%2' because it has an instance field of itself."
 
+    IDS_CLASSLOAD_BYREFLIKE_STATICFIELD     "A value type containing a by-ref instance field, such as Span<T>, cannot be used as the type for a static field."
+    IDS_CLASSLOAD_BYREFLIKE_NOTVALUECLASSFIELD "A value type containing a by-ref instance field, such as Span<T>, cannot be used as the type for a class instance field."
+
     IDS_CLASSLOAD_BAD_NAME                  "Type name '%1' from assembly '%2' is invalid."
     IDS_CLASSLOAD_RANK_TOOLARGE             "'%1' from assembly '%2' has too many dimensions."
     IDS_CLASSLOAD_BAD_MANAGED_RVA           "Managed method '%3' on type '%1' from assembly '%2' is not supported."
index 1391a21545648c2371637a01641bd88a257dae87..77e937a81e23ef0a176320a19f5bf4f9cab34435 100644 (file)
 
 #define IDS_NATIVE_IMAGE_CANNOT_BE_LOADED_MULTIPLE_TIMES                               0x263a
 
-
+#define IDS_CLASSLOAD_BYREFLIKE_STATICFIELD        0x263b
+#define IDS_CLASSLOAD_BYREFLIKE_NOTVALUECLASSFIELD 0x263c
index 682268eb39b1ed29d8012f3358f3e87a887fc97d..4a8b0c758f700529ee6dbedb65967143becbd89e 100644 (file)
@@ -4222,6 +4222,17 @@ VOID    MethodTableBuilder::InitializeFieldDescs(FieldDesc *pFieldDescList,
                 // Inherit IsByRefLike characteristic from fields
                 if (!IsSelfRef(pByValueClass) && pByValueClass->IsByRefLike())
                 {
+                    if (fIsStatic)
+                    {
+                        // By-ref-like types cannot be used for static fields
+                        BuildMethodTableThrowException(IDS_CLASSLOAD_BYREFLIKE_STATICFIELD);
+                    }
+                    if (!IsValueClass())
+                    {
+                        // Non-value-classes cannot contain by-ref-like instance fields
+                        BuildMethodTableThrowException(IDS_CLASSLOAD_BYREFLIKE_NOTVALUECLASSFIELD);
+                    }
+
                     bmtFP->fIsByRefLikeType = true;
                 }