diff options
author | Alena Laskavaia | 2011-02-09 03:19:10 +0000 |
---|---|---|
committer | Alena Laskavaia | 2011-02-09 03:19:10 +0000 |
commit | 53ecdbbc27530891d0dc590fc5d36cf2295d8d2a (patch) | |
tree | 322c3ebc54bfcb1630173108ceeaa915127ae617 /codan/org.eclipse.cdt.codan.core.test/src | |
parent | aadbf2a4774c66a27f5d0d3ff2869e6d98988107 (diff) | |
download | org.eclipse.cdt-53ecdbbc27530891d0dc590fc5d36cf2295d8d2a.tar.gz org.eclipse.cdt-53ecdbbc27530891d0dc590fc5d36cf2295d8d2a.tar.xz org.eclipse.cdt-53ecdbbc27530891d0dc590fc5d36cf2295d8d2a.zip |
Bug 335909 - adjusted cfg generation for switch and dead code
Diffstat (limited to 'codan/org.eclipse.cdt.codan.core.test/src')
-rw-r--r-- | codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cfg/ControlFlowGraphTest.java | 66 |
1 files changed, 59 insertions, 7 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cfg/ControlFlowGraphTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cfg/ControlFlowGraphTest.java index f2c91afd61d..231292c9d6e 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cfg/ControlFlowGraphTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cfg/ControlFlowGraphTest.java @@ -61,38 +61,58 @@ public class ControlFlowGraphTest extends CodanFastCxxAstTestCase { ast.accept(visitor); } + private void checkCfg() { + checkCfg(true); + } + /** * */ - private void checkCfg() { + private void checkCfg(boolean decision) { assertNotNull(graph); assertNotNull(graph.getStartNode()); Collection<IBasicBlock> nodes = graph.getNodes(); for (Iterator<IBasicBlock> iterator = nodes.iterator(); iterator .hasNext();) { IBasicBlock node = iterator.next(); - checkNode(node); + checkNode(node, decision); } } /** * @param node */ - private void checkNode(IBasicBlock node) { + private void checkNode(IBasicBlock node, boolean decision) { IBasicBlock[] incomingNodes = node.getIncomingNodes(); - for (int i = 0; i < incomingNodes.length; i++) { + nodes: for (int i = 0; i < incomingNodes.length; i++) { IBasicBlock b = incomingNodes[i]; - if (!contains(node, b.getOutgoingNodes())) + if (b == null) { + // check if dead node + Iterator<IBasicBlock> iterator = graph + .getUnconnectedNodeIterator(); + boolean dead = false; + for (; iterator.hasNext();) { + IBasicBlock d = iterator.next(); + if (node == d) { + dead = true; + break; + } + } + if (!dead) + fail("Block " + node + " prev is null"); + } else if (!contains(node, b.getOutgoingNodes())) fail("Block " + node + " inconsitent prev/next " + b); } IBasicBlock[] outgoingNodes = node.getOutgoingNodes(); for (int i = 0; i < outgoingNodes.length; i++) { IBasicBlock b = outgoingNodes[i]; + if (b == null) + fail("Block " + node + " next is null"); if (!contains(node, b.getIncomingNodes())) fail("Block " + node + " inconsitent next/prev " + b); } - if (node instanceof IDecisionNode) { - assertTrue("decision node outgping size", + if (node instanceof IDecisionNode && decision) { + assertTrue("decision node outgoing size " + node.getOutgoingSize(), node.getOutgoingSize() > 1); assertNotNull(((IDecisionNode) node).getMergeNode()); } @@ -360,4 +380,36 @@ public class ControlFlowGraphTest extends CodanFastCxxAstTestCase { IBasicBlock m1 = jumpEnd(bElse); assertSame(m1, m2); } + + // foo() { + // switch (0) { + // case 1: ; + // } + // } + public void test_switch1() { + buildCfg(getAboveComment(), false); + checkCfg(false); + } + + // foo() { + // switch (0) { + // case 1: break; + // } + // } + public void test_switchbreak() { + buildCfg(getAboveComment(), false); + checkCfg(false); + } + + // foo() { + // switch (0) { + // a++; + // } + // } + public void test_switchdead() { + buildCfg(getAboveComment(), false); + checkCfg(false); + IStartNode startNode = graph.getStartNode(); + assertEquals(1, graph.getUnconnectedNodeSize()); + } } |