Browse Source

Add IL tests for basic isinst patterns. Undo change mentioned in 54ff546221 (commitcomment-32359757)

pull/1440/head
Siegfried Pammer 6 years ago
parent
commit
5962d4675f
  1. 2
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 6
      ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs
  3. 28
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1389.cs
  4. 74
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1389.il
  5. 2
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

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

@ -67,6 +67,7 @@ @@ -67,6 +67,7 @@
<ItemGroup>
<Compile Include="DisassemblerPrettyTestRunner.cs" />
<Compile Include="TestCases\ILPretty\Issue1389.cs" />
<Compile Include="TestCases\Pretty\MultidimensionalArray.cs" />
<Compile Include="Output\CSharpAmbienceTests.cs" />
<Compile Include="Semantics\ConversionTests.cs" />
@ -81,6 +82,7 @@ @@ -81,6 +82,7 @@
<Compile Include="TestCases\Pretty\EnumTests.cs" />
<Compile Include="TestCases\Pretty\TypeMemberTests.cs" />
<Compile Include="TestCases\Pretty\ValueTypes.cs" />
<None Include="TestCases\ILPretty\Issue1389.il" />
<None Include="TestCases\ILPretty\SequenceOfNestedIfs.cs" />
<Compile Include="TestCases\Pretty\ConstructorInitializers.cs" />
<None Include="TestCases\ILPretty\SequenceOfNestedIfs.il" />

6
ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs

@ -82,6 +82,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -82,6 +82,12 @@ namespace ICSharpCode.Decompiler.Tests
Run();
}
[Test]
public void Issue1389()
{
Run();
}
[Test]
public void FSharpUsing_Debug()
{

28
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1389.cs

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
// Issue1389.Program
using System;
namespace Issue1389
{
public class Program
{
private static object GetObject()
{
throw null;
}
private static void UnusedResultOfIsinst()
{
bool flag = GetObject() is TypeCode;
}
private static bool BoolResultOfIsinst()
{
return GetObject() is TypeCode;
}
private static object EnumResultOfIsinst(object A_0)
{
return (A_0 is TypeCode) ? A_0 : null;
}
}
}

74
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1389.il

@ -0,0 +1,74 @@ @@ -0,0 +1,74 @@
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
.ver 4:0:0:0
}
.assembly Issue1389
{
.hash algorithm 0x00008004
.ver 1:0:4059:39717
}
.module Issue1389.dll
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000003 // ILONLY 32BITREQUIRED
.class public auto ansi beforefieldinit Issue1389.Program
extends [mscorlib]System.Object
{
// Methods
.method /* 06000001 */ private hidebysig static
object GetObject () cil managed
{
// Method begins at RVA 0x2050
// Code size 2 (0x2)
.maxstack 8
IL_0000: ldnull
IL_0001: throw
} // end of method Program::GetObject
.method /* 06000002 */ private hidebysig static
void UnusedResultOfIsinst () cil managed
{
// Method begins at RVA 0x2053
// Code size 12 (0xc)
.maxstack 8
IL_0000: call object Issue1389.Program::GetObject() /* 06000001 */
IL_0005: isinst [mscorlib]System.TypeCode /* 01000002 */
IL_000a: pop
IL_000b: ret
} // end of method Program::UnusedResultOfIsinst
.method /* 06000003 */ private hidebysig static
bool BoolResultOfIsinst () cil managed
{
// Method begins at RVA 0x2060
// Code size 14 (0xe)
.maxstack 8
IL_0000: call object Issue1389.Program::GetObject() /* 06000001 */
IL_0005: isinst [mscorlib]System.TypeCode /* 01000002 */
IL_000a: ldnull
IL_000b: cgt.un
IL_000d: ret
} // end of method Program::BoolResultOfIsinst
.method /* 06000004 */ private hidebysig static
object EnumResultOfIsinst (
object A_0
) cil managed
{
// Method begins at RVA 0x206f
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: isinst [mscorlib]System.TypeCode /* 01000002 */
IL_0006: ret
} // end of method Program::EnumResultOfIsinst
} // end of class Issue1389.Program

2
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -266,7 +266,6 @@ namespace ICSharpCode.Decompiler.CSharp @@ -266,7 +266,6 @@ namespace ICSharpCode.Decompiler.CSharp
protected internal override TranslatedExpression VisitIsInst(IsInst inst, TranslationContext context)
{
var arg = Translate(inst.Argument);
arg = UnwrapBoxingConversion(arg);
if (inst.Type.IsReferenceType == false) {
// isinst with a value type results in an expression of "boxed value type",
// which is not supported in C#.
@ -286,6 +285,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -286,6 +285,7 @@ namespace ICSharpCode.Decompiler.CSharp
return ErrorExpression("isinst with value type is only supported in some contexts");
}
}
arg = UnwrapBoxingConversion(arg);
return new AsExpression(arg.Expression, ConvertType(inst.Type))
.WithILInstruction(inst)
.WithRR(new ConversionResolveResult(inst.Type, arg.ResolveResult, Conversion.TryCast));

Loading…
Cancel
Save