Browse Source

Fix #3344: Add support for the `ckfinite` opcode.

null-coalescing-assignment
Daniel Grunwald 4 months ago
parent
commit
89083eaf48
  1. 2
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 6
      ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs
  3. 22
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue3344CkFinite.cs
  4. 48
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue3344CkFinite.il
  5. 27
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

2
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -100,6 +100,7 @@ @@ -100,6 +100,7 @@
<None Include="TestCases\ILPretty\GuessAccessors.il" />
<None Include="TestCases\ILPretty\Issue2260SwitchString.il" />
<None Include="TestCases\ILPretty\Issue3442.il" />
<None Include="TestCases\ILPretty\Issue3344CkFinite.il" />
<None Include="TestCases\ILPretty\Issue3466.il" />
<None Include="testcases\ilpretty\Issue3504.il" />
<None Include="testcases\ilpretty\Issue3524.il" />
@ -142,6 +143,7 @@ @@ -142,6 +143,7 @@
<Compile Include="ProjectDecompiler\TargetFrameworkTests.cs" />
<Compile Include="ProjectDecompiler\WholeProjectDecompilerTests.cs" />
<Compile Include="TestAssemblyResolver.cs" />
<Compile Include="TestCases\ILPretty\Issue3344CkFinite.cs" />
<Compile Include="TestCases\ILPretty\Issue3421.cs" />
<Compile Include="TestCases\ILPretty\Issue3442.cs" />
<Compile Include="TestCases\ILPretty\Issue3466.cs" />

6
ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs

@ -207,6 +207,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -207,6 +207,12 @@ namespace ICSharpCode.Decompiler.Tests
await Run();
}
[Test]
public async Task Issue3344CkFinite()
{
await Run();
}
[Test]
public async Task Issue3421()
{

22
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue3344CkFinite.cs

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
using System;
namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
{
public class Issue3344
{
private static float GetFloat()
{
return 3.5f;
}
private static float CkFinite()
{
float num = GetFloat();
if (!float.IsFinite(num))
{
throw new ArithmeticException();
}
return num;
}
}
}

48
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue3344CkFinite.il

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
.assembly extern System.Runtime
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly Issue3344
{
.hash algorithm 0x00008004 // SHA1
.ver 0:0:0:0
}
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue3344
extends [System.Runtime]System.Object
{
.method private hidebysig static
float32 GetFloat () cil managed
{
.maxstack 8
IL_0000: ldc.r4 3.5
IL_0005: ret
}
.method private hidebysig static
float32 CkFinite () cil managed
{
.maxstack 1
.locals init (
[0] float32
)
call float32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue3344::GetFloat()
ckfinite
ret
}
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Object::.ctor()
IL_0006: ret
}
}

27
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -1542,5 +1542,32 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1542,5 +1542,32 @@ namespace ICSharpCode.Decompiler.CSharp
stmt.InsertChildAfter(null, new Comment(" IL cpblk instruction"), Roles.Comment);
return stmt.WithILInstruction(inst);
}
protected internal override TranslatedStatement VisitCkfinite(Ckfinite inst)
{
var isFiniteCall = new InvocationExpression {
Target = new MemberReferenceExpression {
Target = new TypeReferenceExpression(new Syntax.PrimitiveType("float")),
MemberName = "IsFinite"
},
Arguments = {
exprBuilder.Translate(inst.Argument)
}
};
var arithmeticException = typeSystem.FindType(typeof(ArithmeticException));
var arithmeticExceptionSyntax = new SimpleType("ArithmeticException");
arithmeticExceptionSyntax.AddAnnotation(new TypeResolveResult(arithmeticException));
return new IfElseStatement {
Condition = new UnaryOperatorExpression {
Operator = UnaryOperatorType.Not,
Expression = isFiniteCall
},
TrueStatement = new ThrowStatement(
new ObjectCreateExpression {
Type = arithmeticExceptionSyntax
}
),
}.WithILInstruction(inst);
}
}
}

Loading…
Cancel
Save