Skip to content

Commit

Permalink
Only tread FlowCaptureReference as read when it's not an assignment t…
Browse files Browse the repository at this point in the history
…arget
  • Loading branch information
Tim-Pohlmann committed Jul 19, 2024
1 parent 1558760 commit fa2b72f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,7 @@ public void ProcessBlock(ControlFlowGraph cfg, BasicBlock block, Dictionary<Capt
{
foreach (var operation in block.OperationsAndBranchValue.ToReversedExecutionOrder().Select(x => x.Instance))
{
if (operation.AsFlowCaptureReference() is { } flowCaptureReference && flowCaptureOperations.TryGetValue(flowCaptureReference.Id, out var symbols))
{
UsedBeforeAssigned.UnionWith(symbols);
}
else
{
ProcessOperation(cfg, operation);
}
ProcessOperation(cfg, operation);
}
}

Expand All @@ -265,6 +258,9 @@ private void ProcessOperation(ControlFlowGraph cfg, IOperation operation)
case OperationKindEx.ParameterReference:
ProcessParameterOrLocalReference(IParameterReferenceOperationWrapper.FromOperation(operation));
break;
case OperationKindEx.FlowCaptureReference:
ProcessParameterOrLocalReference(IFlowCaptureReferenceOperationWrapper.FromOperation(operation));
break;
case OperationKindEx.SimpleAssignment:
ProcessSimpleAssignment(ISimpleAssignmentOperationWrapper.FromOperation(operation));
break;
Expand All @@ -288,7 +284,7 @@ private void ProcessParameterOrLocalReference(IOperationWrapper reference)
Assigned.UnionWith(symbols);
UsedBeforeAssigned.ExceptWith(symbols);
}
else if (!reference.IsAssignmentTarget())
else if (!reference.IsAssignmentTarget() && reference.ToSonar().Parent?.Kind != OperationKindEx.FlowCapture)
{
UsedBeforeAssigned.UnionWith(symbols);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,14 +648,14 @@ public void Unused()
private void ConditionalEvaluation(bool b1, bool b2, object coalesce, object coalesceAssignment)
{
var x = false; // Compliant ignored value
x = true; // Roslyn CFG FN: Consequence of inaccurate LVA state below
x = b1 && b2; // Roslyn CFG FN: Branching with FlowCaptureOperation
x = true; // Noncompliant
x = b1 && b2; // Noncompliant
x = b1 || b2; // Noncompliant
coalesce = coalesce ?? "Value"; // Noncompliant
coalesceAssignment ??= "Value"; // Noncompliant

DeadStores lst;
lst = new DeadStores // FN
lst = new DeadStores // Noncompliant
{
Property = 42
};
Expand Down

0 comments on commit fa2b72f

Please sign in to comment.