Browse Source

Restore P/Invoke test.

pull/863/head
Daniel Grunwald 8 years ago
parent
commit
260d303b8e
  1. 22
      ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
  2. 1
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  3. 96
      ICSharpCode.Decompiler.Tests/PInvoke.cs
  4. 9
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  5. 99
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.cs
  6. 207
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.il
  7. 202
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.opt.il
  8. 205
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.opt.roslyn.il
  9. 211
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.roslyn.il
  10. 6
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs
  11. 27
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.il
  12. 21
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.il
  13. 17
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.roslyn.il
  14. 23
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.roslyn.il
  15. 2
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  16. 7
      ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs
  17. 10
      ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs
  18. 2
      ICSharpCode.Decompiler/IL/Transforms/LoopingTransform.cs

22
ICSharpCode.Decompiler.Tests/Helpers/Tester.cs

@ -24,10 +24,12 @@ using System.IO; @@ -24,10 +24,12 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.CSharp.OutputVisitor;
using ICSharpCode.Decompiler.CSharp.Transforms;
using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.TypeSystem;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
@ -55,6 +57,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -55,6 +57,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
UseDebug = 0x1,
Force32Bit = 0x2,
Library = 0x4,
UseOwnDisassembler = 0x8,
}
public static class Tester
@ -101,8 +104,25 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -101,8 +104,25 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
return outputFile;
}
public static string Disassemble(string sourceFileName, string outputFile)
public static string Disassemble(string sourceFileName, string outputFile, AssemblerOptions asmOptions)
{
if (asmOptions.HasFlag(AssemblerOptions.UseOwnDisassembler)) {
using (ModuleDefinition module = ModuleDefinition.ReadModule(sourceFileName))
using (var writer = new StreamWriter(outputFile)) {
module.Name = Path.GetFileNameWithoutExtension(outputFile);
var output = new PlainTextOutput(writer);
ReflectionDisassembler rd = new ReflectionDisassembler(output, false, CancellationToken.None);
rd.WriteAssemblyReferences(module);
if (module.Assembly != null)
rd.WriteAssemblyHeader(module.Assembly);
output.WriteLine();
rd.WriteModuleHeader(module);
output.WriteLine();
rd.WriteModuleContents(module);
}
return outputFile;
}
string ildasmPath = SdkUtility.GetSdkPath("ildasm.exe");
ProcessStartInfo info = new ProcessStartInfo(ildasmPath);

1
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -90,6 +90,7 @@ @@ -90,6 +90,7 @@
<Compile Include="TestCases\Pretty\ExceptionHandling.cs" />
<Compile Include="TestCases\Pretty\HelloWorld.cs" />
<Compile Include="TestCases\Pretty\InlineAssignmentTest.cs" />
<Compile Include="TestCases\Pretty\PInvoke.cs" />
<Compile Include="TestCases\Pretty\PropertiesAndEvents.cs" />
<Compile Include="TestCases\Pretty\QueryExpressions.cs" />
<Compile Include="TestCases\Pretty\ShortCircuit.cs" />

96
ICSharpCode.Decompiler.Tests/PInvoke.cs

@ -1,96 +0,0 @@ @@ -1,96 +0,0 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Runtime.InteropServices;
// P/Invoke and marshalling attribute tests
public class PInvoke
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 2)]
public struct MarshalAsTest
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public uint[] FixedArray;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4, ArraySubType = UnmanagedType.Bool)]
public int[] FixedBoolArray;
[MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)]
public string[] SafeBStrArray;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
public string FixedString;
}
[StructLayout(LayoutKind.Explicit)]
public struct Rect
{
[FieldOffset(0)]
public int left;
[FieldOffset(4)]
public int top;
[FieldOffset(8)]
public int right;
[FieldOffset(12)]
public int bottom;
}
public static decimal MarshalAttributesOnPropertyAccessors
{
[return: MarshalAs(UnmanagedType.Currency)]
get
{
return 0m;
}
[param: MarshalAs(UnmanagedType.Currency)]
set
{
}
}
[DllImport("xyz.dll", CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Method([MarshalAs(UnmanagedType.LPStr)] string input);
[DllImport("xyz.dll")]
private static extern void New1(int ElemCnt, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] int[] ar);
[DllImport("xyz.dll")]
private static extern void New2([MarshalAs(UnmanagedType.LPArray, SizeConst = 128)] int[] ar);
[DllImport("xyz.dll")]
private static extern void New3([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Bool, SizeConst = 64, SizeParamIndex = 1)] int[] ar);
public void CustomMarshal1([MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "MyCompany.MyMarshaler")] object o)
{
}
public void CustomMarshal2([MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "MyCompany.MyMarshaler", MarshalCookie = "Cookie")] object o)
{
}
[DllImport("ws2_32.dll", SetLastError = true)]
internal static extern IntPtr ioctlsocket([In] IntPtr socketHandle, [In] int cmd, [In] [Out] ref int argp);
public void CallMethodWithInOutParameter()
{
int num = 0;
PInvoke.ioctlsocket(IntPtr.Zero, 0, ref num);
}
}

9
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -154,6 +154,13 @@ namespace ICSharpCode.Decompiler.Tests @@ -154,6 +154,13 @@ namespace ICSharpCode.Decompiler.Tests
Run(cscOptions: cscOptions);
}
[Test]
public void PInvoke([ValueSource("defaultOptions")] CompilerOptions cscOptions)
{
// This tests needs our own disassembler; ildasm has a bug with marshalinfo.
Run(cscOptions: cscOptions, asmOptions: AssemblerOptions.UseOwnDisassembler);
}
void Run([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None)
{
var ilFile = Path.Combine(TestCasePath, testName);
@ -173,7 +180,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -173,7 +180,7 @@ namespace ICSharpCode.Decompiler.Tests
CompilerResults output = null;
try {
output = Tester.CompileCSharp(csFile, cscOptions | CompilerOptions.Library);
Tester.Disassemble(output.PathToAssembly, ilFile);
Tester.Disassemble(output.PathToAssembly, ilFile, asmOptions);
} finally {
if (output != null)
output.TempFiles.Delete();

99
ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.cs

@ -0,0 +1,99 @@ @@ -0,0 +1,99 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Runtime.InteropServices;
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
// P/Invoke and marshalling attribute tests
public class PInvoke
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 2)]
public struct MarshalAsTest
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public uint[] FixedArray;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4, ArraySubType = UnmanagedType.Bool)]
public int[] FixedBoolArray;
[MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)]
public string[] SafeBStrArray;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
public string FixedString;
}
[StructLayout(LayoutKind.Explicit)]
public struct Rect
{
[FieldOffset(0)]
public int left;
[FieldOffset(4)]
public int top;
[FieldOffset(8)]
public int right;
[FieldOffset(12)]
public int bottom;
}
public static decimal MarshalAttributesOnPropertyAccessors {
[return: MarshalAs(UnmanagedType.Currency)]
get {
throw new NotImplementedException();
}
[param: MarshalAs(UnmanagedType.Currency)]
set {
}
}
[DllImport("xyz.dll", CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Method([MarshalAs(UnmanagedType.LPStr)] string input);
[DllImport("xyz.dll")]
private static extern void New1(int ElemCnt, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] int[] ar);
[DllImport("xyz.dll")]
private static extern void New2([MarshalAs(UnmanagedType.LPArray, SizeConst = 128)] int[] ar);
[DllImport("xyz.dll")]
private static extern void New3([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Bool, SizeConst = 64, SizeParamIndex = 1)] int[] ar);
[DllImport("xyz.dll")]
private static extern void New4([MarshalAs(UnmanagedType.LPArray)] int[] ar);
public void CustomMarshal1([MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "MyCompany.MyMarshaler")] object o)
{
}
public void CustomMarshal2([MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "MyCompany.MyMarshaler", MarshalCookie = "Cookie")] object o)
{
}
[DllImport("ws2_32.dll", SetLastError = true)]
internal static extern IntPtr ioctlsocket([In] IntPtr socketHandle, [In] int cmd, [In] [Out] ref int argp);
public void CallMethodWithInOutParameter()
{
int num = 0;
PInvoke.ioctlsocket(IntPtr.Zero, 0, ref num);
}
}
}

207
ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.il

@ -0,0 +1,207 @@ @@ -0,0 +1,207 @@
.module extern xyz.dll
.module extern ws2_32.dll
.assembly extern mscorlib
{
.publickeytoken = (
b7 7a 5c 56 19 34 e0 89
)
.ver 4:0:0:0
}
.assembly c0d101lq
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = (
01 00 08 00 00 00 00 00
)
.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
63 65 70 74 69 6f 6e 54 68 72 6f 77 73 01
)
.permissionset reqmin = {
[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {
property bool SkipVerification = bool(true)
}
}
.hash algorithm 0x00008004 // SHA1
.ver 0:0:0:0
}
.module PInvoke
// MVID: {F608732B-D0A2-45AE-9706-B0B2379F8AAE}
.corflags 0x00000001 // ILOnly
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = (
01 00 00 00
)
.class private auto ansi '<Module>'
{
} // end of class <Module>
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke
extends [mscorlib]System.Object
{
// Nested Types
.class nested public sequential unicode sealed beforefieldinit MarshalAsTest
extends [mscorlib]System.ValueType
{
.pack 2
.size 0
// Fields
.field public marshal(fixed array[3]) uint32[] FixedArray
.field public marshal(fixed array[4] bool) int32[] FixedBoolArray
.field public marshal(safearray bstr) string[] SafeBStrArray
.field public marshal(fixed sysstring[8]) string FixedString
} // end of class MarshalAsTest
.class nested public explicit ansi sealed beforefieldinit Rect
extends [mscorlib]System.ValueType
{
// Fields
.field [0] public int32 left
.field [4] public int32 top
.field [8] public int32 right
.field [12] public int32 bottom
} // end of class Rect
// Methods
.method public hidebysig specialname static
valuetype [mscorlib]System.Decimal marshal(currency) get_MarshalAttributesOnPropertyAccessors () cil managed
{
// Method begins at RVA 0x2050
// Code size 7 (0x7)
.maxstack 8
IL_0000: nop
IL_0001: newobj instance void [mscorlib]System.NotImplementedException::.ctor()
IL_0006: throw
} // end of method PInvoke::get_MarshalAttributesOnPropertyAccessors
.method public hidebysig specialname static
void set_MarshalAttributesOnPropertyAccessors (
valuetype [mscorlib]System.Decimal marshal(currency) 'value'
) cil managed
{
// Method begins at RVA 0x2058
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method PInvoke::set_MarshalAttributesOnPropertyAccessors
.method public hidebysig static pinvokeimpl("xyz.dll" autochar winapi)
bool marshal(bool) Method (
string marshal(lpstr) input
) cil managed preservesig
{
} // end of method PInvoke::Method
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New1 (
int32 ElemCnt,
int32[] marshal([ + 0]) ar
) cil managed preservesig
{
} // end of method PInvoke::New1
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New2 (
int32[] marshal([128]) ar
) cil managed preservesig
{
} // end of method PInvoke::New2
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New3 (
int32[] marshal(bool[64 + 1]) ar
) cil managed preservesig
{
} // end of method PInvoke::New3
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New4 (
int32[] marshal([]) ar
) cil managed preservesig
{
} // end of method PInvoke::New4
.method public hidebysig
instance void CustomMarshal1 (
object marshal(custom("MyCompany.MyMarshaler", "")) o
) cil managed
{
// Method begins at RVA 0x205b
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method PInvoke::CustomMarshal1
.method public hidebysig
instance void CustomMarshal2 (
object marshal(custom("MyCompany.MyMarshaler", "Cookie")) o
) cil managed
{
// Method begins at RVA 0x205e
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method PInvoke::CustomMarshal2
.method assembly hidebysig static pinvokeimpl("ws2_32.dll" lasterr winapi)
native int ioctlsocket (
[in] native int socketHandle,
[in] int32 cmd,
[in] [out] int32& argp
) cil managed preservesig
{
} // end of method PInvoke::ioctlsocket
.method public hidebysig
instance void CallMethodWithInOutParameter () cil managed
{
// Method begins at RVA 0x2064
// Code size 18 (0x12)
.maxstack 3
.locals init (
[0] int32
)
IL_0000: nop
IL_0001: ldc.i4.0
IL_0002: stloc.0
IL_0003: ldsfld native int [mscorlib]System.IntPtr::Zero
IL_0008: ldc.i4.0
IL_0009: ldloca.s 0
IL_000b: call native int ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke::ioctlsocket(native int, int32, int32&)
IL_0010: pop
IL_0011: ret
} // end of method PInvoke::CallMethodWithInOutParameter
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
// Method begins at RVA 0x2082
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method PInvoke::.ctor
// Properties
.property valuetype [mscorlib]System.Decimal MarshalAttributesOnPropertyAccessors()
{
.get valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke::get_MarshalAttributesOnPropertyAccessors()
.set void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke::set_MarshalAttributesOnPropertyAccessors(valuetype [mscorlib]System.Decimal)
}
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke

202
ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.opt.il

@ -0,0 +1,202 @@ @@ -0,0 +1,202 @@
.module extern xyz.dll
.module extern ws2_32.dll
.assembly extern mscorlib
{
.publickeytoken = (
b7 7a 5c 56 19 34 e0 89
)
.ver 4:0:0:0
}
.assembly jfi2am5n
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = (
01 00 08 00 00 00 00 00
)
.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
63 65 70 74 69 6f 6e 54 68 72 6f 77 73 01
)
.permissionset reqmin = {
[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {
property bool SkipVerification = bool(true)
}
}
.hash algorithm 0x00008004 // SHA1
.ver 0:0:0:0
}
.module PInvoke.opt
// MVID: {8A131D15-EAC0-48F2-A958-1AF6CBD25557}
.corflags 0x00000001 // ILOnly
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = (
01 00 00 00
)
.class private auto ansi '<Module>'
{
} // end of class <Module>
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke
extends [mscorlib]System.Object
{
// Nested Types
.class nested public sequential unicode sealed beforefieldinit MarshalAsTest
extends [mscorlib]System.ValueType
{
.pack 2
.size 0
// Fields
.field public marshal(fixed array[3]) uint32[] FixedArray
.field public marshal(fixed array[4] bool) int32[] FixedBoolArray
.field public marshal(safearray bstr) string[] SafeBStrArray
.field public marshal(fixed sysstring[8]) string FixedString
} // end of class MarshalAsTest
.class nested public explicit ansi sealed beforefieldinit Rect
extends [mscorlib]System.ValueType
{
// Fields
.field [0] public int32 left
.field [4] public int32 top
.field [8] public int32 right
.field [12] public int32 bottom
} // end of class Rect
// Methods
.method public hidebysig specialname static
valuetype [mscorlib]System.Decimal marshal(currency) get_MarshalAttributesOnPropertyAccessors () cil managed
{
// Method begins at RVA 0x2050
// Code size 6 (0x6)
.maxstack 8
IL_0000: newobj instance void [mscorlib]System.NotImplementedException::.ctor()
IL_0005: throw
} // end of method PInvoke::get_MarshalAttributesOnPropertyAccessors
.method public hidebysig specialname static
void set_MarshalAttributesOnPropertyAccessors (
valuetype [mscorlib]System.Decimal marshal(currency) 'value'
) cil managed
{
// Method begins at RVA 0x2057
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method PInvoke::set_MarshalAttributesOnPropertyAccessors
.method public hidebysig static pinvokeimpl("xyz.dll" autochar winapi)
bool marshal(bool) Method (
string marshal(lpstr) input
) cil managed preservesig
{
} // end of method PInvoke::Method
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New1 (
int32 ElemCnt,
int32[] marshal([ + 0]) ar
) cil managed preservesig
{
} // end of method PInvoke::New1
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New2 (
int32[] marshal([128]) ar
) cil managed preservesig
{
} // end of method PInvoke::New2
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New3 (
int32[] marshal(bool[64 + 1]) ar
) cil managed preservesig
{
} // end of method PInvoke::New3
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New4 (
int32[] marshal([]) ar
) cil managed preservesig
{
} // end of method PInvoke::New4
.method public hidebysig
instance void CustomMarshal1 (
object marshal(custom("MyCompany.MyMarshaler", "")) o
) cil managed
{
// Method begins at RVA 0x2059
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method PInvoke::CustomMarshal1
.method public hidebysig
instance void CustomMarshal2 (
object marshal(custom("MyCompany.MyMarshaler", "Cookie")) o
) cil managed
{
// Method begins at RVA 0x205b
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method PInvoke::CustomMarshal2
.method assembly hidebysig static pinvokeimpl("ws2_32.dll" lasterr winapi)
native int ioctlsocket (
[in] native int socketHandle,
[in] int32 cmd,
[in] [out] int32& argp
) cil managed preservesig
{
} // end of method PInvoke::ioctlsocket
.method public hidebysig
instance void CallMethodWithInOutParameter () cil managed
{
// Method begins at RVA 0x2060
// Code size 17 (0x11)
.maxstack 3
.locals init (
[0] int32
)
IL_0000: ldc.i4.0
IL_0001: stloc.0
IL_0002: ldsfld native int [mscorlib]System.IntPtr::Zero
IL_0007: ldc.i4.0
IL_0008: ldloca.s 0
IL_000a: call native int ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke::ioctlsocket(native int, int32, int32&)
IL_000f: pop
IL_0010: ret
} // end of method PInvoke::CallMethodWithInOutParameter
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
// Method begins at RVA 0x207d
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method PInvoke::.ctor
// Properties
.property valuetype [mscorlib]System.Decimal MarshalAttributesOnPropertyAccessors()
{
.get valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke::get_MarshalAttributesOnPropertyAccessors()
.set void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke::set_MarshalAttributesOnPropertyAccessors(valuetype [mscorlib]System.Decimal)
}
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke

205
ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.opt.roslyn.il

@ -0,0 +1,205 @@ @@ -0,0 +1,205 @@
.module extern xyz.dll
.module extern ws2_32.dll
.assembly extern mscorlib
{
.publickeytoken = (
b7 7a 5c 56 19 34 e0 89
)
.ver 4:0:0:0
}
.assembly PInvoke
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = (
01 00 08 00 00 00 00 00
)
.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
63 65 70 74 69 6f 6e 54 68 72 6f 77 73 01
)
.custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = (
01 00 02 00 00 00 00 00
)
.permissionset reqmin = {
[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {
property bool SkipVerification = bool(true)
}
}
.hash algorithm 0x00008004 // SHA1
.ver 0:0:0:0
}
.module PInvoke.opt.roslyn
// MVID: {63CD2985-0EDA-4C6F-91E0-BFDEBA4905D5}
.corflags 0x00000001 // ILOnly
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = (
01 00 00 00
)
.class private auto ansi '<Module>'
{
} // end of class <Module>
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke
extends [mscorlib]System.Object
{
// Nested Types
.class nested public sequential unicode sealed beforefieldinit MarshalAsTest
extends [mscorlib]System.ValueType
{
.pack 2
.size 0
// Fields
.field public marshal(fixed array[3]) uint32[] FixedArray
.field public marshal(fixed array[4] bool) int32[] FixedBoolArray
.field public marshal(safearray bstr) string[] SafeBStrArray
.field public marshal(fixed sysstring[8]) string FixedString
} // end of class MarshalAsTest
.class nested public explicit ansi sealed beforefieldinit Rect
extends [mscorlib]System.ValueType
{
// Fields
.field [0] public int32 left
.field [4] public int32 top
.field [8] public int32 right
.field [12] public int32 bottom
} // end of class Rect
// Methods
.method public hidebysig specialname static
valuetype [mscorlib]System.Decimal marshal(currency) get_MarshalAttributesOnPropertyAccessors () cil managed
{
// Method begins at RVA 0x2050
// Code size 6 (0x6)
.maxstack 8
IL_0000: newobj instance void [mscorlib]System.NotImplementedException::.ctor()
IL_0005: throw
} // end of method PInvoke::get_MarshalAttributesOnPropertyAccessors
.method public hidebysig specialname static
void set_MarshalAttributesOnPropertyAccessors (
valuetype [mscorlib]System.Decimal marshal(currency) 'value'
) cil managed
{
// Method begins at RVA 0x2057
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method PInvoke::set_MarshalAttributesOnPropertyAccessors
.method public hidebysig static pinvokeimpl("xyz.dll" autochar winapi)
bool marshal(bool) Method (
string marshal(lpstr) input
) cil managed preservesig
{
} // end of method PInvoke::Method
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New1 (
int32 ElemCnt,
int32[] marshal([ + 0]) ar
) cil managed preservesig
{
} // end of method PInvoke::New1
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New2 (
int32[] marshal([128]) ar
) cil managed preservesig
{
} // end of method PInvoke::New2
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New3 (
int32[] marshal(bool[64 + 1]) ar
) cil managed preservesig
{
} // end of method PInvoke::New3
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New4 (
int32[] marshal([]) ar
) cil managed preservesig
{
} // end of method PInvoke::New4
.method public hidebysig
instance void CustomMarshal1 (
object marshal(custom("MyCompany.MyMarshaler", "")) o
) cil managed
{
// Method begins at RVA 0x2059
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method PInvoke::CustomMarshal1
.method public hidebysig
instance void CustomMarshal2 (
object marshal(custom("MyCompany.MyMarshaler", "Cookie")) o
) cil managed
{
// Method begins at RVA 0x205b
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method PInvoke::CustomMarshal2
.method assembly hidebysig static pinvokeimpl("ws2_32.dll" lasterr winapi)
native int ioctlsocket (
[in] native int socketHandle,
[in] int32 cmd,
[in] [out] int32& argp
) cil managed preservesig
{
} // end of method PInvoke::ioctlsocket
.method public hidebysig
instance void CallMethodWithInOutParameter () cil managed
{
// Method begins at RVA 0x2060
// Code size 17 (0x11)
.maxstack 3
.locals init (
[0] int32
)
IL_0000: ldc.i4.0
IL_0001: stloc.0
IL_0002: ldsfld native int [mscorlib]System.IntPtr::Zero
IL_0007: ldc.i4.0
IL_0008: ldloca.s 0
IL_000a: call native int ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke::ioctlsocket(native int, int32, int32&)
IL_000f: pop
IL_0010: ret
} // end of method PInvoke::CallMethodWithInOutParameter
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
// Method begins at RVA 0x207d
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method PInvoke::.ctor
// Properties
.property valuetype [mscorlib]System.Decimal MarshalAttributesOnPropertyAccessors()
{
.get valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke::get_MarshalAttributesOnPropertyAccessors()
.set void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke::set_MarshalAttributesOnPropertyAccessors(valuetype [mscorlib]System.Decimal)
}
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke

211
ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.roslyn.il

@ -0,0 +1,211 @@ @@ -0,0 +1,211 @@
.module extern xyz.dll
.module extern ws2_32.dll
.assembly extern mscorlib
{
.publickeytoken = (
b7 7a 5c 56 19 34 e0 89
)
.ver 4:0:0:0
}
.assembly PInvoke
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = (
01 00 08 00 00 00 00 00
)
.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
63 65 70 74 69 6f 6e 54 68 72 6f 77 73 01
)
.custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = (
01 00 07 01 00 00 00 00
)
.permissionset reqmin = {
[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {
property bool SkipVerification = bool(true)
}
}
.hash algorithm 0x00008004 // SHA1
.ver 0:0:0:0
}
.module PInvoke.roslyn
// MVID: {86F00A7C-01D7-4EA0-AFE1-EB3A06A0C1FD}
.corflags 0x00000001 // ILOnly
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = (
01 00 00 00
)
.class private auto ansi '<Module>'
{
} // end of class <Module>
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke
extends [mscorlib]System.Object
{
// Nested Types
.class nested public sequential unicode sealed beforefieldinit MarshalAsTest
extends [mscorlib]System.ValueType
{
.pack 2
.size 0
// Fields
.field public marshal(fixed array[3]) uint32[] FixedArray
.field public marshal(fixed array[4] bool) int32[] FixedBoolArray
.field public marshal(safearray bstr) string[] SafeBStrArray
.field public marshal(fixed sysstring[8]) string FixedString
} // end of class MarshalAsTest
.class nested public explicit ansi sealed beforefieldinit Rect
extends [mscorlib]System.ValueType
{
// Fields
.field [0] public int32 left
.field [4] public int32 top
.field [8] public int32 right
.field [12] public int32 bottom
} // end of class Rect
// Methods
.method public hidebysig specialname static
valuetype [mscorlib]System.Decimal marshal(currency) get_MarshalAttributesOnPropertyAccessors () cil managed
{
// Method begins at RVA 0x2050
// Code size 7 (0x7)
.maxstack 8
IL_0000: nop
IL_0001: newobj instance void [mscorlib]System.NotImplementedException::.ctor()
IL_0006: throw
} // end of method PInvoke::get_MarshalAttributesOnPropertyAccessors
.method public hidebysig specialname static
void set_MarshalAttributesOnPropertyAccessors (
valuetype [mscorlib]System.Decimal marshal(currency) 'value'
) cil managed
{
// Method begins at RVA 0x2058
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method PInvoke::set_MarshalAttributesOnPropertyAccessors
.method public hidebysig static pinvokeimpl("xyz.dll" autochar winapi)
bool marshal(bool) Method (
string marshal(lpstr) input
) cil managed preservesig
{
} // end of method PInvoke::Method
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New1 (
int32 ElemCnt,
int32[] marshal([ + 0]) ar
) cil managed preservesig
{
} // end of method PInvoke::New1
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New2 (
int32[] marshal([128]) ar
) cil managed preservesig
{
} // end of method PInvoke::New2
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New3 (
int32[] marshal(bool[64 + 1]) ar
) cil managed preservesig
{
} // end of method PInvoke::New3
.method private hidebysig static pinvokeimpl("xyz.dll" winapi)
void New4 (
int32[] marshal([]) ar
) cil managed preservesig
{
} // end of method PInvoke::New4
.method public hidebysig
instance void CustomMarshal1 (
object marshal(custom("MyCompany.MyMarshaler", "")) o
) cil managed
{
// Method begins at RVA 0x205b
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method PInvoke::CustomMarshal1
.method public hidebysig
instance void CustomMarshal2 (
object marshal(custom("MyCompany.MyMarshaler", "Cookie")) o
) cil managed
{
// Method begins at RVA 0x205e
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method PInvoke::CustomMarshal2
.method assembly hidebysig static pinvokeimpl("ws2_32.dll" lasterr winapi)
native int ioctlsocket (
[in] native int socketHandle,
[in] int32 cmd,
[in] [out] int32& argp
) cil managed preservesig
{
} // end of method PInvoke::ioctlsocket
.method public hidebysig
instance void CallMethodWithInOutParameter () cil managed
{
// Method begins at RVA 0x2064
// Code size 18 (0x12)
.maxstack 3
.locals init (
[0] int32
)
IL_0000: nop
IL_0001: ldc.i4.0
IL_0002: stloc.0
IL_0003: ldsfld native int [mscorlib]System.IntPtr::Zero
IL_0008: ldc.i4.0
IL_0009: ldloca.s 0
IL_000b: call native int ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke::ioctlsocket(native int, int32, int32&)
IL_0010: pop
IL_0011: ret
} // end of method PInvoke::CallMethodWithInOutParameter
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
// Method begins at RVA 0x2082
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method PInvoke::.ctor
// Properties
.property valuetype [mscorlib]System.Decimal MarshalAttributesOnPropertyAccessors()
{
.get valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke::get_MarshalAttributesOnPropertyAccessors()
.set void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke::set_MarshalAttributesOnPropertyAccessors(valuetype [mscorlib]System.Decimal)
}
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.PInvoke

6
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs

@ -184,6 +184,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -184,6 +184,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return this.byteArray[i];
}
public byte UseArrayWithCastToUShort(int i)
{
// Unchecked cast = truncate to 16 bits
return this.byteArray[(ushort)i];
}
public StringComparison EnumDiffNumber(StringComparison data)
{
return data - 1;

27
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.il

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly '3ks4sbnu'
.assembly q5z5ui4l
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.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
@ -20,15 +20,15 @@ @@ -20,15 +20,15 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module '3ks4sbnu.dll'
// MVID: {8D285D1A-ACBF-41C0-93DE-10526C17A0D8}
.module q5z5ui4l.dll
// MVID: {E0E1769A-5636-428C-B7CE-29408F5D108F}
.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: 0x008C0000
// Image base: 0x024D0000
// =============== CLASS MEMBERS DECLARATION ===================
@ -626,6 +626,25 @@ @@ -626,6 +626,25 @@
IL_000d: ret
} // end of method TypeAnalysisTests::UseArrayWithUShort
.method public hidebysig instance uint8
UseArrayWithCastToUShort(int32 i) cil managed
{
// Code size 15 (0xf)
.maxstack 2
.locals init (uint8 V_0)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld uint8[] ICSharpCode.Decompiler.Tests.TestCases.Pretty.TypeAnalysisTests::byteArray
IL_0007: ldarg.1
IL_0008: conv.u2
IL_0009: ldelem.u1
IL_000a: stloc.0
IL_000b: br.s IL_000d
IL_000d: ldloc.0
IL_000e: ret
} // end of method TypeAnalysisTests::UseArrayWithCastToUShort
.method public hidebysig instance valuetype [mscorlib]System.StringComparison
EnumDiffNumber(valuetype [mscorlib]System.StringComparison data) cil managed
{

21
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.il

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly ucb5gp0y
.assembly '5lntuoy2'
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.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
@ -20,15 +20,15 @@ @@ -20,15 +20,15 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module ucb5gp0y.dll
// MVID: {CDCB369D-F3A9-41EF-A248-EFB62F8B25F3}
.module '5lntuoy2.dll'
// MVID: {85A70DA1-7D32-4ED1-89B1-4720D974D969}
.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: 0x00BA0000
// Image base: 0x05730000
// =============== CLASS MEMBERS DECLARATION ===================
@ -437,6 +437,19 @@ @@ -437,6 +437,19 @@
IL_0008: ret
} // end of method TypeAnalysisTests::UseArrayWithUShort
.method public hidebysig instance uint8
UseArrayWithCastToUShort(int32 i) cil managed
{
// Code size 10 (0xa)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld uint8[] ICSharpCode.Decompiler.Tests.TestCases.Pretty.TypeAnalysisTests::byteArray
IL_0006: ldarg.1
IL_0007: conv.u2
IL_0008: ldelem.u1
IL_0009: ret
} // end of method TypeAnalysisTests::UseArrayWithCastToUShort
.method public hidebysig instance valuetype [mscorlib]System.StringComparison
EnumDiffNumber(valuetype [mscorlib]System.StringComparison data) cil managed
{

17
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.roslyn.il

@ -25,14 +25,14 @@ @@ -25,14 +25,14 @@
.ver 0:0:0:0
}
.module TypeAnalysisTests.dll
// MVID: {45EA12AC-D9D0-4E8D-899F-E860FF165BAF}
// MVID: {60E6985E-8E86-4693-9F02-AD3FF7341588}
.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: 0x004F0000
// Image base: 0x02440000
// =============== CLASS MEMBERS DECLARATION ===================
@ -439,6 +439,19 @@ @@ -439,6 +439,19 @@
IL_0008: ret
} // end of method TypeAnalysisTests::UseArrayWithUShort
.method public hidebysig instance uint8
UseArrayWithCastToUShort(int32 i) cil managed
{
// Code size 10 (0xa)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld uint8[] ICSharpCode.Decompiler.Tests.TestCases.Pretty.TypeAnalysisTests::byteArray
IL_0006: ldarg.1
IL_0007: conv.u2
IL_0008: ldelem.u1
IL_0009: ret
} // end of method TypeAnalysisTests::UseArrayWithCastToUShort
.method public hidebysig instance valuetype [mscorlib]System.StringComparison
EnumDiffNumber(valuetype [mscorlib]System.StringComparison data) cil managed
{

23
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.roslyn.il

@ -25,14 +25,14 @@ @@ -25,14 +25,14 @@
.ver 0:0:0:0
}
.module TypeAnalysisTests.dll
// MVID: {7D715AC2-86C7-44AA-B6EB-859E68836342}
// MVID: {389E1347-98C0-49C1-B484-EDF5FFA1CD16}
.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: 0x014B0000
// Image base: 0x027F0000
// =============== CLASS MEMBERS DECLARATION ===================
@ -625,6 +625,25 @@ @@ -625,6 +625,25 @@
IL_000d: ret
} // end of method TypeAnalysisTests::UseArrayWithUShort
.method public hidebysig instance uint8
UseArrayWithCastToUShort(int32 i) cil managed
{
// Code size 15 (0xf)
.maxstack 2
.locals init (uint8 V_0)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld uint8[] ICSharpCode.Decompiler.Tests.TestCases.Pretty.TypeAnalysisTests::byteArray
IL_0007: ldarg.1
IL_0008: conv.u2
IL_0009: ldelem.u1
IL_000a: stloc.0
IL_000b: br.s IL_000d
IL_000d: ldloc.0
IL_000e: ret
} // end of method TypeAnalysisTests::UseArrayWithCastToUShort
.method public hidebysig instance valuetype [mscorlib]System.StringComparison
EnumDiffNumber(valuetype [mscorlib]System.StringComparison data) cil managed
{

2
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -107,7 +107,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -107,7 +107,7 @@ namespace ICSharpCode.Decompiler.CSharp
new TransformAssignment(),
new CopyPropagation(),
new LoopingBlockTransform(
// per-block transforms that depend on each other, and thus need to loop.
// per-block transforms that depend on each other, and thus need to loop (fixpoint iteration).
// Pretty much all transforms that open up new expression inlining
// opportunities belong in this category.
new ExpressionTransforms(),

7
ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs

@ -433,11 +433,10 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -433,11 +433,10 @@ namespace ICSharpCode.Decompiler.Disassembler
if (ami.ElementType != NativeType.Max)
WriteNativeType(ami.ElementType);
output.Write('[');
if (ami.SizeParameterMultiplier == 0) {
if (ami.Size >= 0) {
output.Write(ami.Size.ToString());
} else {
if (ami.Size >= 0)
output.Write(ami.Size.ToString());
}
if (ami.SizeParameterMultiplier != 0 && ami.SizeParameterIndex >= 0) {
output.Write(" + ");
output.Write(ami.SizeParameterIndex.ToString());
}

10
ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs

@ -96,6 +96,16 @@ namespace ICSharpCode.Decompiler.IL @@ -96,6 +96,16 @@ namespace ICSharpCode.Decompiler.IL
/// </summary>
public abstract StackType ResultType { get; }
/// <summary>
/// Gets the underlying result type of the value produced by this instruction.
///
/// If this is a lifted operation, the ResultType will be `StackType.O` (because Nullable{T} is a struct),
/// and UnderlyingResultType will be result type of the corresponding non-lifted operation.
///
/// If this is not a lifted operation, the underlying result type is equal to the result type.
/// </summary>
public virtual StackType UnderlyingResultType { get => ResultType; }
internal static StackType CommonResultType(StackType a, StackType b)
{
if (a == StackType.I || b == StackType.I)

2
ICSharpCode.Decompiler/IL/Transforms/LoopingTransform.cs

@ -22,7 +22,7 @@ using System.Collections.Generic; @@ -22,7 +22,7 @@ using System.Collections.Generic;
namespace ICSharpCode.Decompiler.IL.Transforms
{
/// <summary>
/// Repeats the child transforms until the ILAst no longer changes.
/// Repeats the child transforms until the ILAst no longer changes (fixpoint iteration).
/// </summary>
public class LoopingBlockTransform : IBlockTransform
{

Loading…
Cancel
Save