Skip to content

Commit

Permalink
Fix #1084: Decompiling constants of the target type
Browse files Browse the repository at this point in the history
  • Loading branch information
siegfriedpammer committed Mar 8, 2018
1 parent 85314b4 commit eac591a
Show file tree
Hide file tree
Showing 17 changed files with 769 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public MyAttribute(object val)
public enum ULongEnum : ulong
{
[My(null)]
MaxUInt64 = 18446744073709551615uL
MaxUInt64 = ulong.MaxValue
}
[AttributeUsage(AttributeTargets.Field)]
public class TypesAttribute : Attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<Compile Include="DataFlowTest.cs" />
<Compile Include="TestCases\Correctness\RefLocalsAndReturns.cs" />
<Compile Include="TestCases\Pretty\RefLocalsAndReturns.cs" />
<Compile Include="TestCases\Pretty\WellKnownConstants.cs" />
<Compile Include="VBPrettyTestRunner.cs" />
<Compile Include="TestCases\VBPretty\Async.cs" />
<Compile Include="UglyTestRunner.cs" />
Expand Down
6 changes: 6 additions & 0 deletions ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ public void RefLocalsAndReturns([ValueSource("roslynOnlyOptions")] CSharpCompile
RunForLibrary(cscOptions: cscOptions);
}

[Test]
public void WellKnownConstants([ValueSource("defaultOptions")] CSharpCompilerOptions cscOptions)
{
RunForLibrary(cscOptions: cscOptions);
}

void RunForLibrary([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CSharpCompilerOptions cscOptions = CSharpCompilerOptions.None, DecompilerSettings decompilerSettings = null)
{
Run(testName, asmOptions | AssemblerOptions.Library, cscOptions | CSharpCompilerOptions.Library, decompilerSettings);
Expand Down
2 changes: 1 addition & 1 deletion ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static string SparseIntegerSwitch(int i)
return "ten thousand";
case 10001:
return "ten thousand and one";
case 2147483647:
case int.MaxValue:
return "int.MaxValue";
default:
return "something else";
Expand Down
34 changes: 17 additions & 17 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten.
// Copyright (c) Microsoft Corporation. All rights reserved.



Expand All @@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly rqt3qv2j
.assembly eo05gpu0
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
Expand All @@ -20,15 +20,15 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module rqt3qv2j.dll
// MVID: {0220E31A-C196-4C4B-B009-AED9A1DDD0BE}
.module eo05gpu0.dll
// MVID: {9D56DD8F-56CC-4AA5-939D-F5DC041F1927}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x02D40000
// Image base: 0x04BA0000


// =============== CLASS MEMBERS DECLARATION ===================
Expand Down Expand Up @@ -880,7 +880,7 @@
IL_0015: brfalse IL_00e9

IL_001a: volatile.
IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000d-1'
IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000d-1'
IL_0021: brtrue.s IL_0084

IL_0023: ldc.i4.7
Expand Down Expand Up @@ -921,9 +921,9 @@
IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_007d: volatile.
IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000d-1'
IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000d-1'
IL_0084: volatile.
IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000d-1'
IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000d-1'
IL_008b: ldloc.1
IL_008c: ldloca.s V_2
IL_008e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
Expand Down Expand Up @@ -995,7 +995,7 @@
IL_0013: brfalse IL_0158

IL_0018: volatile.
IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000e-1'
IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000e-1'
IL_001f: brtrue IL_00b8

IL_0024: ldc.i4.s 11
Expand Down Expand Up @@ -1056,9 +1056,9 @@
IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_00b1: volatile.
IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000e-1'
IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000e-1'
IL_00b8: volatile.
IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000e-1'
IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000e-1'
IL_00bf: ldloc.1
IL_00c0: ldloca.s V_2
IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
Expand Down Expand Up @@ -1346,7 +1346,7 @@
IL_003b: brfalse IL_012c

IL_0040: volatile.
IL_0042: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x6000013-1'
IL_0042: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x6000013-1'
IL_0047: brtrue.s IL_009e

IL_0049: ldc.i4.6
Expand Down Expand Up @@ -1382,9 +1382,9 @@
IL_0092: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_0097: volatile.
IL_0099: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x6000013-1'
IL_0099: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x6000013-1'
IL_009e: volatile.
IL_00a0: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x6000013-1'
IL_00a0: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x6000013-1'
IL_00a5: ldloc.s V_5
IL_00a7: ldloca.s V_6
IL_00a9: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
Expand Down Expand Up @@ -1611,17 +1611,17 @@

} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch

.class private auto ansi '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'
.class private auto ansi '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x600000d-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x600000e-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000013-1'
} // end of class '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'
} // end of class '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'


// =============================================================

// *********** DISASSEMBLY COMPLETE ***********************
// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\Switch.res" wurde erstellt.
// WARNING: Created Win32 resource file C:\Users\Siegfried\Projects\ILSpy master\ICSharpCode.Decompiler.Tests\bin\Debug\net46\../../../TestCases/Pretty\Switch.res
34 changes: 17 additions & 17 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten.
// Copyright (c) Microsoft Corporation. All rights reserved.



Expand All @@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly wn5i3ung
.assembly '1cqmq4ya'
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
Expand All @@ -20,15 +20,15 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module wn5i3ung.dll
// MVID: {DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}
.module '1cqmq4ya.dll'
// MVID: {F6D6A0F8-249B-42E0-A06F-7A75134FD239}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x00AB0000
// Image base: 0x05550000


// =============== CLASS MEMBERS DECLARATION ===================
Expand Down Expand Up @@ -749,7 +749,7 @@
IL_0013: brfalse IL_00db

IL_0018: volatile.
IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000d-1'
IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000d-1'
IL_001f: brtrue.s IL_0082

IL_0021: ldc.i4.7
Expand Down Expand Up @@ -790,9 +790,9 @@
IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_007b: volatile.
IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000d-1'
IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000d-1'
IL_0082: volatile.
IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000d-1'
IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000d-1'
IL_0089: ldloc.0
IL_008a: ldloca.s V_1
IL_008c: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
Expand Down Expand Up @@ -850,7 +850,7 @@
IL_0011: brfalse IL_013d

IL_0016: volatile.
IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000e-1'
IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000e-1'
IL_001d: brtrue IL_00b6

IL_0022: ldc.i4.s 11
Expand Down Expand Up @@ -911,9 +911,9 @@
IL_00aa: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_00af: volatile.
IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000e-1'
IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000e-1'
IL_00b6: volatile.
IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000e-1'
IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000e-1'
IL_00bd: ldloc.0
IL_00be: ldloca.s V_1
IL_00c0: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
Expand Down Expand Up @@ -1139,7 +1139,7 @@
IL_0037: brfalse IL_011f

IL_003c: volatile.
IL_003e: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x6000013-1'
IL_003e: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x6000013-1'
IL_0043: brtrue.s IL_009a

IL_0045: ldc.i4.6
Expand Down Expand Up @@ -1175,9 +1175,9 @@
IL_008e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_0093: volatile.
IL_0095: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x6000013-1'
IL_0095: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x6000013-1'
IL_009a: volatile.
IL_009c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x6000013-1'
IL_009c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x6000013-1'
IL_00a1: ldloc.s V_5
IL_00a3: ldloca.s V_6
IL_00a5: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
Expand Down Expand Up @@ -1371,17 +1371,17 @@

} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch

.class private auto ansi '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'
.class private auto ansi '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x600000d-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x600000e-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000013-1'
} // end of class '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'
} // end of class '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'


// =============================================================

// *********** DISASSEMBLY COMPLETE ***********************
// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\Switch.opt.res" wurde erstellt.
// WARNING: Created Win32 resource file C:\Users\Siegfried\Projects\ILSpy master\ICSharpCode.Decompiler.Tests\bin\Debug\net46\../../../TestCases/Pretty\Switch.opt.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten.
// Copyright (c) Microsoft Corporation. All rights reserved.



Expand Down Expand Up @@ -32,7 +32,7 @@
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x01380000
// Image base: 0x031B0000


// =============== CLASS MEMBERS DECLARATION ===================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten.
// Copyright (c) Microsoft Corporation. All rights reserved.



Expand Down Expand Up @@ -32,7 +32,7 @@
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x02460000
// Image base: 0x04490000


// =============== CLASS MEMBERS DECLARATION ===================
Expand Down
Loading

0 comments on commit eac591a

Please sign in to comment.