Skip to content

VB: Fix state tracking in AbstractFlowPass.VisitBinaryConditionalExpression - #84705

Merged
AlekseyTs merged 1 commit into
dotnet:mainfrom
AlekseyTs:Issue_84517
Jul 31, 2026
Merged

VB: Fix state tracking in AbstractFlowPass.VisitBinaryConditionalExpression#84705
AlekseyTs merged 1 commit into
dotnet:mainfrom
AlekseyTs:Issue_84517

Conversation

@AlekseyTs

@AlekseyTs AlekseyTs commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #84517

Microsoft Reviewers: Open in CodeFlow

Copilot AI review requested due to automatic review settings July 30, 2026 12:16
@AlekseyTs
AlekseyTs requested a review from a team as a code owner July 30, 2026 12:16
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Visual Basic flow analysis so the state after a binary conditional If(testExpr, elseExpr) correctly accounts for the possible execution of elseExpr (instead of discarding its effects), addressing a mis-tracking scenario that could lead to incorrect async state-machine spilling/corruption. It also adds a regression test that validates both runtime output and key IL shapes in Debug and Release builds.

Changes:

  • Update AbstractFlowPass.VisitBinaryConditionalExpression to merge (IntersectWith) the post-ElseExpression state with the pre-visit saved state.
  • Add a regression test covering If(GetNothingObj(), Await GetObjAsync()) and verifying output + IL in both Debug and Release configurations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Compilers/VisualBasic/Portable/Analysis/FlowAnalysis/AbstractFlowPass.vb Fixes flow-state merging for binary conditional expressions by intersecting the else-visited state with the saved pre-else state.
src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenAsyncTests.vb Adds a regression test ensuring locals aren’t corrupted across If(,) with Await in the second operand; verifies output and IL for Debug/Release.

@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler Please review

Dim savedState As LocalState = Me.State.Clone()
VisitRvalue(node.ElseExpression)
Me.SetState(savedState)
IntersectWith(Me.State, savedState)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the TestExpression is constant, should we continue to ignore side-effects of ElseExpression?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the TestExpression is constant, should we continue to ignore side-effects of ElseExpression?

Where do we do that "ignore side-effects of ElseExpression"?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, that was imprecise. I simply mean that we would be discarding state of the ElseExpression previously.

So for example something like

Dim a As Object = New Object()
Dim result = If("left", Await FallbackAsync())
Console.WriteLine(a Is Nothing)

would previously not need to hoist a local in Release mode. Now it presumably will.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it presumably will.

Perhaps that is inefficient, but correct. Optimizing handling of non-Nothing constants is outside of the scope for this PR. Given that the scenario is rather pathological, I doubt we would ever do this work without a good customer case.

@AlekseyTs
AlekseyTs requested review from a team and jjonescz July 31, 2026 14:11
@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@jjonescz, @dotnet/roslyn-compiler Please review

@AlekseyTs
AlekseyTs merged commit a75fe2f into dotnet:main Jul 31, 2026
26 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VB.NET Local variable is corrupted after binary If(,) operator with Await in second operand

3 participants