Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

review: fix(control-flow): Handle synchronized statement in CFG #5740

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -798,7 +798,11 @@ public <T, S> void visitCtSwitchExpression(CtSwitchExpression<T, S> switchExpres

@Override
public void visitCtSynchronized(CtSynchronized synchro) {
ControlFlowNode expressionNode = new ControlFlowNode(synchro.getExpression(), result, BranchKind.STATEMENT);
I-Al-Istannen marked this conversation as resolved.
Show resolved Hide resolved
tryAddEdge(lastNode, expressionNode);
lastNode = expressionNode;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to preserve the synchronized statement itself in the graph? I.e. call defaultAction(synchro, BranchKind.STATEMENT) or w/e somewhere? Currently it looks like the synchronized is unrolled and no trace of it is left?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally yes, but in the current CFG model this is not possible in any way I like. This is one of the things I would like to improve with the redesign started in #5742


synchro.getBlock().accept(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ public void testInvocation() throws Exception {
testEdges(graph, 1, 0, 0, null);
}

@Test
public void testSynchronized() throws Exception {
testMethod("synchronization", true, 0, 2, 8);
}

@Test
public void testtestCase() throws Exception {
//branchCount, stmntCount, totalCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,12 @@ public int simple(int a) {
return 10 * a;
}

public void synchronization() {
synchronized (new Object()) {
int a = 0;
}
}

///////////////////////////////////////////////////////////////////////////////////////////


Expand Down
Loading