Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -366,21 +366,24 @@
public override BoundNode VisitTryStatement(BoundTryStatement node)
{
var savedDisposalLabel = _currentDisposalLabel;
LabelSymbol finallyEntry = null;
bool hasCatchBlocks = !node.CatchBlocks.IsEmpty;

Check failure on line 371 in src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs#L371

src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs(371,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 371 in src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs#L371

src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs(371,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 371 in src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs#L371

src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs(371,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 371 in src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs#L371

src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs(371,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
if (node.FinallyBlockOpt is object)
{
var finallyEntry = F.GenerateLabel("finallyEntry");
finallyEntry = F.GenerateLabel("finallyEntry");
_currentDisposalLabel = finallyEntry;

// Add finallyEntry label:
// try
// {
// ...
// finallyEntry:
// }

node = node.Update(
tryBlock: F.Block(node.TryBlock, F.Label(finallyEntry)),
node.CatchBlocks, node.FinallyBlockOpt, node.FinallyLabelOpt, node.PreferFaultHandler);
// When there are no catch blocks, we can place the finallyEntry label at the end
// of the try block (original behavior). But when there are catch blocks, we must
// place it after the entire try-catch-finally structure to avoid invalid IL
// (leaving from a catch block into a try block).
if (!hasCatchBlocks)
{
node = node.Update(
tryBlock: F.Block(node.TryBlock, F.Label(finallyEntry)),
node.CatchBlocks, node.FinallyBlockOpt, node.FinallyLabelOpt, node.PreferFaultHandler);
}
}
else if (node.FinallyLabelOpt is object)
{
Expand All @@ -391,6 +394,30 @@

_currentDisposalLabel = savedDisposalLabel;

if (finallyEntry != null && hasCatchBlocks)
{
// When there are catch blocks, place the finallyEntry label after the try-catch-finally:
// try
// {
// ...
// if (disposeMode) leave to finallyEntry;
// }
// catch
// {
// ...
// if (disposeMode) leave to finallyEntry;
// }
// finally
// {
// ...
// }
// finallyEntry:
// if (disposeMode) goto currentDisposalLabel;
result = F.Block(
result,
F.Label(finallyEntry));
}

if (node.FinallyBlockOpt != null && _currentDisposalLabel is object)
{
// Append:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4729,11 +4729,7 @@ public static async System.Collections.Generic.IAsyncEnumerable<int> M()
}";
var comp = CreateCompilationWithAsyncIterator(new[] { Run(iterations), source }, options: TestOptions.DebugExe);
comp.VerifyDiagnostics();
var verifier = CompileAndVerify(comp, expectedOutput: expectedOutput,
verify: Verification.FailsILVerify with
{
ILVerifyMessage = "[MoveNext]: Leave into try block. { Offset = 0x11a }"
});
var verifier = CompileAndVerify(comp, expectedOutput: expectedOutput);

verifier.VerifyIL("C.<M>d__0.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext()", """
{
Expand Down Expand Up @@ -4859,7 +4855,7 @@ .locals init (int V_0,
IL_00f9: ldarg.0
IL_00fa: ldfld "bool C.<M>d__0.<>w__disposeMode"
IL_00ff: brfalse.s IL_0103
IL_0101: br.s IL_0104
IL_0101: leave.s IL_0130
IL_0103: nop
IL_0104: leave.s IL_011c
}
Expand All @@ -4873,7 +4869,7 @@ .locals init (int V_0,
IL_0113: ldarg.0
IL_0114: ldc.i4.1
IL_0115: stfld "bool C.<M>d__0.<>w__disposeMode"
IL_011a: leave.s IL_0104
IL_011a: leave.s IL_0130
}
IL_011c: leave.s IL_0130
}
Expand Down
Loading