From 94cd8916094c894bdaf8b5d884dbf9e4e25698e8 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 23 Feb 2019 23:01:35 +0100 Subject: [PATCH] Add support for ReadOnlySpan initialization pattern. --- .../TestCases/Pretty/InitializerTests.cs | 18 ++ .../Pretty/InitializerTests.opt.roslyn.il | 191 ++++++++++++------ .../Pretty/InitializerTests.roslyn.il | 191 ++++++++++++------ .../IL/Transforms/ExpressionTransforms.cs | 10 +- .../Transforms/TransformArrayInitializers.cs | 83 +++++--- 5 files changed, 355 insertions(+), 138 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs index 66d4a5ad8..13416aaf1 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs @@ -430,6 +430,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests 1 } }; + +#if ROSLYN + public static ReadOnlySpan StaticData1 => new byte[1] { + 0 + }; + + public static ReadOnlySpan StaticData3 => new byte[3] { + 1, + 2, + 3 + }; + + public static Span StaticData3Span => new byte[3] { + 1, + 2, + 3 + }; +#endif #endregion #region Helper methods used to ensure initializers used within expressions work correctly diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il index 286d091ff..c94033131 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il @@ -8,6 +8,11 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } +.assembly extern System.Memory +{ + .publickeytoken = (CC 7B 13 FF CD 2D DD 51 ) // .{...-.Q + .ver 4:0:1:0 +} .assembly extern System.Core { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. @@ -1200,8 +1205,8 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c' '<>9' - .field public static class [mscorlib]System.EventHandler '<>9__65_0' - .field public static class [mscorlib]System.Func`2 '<>9__79_0' + .field public static class [mscorlib]System.EventHandler '<>9__71_0' + .field public static class [mscorlib]System.Func`2 '<>9__85_0' .method private hidebysig specialname rtspecialname static void .cctor() cil managed { @@ -1223,17 +1228,17 @@ } // end of method '<>c'::.ctor .method assembly hidebysig instance void - 'b__65_0'(object '', + 'b__71_0'(object '', class [mscorlib]System.EventArgs '') cil managed { // Code size 6 (0x6) .maxstack 8 IL_0000: call void [mscorlib]System.Console::WriteLine() IL_0005: ret - } // end of method '<>c'::'b__65_0' + } // end of method '<>c'::'b__71_0' .method assembly hidebysig instance bool - 'b__79_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed + 'b__85_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed { // Code size 17 (0x11) .maxstack 8 @@ -1243,7 +1248,7 @@ IL_000b: call bool [mscorlib]System.String::op_Equality(string, string) IL_0010: ret - } // end of method '<>c'::'b__79_0' + } // end of method '<>c'::'b__85_0' } // end of class '<>c' @@ -1253,6 +1258,48 @@ .field private static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/V3f[][0...,0...] Issue1336_rg1c .field private static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/V3f[0...,0...][] Issue1336_rg1d .field private static int32[0...,0...] Issue1336_rg2 + .method public hidebysig specialname static + valuetype [System.Memory]System.ReadOnlySpan`1 + get_StaticData1() cil managed + { + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldsflda uint8 ''::'5BA93C9DB0CFF93F52B521D7420E43F6EDA2784F' + IL_0005: ldc.i4.1 + IL_0006: newobj instance void valuetype [System.Memory]System.ReadOnlySpan`1::.ctor(void*, + int32) + IL_000b: ret + } // end of method TestCases::get_StaticData1 + + .method public hidebysig specialname static + valuetype [System.Memory]System.ReadOnlySpan`1 + get_StaticData3() cil managed + { + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldsflda valuetype ''/'__StaticArrayInitTypeSize=3' ''::'7037807198C22A7D2B0807371D763779A84FDFCF' + IL_0005: ldc.i4.3 + IL_0006: newobj instance void valuetype [System.Memory]System.ReadOnlySpan`1::.ctor(void*, + int32) + IL_000b: ret + } // end of method TestCases::get_StaticData3 + + .method public hidebysig specialname static + valuetype [System.Memory]System.Span`1 + get_StaticData3Span() cil managed + { + // Code size 23 (0x17) + .maxstack 8 + IL_0000: ldc.i4.3 + IL_0001: newarr [mscorlib]System.Byte + IL_0006: dup + IL_0007: ldtoken field valuetype ''/'__StaticArrayInitTypeSize=3' ''::'7037807198C22A7D2B0807371D763779A84FDFCF' + IL_000c: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array, + valuetype [mscorlib]System.RuntimeFieldHandle) + IL_0011: call valuetype [System.Memory]System.Span`1 valuetype [System.Memory]System.Span`1::op_Implicit(!0[]) + IL_0016: ret + } // end of method TestCases::get_StaticData3Span + .method private hidebysig static void X(object a, object b) cil managed { @@ -2507,18 +2554,18 @@ IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::.ctor() IL_0005: stloc.0 IL_0006: ldloc.0 - IL_0007: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__65_0' + IL_0007: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__71_0' IL_000c: dup IL_000d: brtrue.s IL_0026 IL_000f: pop IL_0010: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9' - IL_0015: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'b__65_0'(object, + IL_0015: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'b__71_0'(object, class [mscorlib]System.EventArgs) IL_001b: newobj instance void [mscorlib]System.EventHandler::.ctor(object, native int) IL_0020: dup - IL_0021: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__65_0' + IL_0021: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__71_0' IL_0026: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::add_TestEvent(class [mscorlib]System.EventHandler) IL_002b: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Y() IL_0030: ldloc.0 @@ -2855,17 +2902,17 @@ IL_0033: callvirt instance void [mscorlib]System.Globalization.CultureInfo::set_DateTimeFormat(class [mscorlib]System.Globalization.DateTimeFormatInfo) IL_0038: dup IL_0039: ldloc.0 - IL_003a: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__79_0' + IL_003a: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__85_0' IL_003f: dup IL_0040: brtrue.s IL_0059 IL_0042: pop IL_0043: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9' - IL_0048: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'b__79_0'(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_0048: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'b__85_0'(class [mscorlib]System.Globalization.NumberFormatInfo) IL_004e: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) IL_0053: dup - IL_0054: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__79_0' + IL_0054: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__85_0' IL_0059: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, class [mscorlib]System.Func`2) IL_005e: call !!0 [System.Core]System.Linq.Enumerable::First(class [mscorlib]System.Collections.Generic.IEnumerable`1) @@ -4235,12 +4282,34 @@ IL_0772: ret } // end of method TestCases::.cctor + .property valuetype [System.Memory]System.ReadOnlySpan`1 + StaticData1() + { + .get valuetype [System.Memory]System.ReadOnlySpan`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::get_StaticData1() + } // end of property TestCases::StaticData1 + .property valuetype [System.Memory]System.ReadOnlySpan`1 + StaticData3() + { + .get valuetype [System.Memory]System.ReadOnlySpan`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::get_StaticData3() + } // end of property TestCases::StaticData3 + .property valuetype [System.Memory]System.Span`1 + StaticData3Span() + { + .get valuetype [System.Memory]System.Span`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::get_StaticData3Span() + } // end of property TestCases::StaticData3Span } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases .class private auto ansi sealed '' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .class explicit ansi sealed nested private '__StaticArrayInitTypeSize=3' + extends [mscorlib]System.ValueType + { + .pack 1 + .size 3 + } // end of class '__StaticArrayInitTypeSize=3' + .class explicit ansi sealed nested private '__StaticArrayInitTypeSize=10' extends [mscorlib]System.ValueType { @@ -4311,68 +4380,76 @@ .size 256 } // end of class '__StaticArrayInitTypeSize=256' - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=72' '1535117EC92E41D4A6B7CA00F965357B05B5DC35' at I_00007040 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=10' '20E3FF489634E18F3F7EB292AD504DBAE9519293' at I_00007088 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=72' '39E94835525CF7B71CD4595742EF462642FBF1B2' at I_00007098 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=10' '56D9EEC8EF899644C40B9BE9D886DF2367A5D078' at I_000070E0 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=12' '735E5A21849E86F68D220F06163E8C5C6376B9C9' at I_000070F0 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=64' '7C39B7B06DD624A17F875AB8E9651554BE6E74D2' at I_00007100 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' '8D903ECAD8D9D75B3183B23AF79F6D2E607369E3' at I_00007140 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=80' '9B1F6E56D755443CC39C1969CE38FD41FD4EF4B7' at I_00007168 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=256' A1EA7DC3FE43B3A54F5B729A92B92AF54181A3EB at I_000071B8 - .field static assembly initonly int64 A6296CAC471BE2954899600137940479D8073C7C at I_000072B8 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=36' B62E59D20E3D69F06A6D9BD5E3C518FF7093EDAB at I_000072C0 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' B9583930B842DBCEF0D7B8E57D4D3F1E8055C39E at I_000072E8 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=24' C4E70AB31EF6C8908F896CAD1C6BC75F7FA65E27 at I_00007310 - .field static assembly initonly int32 C62C27924F4C967F5EDDB1850C091D54C7A2AB58 at I_00007328 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=48' DC7043B0114737ACE19A23DD755893795FD48A23 at I_00007330 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=64' DCF557B883E6FE0AEC05B7F0290F0EF47D0AC2E3 at I_00007360 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_000073A0 - .field static assembly initonly int64 EB0715DBB235F3F696F2C404F5839C6650640898 at I_000073C8 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' F514FF55B79BCAA2CEC9B56C062D976E45F89AB7 at I_000073D0 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=24' FBCB49C1A244C1B5781AA1DB02C5A11F68908526 at I_000073F8 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=72' '1535117EC92E41D4A6B7CA00F965357B05B5DC35' at I_00007240 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=10' '20E3FF489634E18F3F7EB292AD504DBAE9519293' at I_00007288 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=72' '39E94835525CF7B71CD4595742EF462642FBF1B2' at I_00007298 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=10' '56D9EEC8EF899644C40B9BE9D886DF2367A5D078' at I_000072E0 + .field static assembly initonly uint8 '5BA93C9DB0CFF93F52B521D7420E43F6EDA2784F' at I_000072F0 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=3' '7037807198C22A7D2B0807371D763779A84FDFCF' at I_000072F8 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=12' '735E5A21849E86F68D220F06163E8C5C6376B9C9' at I_00007300 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=64' '7C39B7B06DD624A17F875AB8E9651554BE6E74D2' at I_00007310 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' '8D903ECAD8D9D75B3183B23AF79F6D2E607369E3' at I_00007350 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=80' '9B1F6E56D755443CC39C1969CE38FD41FD4EF4B7' at I_00007378 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=256' A1EA7DC3FE43B3A54F5B729A92B92AF54181A3EB at I_000073C8 + .field static assembly initonly int64 A6296CAC471BE2954899600137940479D8073C7C at I_000074C8 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=36' B62E59D20E3D69F06A6D9BD5E3C518FF7093EDAB at I_000074D0 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' B9583930B842DBCEF0D7B8E57D4D3F1E8055C39E at I_000074F8 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=24' C4E70AB31EF6C8908F896CAD1C6BC75F7FA65E27 at I_00007520 + .field static assembly initonly int32 C62C27924F4C967F5EDDB1850C091D54C7A2AB58 at I_00007538 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=48' DC7043B0114737ACE19A23DD755893795FD48A23 at I_00007540 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=64' DCF557B883E6FE0AEC05B7F0290F0EF47D0AC2E3 at I_00007570 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_000075B0 + .field static assembly initonly int64 EB0715DBB235F3F696F2C404F5839C6650640898 at I_000075D8 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' F514FF55B79BCAA2CEC9B56C062D976E45F89AB7 at I_000075E0 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=24' FBCB49C1A244C1B5781AA1DB02C5A11F68908526 at I_00007608 } // end of class '' // ============================================================= -.data cil I_00007040 = bytearray ( +.data cil I_00007240 = bytearray ( 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 09 00 00 00 0B 00 00 00 0C 00 00 00 0D 00 00 00 0E 00 00 00 0F 00 00 00 10 00 00 00 11 00 00 00 12 00 00 00 13 00 00 00) -.data cil I_00007088 = bytearray ( +.data cil I_00007288 = bytearray ( 01 02 03 04 05 06 07 08 FE FF) -.data cil I_00007092 = int8[6] -.data cil I_00007098 = bytearray ( +.data cil I_00007292 = int8[6] +.data cil I_00007298 = bytearray ( 15 00 00 00 16 00 00 00 17 00 00 00 18 00 00 00 19 00 00 00 1A 00 00 00 1B 00 00 00 1C 00 00 00 1D 00 00 00 1F 00 00 00 20 00 00 00 21 00 00 00 // ........ ...!... 22 00 00 00 23 00 00 00 24 00 00 00 25 00 00 00 // "...#...$...%... 26 00 00 00 27 00 00 00) // &...'... -.data cil I_000070E0 = bytearray ( +.data cil I_000072E0 = bytearray ( 00 80 FF FF 00 00 01 00 FF 7F) -.data cil I_000070EA = int8[6] -.data cil I_000070F0 = bytearray ( +.data cil I_000072EA = int8[6] +.data cil I_000072F0 = bytearray ( + 00) +.data cil I_000072F1 = int8[7] +.data cil I_000072F8 = bytearray ( + 01 02 03) +.data cil I_000072FB = int8[5] +.data cil I_00007300 = bytearray ( 00 00 01 00 FF 7F 00 80 FE FF FF FF) -.data cil I_000070FC = int8[4] -.data cil I_00007100 = bytearray ( +.data cil I_0000730C = int8[4] +.data cil I_00007310 = bytearray ( 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00) -.data cil I_00007140 = bytearray ( +.data cil I_00007350 = bytearray ( 01 00 0C BB 7D 6E 9C BA FF FF FF FF FF FF FF FF // ....}n.......... 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 FF FF F3 44 82 91 63 45) // ...D..cE -.data cil I_00007168 = bytearray ( +.data cil I_00007378 = bytearray ( 01 00 00 00 00 00 00 00 00 94 35 77 00 00 00 00 // ..........5w.... 00 5E D0 B2 00 00 00 00 04 00 00 00 00 00 00 00 // .^.............. 05 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 FF FF F3 44 82 91 63 45 FF FF E7 89 04 23 C7 8A) // ...D..cE.....#.. -.data cil I_000071B8 = bytearray ( +.data cil I_000073C8 = bytearray ( 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 @@ -4389,43 +4466,43 @@ 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00) -.data cil I_000072B8 = bytearray ( +.data cil I_000074C8 = bytearray ( 80 81 00 01 02 03 04 7F) -.data cil I_000072C0 = bytearray ( +.data cil I_000074D0 = bytearray ( 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00) -.data cil I_000072E4 = int8[4] -.data cil I_000072E8 = bytearray ( +.data cil I_000074F4 = int8[4] +.data cil I_000074F8 = bytearray ( 01 00 00 00 00 94 35 77 00 5E D0 B2 04 00 00 00 // ......5w.^...... 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 09 00 00 00 0A 00 00 00) -.data cil I_00007310 = bytearray ( +.data cil I_00007520 = bytearray ( 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 06 00 00 00) -.data cil I_00007328 = bytearray ( +.data cil I_00007538 = bytearray ( 00 01 02 FF) -.data cil I_0000732C = int8[4] -.data cil I_00007330 = bytearray ( +.data cil I_0000753C = int8[4] +.data cil I_00007540 = bytearray ( 00 00 00 00 00 00 F8 BF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F8 3F 00 00 00 00 00 00 F0 FF // .......?........ 00 00 00 00 00 00 F0 7F 00 00 00 00 00 00 F8 FF) -.data cil I_00007360 = bytearray ( +.data cil I_00007570 = bytearray ( 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00) -.data cil I_000073A0 = bytearray ( +.data cil I_000075B0 = bytearray ( 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 09 00 00 00 0A 00 00 00) -.data cil I_000073C8 = bytearray ( +.data cil I_000075D8 = bytearray ( 01 00 01 00 00 00 01 01) -.data cil I_000073D0 = bytearray ( +.data cil I_000075E0 = bytearray ( 01 00 00 00 FE FF FF FF 00 94 35 77 04 00 00 00 // ..........5w.... 05 00 00 00 FA FF FF FF 07 00 00 00 08 00 00 00 09 00 00 00 0A 00 00 00) -.data cil I_000073F8 = bytearray ( +.data cil I_00007608 = bytearray ( 00 00 C0 BF 00 00 00 00 00 00 C0 3F 00 00 80 FF // ...........?.... 00 00 80 7F 00 00 C0 FF) // *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il index 48e0576a1..18cf7a72f 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il @@ -8,6 +8,11 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } +.assembly extern System.Memory +{ + .publickeytoken = (CC 7B 13 FF CD 2D DD 51 ) // .{...-.Q + .ver 4:0:1:0 +} .assembly extern System.Core { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. @@ -1270,8 +1275,8 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c' '<>9' - .field public static class [mscorlib]System.EventHandler '<>9__65_0' - .field public static class [mscorlib]System.Func`2 '<>9__79_0' + .field public static class [mscorlib]System.EventHandler '<>9__71_0' + .field public static class [mscorlib]System.Func`2 '<>9__85_0' .method private hidebysig specialname rtspecialname static void .cctor() cil managed { @@ -1294,7 +1299,7 @@ } // end of method '<>c'::.ctor .method assembly hidebysig instance void - 'b__65_0'(object '', + 'b__71_0'(object '', class [mscorlib]System.EventArgs '') cil managed { // Code size 8 (0x8) @@ -1303,10 +1308,10 @@ IL_0001: call void [mscorlib]System.Console::WriteLine() IL_0006: nop IL_0007: ret - } // end of method '<>c'::'b__65_0' + } // end of method '<>c'::'b__71_0' .method assembly hidebysig instance bool - 'b__79_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed + 'b__85_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed { // Code size 17 (0x11) .maxstack 8 @@ -1316,7 +1321,7 @@ IL_000b: call bool [mscorlib]System.String::op_Equality(string, string) IL_0010: ret - } // end of method '<>c'::'b__79_0' + } // end of method '<>c'::'b__85_0' } // end of class '<>c' @@ -1326,6 +1331,48 @@ .field private static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/V3f[][0...,0...] Issue1336_rg1c .field private static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/V3f[0...,0...][] Issue1336_rg1d .field private static int32[0...,0...] Issue1336_rg2 + .method public hidebysig specialname static + valuetype [System.Memory]System.ReadOnlySpan`1 + get_StaticData1() cil managed + { + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldsflda uint8 ''::'5BA93C9DB0CFF93F52B521D7420E43F6EDA2784F' + IL_0005: ldc.i4.1 + IL_0006: newobj instance void valuetype [System.Memory]System.ReadOnlySpan`1::.ctor(void*, + int32) + IL_000b: ret + } // end of method TestCases::get_StaticData1 + + .method public hidebysig specialname static + valuetype [System.Memory]System.ReadOnlySpan`1 + get_StaticData3() cil managed + { + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldsflda valuetype ''/'__StaticArrayInitTypeSize=3' ''::'7037807198C22A7D2B0807371D763779A84FDFCF' + IL_0005: ldc.i4.3 + IL_0006: newobj instance void valuetype [System.Memory]System.ReadOnlySpan`1::.ctor(void*, + int32) + IL_000b: ret + } // end of method TestCases::get_StaticData3 + + .method public hidebysig specialname static + valuetype [System.Memory]System.Span`1 + get_StaticData3Span() cil managed + { + // Code size 23 (0x17) + .maxstack 8 + IL_0000: ldc.i4.3 + IL_0001: newarr [mscorlib]System.Byte + IL_0006: dup + IL_0007: ldtoken field valuetype ''/'__StaticArrayInitTypeSize=3' ''::'7037807198C22A7D2B0807371D763779A84FDFCF' + IL_000c: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array, + valuetype [mscorlib]System.RuntimeFieldHandle) + IL_0011: call valuetype [System.Memory]System.Span`1 valuetype [System.Memory]System.Span`1::op_Implicit(!0[]) + IL_0016: ret + } // end of method TestCases::get_StaticData3Span + .method private hidebysig static void X(object a, object b) cil managed { @@ -2760,18 +2807,18 @@ IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::.ctor() IL_0006: stloc.0 IL_0007: ldloc.0 - IL_0008: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__65_0' + IL_0008: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__71_0' IL_000d: dup IL_000e: brtrue.s IL_0027 IL_0010: pop IL_0011: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9' - IL_0016: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'b__65_0'(object, + IL_0016: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'b__71_0'(object, class [mscorlib]System.EventArgs) IL_001c: newobj instance void [mscorlib]System.EventHandler::.ctor(object, native int) IL_0021: dup - IL_0022: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__65_0' + IL_0022: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__71_0' IL_0027: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::add_TestEvent(class [mscorlib]System.EventHandler) IL_002c: nop IL_002d: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Y() @@ -3171,17 +3218,17 @@ IL_003b: nop IL_003c: dup IL_003d: ldloc.0 - IL_003e: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__79_0' + IL_003e: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__85_0' IL_0043: dup IL_0044: brtrue.s IL_005d IL_0046: pop IL_0047: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9' - IL_004c: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'b__79_0'(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_004c: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'b__85_0'(class [mscorlib]System.Globalization.NumberFormatInfo) IL_0052: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) IL_0057: dup - IL_0058: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__79_0' + IL_0058: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__85_0' IL_005d: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, class [mscorlib]System.Func`2) IL_0062: call !!0 [System.Core]System.Linq.Enumerable::First(class [mscorlib]System.Collections.Generic.IEnumerable`1) @@ -4699,12 +4746,34 @@ IL_0772: ret } // end of method TestCases::.cctor + .property valuetype [System.Memory]System.ReadOnlySpan`1 + StaticData1() + { + .get valuetype [System.Memory]System.ReadOnlySpan`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::get_StaticData1() + } // end of property TestCases::StaticData1 + .property valuetype [System.Memory]System.ReadOnlySpan`1 + StaticData3() + { + .get valuetype [System.Memory]System.ReadOnlySpan`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::get_StaticData3() + } // end of property TestCases::StaticData3 + .property valuetype [System.Memory]System.Span`1 + StaticData3Span() + { + .get valuetype [System.Memory]System.Span`1 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::get_StaticData3Span() + } // end of property TestCases::StaticData3Span } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases .class private auto ansi sealed '' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .class explicit ansi sealed nested private '__StaticArrayInitTypeSize=3' + extends [mscorlib]System.ValueType + { + .pack 1 + .size 3 + } // end of class '__StaticArrayInitTypeSize=3' + .class explicit ansi sealed nested private '__StaticArrayInitTypeSize=10' extends [mscorlib]System.ValueType { @@ -4775,68 +4844,76 @@ .size 256 } // end of class '__StaticArrayInitTypeSize=256' - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=72' '1535117EC92E41D4A6B7CA00F965357B05B5DC35' at I_00007480 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=10' '20E3FF489634E18F3F7EB292AD504DBAE9519293' at I_000074C8 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=72' '39E94835525CF7B71CD4595742EF462642FBF1B2' at I_000074D8 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=10' '56D9EEC8EF899644C40B9BE9D886DF2367A5D078' at I_00007520 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=12' '735E5A21849E86F68D220F06163E8C5C6376B9C9' at I_00007530 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=64' '7C39B7B06DD624A17F875AB8E9651554BE6E74D2' at I_00007540 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' '8D903ECAD8D9D75B3183B23AF79F6D2E607369E3' at I_00007580 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=80' '9B1F6E56D755443CC39C1969CE38FD41FD4EF4B7' at I_000075A8 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=256' A1EA7DC3FE43B3A54F5B729A92B92AF54181A3EB at I_000075F8 - .field static assembly initonly int64 A6296CAC471BE2954899600137940479D8073C7C at I_000076F8 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=36' B62E59D20E3D69F06A6D9BD5E3C518FF7093EDAB at I_00007700 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' B9583930B842DBCEF0D7B8E57D4D3F1E8055C39E at I_00007728 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=24' C4E70AB31EF6C8908F896CAD1C6BC75F7FA65E27 at I_00007750 - .field static assembly initonly int32 C62C27924F4C967F5EDDB1850C091D54C7A2AB58 at I_00007768 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=48' DC7043B0114737ACE19A23DD755893795FD48A23 at I_00007770 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=64' DCF557B883E6FE0AEC05B7F0290F0EF47D0AC2E3 at I_000077A0 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_000077E0 - .field static assembly initonly int64 EB0715DBB235F3F696F2C404F5839C6650640898 at I_00007808 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' F514FF55B79BCAA2CEC9B56C062D976E45F89AB7 at I_00007810 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=24' FBCB49C1A244C1B5781AA1DB02C5A11F68908526 at I_00007838 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=72' '1535117EC92E41D4A6B7CA00F965357B05B5DC35' at I_00007680 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=10' '20E3FF489634E18F3F7EB292AD504DBAE9519293' at I_000076C8 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=72' '39E94835525CF7B71CD4595742EF462642FBF1B2' at I_000076D8 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=10' '56D9EEC8EF899644C40B9BE9D886DF2367A5D078' at I_00007720 + .field static assembly initonly uint8 '5BA93C9DB0CFF93F52B521D7420E43F6EDA2784F' at I_00007730 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=3' '7037807198C22A7D2B0807371D763779A84FDFCF' at I_00007738 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=12' '735E5A21849E86F68D220F06163E8C5C6376B9C9' at I_00007740 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=64' '7C39B7B06DD624A17F875AB8E9651554BE6E74D2' at I_00007750 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' '8D903ECAD8D9D75B3183B23AF79F6D2E607369E3' at I_00007790 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=80' '9B1F6E56D755443CC39C1969CE38FD41FD4EF4B7' at I_000077B8 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=256' A1EA7DC3FE43B3A54F5B729A92B92AF54181A3EB at I_00007808 + .field static assembly initonly int64 A6296CAC471BE2954899600137940479D8073C7C at I_00007908 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=36' B62E59D20E3D69F06A6D9BD5E3C518FF7093EDAB at I_00007910 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' B9583930B842DBCEF0D7B8E57D4D3F1E8055C39E at I_00007938 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=24' C4E70AB31EF6C8908F896CAD1C6BC75F7FA65E27 at I_00007960 + .field static assembly initonly int32 C62C27924F4C967F5EDDB1850C091D54C7A2AB58 at I_00007978 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=48' DC7043B0114737ACE19A23DD755893795FD48A23 at I_00007980 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=64' DCF557B883E6FE0AEC05B7F0290F0EF47D0AC2E3 at I_000079B0 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_000079F0 + .field static assembly initonly int64 EB0715DBB235F3F696F2C404F5839C6650640898 at I_00007A18 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=40' F514FF55B79BCAA2CEC9B56C062D976E45F89AB7 at I_00007A20 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=24' FBCB49C1A244C1B5781AA1DB02C5A11F68908526 at I_00007A48 } // end of class '' // ============================================================= -.data cil I_00007480 = bytearray ( +.data cil I_00007680 = bytearray ( 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 09 00 00 00 0B 00 00 00 0C 00 00 00 0D 00 00 00 0E 00 00 00 0F 00 00 00 10 00 00 00 11 00 00 00 12 00 00 00 13 00 00 00) -.data cil I_000074C8 = bytearray ( +.data cil I_000076C8 = bytearray ( 01 02 03 04 05 06 07 08 FE FF) -.data cil I_000074D2 = int8[6] -.data cil I_000074D8 = bytearray ( +.data cil I_000076D2 = int8[6] +.data cil I_000076D8 = bytearray ( 15 00 00 00 16 00 00 00 17 00 00 00 18 00 00 00 19 00 00 00 1A 00 00 00 1B 00 00 00 1C 00 00 00 1D 00 00 00 1F 00 00 00 20 00 00 00 21 00 00 00 // ........ ...!... 22 00 00 00 23 00 00 00 24 00 00 00 25 00 00 00 // "...#...$...%... 26 00 00 00 27 00 00 00) // &...'... -.data cil I_00007520 = bytearray ( +.data cil I_00007720 = bytearray ( 00 80 FF FF 00 00 01 00 FF 7F) -.data cil I_0000752A = int8[6] -.data cil I_00007530 = bytearray ( +.data cil I_0000772A = int8[6] +.data cil I_00007730 = bytearray ( + 00) +.data cil I_00007731 = int8[7] +.data cil I_00007738 = bytearray ( + 01 02 03) +.data cil I_0000773B = int8[5] +.data cil I_00007740 = bytearray ( 00 00 01 00 FF 7F 00 80 FE FF FF FF) -.data cil I_0000753C = int8[4] -.data cil I_00007540 = bytearray ( +.data cil I_0000774C = int8[4] +.data cil I_00007750 = bytearray ( 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00) -.data cil I_00007580 = bytearray ( +.data cil I_00007790 = bytearray ( 01 00 0C BB 7D 6E 9C BA FF FF FF FF FF FF FF FF // ....}n.......... 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 FF FF F3 44 82 91 63 45) // ...D..cE -.data cil I_000075A8 = bytearray ( +.data cil I_000077B8 = bytearray ( 01 00 00 00 00 00 00 00 00 94 35 77 00 00 00 00 // ..........5w.... 00 5E D0 B2 00 00 00 00 04 00 00 00 00 00 00 00 // .^.............. 05 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 FF FF F3 44 82 91 63 45 FF FF E7 89 04 23 C7 8A) // ...D..cE.....#.. -.data cil I_000075F8 = bytearray ( +.data cil I_00007808 = bytearray ( 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 @@ -4853,43 +4930,43 @@ 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00) -.data cil I_000076F8 = bytearray ( +.data cil I_00007908 = bytearray ( 80 81 00 01 02 03 04 7F) -.data cil I_00007700 = bytearray ( +.data cil I_00007910 = bytearray ( 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00) -.data cil I_00007724 = int8[4] -.data cil I_00007728 = bytearray ( +.data cil I_00007934 = int8[4] +.data cil I_00007938 = bytearray ( 01 00 00 00 00 94 35 77 00 5E D0 B2 04 00 00 00 // ......5w.^...... 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 09 00 00 00 0A 00 00 00) -.data cil I_00007750 = bytearray ( +.data cil I_00007960 = bytearray ( 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 06 00 00 00) -.data cil I_00007768 = bytearray ( +.data cil I_00007978 = bytearray ( 00 01 02 FF) -.data cil I_0000776C = int8[4] -.data cil I_00007770 = bytearray ( +.data cil I_0000797C = int8[4] +.data cil I_00007980 = bytearray ( 00 00 00 00 00 00 F8 BF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F8 3F 00 00 00 00 00 00 F0 FF // .......?........ 00 00 00 00 00 00 F0 7F 00 00 00 00 00 00 F8 FF) -.data cil I_000077A0 = bytearray ( +.data cil I_000079B0 = bytearray ( 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00) -.data cil I_000077E0 = bytearray ( +.data cil I_000079F0 = bytearray ( 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 09 00 00 00 0A 00 00 00) -.data cil I_00007808 = bytearray ( +.data cil I_00007A18 = bytearray ( 01 00 01 00 00 00 01 01) -.data cil I_00007810 = bytearray ( +.data cil I_00007A20 = bytearray ( 01 00 00 00 FE FF FF FF 00 94 35 77 04 00 00 00 // ..........5w.... 05 00 00 00 FA FF FF FF 07 00 00 00 08 00 00 00 09 00 00 00 0A 00 00 00) -.data cil I_00007838 = bytearray ( +.data cil I_00007A48 = bytearray ( 00 00 C0 BF 00 00 00 00 00 00 C0 3F 00 00 80 FF // ...........?.... 00 00 80 7F 00 00 C0 FF) // *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs b/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs index 77e3328c4..af95b2daa 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs @@ -17,9 +17,11 @@ // DEALINGS IN THE SOFTWARE. using System; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Linq.Expressions; +using System.Reflection.Metadata; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem.Implementation; @@ -267,9 +269,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms inst.ReplaceWith(decimalConstant); return; } + Block block; if (TransformSpanTCtorContainingStackAlloc(inst, out ILInstruction locallocSpan)) { inst.ReplaceWith(locallocSpan); - Block block = null; + block = null; ILInstruction stmt = locallocSpan; while (stmt.Parent != null) { if (stmt.Parent is Block b) { @@ -281,6 +284,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms //ILInlining.InlineIfPossible(block, stmt.ChildIndex - 1, context); return; } + if (TransformArrayInitializers.TransformSpanTArrayInitialization(inst, context, out block)) { + context.Step("TransformSpanTArrayInitialization: single-dim", inst); + inst.ReplaceWith(block); + return; + } base.VisitNewObj(inst); } diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs index 9f9e3caf6..c38d233ff 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs @@ -56,8 +56,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; ILInstruction inst = body.Instructions[pos]; if (inst.MatchStLoc(out var v, out var newarrExpr) && MatchNewArr(newarrExpr, out var elementType, out var arrayLength)) { - if (ForwardScanInitializeArrayRuntimeHelper(body, pos + 1, v, elementType, arrayLength, out var values, out var initArrayPos)) { - context.Step("ForwardScanInitializeArrayRuntimeHelper: single-dim", inst); + if (HandleRuntimeHelperInitializeArray(body, pos + 1, v, elementType, arrayLength, out var values, out var initArrayPos)) { + context.Step("HandleRuntimeHelperInitializeArray: single-dim", inst); var tempStore = context.Function.RegisterVariable(VariableKind.InitializerTarget, v.Type); var block = BlockFromInitializer(tempStore, elementType, arrayLength, values); body.Instructions[pos] = new StLoc(v, block); @@ -102,14 +102,52 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; } + internal static bool TransformSpanTArrayInitialization(NewObj inst, StatementTransformContext context, out Block block) + { + block = null; + if (MatchSpanTCtorWithPointerAndSize(inst, context, out var elementType, out var field, out var size)) { + if (field.HasFlag(System.Reflection.FieldAttributes.HasFieldRVA)) { + var valuesList = new List(); + var initialValue = field.GetInitialValue(context.PEFile.Reader, context.TypeSystem); + if (DecodeArrayInitializer(elementType, initialValue, new[] { size }, valuesList)) { + var tempStore = context.Function.RegisterVariable(VariableKind.InitializerTarget, new ArrayType(context.TypeSystem, elementType)); + block = BlockFromInitializer(tempStore, elementType, new[] { size }, valuesList.ToArray()); + return true; + } + } + } + return false; + } + + static bool MatchSpanTCtorWithPointerAndSize(NewObj newObj, StatementTransformContext context, out IType elementType, out FieldDefinition field, out int size) + { + field = default; + size = default; + elementType = null; + IType type = newObj.Method.DeclaringType; + if (!type.IsKnownType(KnownTypeCode.SpanOfT) && !type.IsKnownType(KnownTypeCode.ReadOnlySpanOfT)) + return false; + if (newObj.Arguments.Count != 2 || type.TypeArguments.Count != 1) + return false; + elementType = type.TypeArguments[0]; + if (!newObj.Arguments[0].UnwrapConv(ConversionKind.StopGCTracking).MatchLdsFlda(out var member)) + return false; + if (member.MetadataToken.IsNil) + return false; + if (!newObj.Arguments[1].MatchLdcI4(out size)) + return false; + field = context.PEFile.Metadata.GetFieldDefinition((FieldDefinitionHandle)member.MetadataToken); + return true; + } + bool DoTransformMultiDim(ILFunction function, Block body, int pos) { if (pos >= body.Instructions.Count - 2) return false; ILInstruction inst = body.Instructions[pos]; if (inst.MatchStLoc(out var v, out var newarrExpr) && MatchNewArr(newarrExpr, out var elementType, out var length)) { - if (ForwardScanInitializeArrayRuntimeHelper(body, pos + 1, v, elementType, length, out var values, out var initArrayPos)) { - context.Step("ForwardScanInitializeArrayRuntimeHelper: multi-dim", inst); + if (HandleRuntimeHelperInitializeArray(body, pos + 1, v, elementType, length, out var values, out var initArrayPos)) { + context.Step("HandleRuntimeHelperInitializeArray: multi-dim", inst); var block = BlockFromInitializer(v, elementType, length, values); body.Instructions[pos].ReplaceWith(new StLoc(v, block)); body.Instructions.RemoveAt(initArrayPos); @@ -463,7 +501,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms && initializer.OpCode == OpCode.Block; } - Block BlockFromInitializer(ILVariable v, IType elementType, int[] arrayLength, ILInstruction[] values) + static Block BlockFromInitializer(ILVariable v, IType elementType, int[] arrayLength, ILInstruction[] values) { var block = new Block(BlockKind.ArrayInitializer); block.Instructions.Add(new StLoc(v, new NewArr(elementType, arrayLength.Select(l => new LdcI4(l)).ToArray()))); @@ -496,15 +534,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms } return true; } - - bool MatchInitializeArrayCall(ILInstruction instruction, out IMethod method, out ILVariable array, out FieldDefinition field) + + bool MatchInitializeArrayCall(ILInstruction instruction, out ILVariable array, out FieldDefinition field) { - method = null; array = null; field = default; if (!(instruction is Call call) || call.Arguments.Count != 2) return false; - method = call.Method; + IMethod method = call.Method; if (!method.IsStatic || method.Name != "InitializeArray" || method.DeclaringTypeDefinition == null) return false; var declaringType = method.DeclaringTypeDefinition; @@ -523,13 +560,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms return true; } - bool ForwardScanInitializeArrayRuntimeHelper(Block body, int pos, ILVariable array, IType arrayType, int[] arrayLength, out ILInstruction[] values, out int foundPos) + bool HandleRuntimeHelperInitializeArray(Block body, int pos, ILVariable array, IType arrayType, int[] arrayLength, out ILInstruction[] values, out int foundPos) { - if (MatchInitializeArrayCall(body.Instructions[pos], out var method, out var v2, out var field) && array == v2) { + if (MatchInitializeArrayCall(body.Instructions[pos], out var v2, out var field) && array == v2) { if (field.HasFlag(System.Reflection.FieldAttributes.HasFieldRVA)) { var valuesList = new List(); var initialValue = field.GetInitialValue(context.PEFile.Reader, context.TypeSystem); - if (DecodeArrayInitializer(arrayType, array, initialValue, arrayLength, valuesList)) { + if (DecodeArrayInitializer(arrayType, initialValue, arrayLength, valuesList)) { values = valuesList.ToArray(); foundPos = pos; return true; @@ -541,35 +578,35 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; } - static bool DecodeArrayInitializer(IType type, ILVariable array, BlobReader initialValue, int[] arrayLength, List output) + static bool DecodeArrayInitializer(IType type, BlobReader initialValue, int[] arrayLength, List output) { TypeCode typeCode = ReflectionHelper.GetTypeCode(type); switch (typeCode) { case TypeCode.Boolean: case TypeCode.Byte: - return DecodeArrayInitializer(initialValue, array, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcI4(r.ReadByte())); + return DecodeArrayInitializer(initialValue, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcI4(r.ReadByte())); case TypeCode.SByte: - return DecodeArrayInitializer(initialValue, array, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcI4(r.ReadSByte())); + return DecodeArrayInitializer(initialValue, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcI4(r.ReadSByte())); case TypeCode.Int16: - return DecodeArrayInitializer(initialValue, array, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcI4(r.ReadInt16())); + return DecodeArrayInitializer(initialValue, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcI4(r.ReadInt16())); case TypeCode.Char: case TypeCode.UInt16: - return DecodeArrayInitializer(initialValue, array, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcI4(r.ReadUInt16())); + return DecodeArrayInitializer(initialValue, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcI4(r.ReadUInt16())); case TypeCode.Int32: case TypeCode.UInt32: - return DecodeArrayInitializer(initialValue, array, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcI4(r.ReadInt32())); + return DecodeArrayInitializer(initialValue, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcI4(r.ReadInt32())); case TypeCode.Int64: case TypeCode.UInt64: - return DecodeArrayInitializer(initialValue, array, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcI8(r.ReadInt64())); + return DecodeArrayInitializer(initialValue, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcI8(r.ReadInt64())); case TypeCode.Single: - return DecodeArrayInitializer(initialValue, array, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcF4(r.ReadSingle())); + return DecodeArrayInitializer(initialValue, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcF4(r.ReadSingle())); case TypeCode.Double: - return DecodeArrayInitializer(initialValue, array, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcF8(r.ReadDouble())); + return DecodeArrayInitializer(initialValue, arrayLength, output, typeCode, type, (ref BlobReader r) => new LdcF8(r.ReadDouble())); case TypeCode.Object: case TypeCode.Empty: var typeDef = type.GetDefinition(); if (typeDef != null && typeDef.Kind == TypeKind.Enum) - return DecodeArrayInitializer(typeDef.EnumUnderlyingType, array, initialValue, arrayLength, output); + return DecodeArrayInitializer(typeDef.EnumUnderlyingType, initialValue, arrayLength, output); return false; default: return false; @@ -578,7 +615,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms delegate ILInstruction ValueDecoder(ref BlobReader reader); - static bool DecodeArrayInitializer(BlobReader initialValue, ILVariable array, int[] arrayLength, + static bool DecodeArrayInitializer(BlobReader initialValue, int[] arrayLength, List output, TypeCode elementType, IType type, ValueDecoder decoder) { int elementSize = ElementSizeOf(elementType);