@@ -53,6 +53,7 @@ private static int Main()
5353 TestStaticInterfaceMethod . Run ( ) ;
5454 TestConstrainedCall . Run ( ) ;
5555 TestTypeHandles . Run ( ) ;
56+ TestIndirectLoads . Run ( ) ;
5657#else
5758 Console . WriteLine ( "Preinitialization is disabled in multimodule builds for now. Skipping test." ) ;
5859#endif
@@ -1059,13 +1060,19 @@ static DefaultInstanceAccess()
10591060
10601061 class MoreOperations
10611062 {
1062- public readonly static int Length ;
1063+ public readonly static int IntsLength ;
1064+ public readonly static int StringLength ;
1065+ public readonly static char FirstChar ;
10631066
10641067 private static ReadOnlySpan < int > Ints => new int [ ] { 5 , 6 , 7 , 8 } ;
10651068
1069+ private static ReadOnlySpan < char > GetString ( ) => "Hello World!" ;
1070+
10661071 static MoreOperations ( )
10671072 {
1068- Length = Ints . Length ;
1073+ IntsLength = Ints . Length ;
1074+ StringLength = GetString ( ) . Length ;
1075+ FirstChar = GetString ( ) [ 0 ] ;
10691076 }
10701077 }
10711078
@@ -1083,7 +1090,9 @@ public static void Run()
10831090 DefaultInstanceAccess . Sum . ToString ( ) ; // make sure cctor is looked at
10841091
10851092 Assert . IsPreinitialized ( typeof ( MoreOperations ) ) ;
1086- Assert . AreEqual ( 4 , MoreOperations . Length ) ;
1093+ Assert . AreEqual ( 4 , MoreOperations . IntsLength ) ;
1094+ Assert . AreEqual ( 12 , MoreOperations . StringLength ) ;
1095+ Assert . AreEqual ( 'H' , MoreOperations . FirstChar ) ;
10871096 }
10881097}
10891098
@@ -1192,6 +1201,28 @@ public static void Run()
11921201 }
11931202}
11941203
1204+ class TestIndirectLoads
1205+ {
1206+ static unsafe U Read < T , U > ( T val ) where T : unmanaged where U : unmanaged
1207+ => * ( U * ) & val ;
1208+
1209+ class LdindTester
1210+ {
1211+ public static sbyte SByte = Read < byte , sbyte > ( byte . MaxValue ) ;
1212+ public static short Short = Read < ushort , short > ( ushort . MaxValue ) ;
1213+ public static int Int = Read < uint , int > ( uint . MaxValue ) ;
1214+ public static long Long = Read < ulong , long > ( ulong . MaxValue ) ;
1215+ }
1216+
1217+ public static void Run ( )
1218+ {
1219+ Assert . IsPreinitialized ( typeof ( LdindTester ) ) ;
1220+ Assert . AreEqual ( - 1 , LdindTester . SByte ) ;
1221+ Assert . AreEqual ( - 1 , LdindTester . Short ) ;
1222+ Assert . AreEqual ( - 1 , LdindTester . Int ) ;
1223+ Assert . AreEqual ( - 1 , LdindTester . Long ) ;
1224+ }
1225+ }
11951226
11961227static class Assert
11971228{
0 commit comments