Browse Source

#1314: do not use special constants, if literal is inside array initializer.

pull/1350/head
Siegfried Pammer 7 years ago
parent
commit
640964cb0a
  1. 10
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs
  2. 29
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il
  3. 23
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il
  4. 22
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il
  5. 28
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il
  6. 2
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

10
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs

@ -733,6 +733,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests @@ -733,6 +733,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
}
#endif
private byte[] Issue1314()
{
return new byte[4] {
0,
1,
2,
255
};
}
private void Issue1251_Test(List<Item> list, OtherItem otherItem)
{
list.Add(new Item {

29
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il

@ -2383,6 +2383,26 @@ @@ -2383,6 +2383,26 @@
IL_001a: ret
} // end of method TestCases::Issue1250_Test1
.method private hidebysig instance uint8[]
Issue1314() cil managed
{
// Code size 23 (0x17)
.maxstack 3
.locals init (uint8[] V_0)
IL_0000: nop
IL_0001: ldc.i4.4
IL_0002: newarr [mscorlib]System.Byte
IL_0007: dup
IL_0008: ldtoken field int32 '<PrivateImplementationDetails>'::'$$method0x600002e-1'
IL_000d: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array,
valuetype [mscorlib]System.RuntimeFieldHandle)
IL_0012: stloc.0
IL_0013: br.s IL_0015
IL_0015: ldloc.0
IL_0016: ret
} // end of method TestCases::Issue1314
.method private hidebysig instance void
Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed
@ -2549,7 +2569,16 @@ @@ -2549,7 +2569,16 @@
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases
.class private auto ansi '<PrivateImplementationDetails>'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field static assembly int32 '$$method0x600002e-1' at I_000029A8
} // end of class '<PrivateImplementationDetails>'
// =============================================================
.data cil I_000029A8 = bytearray (
00 01 02 FF)
// *********** DISASSEMBLY COMPLETE ***********************

23
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il

@ -2040,6 +2040,20 @@ @@ -2040,6 +2040,20 @@
IL_0018: ret
} // end of method TestCases::Issue1250_Test1
.method private hidebysig instance uint8[]
Issue1314() cil managed
{
// Code size 18 (0x12)
.maxstack 8
IL_0000: ldc.i4.4
IL_0001: newarr [mscorlib]System.Byte
IL_0006: dup
IL_0007: ldtoken field int32 '<PrivateImplementationDetails>'::'$$method0x600002e-1'
IL_000c: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array,
valuetype [mscorlib]System.RuntimeFieldHandle)
IL_0011: ret
} // end of method TestCases::Issue1314
.method private hidebysig instance void
Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed
@ -2176,7 +2190,16 @@ @@ -2176,7 +2190,16 @@
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases
.class private auto ansi '<PrivateImplementationDetails>'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field static assembly int32 '$$method0x600002e-1' at I_000028A0
} // end of class '<PrivateImplementationDetails>'
// =============================================================
.data cil I_000028A0 = bytearray (
00 01 02 FF)
// *********** DISASSEMBLY COMPLETE ***********************

22
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il

@ -2136,6 +2136,20 @@ @@ -2136,6 +2136,20 @@
IL_0023: ret
} // end of method TestCases::Issue1250_Test4
.method private hidebysig instance uint8[]
Issue1314() cil managed
{
// Code size 18 (0x12)
.maxstack 8
IL_0000: ldc.i4.4
IL_0001: newarr [mscorlib]System.Byte
IL_0006: dup
IL_0007: ldtoken field int32 '<PrivateImplementationDetails>'::C62C27924F4C967F5EDDB1850C091D54C7A2AB58
IL_000c: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array,
valuetype [mscorlib]System.RuntimeFieldHandle)
IL_0011: ret
} // end of method TestCases::Issue1314
.method private hidebysig instance void
Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed
@ -2251,13 +2265,17 @@ @@ -2251,13 +2265,17 @@
.size 40
} // end of class '__StaticArrayInitTypeSize=40'
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_00005180
.field static assembly initonly int32 C62C27924F4C967F5EDDB1850C091D54C7A2AB58 at I_000051F0
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_000051F8
} // end of class '<PrivateImplementationDetails>'
// =============================================================
.data cil I_00005180 = bytearray (
.data cil I_000051F0 = bytearray (
00 01 02 FF)
.data cil I_000051F4 = int8[4]
.data cil I_000051F8 = 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)

28
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il

@ -2432,6 +2432,26 @@ @@ -2432,6 +2432,26 @@
IL_0026: ret
} // end of method TestCases::Issue1250_Test4
.method private hidebysig instance uint8[]
Issue1314() cil managed
{
// Code size 23 (0x17)
.maxstack 3
.locals init (uint8[] V_0)
IL_0000: nop
IL_0001: ldc.i4.4
IL_0002: newarr [mscorlib]System.Byte
IL_0007: dup
IL_0008: ldtoken field int32 '<PrivateImplementationDetails>'::C62C27924F4C967F5EDDB1850C091D54C7A2AB58
IL_000d: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array,
valuetype [mscorlib]System.RuntimeFieldHandle)
IL_0012: stloc.0
IL_0013: br.s IL_0015
IL_0015: ldloc.0
IL_0016: ret
} // end of method TestCases::Issue1314
.method private hidebysig instance void
Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed
@ -2575,13 +2595,17 @@ @@ -2575,13 +2595,17 @@
.size 40
} // end of class '__StaticArrayInitTypeSize=40'
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_0000545C
.field static assembly initonly int32 C62C27924F4C967F5EDDB1850C091D54C7A2AB58 at I_000054E8
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_000054F0
} // end of class '<PrivateImplementationDetails>'
// =============================================================
.data cil I_0000545C = bytearray (
.data cil I_000054E8 = bytearray (
00 01 02 FF)
.data cil I_000054EC = int8[4]
.data cil I_000054F0 = 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)

2
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -2270,7 +2270,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2270,7 +2270,9 @@ namespace ICSharpCode.Decompiler.CSharp
container.Peek().Elements.Add(aie);
container.Push(aie);
}
astBuilder.UseSpecialConstants = !type.IsCSharpPrimitiveIntegerType();
var val = Translate(value, typeHint: type).ConvertTo(type, this, allowImplicitConversion: true);
astBuilder.UseSpecialConstants = true;
container.Peek().Elements.Add(val);
elementResolveResults.Add(val.ResolveResult);
while (container.Count > 0 && container.Peek().Elements.Count == dimensionSizes[container.Count - 1]) {

Loading…
Cancel
Save