Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlena Laskavaia2014-06-18 22:12:15 -0400
committerElena Laskavaia2014-06-21 10:57:37 -0400
commitdb43e03878e285348d08ddab9ae034edf669da70 (patch)
treecd5e591f6ca637a28465dac71af40374b9a40c02 /codan/org.eclipse.cdt.codan.core.test
parent3d78256606069c4a7ab7176ffbdb59ab9d54f296 (diff)
downloadorg.eclipse.cdt-db43e03878e285348d08ddab9ae034edf669da70.tar.gz
org.eclipse.cdt-db43e03878e285348d08ddab9ae034edf669da70.tar.xz
org.eclipse.cdt-db43e03878e285348d08ddab9ae034edf669da70.zip
Bug 394521 Do Constant folding propagation when building CFG
When building control flow graph we can consider constants and not add some branches in decisions nodes, that make CFG more accurate and elimate some false positives Change-Id: I19c623e1e6d2dc7416a0e796a98168df7a976111 Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com> Reviewed-on: https://git.eclipse.org/r/28726
Diffstat (limited to 'codan/org.eclipse.cdt.codan.core.test')
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cfg/ControlFlowGraphTest.java46
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java22
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 dd6c6d2059..d483f52b42 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 d56ff169f0..e1e1f1775c 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

Back to the top