Skip to content

Commit

Permalink
Migration: fix a corner case of post-dominator analysis.
Browse files Browse the repository at this point in the history
When the variable on the LHS of an assignment expression also appears
in its RHS, we want the RHS to contribute to generation of hard edges,
because the RHS is evaluated prior to the assignment.  To achieve this
we need to remove the LHS variable from post-dominator scopes after
visiting the RHS.

Change-Id: Ifef9d69356e78e43f77ef456101b335ba3238312
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/116059
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
stereotype441 authored and commit-bot@chromium.org committed Sep 8, 2019
1 parent 23d2893 commit daaa665
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/nnbd_migration/lib/src/edge_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
// TODO(paulberry)
_unimplemented(node, 'Assignment with operator ${node.operator.lexeme}');
}
_postDominatedLocals.removeReferenceFromAllScopes(node.leftHandSide);
var expressionType = _handleAssignment(node.rightHandSide,
destinationExpression: node.leftHandSide);
var conditionalNode = _conditionalNodes[node.leftHandSide];
Expand Down Expand Up @@ -1513,6 +1512,9 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
source: sourceType,
destination: destinationType,
hard: _postDominatedLocals.isReferenceInScope(expression));
if (destinationExpression != null) {
_postDominatedLocals.removeReferenceFromAllScopes(destinationExpression);
}
if (destinationLocalVariable != null) {
_flowAnalysis.write(destinationLocalVariable);
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/nnbd_migration/test/edge_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3066,6 +3066,18 @@ void test(bool b1, bool b2, bool b3, bool _b) {
assertEdge(decoratedTypeAnnotation('bool b3').node, never, hard: true);
}

test_postDominators_assignment_with_same_var_on_lhs_and_in_rhs() async {
await analyze('''
void f(int i) {
i = g(i);
}
int g(int j) => 0;
''');
assertEdge(decoratedTypeAnnotation('int i').node,
decoratedTypeAnnotation('int j').node,
hard: true);
}

test_postDominators_break() async {
await analyze('''
class C {
Expand Down

0 comments on commit daaa665

Please sign in to comment.