Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
7 changes: 6 additions & 1 deletion ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public async Task Jmp()
public async Task StackTests()
{
// IL contains .corflags = 32BITREQUIRED
await RunIL("StackTests.il", asmOptions: AssemblerOptions.Force32Bit);
await RunIL("StackTests.il", CompilerOptions.Force32Bit, AssemblerOptions.Force32Bit);
}

[Test]
Expand Down Expand Up @@ -483,6 +483,11 @@ async Task RunIL(string testFileName, CompilerOptions options = CompilerOptions.
string outputFile = null;
CompilerResults decompiledOutputFile = null;

bool optionsForce32Bit = options.HasFlag(CompilerOptions.Force32Bit);
bool asmOptionsForce32Bit = asmOptions.HasFlag(AssemblerOptions.Force32Bit);

Assert.AreEqual(optionsForce32Bit, asmOptionsForce32Bit, "Inconsistent architecture.");

try
{
options |= CompilerOptions.UseTestRunner;
Expand Down
11 changes: 6 additions & 5 deletions ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ static Tester()
TesterPath = Path.GetDirectoryName(typeof(Tester).Assembly.Location);
TestCasePath = Path.Combine(TesterPath, "../../../../TestCases");
#if DEBUG
testRunnerBasePath = Path.Combine(TesterPath, "../../../../../ICSharpCode.Decompiler.TestRunner/bin/Debug/net6.0-windows");
testRunnerBasePath = Path.Combine(TesterPath, "../../../../../ICSharpCode.Decompiler.TestRunner/bin/Debug/net7.0");
#else
testRunnerBasePath = Path.Combine(TesterPath, "../../../../../ICSharpCode.Decompiler.TestRunner/bin/Release/net6.0-windows");
testRunnerBasePath = Path.Combine(TesterPath, "../../../../../ICSharpCode.Decompiler.TestRunner/bin/Release/net7.0");
#endif
packagesPropsFile = Path.Combine(TesterPath, "../../../../../packages.props");
roslynLatestVersion = XDocument.Load(packagesPropsFile).XPathSelectElement("//RoslynVersion").Value;
Expand Down Expand Up @@ -270,8 +270,8 @@ private static string ReplacePrivImplDetails(string il)
}

static readonly string coreRefAsmPath = new DotNetCorePathFinder(TargetFrameworkIdentifier.NET,
new Version(6, 0), "Microsoft.NETCore.App")
.GetReferenceAssemblyPath(".NETCoreApp,Version=v6.0");
new Version(7, 0), "Microsoft.NETCore.App")
.GetReferenceAssemblyPath(".NETCoreApp,Version=v7.0");

public static readonly string RefAsmPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
@"Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2");
Expand Down Expand Up @@ -308,7 +308,7 @@ private static string ReplacePrivImplDetails(string il)

const string targetFrameworkAttributeSnippet = @"

[assembly: System.Runtime.Versioning.TargetFramework("".NETCoreApp,Version=v6.0"", FrameworkDisplayName = """")]
[assembly: System.Runtime.Versioning.TargetFramework("".NETCoreApp,Version=v7.0"", FrameworkDisplayName = """")]

";

Expand Down Expand Up @@ -343,6 +343,7 @@ public static List<string> GetPreprocessorSymbols(CompilerOptions flags)
{
preprocessorSymbols.Add("NETCORE");
preprocessorSymbols.Add("NET60");
preprocessorSymbols.Add("NET70");
}
preprocessorSymbols.Add("ROSLYN");
preprocessorSymbols.Add("CS60");
Expand Down
13 changes: 6 additions & 7 deletions ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,11 @@ public async Task Generics([ValueSource(nameof(defaultOptions))] CompilerOptions
[Test]
public async Task Loops([ValueSource(nameof(defaultOptionsWithMcs))] CompilerOptions cscOptions)
{
await RunForLibrary(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings {
// legacy csc generates a dead store in debug builds
RemoveDeadStores = (cscOptions == CompilerOptions.None),
UseExpressionBodyForCalculatedGetterOnlyProperties = false,
FileScopedNamespaces = false,
});
DecompilerSettings settings = Tester.GetSettings(cscOptions);
// legacy csc generates a dead store in debug builds
settings.RemoveDeadStores = (cscOptions == CompilerOptions.None);
settings.UseExpressionBodyForCalculatedGetterOnlyProperties = false;
await RunForLibrary(cscOptions: cscOptions, decompilerSettings: settings);
}

[Test]
Expand Down Expand Up @@ -486,7 +485,7 @@ public async Task NullableRefTypes([ValueSource(nameof(roslyn3OrNewerOptions))]
}

[Test]
public async Task NativeInts([ValueSource(nameof(roslyn3OrNewerOptions))] CompilerOptions cscOptions)
public async Task NativeInts([ValueSource(nameof(roslyn3OrNewerWithNet40Options))] CompilerOptions cscOptions)
{
await RunForLibrary(cscOptions: cscOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ static void Main()
Issue1747();
CallAmbiguousOutParam();
CallWithInParam();
#if CS90
NativeIntTests(new IntPtr(1), 2);
#endif
Issue2444.M2();
Issue2741.B.Test(new Issue2741.C());
}
Expand Down Expand Up @@ -337,6 +340,34 @@ static void InVsRegularParam(int i)
#endif
#endregion

#if CS90
static void NativeIntTests(IntPtr i1, nint i2)
{
Console.WriteLine("NativeIntTests(i1):");
ObjectOrLong((object)i1);
ObjectOrLong((long)i1);
Console.WriteLine("NativeIntTests(i2):");
ObjectOrLong((object)i2);
ObjectOrLong((long)i2);
Console.WriteLine("NativeIntTests(new IntPtr):");
ObjectOrLong((object)new IntPtr(3));
ObjectOrLong((long)new IntPtr(3));
Console.WriteLine("NativeIntTests(IntPtr.Zero):");
ObjectOrLong((object)IntPtr.Zero);
ObjectOrLong((long)IntPtr.Zero);
}

static void ObjectOrLong(object o)
{
Console.WriteLine("object " + o);
}

static void ObjectOrLong(long l)
{
Console.WriteLine("long " + l);
}
#endif

#region #2444
public struct Issue2444
{
Expand Down
18 changes: 17 additions & 1 deletion ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
using System;
#if !(CS110 && NET70)
using System;
#endif
using System.Threading.Tasks;

namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
internal class ConstantsTests
{
#if CS90
public nint? NullableNInt()
{
return null;
}

public nuint? NullableNUInt()
{
return null;
}
#endif

#if !(CS110 && NET70)
public IntPtr? NullableIntPtr()
{
return null;
Expand All @@ -14,6 +29,7 @@ internal class ConstantsTests
{
return null;
}
#endif

public ulong Issue1308(ulong u = 8uL)
{
Expand Down
7 changes: 7 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,17 @@ private static bool ConstantTarget(dynamic a)
return true.Equals(a);
}

#if CS110 && NET70
private static nint NewIntPtr(dynamic a)
{
return new nint(a);
}
#else
private static IntPtr NewIntPtr(dynamic a)
{
return new IntPtr(a);
}
#endif

private static dynamic GetDynamic(int i)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
#if !(CS110 && NET70)
using System;
#endif
using System.Text;

namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Expand All @@ -17,10 +19,17 @@ public static void Overloaded(int a)
return &Overloaded;
}

#if !(CS110 && NET70)
public unsafe IntPtr GetAddressAsIntPtr()
{
return (IntPtr)(delegate*<void>)(&Overloaded);
}
#endif

public unsafe nint GetAddressAsNInt()
{
return (nint)(delegate*<void>)(&Overloaded);
}

public unsafe void* GetAddressAsVoidPtr()
{
Expand Down Expand Up @@ -93,13 +102,16 @@ public class B<U>
internal class FunctionPointersWithNativeIntegerTypes
{
public unsafe delegate*<nint, nint, nint> F1;
#if !(CS110 && NET70)
public unsafe delegate*<IntPtr, IntPtr, nint> F2;
public unsafe delegate*<nint, IntPtr, IntPtr> F3;
public unsafe delegate*<IntPtr, nint, IntPtr> F4;
public unsafe delegate*<delegate*<IntPtr, IntPtr, IntPtr>, nint> F5;
public unsafe delegate*<nint, delegate*<IntPtr, IntPtr, IntPtr>> F6;
public unsafe delegate*<delegate*<IntPtr, IntPtr, nint>, IntPtr> F7;
public unsafe delegate*<IntPtr, delegate*<IntPtr, nint, IntPtr>> F8;
public unsafe delegate*<IntPtr, delegate*<IntPtr, IntPtr, IntPtr>> F9;
#endif
}

internal class FunctionPointersWithRefParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,10 +844,10 @@ int ZZZ_1()
#if CS90
public void Issue2196()
{
EnumWindows(IntPtr.Zero, IntPtr.Zero);
EnumWindows(0L, 0L);

[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "EnumWindows")]
static extern int EnumWindows(IntPtr hWnd, IntPtr lParam);
static extern int EnumWindows(long hWnd, long lParam);
}
#endif
}
Expand Down
36 changes: 34 additions & 2 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/NativeInts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,36 @@ internal class NativeInts
private const nint nint_const = 42;
private const nuint nuint_const = 99u;

#if CS110 && NET70
// C#11 on .NET7 no longer uses NativeIntegerAttribute,
// instead nint+IntPtr are considered to be the same type.
private nint intptr;
private nuint uintptr;
#else
private IntPtr intptr;
private UIntPtr uintptr;
#endif
private nint i;
private nuint u;
private int i32;
private uint u32;
private long i64;
private ulong u64;
#if !(CS110 && NET70)
private (IntPtr, nint, UIntPtr, nuint) tuple_field;
private (object, int, IntPtr, nint, UIntPtr, nuint) tuple_field2;
private Dictionary<nint, IntPtr> dict1;
private Dictionary<IntPtr, nint> dict2;
private Dictionary<IntPtr?, nint?> dict3;
private Dictionary<IntPtr, nint[]> dict4;
#endif
private Dictionary<nuint, nint[]> dict5;

public void Convert()
{
i = (nint)u;
u = (nuint)i;
#if !(CS110 && NET70)
intptr = i;
intptr = (nint)u;
intptr = (nint)(nuint)uintptr;
Expand All @@ -58,15 +71,18 @@ public void Convert()
u = (nuint)i;
u = uintptr;
u = (nuint)(nint)intptr;
#endif
}

public void Convert2()
{
i32 = (int)i;
i = i32;
#if !(CS110 && NET70)
intptr = (IntPtr)i32;

i64 = (long)intptr;
#endif
i64 = i;
i = (nint)i64;

Expand All @@ -79,7 +95,9 @@ public void Convert2()

public void Arithmetic()
{
#if !(CS110 && NET70)
Console.WriteLine((nint)intptr * 2);
#endif
Console.WriteLine(i * 2);

Console.WriteLine(i + (nint)u);
Expand Down Expand Up @@ -155,6 +173,7 @@ public void CompoundAssign()
{
GetInstance(3).u *= 2u;
}
#if !(CS110 && NET70)
GetInstance(4).intptr += (nint)i32;
checked
{
Expand All @@ -164,10 +183,13 @@ public void CompoundAssign()
}
// multiplication results in compiler-error without the cast
GetInstance(6).intptr *= (nint)2;
#endif

GetInstance(7).i <<= i32;
GetInstance(7).i += i32;
GetInstance(8).i <<= i32;
}

#if !(CS110 && NET70)
public void LocalTypeFromStore()
{
nint num = 42;
Expand All @@ -188,17 +210,27 @@ public void LocalTypeFromStore()
intptr = num3;
intptr = intPtr;
}

#endif

public void LocalTypeFromUse()
{
#if CS110 && NET70
nint num = intptr;
nint num2 = intptr;

Console.WriteLine();

intptr = num;
i = num2 + 1;
#else
IntPtr intPtr = intptr;
nint num = intptr;

Console.WriteLine();

intptr = intPtr;
i = num + 1;
#endif
}

public nint NegateUnsigned(nuint x)
Expand Down
7 changes: 6 additions & 1 deletion ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ public void CustomMarshal2([MarshalAs(UnmanagedType.CustomMarshaler, MarshalType
{
}

#if CS110 && NET70
[DllImport("ws2_32.dll", SetLastError = true)]
internal static extern IntPtr ioctlsocket([In] IntPtr socketHandle, [In] int cmd, [In][Out] ref int argp);
internal static extern nint ioctlsocket([In] nint socketHandle, [In] int cmd, [In][Out] ref int argp);

#else
[DllImport("ws2_32.dll", SetLastError = true)]
internal static extern IntPtr ioctlsocket([In] IntPtr socketHandle, [In] int cmd, [In][Out] ref int argp);
#endif
public void CallMethodWithInOutParameter()
{
int argp = 0;
Expand Down
Loading