diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_IfStatement.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_IfStatement.cs
index 0c807fc1072f1508cbcf30ea4ff70362fed2274c..2305c3e63d7189eff3815f1d37449f67b145d47c 100644
--- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_IfStatement.cs
+++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_IfStatement.cs
@@ -59,6 +59,7 @@ public override BoundNode VisitIfStatement(BoundIfStatement node)
builder.Add(new BoundConditionalGoto(rewrittenCondition.Syntax, rewrittenCondition, false, afterif));
builder.Add(rewrittenConsequence);
+ builder.Add(new BoundSequencePoint(null, null));
builder.Add(new BoundLabelStatement(syntax, afterif));
var statements = builder.ToImmutableAndFree();
return new BoundStatementList(syntax, statements, hasErrors);
@@ -86,6 +87,7 @@ public override BoundNode VisitIfStatement(BoundIfStatement node)
builder.Add(new BoundGotoStatement(syntax, afterif));
builder.Add(new BoundLabelStatement(syntax, alt));
builder.Add(rewrittenAlternativeOpt);
+ builder.Add(new BoundSequencePoint(null, null));
builder.Add(new BoundLabelStatement(syntax, afterif));
return new BoundStatementList(syntax, builder.ToImmutableAndFree(), hasErrors);
}
diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ReturnStatement.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ReturnStatement.cs
index a611dffde4a0a37fcfc32ce8876d5780e687f16a..18b2442dbe4a79500a95585eed02f4ceb2893ed9 100644
--- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ReturnStatement.cs
+++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ReturnStatement.cs
@@ -28,10 +28,6 @@ public override BoundNode VisitReturnStatement(BoundReturnStatement node)
{
rewritten = _instrumenter.InstrumentReturnStatement(node, rewritten);
}
- else if (node.WasCompilerGenerated && _factory.CurrentMethod?.IsAsync == true)
- {
- rewritten = new BoundSequencePoint(null, rewritten);
- }
return rewritten;
}
diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLockTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLockTests.cs
index 6a0f3d1eeba359536c89697c955053e17f94e53f..7bca136e11e92aa9b722d206b92c99d582f2d326 100644
--- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLockTests.cs
+++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLockTests.cs
@@ -57,7 +57,7 @@ .maxstack 2
IL_0023: brfalse.s IL_002b
IL_0025: ldloc.0
IL_0026: call ""void System.Threading.Monitor.Exit(object)""
- IL_002b: endfinally
+ ~IL_002b: endfinally
}
-IL_002c: ldstr ""After""
IL_0031: call ""void System.Console.WriteLine(string)""
@@ -112,7 +112,7 @@ .maxstack 2
IL_0027: brfalse.s IL_002f
IL_0029: ldloc.0
IL_002a: call ""void System.Threading.Monitor.Exit(object)""
- IL_002f: endfinally
+ ~IL_002f: endfinally
}
-IL_0030: ldstr ""After""
IL_0035: call ""void System.Console.WriteLine(string)""
@@ -387,7 +387,7 @@ .maxstack 2
IL_0027: brfalse.s IL_002f
IL_0029: ldloc.0
IL_002a: call ""void System.Threading.Monitor.Exit(object)""
- IL_002f: endfinally
+ ~IL_002f: endfinally
}
-IL_0030: ldstr ""After""
IL_0035: call ""void System.Console.WriteLine(string)""
diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/LocalSlotMappingTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/LocalSlotMappingTests.cs
index 7dce777325afd66661bb3c09e8b5414ea4ecea66..2ceeac1661b2fea050acc7e7e8ea6ef0b3e8f082 100644
--- a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/LocalSlotMappingTests.cs
+++ b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/LocalSlotMappingTests.cs
@@ -349,10 +349,12 @@ static void M()
+
+
@@ -370,9 +372,11 @@ static void M()
+
+
@@ -559,7 +563,7 @@ .maxstack 2
IL_002b: ldloc.2
IL_002c: call ""void System.Threading.Monitor.Exit(object)""
IL_0031: nop
- IL_0032: endfinally
+ ~IL_0032: endfinally
}
-IL_0033: nop
IL_0034: leave.s IL_0041
@@ -571,7 +575,7 @@ .maxstack 2
IL_0039: ldloc.0
IL_003a: call ""void System.Threading.Monitor.Exit(object)""
IL_003f: nop
- IL_0040: endfinally
+ ~IL_0040: endfinally
}
-IL_0041: ret
}
@@ -1787,7 +1791,7 @@ .maxstack 2
IL_0010: ldloc.s V_6
IL_0012: callvirt ""void System.IDisposable.Dispose()""
IL_0017: nop
- IL_0018: endfinally
+ ~IL_0018: endfinally
}
-IL_0019: call ""object C.F1()""
IL_001e: stloc.0
@@ -1810,7 +1814,7 @@ .maxstack 2
IL_0031: ldloc.0
IL_0032: call ""void System.Threading.Monitor.Exit(object)""
IL_0037: nop
- IL_0038: endfinally
+ ~IL_0038: endfinally
}
-IL_0039: nop
-IL_003a: call ""string C.F2()""
diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBAsyncTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBAsyncTests.cs
index 12af52598331fc941cd45d259924408908dc1987..44decd73a817f2083fc60d654752232f66dd8c2f 100644
--- a/src/Compilers/CSharp/Test/Emit/PDB/PDBAsyncTests.cs
+++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBAsyncTests.cs
@@ -159,7 +159,7 @@ .maxstack 3
-IL_00e5: ldsfld ""System.Threading.AutoResetEvent Driver.CompletedSignal""
IL_00ea: callvirt ""bool System.Threading.EventWaitHandle.Set()""
IL_00ef: pop
- ~IL_00f0: leave.s IL_010c
+ IL_00f0: leave.s IL_010c
}
catch System.Exception
{
@@ -288,7 +288,6 @@ .maxstack 3
-
@@ -444,7 +443,6 @@ private Task GetNextInt(Random random)
-
@@ -558,7 +556,6 @@ static async void Await(dynamic d)
-
@@ -756,7 +753,6 @@ static async Task M(int b)
-
@@ -850,7 +846,6 @@ static async Task M(int b)
-
@@ -939,7 +934,6 @@ static async Task M(int b)
-
@@ -1028,7 +1022,6 @@ static async Task M(int b)
-
@@ -1117,7 +1110,6 @@ static async Task M()
-
@@ -1196,7 +1188,6 @@ static async Task M()
-
@@ -1284,7 +1275,6 @@ static async Task M()
-
@@ -1731,7 +1721,6 @@ public partial class C
Document: #1
IL_0000:
IL_0007: (5, 28) - (5, 29)
- IL_0008:
IL_000A:
IL_0022: (5, 29) - (5, 30)
IL_002A:
diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBIteratorTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBIteratorTests.cs
index d5ddcde1afa3e852f14c9300c72bfb74357d2e0a..70fb385094fb226770de1369c0492cd6eedd1df5 100644
--- a/src/Compilers/CSharp/Test/Emit/PDB/PDBIteratorTests.cs
+++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBIteratorTests.cs
@@ -403,6 +403,7 @@ static void Main()
+
@@ -555,6 +556,7 @@ public static void Main()
+
diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBLambdaTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBLambdaTests.cs
index 100c4222be53927f3ade2cd66b77bed38bfe04e3..5accc7aa57e88e8a1bd5d6e41ad793531509cc48 100644
--- a/src/Compilers/CSharp/Test/Emit/PDB/PDBLambdaTests.cs
+++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBLambdaTests.cs
@@ -1314,8 +1314,10 @@ static void F()
+
+
diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs
index 667f45ffcd116fa4ce3b6b82c160605ef3c37589..dad8fbff4d285d12d17ec902ca5e55aa15146224 100644
--- a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs
+++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs
@@ -2649,6 +2649,7 @@ static void Main(string[] args)
+
@@ -4486,16 +4487,20 @@ static void Main()
+
+
+
+
@@ -4515,8 +4520,8 @@ static void Main()
");
}
- [Fact(Skip = "https://github.com/dotnet/roslyn/issues/18844"), WorkItem(18844, "https://github.com/dotnet/roslyn/issues/18844")]
- public void UsingStatement_Embedded()
+ [Fact, WorkItem(18844, "https://github.com/dotnet/roslyn/issues/18844")]
+ public void UsingStatement_EmbeddedConditional()
{
var source = @"
class C
@@ -4590,6 +4595,7 @@ .maxstack 1
IL_001d: ldloc.2
IL_001e: callvirt ""void System.IDisposable.Dispose()""
IL_0023: nop
+ // sequence point:
IL_0024: endfinally
}
// sequence point: return value;
@@ -4603,6 +4609,302 @@ .maxstack 1
", sequencePoints: "C.F", source: source);
}
+ [Fact, WorkItem(18844, "https://github.com/dotnet/roslyn/issues/18844")]
+ public void UsingStatement_EmbeddedConditional2()
+ {
+ var source = @"
+class C
+{
+ bool F()
+ {
+ bool x = true;
+ bool value = false;
+ using (var stream = new System.IO.MemoryStream())
+ if (x)
+ {
+ value = true;
+ }
+ else
+ {
+ value = false;
+ }
+
+ return value;
+ }
+}
+";
+
+ var c = CreateCompilationWithMscorlibAndSystemCore(source, options: TestOptions.DebugDll);
+ var v = CompileAndVerify(c);
+ v.VerifyIL("C.F", @"
+{
+ // Code size 47 (0x2f)
+ .maxstack 1
+ .locals init (bool V_0, //x
+ bool V_1, //value
+ System.IO.MemoryStream V_2, //stream
+ bool V_3,
+ bool V_4)
+ // sequence point: {
+ IL_0000: nop
+ // sequence point: bool x = true;
+ IL_0001: ldc.i4.1
+ IL_0002: stloc.0
+ // sequence point: bool value = false;
+ IL_0003: ldc.i4.0
+ IL_0004: stloc.1
+ // sequence point: var stream = new System.IO.MemoryStream()
+ IL_0005: newobj ""System.IO.MemoryStream..ctor()""
+ IL_000a: stloc.2
+ .try
+ {
+ // sequence point: if (x)
+ IL_000b: ldloc.0
+ IL_000c: stloc.3
+ // sequence point:
+ IL_000d: ldloc.3
+ IL_000e: brfalse.s IL_0016
+ // sequence point: {
+ IL_0010: nop
+ // sequence point: value = true;
+ IL_0011: ldc.i4.1
+ IL_0012: stloc.1
+ // sequence point: }
+ IL_0013: nop
+ IL_0014: br.s IL_001a
+ // sequence point: {
+ IL_0016: nop
+ // sequence point: value = false;
+ IL_0017: ldc.i4.0
+ IL_0018: stloc.1
+ // sequence point: }
+ IL_0019: nop
+ // sequence point:
+ IL_001a: leave.s IL_0027
+ }
+ finally
+ {
+ // sequence point:
+ IL_001c: ldloc.2
+ IL_001d: brfalse.s IL_0026
+ IL_001f: ldloc.2
+ IL_0020: callvirt ""void System.IDisposable.Dispose()""
+ IL_0025: nop
+ // sequence point:
+ IL_0026: endfinally
+ }
+ // sequence point: return value;
+ IL_0027: ldloc.1
+ IL_0028: stloc.s V_4
+ IL_002a: br.s IL_002c
+ // sequence point: }
+ IL_002c: ldloc.s V_4
+ IL_002e: ret
+}
+", sequencePoints: "C.F", source: source);
+ }
+
+ [Fact, WorkItem(18844, "https://github.com/dotnet/roslyn/issues/18844")]
+ public void UsingStatement_EmbeddedWhile()
+ {
+ var source = @"
+class C
+{
+ void F(bool x)
+ {
+ using (var stream = new System.IO.MemoryStream())
+ while (x)
+ x = false;
+ }
+}
+";
+
+ var c = CreateCompilationWithMscorlibAndSystemCore(source, options: TestOptions.DebugDll);
+ var v = CompileAndVerify(c);
+ v.VerifyIL("C.F", @"
+{
+ // Code size 31 (0x1f)
+ .maxstack 1
+ .locals init (System.IO.MemoryStream V_0, //stream
+ bool V_1)
+ // sequence point: {
+ IL_0000: nop
+ // sequence point: var stream = new System.IO.MemoryStream()
+ IL_0001: newobj ""System.IO.MemoryStream..ctor()""
+ IL_0006: stloc.0
+ .try
+ {
+ // sequence point:
+ IL_0007: br.s IL_000c
+ // sequence point: x = false;
+ IL_0009: ldc.i4.0
+ IL_000a: starg.s V_1
+ // sequence point: while (x)
+ IL_000c: ldarg.1
+ IL_000d: stloc.1
+ // sequence point:
+ IL_000e: ldloc.1
+ IL_000f: brtrue.s IL_0009
+ IL_0011: leave.s IL_001e
+ }
+ finally
+ {
+ // sequence point:
+ IL_0013: ldloc.0
+ IL_0014: brfalse.s IL_001d
+ IL_0016: ldloc.0
+ IL_0017: callvirt ""void System.IDisposable.Dispose()""
+ IL_001c: nop
+ // sequence point:
+ IL_001d: endfinally
+ }
+ // sequence point: }
+ IL_001e: ret
+}
+", sequencePoints: "C.F", source: source);
+ }
+
+ [Fact, WorkItem(18844, "https://github.com/dotnet/roslyn/issues/18844")]
+ public void UsingStatement_EmbeddedFor()
+ {
+ var source = @"
+class C
+{
+ void F(bool x)
+ {
+ using (var stream = new System.IO.MemoryStream())
+ for ( ; x == true; )
+ x = false;
+ }
+}
+";
+
+ var c = CreateCompilationWithMscorlibAndSystemCore(source, options: TestOptions.DebugDll);
+ var v = CompileAndVerify(c);
+ v.VerifyIL("C.F", @"
+{
+ // Code size 31 (0x1f)
+ .maxstack 1
+ .locals init (System.IO.MemoryStream V_0, //stream
+ bool V_1)
+ // sequence point: {
+ IL_0000: nop
+ // sequence point: var stream = new System.IO.MemoryStream()
+ IL_0001: newobj ""System.IO.MemoryStream..ctor()""
+ IL_0006: stloc.0
+ .try
+ {
+ // sequence point:
+ IL_0007: br.s IL_000c
+ // sequence point: x = false;
+ IL_0009: ldc.i4.0
+ IL_000a: starg.s V_1
+ // sequence point: x == true
+ IL_000c: ldarg.1
+ IL_000d: stloc.1
+ // sequence point:
+ IL_000e: ldloc.1
+ IL_000f: brtrue.s IL_0009
+ IL_0011: leave.s IL_001e
+ }
+ finally
+ {
+ // sequence point:
+ IL_0013: ldloc.0
+ IL_0014: brfalse.s IL_001d
+ IL_0016: ldloc.0
+ IL_0017: callvirt ""void System.IDisposable.Dispose()""
+ IL_001c: nop
+ // sequence point:
+ IL_001d: endfinally
+ }
+ // sequence point: }
+ IL_001e: ret
+}
+", sequencePoints: "C.F", source: source);
+ }
+
+ [Fact, WorkItem(18844, "https://github.com/dotnet/roslyn/issues/18844")]
+ public void LockStatement_EmbeddedIf()
+ {
+ var source = @"
+class C
+{
+ void F(bool x)
+ {
+ string y = """";
+ lock (y)
+ if (!x)
+ System.Console.Write(1);
+ else
+ System.Console.Write(2);
+ }
+}
+";
+
+ var c = CreateCompilationWithMscorlibAndSystemCore(source, options: TestOptions.DebugDll);
+ var v = CompileAndVerify(c);
+ v.VerifyIL("C.F", @"
+{
+ // Code size 58 (0x3a)
+ .maxstack 2
+ .locals init (string V_0, //y
+ string V_1,
+ bool V_2,
+ bool V_3)
+ // sequence point: {
+ IL_0000: nop
+ // sequence point: string y = """";
+ IL_0001: ldstr """"
+ IL_0006: stloc.0
+ // sequence point: lock (y)
+ IL_0007: ldloc.0
+ IL_0008: stloc.1
+ IL_0009: ldc.i4.0
+ IL_000a: stloc.2
+ .try
+ {
+ IL_000b: ldloc.1
+ IL_000c: ldloca.s V_2
+ IL_000e: call ""void System.Threading.Monitor.Enter(object, ref bool)""
+ IL_0013: nop
+ // sequence point: if (!x)
+ IL_0014: ldarg.1
+ IL_0015: ldc.i4.0
+ IL_0016: ceq
+ IL_0018: stloc.3
+ // sequence point:
+ IL_0019: ldloc.3
+ IL_001a: brfalse.s IL_0025
+ // sequence point: System.Console.Write(1);
+ IL_001c: ldc.i4.1
+ IL_001d: call ""void System.Console.Write(int)""
+ IL_0022: nop
+ IL_0023: br.s IL_002c
+ // sequence point: System.Console.Write(2);
+ IL_0025: ldc.i4.2
+ IL_0026: call ""void System.Console.Write(int)""
+ IL_002b: nop
+ // sequence point:
+ IL_002c: leave.s IL_0039
+ }
+ finally
+ {
+ // sequence point:
+ IL_002e: ldloc.2
+ IL_002f: brfalse.s IL_0038
+ IL_0031: ldloc.1
+ IL_0032: call ""void System.Threading.Monitor.Exit(object)""
+ IL_0037: nop
+ // sequence point:
+ IL_0038: endfinally
+ }
+ // sequence point: }
+ IL_0039: ret
+}
+", sequencePoints: "C.F", source: source);
+ }
+
#endregion
// LockStatement tested in CodeGenLock
@@ -5986,7 +6288,6 @@ static async Task F()
-
@@ -6049,7 +6350,6 @@ static void M()
-
@@ -6367,7 +6667,6 @@ public async void M1()
-
@@ -6743,7 +7042,6 @@ .maxstack 2
IL_001a: br.s IL_001e
// sequence point: break;
IL_001c: br.s IL_001e
- // sequence point:
IL_001e: leave.s IL_0038
}
catch System.Exception
@@ -6826,7 +7124,6 @@ .maxstack 2
// sequence point:
IL_0021: ldloc.1
IL_0022: brtrue.s IL_0011
- // sequence point:
IL_0024: leave.s IL_003e
}
catch System.Exception
@@ -6918,7 +7215,6 @@ .maxstack 3
// sequence point:
IL_0031: ldloc.2
IL_0032: brtrue.s IL_0011
- // sequence point:
IL_0034: leave.s IL_004e
}
catch System.Exception
@@ -7013,7 +7309,6 @@ .maxstack 3
// sequence point:
IL_003b: ldloc.2
IL_003c: brtrue.s IL_001b
- // sequence point:
IL_003e: leave.s IL_0058
}
catch System.Exception
diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBTupleTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBTupleTests.cs
index 2a9cb23531aeffc2abe4d873bce2ab7276bc2df1..a394b9160e9b61a82b7514e1ae760fd92f5732eb 100644
--- a/src/Compilers/CSharp/Test/Emit/PDB/PDBTupleTests.cs
+++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBTupleTests.cs
@@ -251,6 +251,7 @@ static void F(System.Collections.Generic.IEnumerable<(int a, int b)> ie)
+
diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBUsingTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBUsingTests.cs
index 1b563f9ad1b549ac780a8d033ab93dc07f252404..61a8b5b5e53bfcd8a34d5100a48525c2f9e9bfc4 100644
--- a/src/Compilers/CSharp/Test/Emit/PDB/PDBUsingTests.cs
+++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBUsingTests.cs
@@ -1734,7 +1734,7 @@ .locals init (Test V_0)
IL_000e: ldloc.0
IL_000f: callvirt ""void System.IDisposable.Dispose()""
IL_0014: nop
- IL_0015: endfinally
+ ~IL_0015: endfinally
}
-IL_0016: ret
}", sequencePoints: "Test.Main");