diff options
Diffstat (limited to 'codan/org.eclipse.cdt.codan.core.test')
2 files changed, 66 insertions, 2 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 dd6c6d20592..d483f52b425 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 @@ -294,8 +294,8 @@ public class ControlFlowGraphTest extends CodanFastCxxAstTestCase { assertEquals(1, graph.getUnconnectedNodeSize()); } - // foo() { - // int a=10, x=5; + // foo(int x) { + // int a=10; // if (a--) { // if (x<0) // a++; @@ -408,4 +408,46 @@ public class ControlFlowGraphTest extends CodanFastCxxAstTestCase { IStartNode startNode = graph.getStartNode(); assertEquals(1, graph.getUnconnectedNodeSize()); } + + // foo() { + // int a=10,x=5; + // if (x<0) + // a++; + // } + public void test_deadbranch() { + buildCfg(getAboveComment(), false); + checkCfg(false); + IStartNode startNode = graph.getStartNode(); + IPlainNode decl = (IPlainNode) startNode.getOutgoing(); + IDecisionNode des = (IDecisionNode) decl.getOutgoing(); + assertEquals("x<0", data(des)); + IBasicBlock bElse = branchEnd(des, IBranchNode.ELSE); + IBasicBlock m2 = jumpEnd(branchEnd(des, IBranchNode.THEN)); + IBasicBlock m1 = jumpEnd(bElse); + + assertNull(m2); + assertNotNull(m1); + } + +// int test1_f() +// { +// while (1) +// { +// } +// } + public void test_infiniloop() { + buildCfg(getAboveComment(), false); + checkCfg(false); + IStartNode startNode = graph.getStartNode(); + IConnectorNode conn = (IConnectorNode) startNode.getOutgoing(); + IDecisionNode des = (IDecisionNode) conn.getOutgoing(); + assertEquals("1", data(des)); + IBasicBlock bElse = branchEnd(des, IBranchNode.ELSE); + IBasicBlock bThen = branchEnd(des, IBranchNode.THEN); + IBasicBlock m2 = jumpEnd(bThen); + IBasicBlock m1 = jumpEnd(bElse); + + assertNotNull(m2); + assertNull(m1); + } } diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java index d56ff169f05..e1e1f1775c1 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java @@ -384,4 +384,26 @@ public class ReturnCheckerTest extends CheckerTestCase { checkNoErrors(); } +// int test1() { +// do { +// return 1; +// } while (0); +// } + public void testNoRetInfinitLoop() throws Exception { + // Bug 394521 + loadCodeAndRunCpp(getAboveComment()); + checkNoErrors(); + } + +// int test1_f() // WARNING HERE: "No return, in function returning non-void" +// { +// while (1) +// { +// } +// } + public void testNoRetInfinitLoop2() throws Exception { + // Bug 394521 + loadCodeAndRunCpp(getAboveComment()); + checkNoErrors(); + } }
\ No newline at end of file |