From 43097ce04e05b0b8183d938b2d078211cfb535db Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Tue, 17 Feb 2015 02:18:31 -0500 Subject: Bug 455828 - Proper handling of 'switch' without explicit default (including empty switch) Change-Id: I3e20400f86c5e4273d8b0c62ed9ac3f429a84879 Signed-off-by: Nathan Ridge --- .../cdt/codan/core/cfg/ControlFlowGraphTest.java | 23 ++++++++++++++++++ .../core/internal/checkers/ReturnCheckerTest.java | 27 ++++++++++++++++++---- 2 files changed, 46 insertions(+), 4 deletions(-) (limited to 'codan/org.eclipse.cdt.codan.core.test') 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 74c9ae466cb..baf1b3763b7 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 @@ -638,4 +638,27 @@ public class ControlFlowGraphTest extends CodanFastCxxAstTestCase { IJumpNode case1Jump = (IJumpNode) case1Branch.getOutgoing(); assertEquals(swittch.getMergeNode(), case1Jump.getJumpNode()); } + + // int main(int a) { + // switch (a) { + // } + // } + public void test_empty_switch() { + buildAndCheck(getAboveComment()); + // Decision node should be optimized away entirely + assertFalse(graph.getStartNode() instanceof IDecisionNode); + } + + // int main(int a) { + // switch (a) { + // case 1: { + // break; + // } + // } + // } + public void test_switch_no_explicit_default() { + buildAndCheck(getAboveComment()); + IDecisionNode swittch = (IDecisionNode) graph.getStartNode().getOutgoing(); + assertTrue(swittch.getOutgoingSize() == 2); + } } 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 a5b01093749..f1349c634b5 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 @@ -241,10 +241,20 @@ public class ReturnCheckerTest extends CheckerTestCase { // { // switch (g()) { // case 1: return 1; -// case 2: -// return 0; +// case 2: return 0; // } - public void testBranchesSwitch_Bug343767() { + public void testBranchesSwitch_Bug343767a() { + loadCodeAndRunCpp(getAboveComment()); + checkErrorLine(1); + } +// int f() +// { +// switch (g()) { +// case 1: return 1; +// case 2: return 0; +// default: return -1; +// } + public void testBranchesSwitch_Bug343767b() { loadCodeAndRunCpp(getAboveComment()); checkNoErrors(); } @@ -429,4 +439,13 @@ public class ReturnCheckerTest extends CheckerTestCase { // Just check that codan runs without any exceptions being thrown. loadCodeAndRunCpp(getAboveComment()); } -} \ No newline at end of file + + // int foo(int x) { // no warning + // switch (x) { + // } + // } + public void testEmptySwitch_455828() throws Exception { + loadCodeAndRunCpp(getAboveComment()); + checkErrorLine(1); + } +} -- cgit v1.2.3