Browse Source

Merge pull request #910 from mohe2015/fix-bugs

Fix special cases in catch with object
pull/909/merge
Daniel Grunwald 8 years ago committed by GitHub
parent
commit
f9eb9bcacc
  1. 17
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs
  2. 14
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.il
  3. 14
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.il
  4. 259
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.roslyn.il
  5. 255
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.roslyn.il
  6. 68
      ICSharpCode.Decompiler/IL/Transforms/DetectCatchWhenConditionBlocks.cs

17
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs

@ -97,6 +97,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -97,6 +97,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
return false;
}
public void CatchWhenWithConditionWithoutExceptionVar()
{
int num = 0;
try {
throw new Exception();
} catch (Exception) when (num == 0) {
Console.WriteLine("jo");
}
}
#endif
public bool SimpleTryFinally()
@ -144,7 +155,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -144,7 +155,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Console.WriteLine("Try");
} catch (InvalidOperationException ex) {
Console.WriteLine(ex.Message);
} catch (Exception ex2) {
} catch (SystemException ex2) {
Console.WriteLine(ex2.Message);
} catch {
Console.WriteLine("other");
@ -176,5 +187,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -176,5 +187,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
}
}
}
}
}

14
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.il

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -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 lxxrs5dq
.assembly vicbdq3v
{
.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 lxxrs5dq.dll
// MVID: {82D6FFAF-FF9D-4E8C-AC93-080CC89EB80E}
.module vicbdq3v.dll
// MVID: {5E2AA050-D333-4323-8C5A-29B86C8D98BB}
.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: 0x02E30000
// Image base: 0x01160000
// =============== CLASS MEMBERS DECLARATION ===================
@ -323,7 +323,7 @@ @@ -323,7 +323,7 @@
// Code size 68 (0x44)
.maxstack 1
.locals init (class [mscorlib]System.InvalidOperationException V_0,
class [mscorlib]System.Exception V_1)
class [mscorlib]System.SystemException V_1)
IL_0000: nop
.try
{
@ -347,7 +347,7 @@ @@ -347,7 +347,7 @@
IL_001f: leave.s IL_0042
} // end handler
catch [mscorlib]System.Exception
catch [mscorlib]System.SystemException
{
IL_0021: stloc.1
IL_0022: nop

14
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.il

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -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 mydv32cl
.assembly uidw4n1e
{
.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 mydv32cl.dll
// MVID: {6B95C83E-B82F-493E-BD92-AF0A5E82F1B4}
.module uidw4n1e.dll
// MVID: {A6A100AA-2C72-4B40-9C9F-50DA438D4727}
.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: 0x014A0000
// Image base: 0x00380000
// =============== CLASS MEMBERS DECLARATION ===================
@ -258,7 +258,7 @@ @@ -258,7 +258,7 @@
// Code size 54 (0x36)
.maxstack 1
.locals init (class [mscorlib]System.InvalidOperationException V_0,
class [mscorlib]System.Exception V_1)
class [mscorlib]System.SystemException V_1)
.try
{
IL_0000: ldstr "Try"
@ -275,7 +275,7 @@ @@ -275,7 +275,7 @@
IL_0018: leave.s IL_0035
} // end handler
catch [mscorlib]System.Exception
catch [mscorlib]System.SystemException
{
IL_001a: stloc.1
IL_001b: ldloc.1

259
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.opt.roslyn.il

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -25,14 +25,14 @@ @@ -25,14 +25,14 @@
.ver 0:0:0:0
}
.module ExceptionHandling.dll
// MVID: {07FDA375-CD7B-478B-922A-E82E4CA881CF}
// MVID: {A4875794-8C32-4802-A38C-B190A38BD06B}
.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: 0x02CE0000
// Image base: 0x029B0000
// =============== CLASS MEMBERS DECLARATION ===================
@ -53,135 +53,136 @@ @@ -53,135 +53,136 @@
instance void MoveNext() cil managed
{
.override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::MoveNext
// Code size 242 (0xf2)
// Code size 240 (0xf0)
.maxstack 3
.locals init (int32 V_0,
bool V_1,
valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool> V_2,
class [mscorlib]System.Exception V_3,
class [mscorlib]System.Exception V_4)
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling V_1,
bool V_2,
valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool> V_3,
class [mscorlib]System.Exception V_4,
class [mscorlib]System.Exception V_5)
IL_0000: ldarg.0
IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_0006: stloc.0
IL_0007: ldarg.0
IL_0008: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>4__this'
IL_000d: stloc.1
.try
{
IL_0007: ldloc.0
IL_0008: pop
IL_0009: nop
IL_000e: ldloc.0
IL_000f: pop
IL_0010: nop
.try
{
IL_000a: ldloc.0
IL_000b: brfalse.s IL_0054
IL_000d: ldstr "Try"
IL_0012: call void [mscorlib]System.Console::WriteLine(string)
IL_0017: ldarg.0
IL_0018: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>4__this'
IL_001d: callvirt instance class [mscorlib]System.Threading.Tasks.Task`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling::T()
IL_0022: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<!0> class [mscorlib]System.Threading.Tasks.Task`1<bool>::GetAwaiter()
IL_0027: stloc.2
IL_0028: ldloca.s V_2
IL_002a: call instance bool valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>::get_IsCompleted()
IL_002f: brtrue.s IL_0070
IL_0031: ldarg.0
IL_0032: ldc.i4.0
IL_0033: dup
IL_0034: stloc.0
IL_0035: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_003a: ldarg.0
IL_003b: ldloc.2
IL_003c: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>u__1'
IL_0041: ldarg.0
IL_0042: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>t__builder'
IL_0047: ldloca.s V_2
IL_0049: ldarg.0
IL_004a: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool>::AwaitUnsafeOnCompleted<valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>,valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'>(!!0&,
IL_0011: ldloc.0
IL_0012: brfalse.s IL_0056
IL_0014: ldstr "Try"
IL_0019: call void [mscorlib]System.Console::WriteLine(string)
IL_001e: ldloc.1
IL_001f: callvirt instance class [mscorlib]System.Threading.Tasks.Task`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling::T()
IL_0024: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<!0> class [mscorlib]System.Threading.Tasks.Task`1<bool>::GetAwaiter()
IL_0029: stloc.3
IL_002a: ldloca.s V_3
IL_002c: call instance bool valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>::get_IsCompleted()
IL_0031: brtrue.s IL_0072
IL_0033: ldarg.0
IL_0034: ldc.i4.0
IL_0035: dup
IL_0036: stloc.0
IL_0037: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_003c: ldarg.0
IL_003d: ldloc.3
IL_003e: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>u__1'
IL_0043: ldarg.0
IL_0044: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>t__builder'
IL_0049: ldloca.s V_3
IL_004b: ldarg.0
IL_004c: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool>::AwaitUnsafeOnCompleted<valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>,valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'>(!!0&,
!!1&)
IL_004f: leave IL_00f1
IL_0054: ldarg.0
IL_0055: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>u__1'
IL_005a: stloc.2
IL_005b: ldarg.0
IL_005c: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>u__1'
IL_0061: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>
IL_0067: ldarg.0
IL_0068: ldc.i4.m1
IL_0069: dup
IL_006a: stloc.0
IL_006b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_0070: ldloca.s V_2
IL_0072: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>::GetResult()
IL_0077: ldloca.s V_2
IL_0079: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>
IL_007f: stloc.1
IL_0080: leave.s IL_00dd
IL_0051: leave IL_00ef
IL_0056: ldarg.0
IL_0057: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>u__1'
IL_005c: stloc.3
IL_005d: ldarg.0
IL_005e: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>u__1'
IL_0063: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>
IL_0069: ldarg.0
IL_006a: ldc.i4.m1
IL_006b: dup
IL_006c: stloc.0
IL_006d: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_0072: ldloca.s V_3
IL_0074: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>::GetResult()
IL_0079: stloc.2
IL_007a: leave.s IL_00db
} // end .try
filter
{
IL_0082: isinst [mscorlib]System.Exception
IL_0087: dup
IL_0088: brtrue.s IL_008e
IL_008a: pop
IL_008b: ldc.i4.0
IL_008c: br.s IL_00a6
IL_008e: stloc.3
IL_008f: ldloc.3
IL_0090: isinst [mscorlib]System.ArgumentException
IL_0095: brtrue.s IL_00a2
IL_0097: ldloc.3
IL_0098: isinst [mscorlib]System.IO.IOException
IL_009d: ldnull
IL_009e: cgt.un
IL_00a0: br.s IL_00a3
IL_00a2: ldc.i4.1
IL_00a3: ldc.i4.0
IL_00a4: cgt.un
IL_00a6: endfilter
IL_007c: isinst [mscorlib]System.Exception
IL_0081: dup
IL_0082: brtrue.s IL_0088
IL_0084: pop
IL_0085: ldc.i4.0
IL_0086: br.s IL_00a3
IL_0088: stloc.s V_4
IL_008a: ldloc.s V_4
IL_008c: isinst [mscorlib]System.ArgumentException
IL_0091: brtrue.s IL_009f
IL_0093: ldloc.s V_4
IL_0095: isinst [mscorlib]System.IO.IOException
IL_009a: ldnull
IL_009b: cgt.un
IL_009d: br.s IL_00a0
IL_009f: ldc.i4.1
IL_00a0: ldc.i4.0
IL_00a1: cgt.un
IL_00a3: endfilter
} // end filter
{ // handler
IL_00a8: pop
IL_00a9: ldstr "CatchException ex: "
IL_00ae: ldloc.3
IL_00af: callvirt instance string [mscorlib]System.Object::ToString()
IL_00b4: call string [mscorlib]System.String::Concat(string,
IL_00a5: pop
IL_00a6: ldstr "CatchException ex: "
IL_00ab: ldloc.s V_4
IL_00ad: callvirt instance string [mscorlib]System.Object::ToString()
IL_00b2: call string [mscorlib]System.String::Concat(string,
string)
IL_00b9: call void [mscorlib]System.Console::WriteLine(string)
IL_00be: leave.s IL_00c0
IL_00b7: call void [mscorlib]System.Console::WriteLine(string)
IL_00bc: leave.s IL_00be
} // end handler
IL_00c0: ldc.i4.0
IL_00c1: stloc.1
IL_00c2: leave.s IL_00dd
IL_00be: ldc.i4.0
IL_00bf: stloc.2
IL_00c0: leave.s IL_00db
} // end .try
catch [mscorlib]System.Exception
{
IL_00c4: stloc.s V_4
IL_00c6: ldarg.0
IL_00c7: ldc.i4.s -2
IL_00c9: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_00ce: ldarg.0
IL_00cf: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>t__builder'
IL_00d4: ldloc.s V_4
IL_00d6: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool>::SetException(class [mscorlib]System.Exception)
IL_00db: leave.s IL_00f1
IL_00c2: stloc.s V_5
IL_00c4: ldarg.0
IL_00c5: ldc.i4.s -2
IL_00c7: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_00cc: ldarg.0
IL_00cd: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>t__builder'
IL_00d2: ldloc.s V_5
IL_00d4: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool>::SetException(class [mscorlib]System.Exception)
IL_00d9: leave.s IL_00ef
} // end handler
IL_00dd: ldarg.0
IL_00de: ldc.i4.s -2
IL_00e0: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_00e5: ldarg.0
IL_00e6: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>t__builder'
IL_00eb: ldloc.1
IL_00ec: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool>::SetResult(!0)
IL_00f1: ret
IL_00db: ldarg.0
IL_00dc: ldc.i4.s -2
IL_00de: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_00e3: ldarg.0
IL_00e4: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>t__builder'
IL_00e9: ldloc.2
IL_00ea: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool>::SetResult(!0)
IL_00ef: ret
} // end of method '<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::MoveNext
.method private hidebysig newslot virtual final
@ -478,6 +479,48 @@ @@ -478,6 +479,48 @@
IL_0038: ret
} // end of method ExceptionHandling::SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr
.method public hidebysig instance void
CatchWhenWithConditionWithoutExceptionVar() cil managed
{
// Code size 44 (0x2c)
.maxstack 2
.locals init (int32 V_0)
IL_0000: ldc.i4.0
IL_0001: stloc.0
.try
{
IL_0002: newobj instance void [mscorlib]System.Exception::.ctor()
IL_0007: throw
} // end .try
filter
{
IL_0008: isinst [mscorlib]System.Exception
IL_000d: dup
IL_000e: brtrue.s IL_0014
IL_0010: pop
IL_0011: ldc.i4.0
IL_0012: br.s IL_001c
IL_0014: pop
IL_0015: ldloc.0
IL_0016: ldc.i4.0
IL_0017: ceq
IL_0019: ldc.i4.0
IL_001a: cgt.un
IL_001c: endfilter
} // end filter
{ // handler
IL_001e: pop
IL_001f: ldstr "jo"
IL_0024: call void [mscorlib]System.Console::WriteLine(string)
IL_0029: leave.s IL_002b
} // end handler
IL_002b: ret
} // end of method ExceptionHandling::CatchWhenWithConditionWithoutExceptionVar
.method public hidebysig instance bool
SimpleTryFinally() cil managed
{
@ -586,7 +629,7 @@ @@ -586,7 +629,7 @@
IL_0016: leave.s IL_0031
} // end handler
catch [mscorlib]System.Exception
catch [mscorlib]System.SystemException
{
IL_0018: callvirt instance string [mscorlib]System.Exception::get_Message()
IL_001d: call void [mscorlib]System.Console::WriteLine(string)

255
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.roslyn.il

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -25,14 +25,14 @@ @@ -25,14 +25,14 @@
.ver 0:0:0:0
}
.module ExceptionHandling.dll
// MVID: {07B52948-317B-4C30-A2A5-A7482568AD67}
// MVID: {9413A96F-08C3-4F13-A800-C6BE70786A44}
.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: 0x00ED0000
// Image base: 0x00370000
// =============== CLASS MEMBERS DECLARATION ===================
@ -66,15 +66,14 @@ @@ -66,15 +66,14 @@
instance void MoveNext() cil managed
{
.override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::MoveNext
// Code size 306 (0x132)
// Code size 295 (0x127)
.maxstack 3
.locals init (int32 V_0,
bool V_1,
valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool> V_2,
bool V_3,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8' V_4,
class [mscorlib]System.Exception V_5,
bool V_6)
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8' V_3,
class [mscorlib]System.Exception V_4,
bool V_5)
IL_0000: ldarg.0
IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_0006: stloc.0
@ -96,7 +95,7 @@ @@ -96,7 +95,7 @@
IL_0013: br.s IL_0017
IL_0015: br.s IL_0065
IL_0015: br.s IL_0064
IL_0017: nop
IL_0018: ldstr "Try"
@ -109,7 +108,7 @@ @@ -109,7 +108,7 @@
IL_0033: stloc.2
IL_0034: ldloca.s V_2
IL_0036: call instance bool valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>::get_IsCompleted()
IL_003b: brtrue.s IL_0081
IL_003b: brtrue.s IL_0080
IL_003d: ldarg.0
IL_003e: ldc.i4.0
@ -120,117 +119,113 @@ @@ -120,117 +119,113 @@
IL_0047: ldloc.2
IL_0048: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>u__1'
IL_004d: ldarg.0
IL_004e: stloc.s V_4
IL_0050: ldarg.0
IL_0051: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>t__builder'
IL_0056: ldloca.s V_2
IL_0058: ldloca.s V_4
IL_005a: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool>::AwaitUnsafeOnCompleted<valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>,class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'>(!!0&,
IL_004e: stloc.3
IL_004f: ldarg.0
IL_0050: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>t__builder'
IL_0055: ldloca.s V_2
IL_0057: ldloca.s V_3
IL_0059: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool>::AwaitUnsafeOnCompleted<valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>,class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'>(!!0&,
!!1&)
IL_005f: nop
IL_0060: leave IL_0131
IL_0065: ldarg.0
IL_0066: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>u__1'
IL_006b: stloc.2
IL_006c: ldarg.0
IL_006d: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>u__1'
IL_0072: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>
IL_0078: ldarg.0
IL_0079: ldc.i4.m1
IL_007a: dup
IL_007b: stloc.0
IL_007c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_005e: nop
IL_005f: leave IL_0126
IL_0064: ldarg.0
IL_0065: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>u__1'
IL_006a: stloc.2
IL_006b: ldarg.0
IL_006c: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>u__1'
IL_0071: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>
IL_0077: ldarg.0
IL_0078: ldc.i4.m1
IL_0079: dup
IL_007a: stloc.0
IL_007b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_0080: ldarg.0
IL_0081: ldloca.s V_2
IL_0083: call instance !0 valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>::GetResult()
IL_0088: stloc.3
IL_0089: ldloca.s V_2
IL_008b: initobj valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>
IL_0091: ldarg.0
IL_0092: ldloc.3
IL_0093: stfld bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>s__1'
IL_0098: ldarg.0
IL_0099: ldfld bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>s__1'
IL_009e: stloc.1
IL_009f: leave.s IL_011c
IL_0088: stfld bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>s__1'
IL_008d: ldarg.0
IL_008e: ldfld bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>s__1'
IL_0093: stloc.1
IL_0094: leave.s IL_0111
} // end .try
filter
{
IL_00a1: isinst [mscorlib]System.Exception
IL_00a6: dup
IL_00a7: brtrue.s IL_00ad
IL_00a9: pop
IL_00aa: ldc.i4.0
IL_00ab: br.s IL_00dc
IL_00ad: stloc.s V_5
IL_00af: ldarg.0
IL_00b0: ldloc.s V_5
IL_00b2: stfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<ex>5__2'
IL_00b7: ldarg.0
IL_00b8: ldfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<ex>5__2'
IL_00bd: isinst [mscorlib]System.ArgumentException
IL_00c2: brtrue.s IL_00d4
IL_00c4: ldarg.0
IL_00c5: ldfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<ex>5__2'
IL_00ca: isinst [mscorlib]System.IO.IOException
IL_00cf: ldnull
IL_00d0: cgt.un
IL_00d2: br.s IL_00d5
IL_00d4: ldc.i4.1
IL_00d5: stloc.s V_6
IL_00d7: ldloc.s V_6
IL_00d9: ldc.i4.0
IL_00da: cgt.un
IL_00dc: endfilter
IL_0096: isinst [mscorlib]System.Exception
IL_009b: dup
IL_009c: brtrue.s IL_00a2
IL_009e: pop
IL_009f: ldc.i4.0
IL_00a0: br.s IL_00d1
IL_00a2: stloc.s V_4
IL_00a4: ldarg.0
IL_00a5: ldloc.s V_4
IL_00a7: stfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<ex>5__2'
IL_00ac: ldarg.0
IL_00ad: ldfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<ex>5__2'
IL_00b2: isinst [mscorlib]System.ArgumentException
IL_00b7: brtrue.s IL_00c9
IL_00b9: ldarg.0
IL_00ba: ldfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<ex>5__2'
IL_00bf: isinst [mscorlib]System.IO.IOException
IL_00c4: ldnull
IL_00c5: cgt.un
IL_00c7: br.s IL_00ca
IL_00c9: ldc.i4.1
IL_00ca: stloc.s V_5
IL_00cc: ldloc.s V_5
IL_00ce: ldc.i4.0
IL_00cf: cgt.un
IL_00d1: endfilter
} // end filter
{ // handler
IL_00de: pop
IL_00df: nop
IL_00e0: ldstr "CatchException ex: "
IL_00e5: ldarg.0
IL_00e6: ldfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<ex>5__2'
IL_00eb: callvirt instance string [mscorlib]System.Object::ToString()
IL_00f0: call string [mscorlib]System.String::Concat(string,
IL_00d3: pop
IL_00d4: nop
IL_00d5: ldstr "CatchException ex: "
IL_00da: ldarg.0
IL_00db: ldfld class [mscorlib]System.Exception ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<ex>5__2'
IL_00e0: callvirt instance string [mscorlib]System.Object::ToString()
IL_00e5: call string [mscorlib]System.String::Concat(string,
string)
IL_00f5: call void [mscorlib]System.Console::WriteLine(string)
IL_00fa: nop
IL_00fb: nop
IL_00fc: leave.s IL_00fe
IL_00ea: call void [mscorlib]System.Console::WriteLine(string)
IL_00ef: nop
IL_00f0: nop
IL_00f1: leave.s IL_00f3
} // end handler
IL_00fe: ldc.i4.0
IL_00ff: stloc.1
IL_0100: leave.s IL_011c
IL_00f3: ldc.i4.0
IL_00f4: stloc.1
IL_00f5: leave.s IL_0111
} // end .try
catch [mscorlib]System.Exception
{
IL_0102: stloc.s V_5
IL_0104: ldarg.0
IL_0105: ldc.i4.s -2
IL_0107: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_010c: ldarg.0
IL_010d: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>t__builder'
IL_0112: ldloc.s V_5
IL_0114: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool>::SetException(class [mscorlib]System.Exception)
IL_0119: nop
IL_011a: leave.s IL_0131
IL_00f7: stloc.s V_4
IL_00f9: ldarg.0
IL_00fa: ldc.i4.s -2
IL_00fc: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_0101: ldarg.0
IL_0102: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>t__builder'
IL_0107: ldloc.s V_4
IL_0109: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool>::SetException(class [mscorlib]System.Exception)
IL_010e: nop
IL_010f: leave.s IL_0126
} // end handler
IL_011c: ldarg.0
IL_011d: ldc.i4.s -2
IL_011f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_0124: ldarg.0
IL_0125: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>t__builder'
IL_012a: ldloc.1
IL_012b: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool>::SetResult(!0)
IL_0130: nop
IL_0131: ret
IL_0111: ldarg.0
IL_0112: ldc.i4.s -2
IL_0114: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>1__state'
IL_0119: ldarg.0
IL_011a: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExceptionHandling/'<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::'<>t__builder'
IL_011f: ldloc.1
IL_0120: call instance void valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<bool>::SetResult(!0)
IL_0125: nop
IL_0126: ret
} // end of method '<SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr>d__8'::MoveNext
.method private hidebysig newslot virtual final
@ -570,6 +565,56 @@ @@ -570,6 +565,56 @@
IL_003a: ret
} // end of method ExceptionHandling::SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr
.method public hidebysig instance void
CatchWhenWithConditionWithoutExceptionVar() cil managed
{
// Code size 51 (0x33)
.maxstack 2
.locals init (int32 V_0,
bool V_1)
IL_0000: nop
IL_0001: ldc.i4.0
IL_0002: stloc.0
.try
{
IL_0003: nop
IL_0004: newobj instance void [mscorlib]System.Exception::.ctor()
IL_0009: throw
} // end .try
filter
{
IL_000a: isinst [mscorlib]System.Exception
IL_000f: dup
IL_0010: brtrue.s IL_0016
IL_0012: pop
IL_0013: ldc.i4.0
IL_0014: br.s IL_0020
IL_0016: pop
IL_0017: ldloc.0
IL_0018: ldc.i4.0
IL_0019: ceq
IL_001b: stloc.1
IL_001c: ldloc.1
IL_001d: ldc.i4.0
IL_001e: cgt.un
IL_0020: endfilter
} // end filter
{ // handler
IL_0022: pop
IL_0023: nop
IL_0024: ldstr "jo"
IL_0029: call void [mscorlib]System.Console::WriteLine(string)
IL_002e: nop
IL_002f: nop
IL_0030: leave.s IL_0032
} // end handler
IL_0032: ret
} // end of method ExceptionHandling::CatchWhenWithConditionWithoutExceptionVar
.method public hidebysig instance bool
SimpleTryFinally() cil managed
{
@ -700,7 +745,7 @@ @@ -700,7 +745,7 @@
// Code size 67 (0x43)
.maxstack 1
.locals init (class [mscorlib]System.InvalidOperationException V_0,
class [mscorlib]System.Exception V_1)
class [mscorlib]System.SystemException V_1)
IL_0000: nop
.try
{
@ -724,7 +769,7 @@ @@ -724,7 +769,7 @@
IL_001f: leave.s IL_0042
} // end handler
catch [mscorlib]System.Exception
catch [mscorlib]System.SystemException
{
IL_0021: stloc.1
IL_0022: nop

68
ICSharpCode.Decompiler/IL/Transforms/DetectCatchWhenConditionBlocks.cs

@ -41,10 +41,21 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -41,10 +41,21 @@ namespace ICSharpCode.Decompiler.IL.Transforms
// br whenConditionBlock
// }
var instructions = container.EntryPoint.Instructions;
((StLoc)instructions[0]).Value = exceptionSlot;
instructions[1].ReplaceWith(new Branch(whenConditionBlock));
instructions.RemoveAt(2);
container.SortBlocks(deleteUnreachableBlocks: true);
if (instructions.Count == 3) {
// stloc temp(isinst exceptionType(ldloc exceptionVar))
// if (comp(ldloc temp != ldnull)) br whenConditionBlock
// br falseBlock
((StLoc)instructions[0]).Value = exceptionSlot;
instructions[1].ReplaceWith(new Branch(whenConditionBlock));
instructions.RemoveAt(2);
container.SortBlocks(deleteUnreachableBlocks: true);
} else if (instructions.Count == 2) {
// if (comp(isinst exceptionType(ldloc exceptionVar) != ldnull)) br whenConditionBlock
// br falseBlock
instructions[0].ReplaceWith(new Branch(whenConditionBlock));
instructions.RemoveAt(1);
container.SortBlocks(deleteUnreachableBlocks: true);
}
}
}
}
@ -61,21 +72,42 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -61,21 +72,42 @@ namespace ICSharpCode.Decompiler.IL.Transforms
exceptionType = null;
exceptionSlot = null;
whenConditionBlock = null;
if (entryPoint == null || entryPoint.IncomingEdgeCount != 1 || entryPoint.Instructions.Count != 3)
if (entryPoint == null || entryPoint.IncomingEdgeCount != 1)
return false;
if (!entryPoint.Instructions[0].MatchStLoc(out var temp, out var isinst) ||
temp.Kind != VariableKind.StackSlot || !isinst.MatchIsInst(out exceptionSlot, out exceptionType))
return false;
if (!exceptionSlot.MatchLdLoc(out var exceptionVar) || exceptionVar.Kind != VariableKind.Exception)
return false;
if (!entryPoint.Instructions[1].MatchIfInstruction(out var condition, out var branch))
return false;
if (!condition.MatchCompNotEquals(out var left, out var right))
return false;
if (!entryPoint.Instructions[2].MatchBranch(out var falseBlock) || !MatchFalseBlock(container, falseBlock, out var returnVar, out var exitBlock))
return false;
if ((left.MatchLdNull() && right.MatchLdLoc(temp)) || (right.MatchLdNull() && left.MatchLdLoc(temp))) {
return branch.MatchBranch(out whenConditionBlock);
if (entryPoint.Instructions.Count == 3) {
// stloc temp(isinst exceptionType(ldloc exceptionVar))
// if (comp(ldloc temp != ldnull)) br whenConditionBlock
// br falseBlock
if (!entryPoint.Instructions[0].MatchStLoc(out var temp, out var isinst) ||
temp.Kind != VariableKind.StackSlot || !isinst.MatchIsInst(out exceptionSlot, out exceptionType))
return false;
if (!exceptionSlot.MatchLdLoc(out var exceptionVar) || exceptionVar.Kind != VariableKind.Exception)
return false;
if (!entryPoint.Instructions[1].MatchIfInstruction(out var condition, out var branch))
return false;
if (!condition.MatchCompNotEquals(out var left, out var right))
return false;
if (!entryPoint.Instructions[2].MatchBranch(out var falseBlock) || !MatchFalseBlock(container, falseBlock, out var returnVar, out var exitBlock))
return false;
if ((left.MatchLdNull() && right.MatchLdLoc(temp)) || (right.MatchLdNull() && left.MatchLdLoc(temp))) {
return branch.MatchBranch(out whenConditionBlock);
}
} else if (entryPoint.Instructions.Count == 2) {
// if (comp(isinst exceptionType(ldloc exceptionVar) != ldnull)) br whenConditionBlock
// br falseBlock
if (!entryPoint.Instructions[0].MatchIfInstruction(out var condition, out var branch))
return false;
if (!condition.MatchCompNotEquals(out var left, out var right))
return false;
if (!entryPoint.Instructions[1].MatchBranch(out var falseBlock) || !MatchFalseBlock(container, falseBlock, out var returnVar, out var exitBlock))
return false;
if (!left.MatchIsInst(out exceptionSlot, out exceptionType))
return false;
if (!exceptionSlot.MatchLdLoc(out var exceptionVar) || exceptionVar.Kind != VariableKind.Exception)
return false;
if (right.MatchLdNull()) {
return branch.MatchBranch(out whenConditionBlock);
}
}
return false;
}

Loading…
Cancel
Save