Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmcs/mcs/ChangeLog4
-rwxr-xr-xmcs/mcs/statement.cs5
-rwxr-xr-xmcs/tests/test-52.cs19
3 files changed, 27 insertions, 1 deletions
diff --git a/mcs/mcs/ChangeLog b/mcs/mcs/ChangeLog
index a05413c986c..6973c9cdf3d 100755
--- a/mcs/mcs/ChangeLog
+++ b/mcs/mcs/ChangeLog
@@ -1,5 +1,9 @@
2002-07-09 Miguel de Icaza <miguel@ximian.com>
+ * statement.cs (Break): We can be breaking out of a Try/Catch
+ controlled section (foreach might have an implicit try/catch
+ clause), so we need to use Leave instead of Br.
+
* ecore.cs (FieldExpr.AddressOf): Fix for test-139 (augmented
now). If the instace expression supports IMemoryLocation, we use
the AddressOf method from the IMemoryLocation to extract the
diff --git a/mcs/mcs/statement.cs b/mcs/mcs/statement.cs
index ec4aa95f1bf..31280775adb 100755
--- a/mcs/mcs/statement.cs
+++ b/mcs/mcs/statement.cs
@@ -757,7 +757,10 @@ namespace Mono.CSharp {
}
ec.Breaks = true;
- ig.Emit (OpCodes.Br, ec.LoopEnd);
+ if (ec.InTry || ec.InCatch)
+ ig.Emit (OpCodes.Leave, ec.LoopEnd);
+ else
+ ig.Emit (OpCodes.Br, ec.LoopEnd);
return false;
}
diff --git a/mcs/tests/test-52.cs b/mcs/tests/test-52.cs
index f16e6264696..c6b0726c3a7 100755
--- a/mcs/tests/test-52.cs
+++ b/mcs/tests/test-52.cs
@@ -73,6 +73,25 @@ class X {
if (total2 != "AB")
return 3;
+ ArrayList list = new ArrayList ();
+ list.Add ("one");
+ list.Add ("two");
+ list.Add ("three");
+ int count = 0;
+
+ //
+ // This test will make sure that `break' inside foreach will
+ // actually use a `leave' opcode instead of a `br' opcode
+ //
+ foreach (string s in list){
+ if (s == "two"){
+ break;
+ }
+ count++;
+ }
+ if (count != 1)
+ return 4;
+
Console.WriteLine ("test passes");
return 0;
}