mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 08:46:02 +02:00
Bug 455828 - Proper handling of 'break' inside compound statement in a
case of a switch Change-Id: I73329a8769bc20a4fc4e017faad627e03adce9d9 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
parent
340b507e38
commit
3586267e6b
2 changed files with 45 additions and 22 deletions
|
@ -336,30 +336,32 @@ public class ControlFlowGraphBuilder {
|
||||||
return; // bad
|
return; // bad
|
||||||
IASTCompoundStatement comp = (IASTCompoundStatement) body;
|
IASTCompoundStatement comp = (IASTCompoundStatement) body;
|
||||||
IBasicBlock prev = switchNode;
|
IBasicBlock prev = switchNode;
|
||||||
for (IASTStatement statement : comp.getStatements()) {
|
IConnectorNode savedBreak = outerBreak;
|
||||||
if (statement instanceof IASTCaseStatement || statement instanceof IASTDefaultStatement) {
|
outerBreak = mergeNode;
|
||||||
IBranchNode lbl = null;
|
try {
|
||||||
if (statement instanceof IASTCaseStatement) {
|
for (IASTStatement statement : comp.getStatements()) {
|
||||||
lbl = factory.createBranchNode(statement);
|
if (statement instanceof IASTCaseStatement || statement instanceof IASTDefaultStatement) {
|
||||||
} else if (statement instanceof IASTDefaultStatement) {
|
IBranchNode lbl = null;
|
||||||
lbl = factory.createBranchNode(IBranchNode.DEFAULT);
|
if (statement instanceof IASTCaseStatement) {
|
||||||
|
lbl = factory.createBranchNode(statement);
|
||||||
|
} else if (statement instanceof IASTDefaultStatement) {
|
||||||
|
lbl = factory.createBranchNode(IBranchNode.DEFAULT);
|
||||||
|
}
|
||||||
|
if (!(prev instanceof IExitNode) && prev != switchNode) {
|
||||||
|
IConnectorNode here = factory.createConnectorNode();
|
||||||
|
addJump(prev, here);
|
||||||
|
addOutgoing(lbl, here);
|
||||||
|
prev = here;
|
||||||
|
} else {
|
||||||
|
prev = lbl;
|
||||||
|
}
|
||||||
|
addOutgoing(switchNode, lbl);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (!(prev instanceof IExitNode) && prev != switchNode) {
|
prev = createSubGraph(prev, statement);
|
||||||
IConnectorNode here = factory.createConnectorNode();
|
|
||||||
addJump(prev, here);
|
|
||||||
addOutgoing(lbl, here);
|
|
||||||
prev = here;
|
|
||||||
} else {
|
|
||||||
prev = lbl;
|
|
||||||
}
|
|
||||||
addOutgoing(switchNode, lbl);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (statement instanceof IASTBreakStatement) {
|
} finally {
|
||||||
prev = addJump(prev, mergeNode);
|
outerBreak = savedBreak;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
prev = createSubGraph(prev, statement);
|
|
||||||
}
|
}
|
||||||
addJump(prev, mergeNode);
|
addJump(prev, mergeNode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -617,4 +617,25 @@ public class ControlFlowGraphTest extends CodanFastCxxAstTestCase {
|
||||||
IBranchNode trueBranch = (IBranchNode) graph.getUnconnectedNodeIterator().next();
|
IBranchNode trueBranch = (IBranchNode) graph.getUnconnectedNodeIterator().next();
|
||||||
assertEquals("return 1;", data(trueBranch.getOutgoing()));
|
assertEquals("return 1;", data(trueBranch.getOutgoing()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// int main(int a) {
|
||||||
|
// switch (a) {
|
||||||
|
// case 1: {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case 2: {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
public void test_switch_break_in_compound_statement() {
|
||||||
|
// Test that the target node of the jump for the 'break' in a case
|
||||||
|
// is the connector node at the end of the switch, not the connector
|
||||||
|
// node for the next case.
|
||||||
|
buildAndCheck(getAboveComment());
|
||||||
|
IDecisionNode swittch = (IDecisionNode) graph.getStartNode().getOutgoing();
|
||||||
|
IPlainNode case1Branch = (IPlainNode) swittch.getOutgoingNodes()[0];
|
||||||
|
IJumpNode case1Jump = (IJumpNode) case1Branch.getOutgoing();
|
||||||
|
assertEquals(swittch.getMergeNode(), case1Jump.getJumpNode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue