From e06781fb7a9404144a12c9ae9cd04a4bdf337601 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Tue, 30 May 2017 11:39:46 +0200 Subject: [PATCH] [mcs] Reset catch state variable after it has been checked. Fixes #54322 --- mcs/mcs/statement.cs | 4 +++ mcs/tests/test-async-93.cs | 44 ++++++++++++++++++++++++++++ mcs/tests/ver-il-net_4_x.xml | 57 +++++++++++++++++++++++++++++------- 3 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 mcs/tests/test-async-93.cs diff --git a/mcs/mcs/statement.cs b/mcs/mcs/statement.cs index 20eb19e6cee..d500eea093d 100644 --- a/mcs/mcs/statement.cs +++ b/mcs/mcs/statement.cs @@ -7459,6 +7459,10 @@ namespace Mono.CSharp { ec.Emit (OpCodes.Br, end); ec.MarkLabel (labels [i + 1]); + + ec.EmitInt (0); + ec.Emit (OpCodes.Stloc, state_variable); + c = catch_sm [i]; ec.AsyncThrowVariable = c.Variable; c.Block.Emit (ec); diff --git a/mcs/tests/test-async-93.cs b/mcs/tests/test-async-93.cs new file mode 100644 index 00000000000..249de2aed77 --- /dev/null +++ b/mcs/tests/test-async-93.cs @@ -0,0 +1,44 @@ +using System; +using System.Threading.Tasks; + +public class Test +{ + public static int Main() + { + var t = new Test (); + t.Entry().Wait(); + if (t.caughtCounter != 1) + return 1; + + return 0; + } + + int caughtCounter; + + async Task Entry() + { + for (int i = 0; i < 5; ++i) { + try { + var result = Func(i); + Console.WriteLine($"{i} result {result}"); + } catch (Exception e) { + await Nothing(); + Console.WriteLine($"{i} caught"); + ++caughtCounter; + } + } + } + + bool Func(int i) + { + if (i == 0) { + throw new Exception(); + } else { + return true; + } + } + + async Task Nothing() + { + } +} \ No newline at end of file diff --git a/mcs/tests/ver-il-net_4_x.xml b/mcs/tests/ver-il-net_4_x.xml index 64f69ccf611..79635e22c07 100644 --- a/mcs/tests/ver-il-net_4_x.xml +++ b/mcs/tests/ver-il-net_4_x.xml @@ -65697,7 +65697,7 @@ - 274 + 276 13 @@ -65705,7 +65705,7 @@ - 419 + 423 13 @@ -65754,7 +65754,7 @@ - 363 + 367 13 @@ -66000,7 +66000,7 @@ - 903 + 906 13 @@ -66008,7 +66008,7 @@ - 903 + 906 13 @@ -66478,7 +66478,7 @@ - 543 + 545 13 @@ -66486,7 +66486,7 @@ - 398 + 400 13 @@ -66621,7 +66621,7 @@ - 460 + 463 13 @@ -66783,6 +66783,41 @@ + + + + 46 + + + 41 + + + 24 + + + 33 + + + 7 + + + + + 344 + + + 13 + + + + + 61 + + + 13 + + + @@ -68519,7 +68554,7 @@ - 281 + 283 13 @@ -68527,7 +68562,7 @@ - 250 + 252 13 @@ -68551,7 +68586,7 @@ - 491 + 495 13 -- 2.25.1